FairRoot/PandaRoot
PndEmcMakeClusterOnline.cxx
Go to the documentation of this file.
1 //---------------------------------------------------------------------
2 // File and Version Information:
3 // $Id: $
4 //
5 // Description:
6 // This object constructs a list of clusters from a list of digis.
7 //
8 // Environment:
9 // Software developed for the PANDA Detector at GSI.
10 //
11 // STUB FOR MARCEL TIEMENS to implement online clustering algorithm in pandaroot
12 
13 
15 
17 #include "PndEmcXClMoments.h"
18 #include "PndEmcStructure.h"
19 #include "PndEmcMapper.h"
20 #include "PndEmcGeoPar.h"
21 #include "PndEmcDigiPar.h"
22 #include "PndEmcRecoPar.h"
23 #include "PndEmcCluster.h"
24 #include "PndEmcDigi.h"
25 
26 #include "FairRootManager.h"
27 #include "FairRunAna.h"
28 #include "FairRuntimeDb.h"
29 
30 #include "TClonesArray.h"
31 #include "TROOT.h"
32 
33 
34 #include <iostream>
35 
36 using std::cout;
37 using std::endl;
38 
39 
40 static Int_t evtCounter = 0;
41 static Int_t digiCounter = 0;
42 
44  PndPersistencyTask("EmcClusteringTask", verbose),
45  fDigiArray(NULL),
46  fClusterArray(NULL),
47  fGeoPar(new PndEmcGeoPar()),
48  fRecoPar(new PndEmcRecoPar()),
49  fDigiEnergyTresholdBarrel(0.), fDigiEnergyTresholdFWD(0.), fDigiEnergyTresholdBWD(0.), fDigiEnergyTresholdShashlyk(0.),
50  fClusterActiveTime(0.),
51  fDigiFunctor(NULL),
52  fStoreClusterBase(kTRUE)
53 {
54  SetPersistency(storeclusters);
55 }
56 
57 //--------------
58 // Destructor --
59 //--------------
60 
62 {
63 }
64 
65 // ----- Public method Init -------------------------------
67 
68  // Get RootManager
69  FairRootManager* ioman = FairRootManager::Instance();
70  if ( ! ioman )
71  {
72  cout << "-E- PndEmcMakeClusterOnline::Init: " << "RootManager not instantiated!" << endl;
73  return kFATAL;
74  }
75 
76  if(!FairRunAna::Instance()->IsTimeStamp()) {
77  cout << "-E- PndEmcMakeClusterOnline::Init: " << "This task can be activated only online" << endl;
78  return kFATAL;
79  }
80 
81  // Get input array
82  fDigiArray = (TClonesArray*) ioman->GetObject("EmcDigiSorted");
83  if (!fDigiArray) {
84  cout << "-W- PndEmcMakeClusterOnline::Init: " << "No PndEmcDigi array!" << endl;
85  return kERROR;
86  }
87 
88  // Create and register output array
89  fClusterArray = new TClonesArray("PndEmcCluster");
90  ioman->Register("EmcCluster","Emc", fClusterArray, GetPersistency());
91 
92  // for subsequent methods we need the "event grouping" as given by the TS buffer
93  // --> fDigiArray becomes an output array.
94  //
95  // can be removed once PndEmcCluster object has been rewritten
96  fDigiArray = new TClonesArray(fDigiArray->GetClass()); //still needed to activate array
97  ioman->Register("EmcDigiClusterBase", "Emc", fDigiArray, fStoreClusterBase);
98 
99  // searching for time gaps in digi stream
100  fDigiFunctor = new TimeGap();
101 
104 
105  // get some parameters from the parbase
110 
111  //convert from seconds to nanoseconds...in parfile everything is seconds...here we need nanoseconds
113 
114  cout << "-I- PndEmcMakeClusterOnline: Intialization successfull" << endl;
115  return kSUCCESS;
116 }
117 
118 
120 
121  if (fVerbose>2){
122  fTimer.Start();
123  }
124 
125  // Reset output arrays
126  if ( ! fClusterArray ) Fatal("Exec", "No Cluster Array");
127  fClusterArray->Delete();
128  fDigiArray->Delete();
129 
130 
131  // Get all digis up to a certain time gap specified by fClusterActiveTime
132  fDigiArray->AbsorbObjects(FairRootManager::Instance()->GetData("EmcDigiSorted", fDigiFunctor, fClusterActiveTime));
133 
134  // --------------------- start coding here :-) ---------------------------
135 
136 
137  Int_t nDigis = fDigiArray->GetEntriesFast();
138 
139  if (fVerbose>2){
140  cout<<"Event no: " << evtCounter++ << "\tDigiList length: "<<nDigis<<endl;
141  digiCounter += nDigis;
142  }
143 
144  /* create a new cluster like this */
145  PndEmcCluster* cluster_A = new((*fClusterArray)[fClusterArray->GetEntriesFast()]) PndEmcCluster();
146  PndEmcCluster* cluster_B = new((*fClusterArray)[fClusterArray->GetEntriesFast()]) PndEmcCluster();
147 
148 
149  //loop over all digis to add them to clusters
150 
151  for (Int_t iDigi=0; iDigi<nDigis; ++iDigi) {
152 
153  /* Get a new digi from the digi array */
154  PndEmcDigi* theDigi = (PndEmcDigi*) fDigiArray->At(iDigi);
155 
156  // thresholds: if energy is below the corresponding threshold, digi is not considered in clustering
157  {
158  Int_t module=theDigi->GetModule();
159  if ((module==1||module==2) && (theDigi->GetEnergy()< fDigiEnergyTresholdBarrel)) continue;
160  if ((module==3) && (theDigi->GetEnergy()< fDigiEnergyTresholdFWD)) continue;
161  if ((module==4) && (theDigi->GetEnergy()< fDigiEnergyTresholdBWD)) continue;
162  if ((module==5) && (theDigi->GetEnergy()< fDigiEnergyTresholdShashlyk)) continue;
163  }
164 
165  /* add digis alternating to cluster_A resp. to cluster_B */
166  {
167  if(iDigi%2) {
168  cluster_A->addDigi(fDigiArray, iDigi);
169  cluster_A->AddLink(theDigi->GetEntryNr());
170  } else {
171  cluster_B->addDigi(fDigiArray, iDigi);
172  cluster_B->AddLink(theDigi->GetEntryNr());
173  }
174  }
175 
176  if(fVerbose>5) {
177  /* function to ask weather a digi belongs to a cluster (i.e. is a neighbor) */
178  if(cluster_A->isInCluster(theDigi, fDigiArray)) {
179  cout << "incoming digi " << theDigi << " belongs to (is direct neighbor) cluster_A (" << cluster_A <<")" << endl;
180  }
181  if(cluster_B->isInCluster(theDigi, fDigiArray)) {
182  cout << "incoming digi " << theDigi << " belongs to (is direct neighbor) cluster_B (" << cluster_A <<")" << endl;
183  }
184  }
185  }
186 
187  /* merge two clusters */
188  cluster_A->addCluster(cluster_B, fDigiArray);
189  fClusterArray->Remove(cluster_B); //remove cluster_B now from the list of clusters
190  fClusterArray->Compress(); //remove open position from TClonesArray
191 
192  // --------------------- stop---------------------------------------------
193 
194  FinishClusters();
195 
196 }
197 
198 
200 
201  Int_t nCluster = fClusterArray->GetEntriesFast();
202  for (Int_t i=0; i<nCluster; i++) {
204  }
205 
206  if (fVerbose>2){
207  fTimer.Stop();
208  Double_t rtime = fTimer.RealTime();
209  Double_t ctime = fTimer.CpuTime();
210  fTimer.Reset();
211  cout << "PndEmcMakeClusterOnline, Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
212  }
213 }
214 
216 
217  //----here you might set energy and time etc. to the clusters, e.g. like follows
218 
219  std::vector<Int_t> list = cluster->DigiList();
220 
221  Double_t total_energy = 0;
222  Double_t max_energy = 0;
223  Int_t max_energy_idx = 0;
224 
225  for(size_t iDigi=0; iDigi<list.size(); ++iDigi) {
226  Int_t idx = list[iDigi];
227  PndEmcDigi* thedigi = (PndEmcDigi*) fDigiArray->UncheckedAt(idx);
228 
229  total_energy += thedigi->GetEnergy();
230  if(thedigi->GetEnergy() > max_energy) {
231  max_energy = thedigi->GetEnergy();
232  max_energy_idx = idx;
233  }
234  }
235 
236  cluster->SetEnergy(total_energy);
237  cluster->SetTimeStamp(static_cast<PndEmcDigi*>(fDigiArray->UncheckedAt(max_energy_idx))->GetTimeStamp());
238 
239  //-------------------stop-------------------------------------------------------------
240 }
241 
242 
244  if(fVerbose>2) {
245  std::cout << "Processed in total " << digiCounter << " digis within " << evtCounter << " events." << std::endl;
246  }
247 }
248 
250 
251  // Get run and runtime database
252  FairRun* run = FairRun::Instance();
253  if ( ! run ) Fatal("SetParContainers", "No analysis run");
254 
255  FairRuntimeDb* db = run->GetRuntimeDb();
256  if ( ! db ) Fatal("SetParContainers", "No runtime database");
257 
258  // Get Emc geometry parameter container
259  fGeoPar = (PndEmcGeoPar*) db->getContainer("PndEmcGeoPar");
260 
261  // Get Emc reconstruction parameter container
262  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
263 }
264 
265 
267  SetPersistency(val);
268  return;
269 }
270 
271 
272 
void SetEnergy(Double_t en)
int fVerbose
Definition: poormantracks.C:24
bool isInCluster(PndEmcDigi *theDigi, const TClonesArray *digiArray)
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
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
#define verbose
Double_t GetEnergyThresholdBarrel()
Definition: PndEmcRecoPar.h:15
void SetPersistency(Bool_t val=kTRUE)
const std::vector< Int_t > & DigiList() const
Definition: PndEmcCluster.h:40
static Int_t evtCounter
static Int_t digiCounter
Short_t GetModule() const
Definition: PndEmcDigi.h:103
void InitEmcMapper()
void addCluster(PndEmcCluster *cluster, const TClonesArray *digiArray)
int idx[MAX]
Definition: autocutx.C:38
Double_t GetClusterActiveTime()
Definition: PndEmcRecoPar.h:19
Double_t
Double_t GetEnergyThresholdFWD()
Definition: PndEmcRecoPar.h:16
void FinishCluster(PndEmcCluster *tmpcluster)
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
Double_t ctime
Definition: hit_dirc.C:114
TClonesArray * fClusterArray
active clusters
ClassImp(PndAnaContFact)
virtual void Exec(Option_t *opt)
Double_t GetEnergyThresholdShashlyk()
Definition: PndEmcRecoPar.h:18
Double_t fClusterActiveTime
Defines how long clusters are kept open in timebased reconstruction.
static PndEmcStructure * Instance()
Double_t rtime
Definition: hit_dirc.C:113
Double_t GetEnergyThresholdBWD()
Definition: PndEmcRecoPar.h:17
void SetStorageOfData(Bool_t val)
Method to specify whether clusters are stored or not.
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12
virtual void addDigi(const TClonesArray *digiArray, Int_t iDigi)
PndEmcMakeClusterOnline(Int_t verbose=0, Bool_t storeclusters=kTRUE)