FairRoot/PandaRoot
PndLmdPixelClusterTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndLmdPixelClusterTasksource file -----
3 // -------------------------------------------------------------------------
4 
7 #include "PndLmdContFact.h"
9 #include "PndSdsClusterPixel.h"
10 #include "PndSdsPixelDigiPar.h"
11 
12 // FAIR
13 #include "FairBaseParSet.h"
14 #include "FairRootManager.h"
15 #include "FairRunAna.h"
16 #include "FairRuntimeDb.h"
17 
18 #include "TLorentzVector.h"
19 
20 // ----- Default constructor -------------------------------------------
22  : PndSdsPixelClusterTask("LMD Clustertisation Task") {
23  SetPersistency(kTRUE);
24  // flagMS = true;
25 }
26 // -------------------------------------------------------------------------
27 
28 // ----- Destructor ----------------------------------------------------
30  if (fBackMapping != 0)
31  delete fBackMapping;
32  if (fClusterFinder != 0)
33  delete fClusterFinder;
34  if (fFunctor != 0)
35  delete fFunctor;
36 
37  if (fStartFunctor != 0)
38  delete fStartFunctor;
39  if (fGeoH != 0)
40  delete fGeoH;
41 }
42 // -------------------------------------------------------------------------
43 
46 
49 
50  FairRootManager* ioman = FairRootManager::Instance();
51 
52  if (!ioman) {
53  std::cout << "-E- PndSdsPixelClusterTask::Init: " << "RootManager not instantiated!"
54  << std::endl;
55  return kFATAL;
56  }
57 
58  // Get input array
59  fDigiArray = (TClonesArray*) ioman->GetObject(fInBranchName);
60  //
61  if (!fDigiArray) {
62  std::cout << "-E- PndSdsPixelClusterTask::Init: " << "No SDSDigi array!" << std::endl;
63  return kERROR;
64  }
65 
66  fClusterArray = ioman->Register(fClustBranchName, "PndSdsClusterPixel",
68 
69  fHitArray =
70  ioman->Register(fOutBranchName, "PndSdsHit", fFolderName, GetPersistency());
71 
72  SetInBranchId();
73 
74  fFunctor = new TimeGap();
75  fStartFunctor = new StopTime();
76 
77  if (fVerbose > 1)
78  fDigiPar->Print();
79 
81 
82  std::cout << "-I- PndSdsPixelClusterTask: Initialisation successfull" << std::endl;
83  return kSUCCESS;
84 }
85 // -------------------------------------------------------------------------
86 
87 // ----- Initialization of Parameter Containers -------------------------
89  std::cout << "PndLmdPixelClusterTask::SetParContainers() " << std::endl;
90  // Get Base Container
91  ana = FairRun::Instance();
92  rtdb = ana->GetRuntimeDb();
93  fDigiPar = (PndSdsPixelDigiPar*) (rtdb->getContainer("LMDPixelDigiPar"));
94  // rtdb->getContainer("LMDPixelTotDigiPar");
95 
96  PndLmdContFact* themvdcontfact = (PndLmdContFact*) rtdb->getContFactory("PndLmdContFact");
97  // read params for lumi alignment
98  TList* theAlignLMDContNames = themvdcontfact->GetAlignParNames();
99  Info("SetParContainers()", "AlignLMD The container names list contains %i entries",
100  theAlignLMDContNames->GetEntries());
101  TIter cfAlIter(theAlignLMDContNames);
102  while (TObjString* contname = (TObjString*) cfAlIter()) {
103  TString parsetname = contname->String();
104  Info("SetParContainers()", "%s", parsetname.Data());
105  }
106  // //
108 }
109 
111  // at Init() stage we already have fGeoH filled with the parameters
113 }
114 
116  std::cout << "PndLmdPixelClusterTask::SetClusterFinder() " << std::endl;
118 }
119 
120 // ----- Manula I/O folders/branches
121 // ----------------------------------------------------
122 void PndLmdPixelClusterTask::SetBranchNames(TString inBranchname, TString outHitBranchname,
123  TString outClustBranchname, TString folderName) {
124  fInBranchName = inBranchname;
125  fOutBranchName = outHitBranchname;
126  fClustBranchName = outClustBranchname;
127  fFolderName = folderName;
128 }
129 
130 // ----- Default I/O folder/branches
131 // ----------------------------------------------------
133  if (FairRunAna::Instance()->IsTimeStamp())
134  fInBranchName = "LMDSortedPixelDigis";
135  else
136  fInBranchName = "LMDPixelDigis";
137  fOutBranchName = "LMDHitsPixel";
138  fClustBranchName = "LMDPixelClusterCand";
139  fFolderName = "pndsim";
140 }
141 
142 // ----- Public method Exec --------------------------------------------
144  // std::cout<<" fEventNr = "<< fEventNr<<std::endl;
145  // Reset output array
146  fClusterArray = FairRootManager::Instance()->GetTClonesArray(fClustBranchName);
147  if (!fClusterArray)
148  Fatal("Exec", "No ClusterArray");
149  fClusterArray->Delete();
150 
151  fHitArray = FairRootManager::Instance()->GetTClonesArray(fOutBranchName);
152  if (!fHitArray)
153  Fatal("Exec", "No HitArray");
154  fHitArray->Delete();
155 
156  std::vector<PndSdsDigiPixel> DigiPixelArray;
157  DigiPixelArray.clear();
158 
159  Double_t EventTime = FairRootManager::Instance()->GetEventTime();
160 
161  if (fVerbose > 0)
162  std::cout << "-I- PndSdsPixelClusterTask::Exec EventTime: " << EventTime << std::endl;
163 
164  // Get input array
165  if (FairRunAna::Instance()->IsTimeStamp()) {
166  fDigiArray->Clear();
167  fDigiArray = FairRootManager::Instance()->GetData(fInBranchName, fStartFunctor, EventTime + 10);
168  } else
169  fDigiArray = (TClonesArray*) FairRootManager::Instance()->GetObject(fInBranchName);
170 
171  Int_t nPoints = fDigiArray->GetEntriesFast();
172 
173  // convert from TClonesArray to a std::vector
174  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
175  PndSdsDigiPixel myDigi = *(PndSdsDigiPixel*) (fDigiArray->At(iPoint));
176  DigiPixelArray.push_back(myDigi);
177  myDigi.Clear();
178  }
179  // Retrieve the calculated clusters with the chosen clusterfinder
180  std::vector<std::vector<Int_t> > clusters = fClusterFinder->GetClusters(DigiPixelArray);
181  if (fVerbose > 1)
182  std::cout << " -I- PndSdsPixelClusterTask::Exec(): We have " << clusters.size()
183  << " pixel clusters" << std::endl;
184  // store the list
185  for (UInt_t i = 0; i < clusters.size(); i++) {
186  PndSdsClusterPixel* tempCluster = new ((*fClusterArray)[i]) PndSdsClusterPixel(fInBranchId,
187  clusters[i]);
188  if (FairRunAna::Instance()->IsTimeStamp()) {
189  tempCluster->ResetLinks();
190  for (UInt_t j = 0; j < clusters[i].size(); j++) {
191  PndSdsDigiPixel* tempDigi = (PndSdsDigiPixel*) fDigiArray->At(clusters[i][j]);
192  tempCluster->AddLink(FairLink(tempDigi->GetEntryNr()));
193  tempDigi->Clear();
194  }
195  }
196  }
197 
198  // do the backmapping with charge-weight
199  for (UInt_t i = 0; i < clusters.size(); i++) {
200  // if(fVerbose>2) std::cout << clusters[i].size() << " " << std::endl;
201  std::vector<PndSdsDigiPixel> clusterArray;
202  for (UInt_t j = 0; j < clusters[i].size(); j++) { // convert
203  clusterArray.push_back(DigiPixelArray[clusters[i][j]]);
204  }
205 
206  // mapping with the choosen back mapping
207  // Int_t iHits = fHitArray->GetEntriesFast(); //[R.K. 01/2017] unused
208  // variable
209  // PndSdsHit *myHit = new((*fHitArray)[iHits])
210  // PndSdsHit(fBackMapping->GetCluster(clusterArray));
211  PndSdsHit myHit = fBackMapping->GetCluster(clusterArray);
212  clusterArray.clear();
214  TVector3 hitPos = myHit.GetPosition();
215  TMatrixD hitCov = myHit.GetCov();
216  // hitCov(0,0) = 5.29e-06; //assuming hit resolution for x-y 23 mkm
217  // hitCov(1,1) = 5.29e-06; //assuming hit resolution for x-y 23 mkm
218  hitCov(0, 0) = 2.25e-06; // assuming hit resolution for x-y 15 mkm
219  hitCov(1, 1) = 2.25e-06; // assuming hit resolution for x-y 15 mkm
220  hitCov(2, 2) = 4.28489999999999954e-08; // assuming hit resolution for z
221  // 2.07 mkm NB: isn't used in Trk
222  // rec.
223 
224  // //Add multiple scattering error ---------------
225  // if(flagMS){
226  // // TVector3 hitPos = myHit.GetPosition();
227  // TVector3
228  // hitErr(sqrt(hitCov[0][0]),sqrt(hitCov[1][1]),sqrt(hitCov[2][2]));
229  // TVector3 hitErrMSadd = AddMSErr(hitPos, hitErr);
230  // hitCov[0][0] = TMath::Power(hitErrMSadd.X(),2);
231  // hitCov[1][1] = TMath::Power(hitErrMSadd.Y(),2);
232  // hitCov[2][2] = TMath::Power(hitErrMSadd.Z(),2);
233  // }
234  // cout<<"!!!!!!!!!"<<endl;
235  // hitCov.Print();
236  // cout<<"!!!!!!!!!"<<endl;
237  myHit.SetCov(hitCov); // save value
238  myHit.SetDx(sqrt(hitCov[0][0]));
239  myHit.SetDy(sqrt(hitCov[1][1]));
240  myHit.SetDz(sqrt(hitCov[2][2]));
241 
242  if (fVerbose > 0) {
243  std::cout << " -I- PndSdsPixelClusterTask::Exec(): Calculated Hit(LUMI "
244  "frame): " << std::endl;
245  myHit.Print();
246 #if (ROOT_VERSION_CODE >= ROOT_VERSION(5, 34, 10))
247  ((FairMultiLinkedData_Interface) (myHit)).Print();
248 #else
249  ((FairMultiLinkedData)(myHit)).Print();
250 #endif
251  }
252  TClonesArray& clref = *fHitArray;
253  Int_t size = clref.GetEntriesFast();
254  new (clref[size]) PndSdsHit(myHit); // PndSdsHit *freshHit = //[R.K.03/2017] unused variable
255  // myHit.Delete();
256  // myHit.Clear();
257  // std::cout<<"fHitArray.size() = "<<sizeof(*fHitArray)<<std::endl;
258  }
259  clusters.clear();
260  DigiPixelArray.clear();
261  if (fVerbose > 1)
262  std::cout << std::endl;
263 
264  if (fVerbose > 1) {
265  std::cout << "-I- PndLmdPixelClusterTask: " << fClusterArray->GetEntriesFast()
266  << " Sds Clusters and " << fHitArray->GetEntriesFast() << " Hits calculated."
267  << std::endl;
268  }
269  fEventNr++;
270  fHitArray->Sort();
271 
272  // fDigiArray->Delete();
273 
274  // std::cout<<"lmddim.size() = "<<sizeof(*lmddim)<<std::endl;
275 
276  // std::cout<<"DigiPixelArray.size() = "<<DigiPixelArray.size()<< std::endl;
277  // FinishEvent();
278  // std::cout<<"size() = "<<sizeof(*this)<<std::endl;
279  return;
280 }
281 
283  if (fDigiArray != NULL)
284  fDigiArray->Delete();
285  if (fHitArray != NULL)
286  fHitArray->Delete();
287  if (fClusterArray != NULL)
288  fClusterArray->Delete();
289  FinishEvents();
290  // std::cout << "-I- PndLmdPixelClusterTask: FinishEvent()" << std::endl;
291 }
292 
MechFsc Print()
PndSdsChargedWeightedPixelMapping: Gets a vector of DigiHits and calculates the cluster center weight...
int fVerbose
Definition: poormantracks.C:24
virtual void Print(const Option_t *opt=0) const
Definition: PndSdsHit.cxx:66
Int_t fInBranchId
Definition: PndSdsTask.h:43
TList * GetAlignParNames()
PndSdsPixelBackMapping * fBackMapping
TString fOutBranchName
Definition: PndSdsTask.h:40
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
void SetClusterIndex(Int_t datasource, Int_t id, Int_t fileId=-1, Int_t evtId=-1)
Definition: PndSdsHit.h:82
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
void SetPersistency(Bool_t val=kTRUE)
TMatrixD GetCov() const
Definition: PndSdsHit.h:98
ClassImp(PndLmdPixelClusterTask)
Double_t
PndSdsPixelDigiPar * fDigiPar
TString fInBranchName
Definition: PndSdsTask.h:39
PndSdsPixelClusterFinder * fClusterFinder
TString fFolderName
Definition: PndSdsTask.h:41
void SetVerbose(Int_t v)
virtual void Print(std::ostream &out=std::cout) const
Data class to store the digi output of a pixel module.
void SetCov(TMatrixD cov)
Definition: PndSdsHit.cxx:70
virtual PndSdsHit GetCluster(std::vector< PndSdsDigiPixel > pixelArray)=0
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
virtual std::vector< std::vector< Int_t > > GetClusters(std::vector< PndSdsDigiPixel > hits)=0
Digitization Parameter Class for SDS-Pixel part.