FairRoot/PandaRoot
PndSdsPixelClusterTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndSdsPixelClusterTasksource file -----
3 // -------------------------------------------------------------------------
4 
5 
6 #include "TClonesArray.h"
7 #include "TArrayD.h"
8 #include "TGeoManager.h"
9 
10 #include "FairRootManager.h"
11 #include "FairRunAna.h"
12 #include "FairRuntimeDb.h"
13 #include "FairGeoNode.h"
14 #include "FairGeoVector.h"
15 #include "FairEventHeader.h"
16 
17 #include "PndStringSeparator.h"
18 
19 #include "PndSdsPixelClusterTask.h"
20 #include "PndSdsMCPoint.h"
21 #include "PndSdsCalcPixel.h"
22 //#include "PndSdsCalcFePixel.h"
23 #include "PndSdsDigiPixel.h"
24 // #include "PndSdsPixelCluster.h"
25 #include "PndSdsClusterPixel.h"
26 #include "PndGeoHandling.h"
27 
30 #include "PndSdsFESimple.h"
31 
32 #if (ROOT_VERSION_CODE >= ROOT_VERSION(5,34,10))
33  #include "FairMultiLinkedData_Interface.h"
34 #endif
35 
36 // ----- Default constructor -------------------------------------------
38 PndSdsTask("SDS Clustertisation Task"),
39  fUseNoiseSuppression(kTRUE),
40  fFEModel(NULL),
41  fDigiArray(NULL),
42  fDigiPar(NULL),
43  fChargeConverter(NULL),
44  fGeoH(NULL),
45  fClustBranchName(""),
46  fClusterArray(NULL),
47  fHitArray(NULL),
48  fEventHeader(0),
49  fFunctor(NULL),
50  fStartFunctor(NULL),
51  fClusterType(-1),
52  fEventNr(0),
53  fClusterFinder(NULL),
54  fBackMapping(NULL)
55 {
56  SetPersistency(kTRUE);
57 }
58 // -------------------------------------------------------------------------
59 
60 // ----- Named constructor ---------------------------------------------
62 PndSdsTask(name),
63  fUseNoiseSuppression(kTRUE),
64  fFEModel(NULL),
65  fDigiArray(NULL),
66  fDigiPar(NULL),
67  fChargeConverter(NULL),
68  fGeoH(NULL),
69  fClustBranchName(""),
70  fClusterArray(NULL),
71  fHitArray(NULL),
72  fEventHeader(0),
73  fFunctor(NULL),
74  fStartFunctor(NULL),
75  fClusterType(-1),
76  fEventNr(0),
77  fClusterFinder(NULL),
78  fBackMapping(NULL)
79 {
80  SetPersistency(kTRUE);
81 }
82 // -------------------------------------------------------------------------
83 
84 // ----- Destructor ----------------------------------------------------
86 {
87  if (fBackMapping != 0) delete fBackMapping;
88  if (fClusterFinder != 0) delete fClusterFinder;
89  if (fFunctor != 0) delete fFunctor;
90 }
91 // -------------------------------------------------------------------------
92 
93 // -------------------------------------------------------------------------
94 void PndSdsPixelClusterTask::InitMQ(TList* tempList) {
95  LOG(INFO) << "********************************************** PixelFindHits::InitMQ()" << FairLogger::endl;
96 // fDigiPar = (PndSdsPixelDigiPar*)tempList->FindObject(fParName.Data());
97 
98  fHitArray = new TClonesArray("PndSdsHit",10000);
99  fHitArray->SetName("MVDHitsPixel");
100  fClusterArray = new TClonesArray("PndSdsClusterPixel", 10000);
101  fClusterArray->SetName("MVDPixelCluster");
102 
103  SetClusterFinderMQ(tempList);
104  SetBackMappingMQ(tempList);
105 
106  return;
107 }
108 // -------------------------------------------------------------------------
109 
110 // -------------------------------------------------------------------------
111 void PndSdsPixelClusterTask::ExecMQ(TList* inputList,TList* outputList) {
112  // LOG(INFO) << "********************************************** PixelFindHits::ExecMQ(" << inputList->GetName() << "," << outputList->GetName() << "), Event " << fTNofEvents << FairLogger::endl;
113  // LOG(INFO) << "********************************************** PixelFindHits::ExecMQ(), Event " << fTNofEvents << FairLogger::endl;
114 // inputList->Print();
115  fDigiArray = (TClonesArray*) inputList->FindObject("PndSdsDigiPixels");
116  fEventHeader = (FairEventHeader*) inputList->FindObject("EventHeader.");
117  LOG(INFO) << "DigiArray: " << fDigiArray->GetEntriesFast() << FairLogger::endl;
118 
119 
120  outputList->Add(fClusterArray);
121  outputList->Add(fHitArray);
122  Exec("");
123  return;
124 }
125 // -------------------------------------------------------------------------
126 
127 void PndSdsPixelClusterTask::GetParList(TList* ) { //tempList //[R.K.03/2017] unused variable(s)
128 }
129 
130 // ----- Initialization of Parameter Containers -------------------------
132 {
133  if ( fGeoH == NULL ) {
135  }
137  if( ! fDigiPar) Fatal("SetParContainers","No digitization parameters specified");
138  if(fVerbose>1) Info("SetParContainers","done.");
139  return;
140 }
141 
142 
143 // ----- Initialization of Parameter Containers -------------------------
144 
146 {
147 
148  /*
149  FairRun* ana = FairRun::Instance();
150  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
151  fGeoPar=(PndSdsGeoPar*)(rtdb->getContainer("PndSdsGeoPar"));
152 
153  return kSUCCESS;
154  */
155 
156  return kSUCCESS; // TODO: Fill in sense here...
157 }
158 
159 // ----- Public method Init --------------------------------------------
161 {
162  SetBranchNames();
163 
164  SetBackMapping();
166 
167  FairRootManager* ioman = FairRootManager::Instance();
168 
169  if ( ! ioman )
170  {
171  std::cout << "-E- PndSdsPixelClusterTask::Init: "
172  << "RootManager not instantiated!" << std::endl;
173  return kFATAL;
174  }
175 
176 
177  // Get input array
178  fDigiArray = (TClonesArray*) ioman->GetObject(fInBranchName);
179 //
180  if ( ! fDigiArray )
181  {
182  std::cout << "-E- PndSdsPixelClusterTask::Init: "
183  << "No SDSDigi array!" << std::endl;
184  return kERROR;
185  }
186 
187  fClusterArray = ioman->Register(fClustBranchName, "PndSdsClusterPixel", fFolderName, GetPersistency());
188 
189  fHitArray = ioman->Register(fOutBranchName, "PndSdsHit", fFolderName, GetPersistency());
190 
191  SetInBranchId();
192 
193  fFunctor = new TimeGap();
194  fStartFunctor = new StopTime();
195 // fFEModel = new PndSdsFESimple();
196 
197 
198  if(fVerbose>1) fDigiPar->Print();
199 
200  std::cout << "-I- PndSdsPixelClusterTask: Initialisation successfull" << std::endl;
201  return kSUCCESS;
202 }
203 // -------------------------------------------------------------------------
204 
205 
206 
207 // ----- Public method Exec --------------------------------------------
209 {
210  std::vector<PndSdsDigiPixel> DigiPixelArray;
211 // // Reset output array
212  if ( ! fClusterArray ) Fatal("Exec", "No ClusterArray");
213 
215 
216  //Double_t eventTime = 0; //[R.K. 01/2017] unused variable
217  Int_t entryNumber = -1;
218  if (fEventHeader != 0){
219  //eventTime = fEventHeader->GetEventTime(); //[R.K. 01/2017] unused variable
220  entryNumber = fEventHeader->GetMCEntryNumber();
221  }
222  else {
223  //eventTime = FairRootManager::Instance()->GetEventTime(); //[R.K. 01/2017] unused variable
224  entryNumber = FairRootManager::Instance()->GetEntryNr();
225  }
226 
227 // if(fVerbose>0)
228 // std::cout << "-I- PndSdsPixelClusterTask::Exec EventNumber: " << fEventNr << " EventTime: " << EventTime << std::endl;
229 
230  if (FairRunAna::Instance() != 0 && FairRunAna::Instance()->IsTimeStamp()){
231  if(fVerbose>0) std::cout << "TimeStepPixel: " << fDigiPar->GetTimeStep();
232  fDigiArray = FairRootManager::Instance()->GetData(fInBranchName, fFunctor, fDigiPar->GetTimeStep() * 2);
233  }
234 
235  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
236 
237  //Int_t nPoints = fDigiArray->GetEntriesFast();
238 // if (fVerbose > 1)
239 // std::cout << "Points in DigiArray: " << nPoints << std::endl;
240 
241  // convert from TClonesArray to a std::vector
242 
243  DigiPixelArray = ConvertAndFilter(fDigiArray);
244 
245  // Retrieve the calculated clusters with the chosen clusterfinder
246  std::vector< std::vector< Int_t> > clusters = fClusterFinder->GetClusters(DigiPixelArray);
247 // if(fVerbose>1)
248 // std::cout << " -I- PndSdsPixelClusterTask::Exec(): We have "<<clusters.size()<<" pixel clusters" << std::endl;
249 
250  // Get rid of noise hits with a single digi in cluster and minimum charge
251  if (fUseNoiseSuppression) {
252  UInt_t clusterSize = clusters.size();
253  for (UInt_t i = 0 ; i < clusterSize; i++)
254  {
255  if (clusters[i].size() == 1){
256  PndSdsDigiPixel tempDigi = DigiPixelArray[clusters[i][0]];
257  if (tempDigi.GetCharge() < 40){
258  if (fVerbose > 2) std::cout << "-I- PndSdsPixelClusterTask::Exec():Erased cluster with digi " << tempDigi << std::endl;
259  clusters.erase(clusters.begin() + i);
260  i--;
261  clusterSize = clusters.size();
262  }
263  }
264  }
265  }
266 
267  // store the list
268  if(fVerbose > 2) std::cout << "Cluster Size after Erase: " << clusters.size() << std::endl;
269  for (UInt_t i = 0; i < clusters.size(); i++)
270  {
271 
272  PndSdsClusterPixel* tempCluster = new((*fClusterArray)[i]) PndSdsClusterPixel(fInBranchId, clusters[i]);
273 
274  if (FairRunAna::Instance() != 0 && FairRunAna::Instance()->IsTimeStamp()){
275  tempCluster->ResetLinks();
276  for (UInt_t j = 0; j < clusters[i].size(); j++){
277  PndSdsDigiPixel* tempDigi = (PndSdsDigiPixel*)fDigiArray->At(clusters[i][j]);
278  tempCluster->AddInterfaceData(tempDigi);
279  }
280  }
281 
282  std::vector<PndSdsDigiPixel> clusterArray;
283  for (UInt_t j=0;j < clusters[i].size();j++)
284  { // convert
285  clusterArray.push_back(DigiPixelArray[clusters[i][j]]);
286  }
287 
288  // mapping with the chosen back mapping
289  PndSdsHit myHit = fBackMapping->GetCluster(clusterArray);
290  myHit.SetClusterIndex(fClusterType,i, -1, entryNumber);
291 
292  // myHit.SetCharge(myHit.GetCharge());
293 // if(fVerbose>0){
294 // std::cout << " -I- PndSdsPixelClusterTask::Exec(): Calculated Hit: " << std::endl;
295 // myHit.Print();
296 //#if (ROOT_VERSION_CODE >= ROOT_VERSION(5,34,10))
297 // ((FairMultiLinkedData_Interface)(myHit)).Print();
298 //#else
299 // ((FairMultiLinkedData)(myHit)).Print();
300 //#endif
301 // }
302  new ((*fHitArray)[i]) PndSdsHit(myHit);
303  }
304 
305 
306 
307  if(fVerbose>1)std::cout << std::endl;
308 
309  if(fVerbose>1){
310  std::cout << "-I- PndSdsPixelClusterTask: " << fClusterArray->GetEntriesFast()
311  << " Sds Clusters and " << fHitArray->GetEntriesFast()<<" Hits calculated." << std::endl;
312  }
313  fEventNr++;
314  fHitArray->Sort();
315  return;
316 
317 }
318 
319 std::vector<PndSdsDigiPixel> PndSdsPixelClusterTask::ConvertAndFilter(TClonesArray* digidata)
320 {
321  std::vector<PndSdsDigiPixel> result;
322  for (Int_t iPoint = 0; iPoint < digidata->GetEntriesFast(); iPoint++){ // Just conversion
323  PndSdsDigiPixel myDigi = *(PndSdsDigiPixel*)(digidata->At(iPoint));
324  result.push_back(myDigi);
325  }
326  return result;
327 }
328 
330 
331  if (fDigiArray != NULL) fDigiArray->Delete();
332  if (fHitArray != NULL) fHitArray->Delete();
333  if (fClusterArray != NULL) fClusterArray->Delete();
334 }
335 
337 
virtual void ExecMQ(TList *inputList, TList *outputList)
int fVerbose
Definition: poormantracks.C:24
Int_t fInBranchId
Definition: PndSdsTask.h:43
PndSdsPixelBackMapping * fBackMapping
TString fOutBranchName
Definition: PndSdsTask.h:40
Int_t i
Definition: run_full.C:25
PndGeoHandling * fGeoH
Definition: anasim.C:34
void SetClusterIndex(Int_t datasource, Int_t id, Int_t fileId=-1, Int_t evtId=-1)
Definition: PndSdsHit.h:82
virtual void SetParContainers()
Double_t GetTimeStep() const
Time step of one clock cycle in ns.
Double_t GetCharge() const
Definition: PndSdsDigi.h:60
void SetPersistency(Bool_t val=kTRUE)
virtual void SetClusterFinder()=0
PndSdsPixelDigiPar * fDigiPar
TString fInBranchName
Definition: PndSdsTask.h:39
virtual void SetBranchNames()=0
PndSdsPixelClusterFinder * fClusterFinder
virtual void InitMQ(TList *tempList)
virtual void SetBackMapping()=0
TString fFolderName
Definition: PndSdsTask.h:41
static PndGeoHandling * Instance()
TString name
void SetVerbose(Int_t v)
virtual void Print(std::ostream &out=std::cout) const
ClassImp(PndAnaContFact)
virtual std::vector< PndSdsDigiPixel > ConvertAndFilter(TClonesArray *digidata)
convert TClonesArray into std::vector and remove corrupted data (for test beam analysis) ...
Data class to store the digi output of a pixel module.
virtual void GetParList(TList *tempList)
virtual void SetClusterFinderMQ(TList *)
virtual PndSdsHit GetCluster(std::vector< PndSdsDigiPixel > pixelArray)=0
virtual void SetBackMappingMQ(TList *)
virtual std::vector< std::vector< Int_t > > GetClusters(std::vector< PndSdsDigiPixel > hits)=0