FairRoot/PandaRoot
PndEmcPhiBumpSplitter.cxx
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // File and Version Information:
3 // $Id:$
4 //
5 // Description:
6 // Class PndEmcPhiBumpSplitter
7 // Implementation of PhiBumpSplitter which splits clusters based on
8 // local maxima in the Phi Direction for use with Bremstrahlung correction
9 //
10 // Environment:
11 // Software developed for the BaBar Detector at the SLAC B-Factory.
12 //
13 // Adapted for the PANDA experiment at GSI
14 //
15 // Author List:
16 // Phil Strother
17 //
18 // Copyright Information:
19 // Copyright (C) 1997 Imperial College
20 //
21 // Modified:
22 // Binsong Ma, Ermias Atomssa
23 //------------------------------------------------------------------------
24 
25 // Path of file:
26 // ----- $pandaroot/emc/EmcReco
27 
28 //-----------------------
29 // This Class's Header --
30 //-----------------------
31 #include "PndEmcPhiBumpSplitter.h"
32 
33 //---------------
34 // C++ Headers --
35 //---------------
36 //#include <vector>
37 //#include <set>
38 //#include <map>
39 #include <iostream>
40 
41 //-------------------------------
42 // Collaborating Class Headers --
43 //-------------------------------
44 
45 #include "FairRootManager.h"
46 #include "FairRunAna.h"
47 #include "FairRuntimeDb.h"
48 #include "TClonesArray.h"
49 
51 #include "PndEmcXClMoments.h"
52 
53 #include "PndEmcRecoPar.h"
54 #include "PndEmcGeoPar.h"
55 #include "PndEmcDigiPar.h"
56 #include "PndEmcStructure.h"
57 #include "PndEmcMapper.h"
58 
59 #include "PndDetectorList.h"
60 #include "PndEmcTwoCoordIndex.h"
61 #include "PndEmcBump.h"
62 #include "PndEmcCluster.h"
63 #include "PndEmcDigi.h"
64 #include "PndEmcSharedDigi.h"
65 #include "PndEmcXtal.h"
66 #include "PndEmcDataTypes.h"
67 
68 
69 using std::endl;
70 
71 //----------------
72 // Constructors --
73 //----------------
74 
76  fDigiArray(0), fClusterArray(0), fPhiBumpArray(0), fGeoPar(new PndEmcGeoPar()), fDigiPar(new PndEmcDigiPar()), fRecoPar(new PndEmcRecoPar()), fClusterPosParam()
77 
78 {
79  fClusterPosParam.clear();
80  SetPersistency(kTRUE);
81 }
82 
83 //--------------
84 // Destructor --
85 //--------------
86 
88 {
89 }
90 
98 {
99  // Get RootManager
100  FairRootManager* ioman = FairRootManager::Instance();
101  if ( ! ioman ){
102  cout << "-E- PndEmcPhiBumpSplitter::Init: "
103  << "RootManager not instantiated!" << endl;
104  return kFATAL;
105  }
106 
107  // Geometry loading
110 
111  // Get input array
112  fDigiArray = dynamic_cast<TClonesArray *> (ioman->GetObject("EmcDigi"));
113  if ( ! fDigiArray ) {
114  cout << "-W- PndEmcPhiBumpSplitter::Init: "
115  << "No PndEmcDigi array!" << endl;
116  return kERROR;
117  }
118 
119  fClusterArray = dynamic_cast<TClonesArray *> (ioman->GetObject("EmcCluster"));
120  if ( ! fClusterArray ) {
121  cout << "-W- PndEmcPhiBumpSplitter::Init: "
122  << "No PndEmcCluster array!" << endl;
123  return kERROR;
124  }
125 
126  // Set minimum SharedDigi energy to 20keV.
127  if (!strcmp(fRecoPar->GetEmcClusterPosMethod(),"lilo")) {
128  cout<<"Lilo cluster position method"<<endl;
132  }
133 
134  // Create and register output array
135  fPhiBumpArray = new TClonesArray("PndEmcBump");
136  ioman->Register("EmcPhiBump","Emc",fPhiBumpArray,GetPersistency());
137 
138  cout << "-I- PndEmcPhiBumpSplitter: Intialization successfull" << endl;
139 
140  return kSUCCESS;
141 }
142 
150 {
151  PndEmcMapper::Instance(); //PndEmcMapper *fEmcMap= //[R.K.03/2017] unused variable
152 
153  // Reset output array
154  if ( ! fPhiBumpArray ) Fatal("Exec", "No Phi-Bump Array");
155  fPhiBumpArray->Delete();
156 
157  // loop on each cluster. For each cluster there can be any number of phi_bumps (atleast one)
158  int nClusters = fClusterArray->GetEntriesFast();
159  for (Int_t iCluster = 0; iCluster < nClusters; iCluster++){
160 
161  PndEmcCluster* theCluster = (PndEmcCluster*) fClusterArray->At(iCluster);
162 
163  const Int_t TotNumOfHitPhi = 160;
164 
165  std::vector<double> phi_bump(TotNumOfHitPhi,0);
166 
167  Int_t digiSize = theCluster->DigiList().size();
168  std::vector<Int_t> digiList = theCluster->DigiList();
169  for (Int_t i_digi = 0; i_digi<digiSize; ++i_digi)
170  {
171  PndEmcDigi *emcDigi = (PndEmcDigi *) fDigiArray->At(digiList[i_digi]);
172  Double_t emcDigiPhi = emcDigi->GetPhi()*TMath::RadToDeg();
173  Double_t emcDigiEnergy = emcDigi->GetEnergy();
174  if ( fabs(emcDigiPhi)<=180 ) {
175  Int_t iEmcDigiPhi = int( (emcDigiPhi + 180.) * TotNumOfHitPhi / 360. );
176  phi_bump.at(iEmcDigiPhi) += emcDigiEnergy;
177  }
178  }
179 
180  std::vector<double> vPhiList;
181  std::vector<double> vDepoEnergyList;
182  std::vector<int> vGapSizeList;
183 
184  int i_phi_prev = 0;
185  for (Int_t i_phi=0; i_phi < TotNumOfHitPhi; ++i_phi) {
186  Double_t BinValue = phi_bump.at(i_phi);
187  if (BinValue != 0)
188  {
189  vPhiList.push_back(-180. + ((0.5+i_phi)*360./TotNumOfHitPhi));
190  vDepoEnergyList.push_back(BinValue);
191  vGapSizeList.push_back(i_phi - i_phi_prev );
192  i_phi_prev = i_phi;
193  }
194  }
195 
196  // Find start bin number for the phi projection of cluster.
197  Int_t StartIndex = 0;
198  for (size_t i = 0;i < vGapSizeList.size();i++)
199  {
200  if (vGapSizeList.at(i) > vGapSizeList.at(StartIndex)) StartIndex = i;
201  }
202 
203  // Rotate to the begining of the cluster in case cluster folds over to index=0
204  std::rotate(vDepoEnergyList.begin(),vDepoEnergyList.begin()+StartIndex,vDepoEnergyList.end());
205  vDepoEnergyList.push_back(0);
206  vDepoEnergyList.push_back(0);
207  std::rotate(vDepoEnergyList.begin(),vDepoEnergyList.begin()+(vDepoEnergyList.size()-1),vDepoEnergyList.end());
208  // Do the same for the phi positions
209  std::rotate(vPhiList.begin(),vPhiList.begin()+StartIndex,vPhiList.end());
210  vPhiList.push_back(0);
211  vPhiList.push_back(0);
212  std::rotate(vPhiList.begin(),vPhiList.begin()+(vPhiList.size()-1),vPhiList.end());
213 
214  // Loop through deposited energy vector and identify "valley" type bins => -_- and calculate wieghts to split energy
215  std::vector<int> ValleyType;
216  std::vector<double> Weight;
217  double _Weight = 0;
218  Weight.push_back(0);
219  ValleyType.push_back(0);
220  for (size_t n_sel = 1; n_sel < vDepoEnergyList.size()-1; n_sel++)
221  {
222  if(vDepoEnergyList.at(n_sel-1) > vDepoEnergyList.at(n_sel) &&
223  vDepoEnergyList.at(n_sel) < vDepoEnergyList.at(n_sel+1) ) {
224  ValleyType.push_back(1);
225  Weight.push_back(_Weight);
226  _Weight = 0;
227  } else {
228  _Weight += vDepoEnergyList.at(n_sel);
229  ValleyType.push_back(0);
230  }
231  }
232  Weight.push_back(_Weight);
233  Weight.push_back(0);
234 
235  std::vector<double> enePhiBump, phiPhiBump;
236  int ValleyIndex = 0;
237  int iWeight = 0;
238  for (size_t n_sel = 1; n_sel < vDepoEnergyList.size()-1; n_sel++)
239  {
240  if (ValleyType.at(n_sel) == 1 || n_sel == vDepoEnergyList.size()-2)
241  {
242  iWeight++;
243 
244  const double _eneRightEdge = vDepoEnergyList.at(ValleyIndex)*(Weight.at(iWeight)/(Weight.at(iWeight)+Weight.at(iWeight-1)));
245  double _enePhiBump = _eneRightEdge;
246  double _phiPhiBump = vPhiList.at(ValleyIndex)*_eneRightEdge;
247  for(size_t p = ValleyIndex+1;p < n_sel;p++) {
248  _enePhiBump += vDepoEnergyList.at(p);
249  _phiPhiBump += vPhiList.at(p)*vDepoEnergyList.at(p);
250  }
251  const double _eneLeftEdge = vDepoEnergyList.at(n_sel)*(Weight.at(iWeight)/(Weight.at(iWeight)+Weight.at(iWeight+1) ));
252  _enePhiBump += _eneLeftEdge;
253  _phiPhiBump += vPhiList.at(n_sel)*_eneLeftEdge;
254  _phiPhiBump /= _enePhiBump;
255  enePhiBump.push_back(_enePhiBump);
256  phiPhiBump.push_back(_phiPhiBump);
257  ValleyIndex = n_sel;
258  }
259  }
260 
261  TVector3 posClust = theCluster->position();
262  for (size_t i_phibump=0; i_phibump<enePhiBump.size(); ++i_phibump) {
263  PndEmcBump* theNewPhiBump = AddPhiBump();
264  theNewPhiBump->MadeFrom(iCluster);
265  theNewPhiBump->SetLink(FairLink("EmcCluster", iCluster));
266  theNewPhiBump->SetEnergy(enePhiBump.at(i_phibump));
267  theNewPhiBump->SetTimeStamp(theCluster->GetTimeStamp());
268  theNewPhiBump->SetTimeStampError(theCluster->GetTimeStampError());
269  TVector3 posPhiBump;
270  posPhiBump.SetMagThetaPhi(posClust.Mag(),posClust.Theta(),phiPhiBump.at(i_phibump)*TMath::DegToRad());
271  theNewPhiBump->SetPosition(posPhiBump);
272  }
273 
274  }
275 
276 }
277 
284 {
285  TClonesArray& clref = *fPhiBumpArray;
286  Int_t size = clref.GetEntriesFast();
287  return new(clref[size]) PndEmcBump();
288 }
289 
296 {
297  cout<<"================================================="<<endl;
298  cout<<"PndEmcPhiBumpSplitter::FinishTask"<<endl;
299  cout<<"================================================="<<endl;
300 }
301 
303 
304  // Get run and runtime database
305  FairRun* run = FairRun::Instance();
306  if ( ! run ) Fatal("SetParContainers", "No analysis run");
307 
308  FairRuntimeDb* db = run->GetRuntimeDb();
309  if ( ! db ) Fatal("SetParContainers", "No runtime database");
310  // Get Emc digitisation parameter container
311  fGeoPar = (PndEmcGeoPar*) db->getContainer("PndEmcGeoPar");
312  // Get Emc digitisation parameter container
313  fDigiPar = (PndEmcDigiPar*) db->getContainer("PndEmcDigiPar");
314  // Get Emc reconstruction parameter container
315  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
316 }
317 
void SetEnergy(Double_t en)
virtual void MadeFrom(Int_t clusterIndex)
Definition: PndEmcBump.cxx:76
splits clusters based on local maxima in the Phi direction for use with Bremstrahlung correction...
Int_t run
Definition: autocutx.C:47
virtual Double_t GetEnergy() const
Definition: PndEmcDigi.cxx:296
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
Int_t i
Definition: run_full.C:25
#define verbose
void SetPersistency(Bool_t val=kTRUE)
const std::vector< Int_t > & DigiList() const
Definition: PndEmcCluster.h:40
virtual void Exec(Option_t *opt)
Runs the task.
std::vector< Double_t > fClusterPosParam
Double_t GetOffsetParmB()
Definition: PndEmcRecoPar.h:22
Double_t GetOffsetParmC()
Definition: PndEmcRecoPar.h:23
Double_t p
Definition: anasim.C:58
void InitEmcMapper()
TVector3 position() const
virtual void FinishTask()
Called at end of task.
Double_t
parameter set of Emc digitisation
Definition: PndEmcDigiPar.h:12
Double_t GetOffsetParmA()
Definition: PndEmcRecoPar.h:21
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
TVector3 rotate(TVector3 vec, TGeoRotation *rotma)
Double_t GetPhi() const
Definition: PndEmcDigi.h:102
ClassImp(PndAnaContFact)
void SetPosition(TVector3 pos)
PndEmcPhiBumpSplitter(Int_t verbose=0)
Text_t * GetEmcClusterPosMethod()
Definition: PndEmcRecoPar.h:20
static PndEmcStructure * Instance()
static PndEmcMapper * Instance()
represents a reconstructed (splitted) emc cluster
Definition: PndEmcBump.h:34
virtual InitStatus Init()
Init Task.
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12
PndEmcBump * AddPhiBump()
Adds a new PndEmcBump to fPhiBumpArray and returns it.