CbmRoot
CbmTrdClusterFinder.cxx
Go to the documentation of this file.
1 #include "CbmTrdClusterFinder.h"
2 
3 #include "CbmDigiManager.h"
4 #include "CbmTrdParAsic.h"
5 #include "CbmTrdParModDigi.h"
6 #include "CbmTrdParModGain.h"
7 #include "CbmTrdParModGas.h"
8 #include "CbmTrdParSetAsic.h"
9 #include "CbmTrdParSetDigi.h"
10 #include "CbmTrdParSetGain.h"
11 #include "CbmTrdParSetGas.h"
12 #include "CbmTrdParSetGeo.h"
13 
14 #include "CbmTrdCluster.h"
15 #include "CbmTrdDigi.h"
16 #include "CbmTrdGeoHandler.h"
17 #include "CbmTrdModuleRecR.h"
18 #include "CbmTrdModuleRecT.h"
19 
20 #include <FairLogger.h>
21 #include <FairRootManager.h>
22 #include <FairRunAna.h>
23 #include <FairRuntimeDb.h>
24 
25 #include <TArray.h>
26 #include <TBits.h>
27 #include <TClonesArray.h>
28 #include <TGeoPhysicalNode.h>
29 #include <TStopwatch.h>
30 // #include "TCanvas.h"
31 // #include "TImage.h"
32 
33 #include <cmath>
34 #include <iomanip>
35 #include <iostream>
36 using std::cout;
37 using std::endl;
38 using std::fabs;
39 using std::setprecision;
40 
43 //_____________________________________________________________________
45  : FairTask("TrdClusterFinder", 1)
46  , fClusters(NULL)
47  , fDigiMap()
48  , fModuleMap()
49  , fNeighbours()
50  , fModDigiMap()
51  , fDigiRow()
52  , fDigiCol()
53  , fDigiCharge()
54  , fClusterBuffer()
55  , fModClusterDigiMap()
56  ,
57  //=======================
58  fModules()
59  , fAsicPar(NULL)
60  , fGasPar(NULL)
61  , fDigiPar(NULL)
62  , fGainPar(NULL)
63  , fGeoPar(NULL)
64 
65 {}
66 // --------------------------------------------------------------------
67 
68 // ---- Destructor ----------------------------------------------------
70 
71  if (fClusters) {
72  fClusters->Clear("C");
73  fClusters->Delete();
74  delete fClusters;
75  }
76  if (fGeoPar) { delete fGeoPar; }
77  // if(fModuleInfo){
78  // delete fModuleInfo;
79  // }
80 }
81 
82 //_____________________________________________________________________
84  Int_t ncl(fClusters->GetEntriesFast());
85  new ((*fClusters)[ncl++]) CbmTrdCluster(*c);
86  return kTRUE;
87 }
88 
89 //____________________________________________________________________________________
91  Int_t address = digi->GetAddressModule();
92  CbmTrdModuleRec* module(NULL);
93  if (digi->GetType() == CbmTrdDigi::kFASP)
94  module = fModules[address] = new CbmTrdModuleRecT(address);
95  else
96  module = fModules[address] = new CbmTrdModuleRecR(address);
97 
98  // try to load Geometry parameters for module
99  const CbmTrdParModGeo* pGeo(NULL);
100  if (!fGeoPar
101  || !(pGeo = (const CbmTrdParModGeo*) fGeoPar->GetModulePar(address))) {
102  LOG(fatal) << GetName() << "::AddModule : No Geo params for module "
103  << address << ". Using default.";
104  } else
105  module->SetGeoPar(pGeo);
106 
107  // try to load read-out parameters for module
108  const CbmTrdParModDigi* pDigi(NULL);
109  if (!fDigiPar
110  || !(pDigi = (const CbmTrdParModDigi*) fDigiPar->GetModulePar(address))) {
111  LOG(warn) << GetName() << "::AddModule : No Read-Out params for modAddress "
112  << address << ". Using default.";
113  } else
114  module->SetDigiPar(pDigi);
115 
116  // try to load ASIC parameters for module
117  CbmTrdParSetAsic* pAsic(NULL);
118  if (!fAsicPar
119  || !(pAsic = (CbmTrdParSetAsic*) fAsicPar->GetModuleSet(address))) {
120  LOG(warn) << GetName() << "::AddModule : No ASIC params for modAddress "
121  << address << ". Using default.";
122  // module->SetAsicPar(); // map ASIC channels to read-out channels - need ParModDigi already loaded
123  } else
124  module->SetAsicPar(pAsic);
125 
126  // try to load Chamber parameters for module
127  const CbmTrdParModGas* pChmb(NULL);
128  if (!fGasPar
129  || !(pChmb = (const CbmTrdParModGas*) fGasPar->GetModulePar(address))) {
130  LOG(warn) << GetName() << "::AddModule : No Gas params for modAddress "
131  << address << ". Using default.";
132  } else
133  module->SetChmbPar(pChmb);
134 
135  // try to load Gain parameters for module
136  if (digi->GetType() == CbmTrdDigi::kFASP) {
137  const CbmTrdParModGain* pGain(NULL);
138  if (!fGainPar
139  || !(pGain =
140  (const CbmTrdParModGain*) fGainPar->GetModulePar(address))) {
141  //LOG(warn) << GetName() << "::AddModule : No Gain params for modAddress "<< address <<". Using default.";
142  } else
143  module->SetGainPar(pGain);
144  }
145  return module;
146 }
147 
148 //_____________________________________________________________________
150  fAsicPar = static_cast<CbmTrdParSetAsic*>(
151  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetAsic"));
152  fGasPar = static_cast<CbmTrdParSetGas*>(
153  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGas"));
154  fDigiPar = static_cast<CbmTrdParSetDigi*>(
155  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetDigi"));
156  fGainPar = static_cast<CbmTrdParSetGain*>(
157  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGain"));
158  // Get the full geometry information of the TRD modules
159  fGeoPar = new CbmTrdParSetGeo();
160 }
161 
162 //_____________________________________________________________________
164 
165  FairRootManager* ioman = FairRootManager::Instance();
166 
167 
169  if (!CbmDigiManager::Instance()->IsPresent(ECbmModuleId::kTrd)) LOG(fatal);
170 
171  fClusters = new TClonesArray("CbmTrdCluster", 100);
172  ioman->Register(
173  "TrdCluster", "TRD", fClusters, IsOutputBranchPersistent("TrdCluster"));
174 
175  if (!IsTimeBased() && !ioman->GetObject("Event")) {
176  LOG(warn) << GetName()
177  << ": Event mode selected but no event array found! Run in "
178  "time-based mode.";
179  SetTimeBased();
180  }
181  // // Get the full geometry information of the detector gas layers and store
182  // // them with the CbmTrdModuleRec. This information can then be used for
183  // // transformation calculations
184  // std::map<Int_t, TGeoPhysicalNode*> moduleMap = fGeoHandler->FillModuleMap();
185  //
186  // Int_t nrModules = fDigiPar->GetNrOfModules();
187  // Int_t nrNodes = moduleMap.size();
188  // if (nrModules != nrNodes) LOG(fatal) << "Geometry and parameter files have different number of modules.";
189  // for (Int_t loop=0; loop< nrModules; ++loop) {
190  // Int_t address = fDigiPar->GetModuleId(loop);
191  // std::map<Int_t, TGeoPhysicalNode*>::iterator it = moduleMap.find(address);
192  // if ( it == moduleMap.end() ) {
193  // LOG(fatal) << "Expected module with address " << address << " wasn't found in the map with TGeoNode information.";
194  // }
195  // AddModule(address, it->second);
196  // }
197 
198  // // new call needed when parameters are initialized from ROOT file
199  // fDigiPar->Initialize();
200 
201  LOG(info) << "================ TRD Cluster Finder ===============";
202  LOG(info) << " Free streaming : " << (IsTimeBased() ? "yes" : "no");
203  LOG(info) << " Multi hit detect : " << (HasMultiHit() ? "yes" : "no");
204  LOG(info) << " Row merger : " << (HasRowMerger() ? "yes" : "no");
205  LOG(info) << " c-Neighbour enable: " << (HasNeighbourCol() ? "yes" : "no");
206  LOG(info) << " r-Neighbour enable: " << (HasNeighbourRow() ? "yes" : "no");
207  LOG(info) << " Write clusters : " << (HasDumpClusters() ? "yes" : "no");
208 
209  return kSUCCESS;
210 }
211 
212 //_____________________________________________________________________
213 void CbmTrdClusterFinder::Exec(Option_t* /*option*/) {
227  fClusters->Delete();
228 
229  TStopwatch timer;
230  timer.Start();
231 
232  // Int_t nentries = fDigis->GetEntries();
233  //printf("processing %d entries\n", nentries);
234  CbmTrdModuleRec* mod(NULL);
236  for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
237 
238  const CbmTrdDigi* digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(iDigi);
239 
240 
241  //CbmTrdDigi *digi = (CbmTrdDigi*) fDigis->At(iDigi);
242  Int_t moduleAddress = digi->GetAddressModule();
243 
244  std::map<Int_t, CbmTrdModuleRec*>::iterator imod =
245  fModules.find(moduleAddress);
246  if (imod == fModules.end())
247  mod = AddModule(digi);
248  else
249  mod = imod->second;
250  // std::cout<<digi->GetTime()<<std::endl;
251 
252  mod->AddDigi(digi, iDigi);
253  }
254 
255  Int_t digiCounter(0), clsCounter(0);
256  for (std::map<Int_t, CbmTrdModuleRec*>::iterator imod = fModules.begin();
257  imod != fModules.end();
258  imod++) {
259  mod = imod->second;
260  digiCounter += mod->GetOverThreshold();
261  clsCounter += mod->FindClusters();
262  AddClusters(mod->GetClusters(), kTRUE);
263  }
264 
265  // remove local data from all modules
266  for (std::map<Int_t, CbmTrdModuleRec*>::iterator imod = fModules.begin();
267  imod != fModules.end();
268  imod++)
269  imod->second->Clear("cls");
270 
271  timer.Stop();
272 
273  LOG(info) << GetName() << "::Exec : Digis : " << nDigis << " / "
274  << digiCounter << " above threshold (" << 1e6 * fgMinimumChargeTH
275  << " keV)";
276  LOG(info) << GetName() << "::Exec : Clusters : " << clsCounter;
277  LOG(info) << GetName() << "::Exec : real time=" << timer.RealTime()
278  << " CPU time=" << timer.CpuTime();
279 
280  // //cout << " " << counterI << " (" << counterI*100.0/Float_t(counterJ) << "%)" << " are reconstructed with fRowClusterMerger" << endl;
281  // //printf(" %4d modules (%6.3f%%) are reconstructed with fRowClusterMerger\n",counterI,counterI*100/Float_t(counterJ));
282  // LOG(info) << "CbmTrdClusterFinder::Exec : RowClusterMerger are used " << fRowMergerCounter << " times";
283 }
284 
285 //_____________________________________________________________________
286 Int_t CbmTrdClusterFinder::AddClusters(TClonesArray* clusters,
287  Bool_t /* move*/) {
288  if (!clusters) return 0;
289  CbmTrdCluster *cls(NULL), *clsSave(NULL);
290  const CbmTrdDigi* digi(NULL);
291  CbmTrdParModDigi* digiPar(NULL);
292  TBits cols, rows;
293  Int_t ncl(fClusters->GetEntriesFast()), mcl(0), ncols(0);
294 
295  for (Int_t ic(0); ic < clusters->GetEntriesFast(); ic++) {
296  if (!(cls = (CbmTrdCluster*) (*clusters)[ic])) continue;
297 
298  if (!cls->HasTrianglePads()) { // only for rectangular clusters
299  if (!ncols) {
300  digiPar = (CbmTrdParModDigi*) fDigiPar->GetModulePar(cls->GetAddress());
301  if (!digiPar) {
302  LOG(error) << "CbmTrdClusterFinder::AddClusters : Can't find "
303  "ParModDigi for address"
304  << cls->GetAddress();
305  continue;
306  }
307  ncols = digiPar->GetNofColumns();
308  }
309  cols.Clear();
310  rows.Clear();
311  for (Int_t id = 0; id < cls->GetNofDigis(); id++) {
312  digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(cls->GetDigi(id));
313  Int_t digiChannel = digi->GetAddressChannel();
314  Int_t colId = digiChannel % ncols;
315  Int_t globalRow = digiChannel / ncols;
316 
317  Int_t combiId = globalRow * ncols + colId;
318  cols.SetBitNumber(combiId);
319  rows.SetBitNumber(globalRow);
320  }
321  // store information in cluster
322  cls->SetNCols(cols.CountBits());
323  cls->SetNRows(rows.CountBits());
324  }
325  clsSave = new ((*fClusters)[ncl++])
326  CbmTrdCluster(*cls); // TODO implement copy constructor
327  clsSave->SetTrianglePads(cls->HasTrianglePads());
328  if (cls->GetMatch() != NULL)
329  delete cls; //only the matches have pointers to allocated memory, so otherwise the clear does the trick
330  mcl++;
331  }
332  //clusters->Clear();
333  return mcl;
334 }
335 
336 //_____________________________________________________________________
338 
CbmTrdParModGas.h
CbmTrdParSetAsic::GetModuleSet
virtual const CbmTrdParSet * GetModuleSet(Int_t detId) const
Definition: CbmTrdParSetAsic.cxx:238
CbmTrdClusterFinder::AddCluster
Bool_t AddCluster(CbmTrdCluster *c)
Save one finished cluster to the output.
Definition: CbmTrdClusterFinder.cxx:83
CbmTrdModuleRec::AddDigi
virtual Bool_t AddDigi(const CbmTrdDigi *, Int_t)
Add digi to local module.
Definition: CbmTrdModuleRec.h:32
CbmTrdParSetGas
Describe TRD module working settings (HV, etc)
Definition: CbmTrdParSetGas.h:15
CbmTrdParSetGeo.h
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmTrdDigi::GetAddressChannel
Int_t GetAddressChannel() const
Getter read-out id.
Definition: CbmTrdDigi.cxx:119
CbmTrdModuleRecT.h
CbmTrdParSetAsic
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition: CbmTrdParSetAsic.h:18
CbmTrdClusterFinder::HasDumpClusters
static Bool_t HasDumpClusters()
Definition: CbmTrdClusterFinder.h:63
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmTrdModuleRec
Abstract class for module wise cluster finding and hit reconstruction.
Definition: CbmTrdModuleRec.h:16
CbmTrdDigi::kFASP
@ kFASP
Definition: CbmTrdDigi.h:16
CbmTrdModuleAbstract::SetAsicPar
virtual void SetAsicPar(CbmTrdParSetAsic *p=nullptr)
Definition: CbmTrdModuleAbstract.h:70
CbmTrdParAsic.h
CbmTrdParSetAsic.h
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmTrdParModGain.h
CbmTrdCluster
Data Container for TRD clusters.
Definition: CbmTrdCluster.h:23
CbmTrdParSetGain
Definition: CbmTrdParSetGain.h:16
CbmTrdClusterFinder::AddClusters
Int_t AddClusters(TClonesArray *clusters, Bool_t moveOwner=kTRUE)
Definition: CbmTrdClusterFinder.cxx:286
CbmTrdDigi.h
CbmTrdClusterFinder
Definition: CbmTrdClusterFinder.h:37
CbmTrdClusterFinder::CbmTrdModuleRecT
friend class CbmTrdModuleRecT
Definition: CbmTrdClusterFinder.h:39
CbmTrdParModGeo
Definition of geometry for one TRD module.
Definition: CbmTrdParModGeo.h:12
CbmTrdClusterFinder::fGainPar
CbmTrdParSetGain * fGainPar
parameter list for keV->ADC gain conversion
Definition: CbmTrdClusterFinder.h:138
CbmTrdModuleRecR.h
CbmTrdCluster::SetTrianglePads
void SetTrianglePads(Bool_t set=kTRUE)
Definition: CbmTrdCluster.h:96
CbmTrdGeoHandler.h
Helper class to extract information from the GeoManager.
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
CbmTrdClusterFinder::HasNeighbourRow
static Bool_t HasNeighbourRow()
Definition: CbmTrdClusterFinder.h:66
CbmTrdParModDigi
Definition of chamber gain conversion for one TRD module.
Definition: CbmTrdParModDigi.h:14
CbmTrdClusterFinder::HasRowMerger
static Bool_t HasRowMerger()
Definition: CbmTrdClusterFinder.h:67
CbmTrdParModDigi.h
CbmTrdClusterFinder::fgMinimumChargeTH
static Float_t fgMinimumChargeTH
Definition: CbmTrdClusterFinder.h:113
CbmTrdParSetGain.h
CbmTrdModuleRec::GetClusters
virtual TClonesArray * GetClusters()
Definition: CbmTrdModuleRec.h:48
CbmTrdClusterFinder::fDigiPar
CbmTrdParSetDigi * fDigiPar
parameter list for read-out geometry
Definition: CbmTrdClusterFinder.h:137
CbmTrdParSet::GetModulePar
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
Definition: CbmTrdParSet.cxx:45
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdClusterFinder::HasMultiHit
static Bool_t HasMultiHit()
Definition: CbmTrdClusterFinder.h:64
CbmTrdModuleAbstract::SetDigiPar
virtual void SetDigiPar(const CbmTrdParModDigi *p)
Definition: CbmTrdModuleAbstract.h:72
CbmTrdClusterFinder::HasNeighbourCol
static Bool_t HasNeighbourCol()
Definition: CbmTrdClusterFinder.h:65
CbmTrdClusterFinder::AddModule
CbmTrdModuleRec * AddModule(const CbmTrdDigi *d)
Definition: CbmTrdClusterFinder.cxx:90
CbmTrdClusterFinder::fGasPar
CbmTrdParSetGas * fGasPar
parameter list for HV status
Definition: CbmTrdClusterFinder.h:136
CbmTrdParSetGeo
Definition: CbmTrdParSetGeo.h:9
CbmTrdModuleAbstract::SetChmbPar
virtual void SetChmbPar(const CbmTrdParModGas *p)
Definition: CbmTrdModuleAbstract.h:71
CbmTrdModuleRec::GetOverThreshold
virtual Int_t GetOverThreshold() const
Definition: CbmTrdModuleRec.h:47
CbmTrdParSetDigi.h
CbmTrdClusterFinder::CbmTrdClusterFinder
CbmTrdClusterFinder()
Default constructor.
Definition: CbmTrdClusterFinder.cxx:44
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmTrdClusterFinder::fAsicPar
CbmTrdParSetAsic * fAsicPar
parameter list for ASIC characterization
Definition: CbmTrdClusterFinder.h:135
CbmTrdClusterFinder::fgConfig
static Int_t fgConfig
Configuration map for the clusterizer. See CbmTrdRecDef for details.
Definition: CbmTrdClusterFinder.h:112
CbmTrdClusterFinder::fClusters
TClonesArray * fClusters
Definition: CbmTrdClusterFinder.h:116
CbmTrdDigi::GetType
CbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
Definition: CbmTrdDigi.h:137
CbmTrdClusterFinder::SetParContainers
virtual void SetParContainers()
Definition: CbmTrdClusterFinder.cxx:149
CbmTrdModuleAbstract::SetGeoPar
virtual void SetGeoPar(const CbmTrdParModGeo *p)
Definition: CbmTrdModuleAbstract.h:74
CbmTrdClusterFinder::fGeoPar
CbmTrdParSetGeo * fGeoPar
parameter list for modules geometry
Definition: CbmTrdClusterFinder.h:139
CbmDigiManager.h
CbmTrdClusterFinder::IsTimeBased
static Bool_t IsTimeBased()
Definition: CbmTrdClusterFinder.h:68
CbmTrdClusterFinder::SetTimeBased
static void SetTimeBased(Bool_t set=kTRUE)
Definition: CbmTrdClusterFinder.h:96
fabs
friend F32vec4 fabs(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:60
CbmTrdClusterFinder::~CbmTrdClusterFinder
~CbmTrdClusterFinder()
Default destructor.
Definition: CbmTrdClusterFinder.cxx:69
CbmTrdClusterFinder::fModules
std::map< Int_t, CbmTrdModuleRec * > fModules
list of modules being processed
Definition: CbmTrdClusterFinder.h:134
CbmTrdDigi
Definition: CbmTrdDigi.h:14
CbmTrdClusterFinder.h
CbmTrdParSetDigi
Definition: CbmTrdParSetDigi.h:15
CbmTrdClusterFinder::Exec
virtual void Exec(Option_t *option)
Executed task.
Definition: CbmTrdClusterFinder.cxx:213
CbmTrdCluster.h
Data Container for TRD clusters.
CbmTrdParSetGas.h
CbmTrdClusterFinder::Finish
virtual void Finish()
Definition: CbmTrdClusterFinder.cxx:337
CbmTrdModuleAbstract::SetGainPar
virtual void SetGainPar(const CbmTrdParModGain *p)
Definition: CbmTrdModuleAbstract.h:73
CbmTrdParModGas
Definition of gas parameters for one TRD module.
Definition: CbmTrdParModGas.h:16
CbmTrdParModGain
Definition of gain parameters for one TRD module.
Definition: CbmTrdParModGain.h:9
CbmTrdParModDigi::GetNofColumns
Int_t GetNofColumns() const
Definition: CbmTrdParModDigi.cxx:321
CbmTrdModuleRec::FindClusters
virtual Int_t FindClusters()=0
Steering routine for finding digits clusters.
CbmTrdClusterFinder::CbmTrdModuleRecR
friend class CbmTrdModuleRecR
Definition: CbmTrdClusterFinder.h:38
CbmTrdDigi::GetAddressModule
Int_t GetAddressModule() const
Getter module address in the experiment.
Definition: CbmTrdDigi.cxx:126
CbmTrdClusterFinder::Init
virtual InitStatus Init()
Definition: CbmTrdClusterFinder.cxx:163