CbmRoot
CbmTrdHitProducer.cxx
Go to the documentation of this file.
1 #include "CbmTrdHitProducer.h"
2 #include "CbmDigiManager.h"
3 #include "CbmTrdAddress.h"
4 #include "CbmTrdCluster.h"
5 #include "CbmTrdDigi.h"
6 #include "CbmTrdGeoHandler.h"
7 #include "CbmTrdHit.h"
8 #include "CbmTrdModuleRecR.h"
9 #include "CbmTrdModuleRecT.h"
10 #include "CbmTrdParAsic.h"
11 #include "CbmTrdParModDigi.h"
12 #include "CbmTrdParModGain.h"
13 #include "CbmTrdParModGas.h"
14 #include "CbmTrdParSetAsic.h"
15 #include "CbmTrdParSetDigi.h"
16 #include "CbmTrdParSetGain.h"
17 #include "CbmTrdParSetGas.h"
18 #include "CbmTrdParSetGeo.h"
19 
20 #include "TGeoPhysicalNode.h"
21 #include <TClonesArray.h>
22 #include <TGeoManager.h>
23 #include <TStopwatch.h>
24 #include <TVector3.h>
25 
26 #include <FairLogger.h>
27 #include <FairRootManager.h>
28 #include <FairRunAna.h>
29 #include <FairRuntimeDb.h>
30 
31 #include <map>
32 //____________________________________________________________________________________
34  : FairTask("TrdHitProducer")
35  , fClusters(NULL)
36  , fHits(NULL)
37  , fModules()
38  , fAsicPar(NULL)
39  , fGasPar(NULL)
40  , fDigiPar(NULL)
41  , fGainPar(NULL)
42  , fGeoPar(NULL) {}
43 
44 //____________________________________________________________________________________
46  fHits->Clear();
47  delete fHits;
48  if (fGeoPar) delete fGeoPar;
49 }
50 
51 //____________________________________________________________________________________
52 Int_t CbmTrdHitProducer::AddHits(TClonesArray* hits, Bool_t /*moveOwner*/) {
53 
58  if (!hits) return 0;
59 
60  Int_t nhits {hits->GetEntriesFast()};
61  fHits->AbsorbObjects(hits);
62 
63  return nhits;
64 }
65 
66 //____________________________________________________________________________________
68  TGeoPhysicalNode* node) {
69  TString s(node->GetName());
70  Int_t typ = TString(s[s.Index("module") + 6]).Atoi();
71 
72  CbmTrdModuleRec* module(NULL);
73  if (typ == 9) {
74  module = fModules[address] = new CbmTrdModuleRecT(address);
75  } else {
76  module = fModules[address] = new CbmTrdModuleRecR(address);
77  }
78 
79  // Try to load geometry parameters for the module
80  const CbmTrdParModGeo* pGeo = nullptr;
81  if (!fGeoPar)
82  LOG(warn) << GetName() << ": No geometry parameter container!";
83  else
84  pGeo = (const CbmTrdParModGeo*) fGeoPar->GetModulePar(address);
85  if (!pGeo)
86  LOG(warn) << GetName() << ": No geometry parameters for module " << address;
87  else
88  module->SetGeoPar(pGeo);
89 
90 
91  // try to load read-out parameters for module
92  const CbmTrdParModDigi* pDigi(NULL);
93  if (!fDigiPar
94  || !(pDigi = (const CbmTrdParModDigi*) fDigiPar->GetModulePar(address))) {
95  LOG(warn) << GetName() << "::AddModule : No Read-Out params for modAddress "
96  << address << ". Using default.";
97  } else
98  module->SetDigiPar(pDigi);
99 
100  // try to load ASIC parameters for module
101  CbmTrdParSetAsic* pAsic(NULL);
102  if (!fAsicPar
103  || !(pAsic = (CbmTrdParSetAsic*) fAsicPar->GetModuleSet(address))) {
104  LOG(warn) << GetName() << "::AddModule : No ASIC params for modAddress "
105  << address << ". Using default.";
106  // module->SetAsicPar(); // map ASIC channels to read-out channels - need ParModDigi already loaded
107  } else
108  module->SetAsicPar(pAsic);
109 
110  // try to load Chamber parameters for module
111  const CbmTrdParModGas* pChmb(NULL);
112  if (!fGasPar
113  || !(pChmb = (const CbmTrdParModGas*) fGasPar->GetModulePar(address))) {
114  LOG(warn) << GetName() << "::AddModule : No Gas params for modAddress "
115  << address << ". Using default.";
116  } else
117  module->SetChmbPar(pChmb);
118 
119  // try to load Gain parameters for module
120  if (typ == 9) {
121  const CbmTrdParModGain* pGain(NULL);
122  if (!fGainPar
123  || !(pGain =
124  (const CbmTrdParModGain*) fGainPar->GetModulePar(address))) {
125  //LOG(warn) << GetName() << "::AddModule : No Gain params for modAddress "<< address <<". Using default.";
126  } else
127  module->SetGainPar(pGain);
128  }
129  return module;
130 }
131 
132 //____________________________________________________________________________________
134  FairRootManager* rootMgr = FairRootManager::Instance();
135  if (NULL == rootMgr) {
136  LOG(error) << GetName() << "::Init: "
137  << "ROOT manager is not instantiated!";
138  return kFATAL;
139  }
140 
142  if (!CbmDigiManager::Instance()->IsPresent(ECbmModuleId::kTrd)) LOG(fatal);
143 
144  fClusters = (TClonesArray*) rootMgr->GetObject("TrdCluster");
145  if (!fClusters) {
146  LOG(error) << GetName() << "::Init: "
147  << "no TrdCluster array!";
148  return kFATAL;
149  }
150 
151  fHits = new TClonesArray("CbmTrdHit", 100);
152  rootMgr->Register("TrdHit", "TRD", fHits, IsOutputBranchPersistent("TrdHit"));
153 
154  // Get the full geometry information of the detector gas layers and store
155  // them with the CbmTrdModuleRec. This information can then be used for
156  // transformation calculations
157  CbmTrdGeoHandler geoHandler;
158  std::map<Int_t, TGeoPhysicalNode*> moduleMap = geoHandler.FillModuleMap();
159 
160  Int_t nrModules = fDigiPar->GetNrOfModules();
161  Int_t nrNodes = moduleMap.size();
162  if (nrModules != nrNodes)
163  LOG(fatal)
164  << "Geometry and parameter files have different number of modules.";
165  for (Int_t loop = 0; loop < nrModules; ++loop) {
166  Int_t address = fDigiPar->GetModuleId(loop);
167  std::map<Int_t, TGeoPhysicalNode*>::iterator it = moduleMap.find(address);
168  if (it == moduleMap.end()) {
169  LOG(fatal) << "Expected module with address " << address
170  << " wasn't found in the map with TGeoNode information.";
171  }
172  AddModule(address, it->second);
173  }
174  return kSUCCESS;
175 }
176 
177 //____________________________________________________________________________________
178 void CbmTrdHitProducer::Exec(Option_t*) {
179  fHits->Delete();
180 
181  TStopwatch timer;
182  timer.Start();
183 
184  CbmTrdModuleRec* mod(NULL);
185  std::vector<const CbmTrdDigi*> digis;
186  Int_t nofCluster = fClusters->GetEntries();
187  for (Int_t iCluster = 0; iCluster < nofCluster; iCluster++) {
188 
189  const CbmTrdCluster* cluster =
190  static_cast<const CbmTrdCluster*>(fClusters->At(iCluster));
191  // if(!cluster) continue;
192 
193  // get/build module for current cluster
194  std::map<Int_t, CbmTrdModuleRec*>::iterator imod =
195  fModules.find(cluster->GetAddress());
196  mod = imod->second;
197 
198  // get digi for current cluster
199  for (Int_t iDigi = 0; iDigi < cluster->GetNofDigis(); iDigi++) {
200  const CbmTrdDigi* digi =
201  CbmDigiManager::Instance()->Get<CbmTrdDigi>(cluster->GetDigi(iDigi));
202  //const CbmTrdDigi* digi = static_cast<const CbmTrdDigi*>(fDigis->At(cluster->GetDigi(iDigi)));
203  if (digi->GetType() == CbmTrdDigi::kSPADIC && digi->GetCharge() <= 0)
204  continue;
205  digis.push_back(digi);
206  }
207 
208  // run hit reconstruction
209  // std::cout<<" make hit"<<std::endl;
210  mod->MakeHit(iCluster, cluster, &digis);
211  digis.clear();
212  }
213 
214  Int_t hitCounter(0);
215  for (std::map<Int_t, CbmTrdModuleRec*>::iterator imod = fModules.begin();
216  imod != fModules.end();
217  imod++) {
218  mod = imod->second;
219  //hitCounter += mod->GetNhits();
220 
221  mod->Finalize();
222  // std::cout<<" add hit"<<std::endl;
223  hitCounter += AddHits(mod->GetHits(), kTRUE);
224  }
225  // remove local data from all modules
226  // Not needed any longer since AbsorbObjects take care
227  // for(std::map<Int_t, CbmTrdModuleRec*>::iterator imod = fModules.begin(); imod!=fModules.end(); imod++) imod->second->Clear("hit");
228 
229  timer.Stop();
230  LOG(info) << GetName() << "::Exec: "
231  << " Clusters : " << fClusters->GetEntriesFast();
232  LOG(info) << GetName() << "::Exec: "
233  << " Hits : " << hitCounter;
234  LOG(info) << GetName() << "::Exec: real time=" << timer.RealTime()
235  << " CPU time=" << timer.CpuTime();
236 }
237 
238 //____________________________________________________________________________________
240 
241 //________________________________________________________________________________________
243  fAsicPar = static_cast<CbmTrdParSetAsic*>(
244  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetAsic"));
245  fGasPar = static_cast<CbmTrdParSetGas*>(
246  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGas"));
247  fDigiPar = static_cast<CbmTrdParSetDigi*>(
248  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetDigi"));
249  fGainPar = static_cast<CbmTrdParSetGain*>(
250  FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGain"));
251  fGeoPar = new CbmTrdParSetGeo();
252 }
253 
254 
CbmTrdHitProducer::fHits
TClonesArray * fHits
Definition: CbmTrdHitProducer.h:52
ClassImp
ClassImp(CbmTrdHitProducer)
CbmTrdParModGas.h
CbmTrdParSetAsic::GetModuleSet
virtual const CbmTrdParSet * GetModuleSet(Int_t detId) const
Definition: CbmTrdParSetAsic.cxx:238
CbmTrdHitProducer::fAsicPar
CbmTrdParSetAsic * fAsicPar
parameter list for ASIC characterization
Definition: CbmTrdHitProducer.h:56
CbmTrdHitProducer::fGasPar
CbmTrdParSetGas * fGasPar
parameter list for HV status
Definition: CbmTrdHitProducer.h:57
CbmTrdHitProducer::CbmTrdHitProducer
CbmTrdHitProducer()
Constructor.
Definition: CbmTrdHitProducer.cxx:33
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdHitProducer::AddHits
Int_t AddHits(TClonesArray *hits, Bool_t moveOwner=kTRUE)
Definition: CbmTrdHitProducer.cxx:52
CbmTrdHitProducer::fGainPar
CbmTrdParSetGain * fGainPar
parameter list for keV->ADC gain conversion
Definition: CbmTrdHitProducer.h:59
CbmTrdHitProducer::fDigiPar
CbmTrdParSetDigi * fDigiPar
parameter list for read-out geometry
Definition: CbmTrdHitProducer.h:58
CbmTrdModuleRec::MakeHit
virtual CbmTrdHit * MakeHit(Int_t cId, const CbmTrdCluster *c, std::vector< const CbmTrdDigi * > *digis)=0
Steering routine for converting cluster to hit.
CbmTrdParSetGas
Describe TRD module working settings (HV, etc)
Definition: CbmTrdParSetGas.h:15
CbmTrdParSetGeo.h
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmTrdHitProducer::~CbmTrdHitProducer
virtual ~CbmTrdHitProducer()
Destructor.
Definition: CbmTrdHitProducer.cxx:45
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmTrdModuleRecT.h
CbmTrdParSetAsic
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition: CbmTrdParSetAsic.h:18
CbmTrdModuleRec
Abstract class for module wise cluster finding and hit reconstruction.
Definition: CbmTrdModuleRec.h:16
CbmTrdModuleAbstract::SetAsicPar
virtual void SetAsicPar(CbmTrdParSetAsic *p=nullptr)
Definition: CbmTrdModuleAbstract.h:70
CbmTrdParAsic.h
CbmTrdParSetAsic.h
CbmTrdGeoHandler
Definition: CbmTrdGeoHandler.h:29
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmCluster::GetNofDigis
Int_t GetNofDigis() const
Number of digis in cluster.
Definition: CbmCluster.h:69
CbmTrdParModGain.h
CbmTrdCluster
Data Container for TRD clusters.
Definition: CbmTrdCluster.h:23
CbmTrdParSet::GetNrOfModules
virtual Int_t GetNrOfModules() const
Definition: CbmTrdParSet.h:34
CbmTrdParSetGain
Definition: CbmTrdParSetGain.h:16
CbmTrdDigi.h
CbmTrdHitProducer::AddModule
CbmTrdModuleRec * AddModule(Int_t address, TGeoPhysicalNode *node)
Definition: CbmTrdHitProducer.cxx:67
CbmTrdHitProducer::Finish
virtual void Finish()
Inherited from FairTask.
Definition: CbmTrdHitProducer.cxx:239
CbmTrdParModGeo
Definition of geometry for one TRD module.
Definition: CbmTrdParModGeo.h:12
CbmTrdModuleRecR.h
CbmTrdParSet::GetModuleId
virtual Int_t GetModuleId(Int_t i) const
Definition: CbmTrdParSet.cxx:32
CbmTrdModuleRec::Finalize
virtual Bool_t Finalize()
Reconstruct physics observables on hits.
Definition: CbmTrdModuleRec.h:42
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
CbmTrdParModDigi
Definition of chamber gain conversion for one TRD module.
Definition: CbmTrdParModDigi.h:14
CbmTrdHitProducer::fModules
std::map< Int_t, CbmTrdModuleRec * > fModules
list of modules being processed
Definition: CbmTrdHitProducer.h:55
CbmTrdModuleRec::GetHits
virtual TClonesArray * GetHits()
Definition: CbmTrdModuleRec.h:50
CbmTrdParModDigi.h
CbmTrdParSetGain.h
CbmCluster::GetAddress
Int_t GetAddress() const
Definition: CbmCluster.h:90
CbmTrdParSet::GetModulePar
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
Definition: CbmTrdParSet.cxx:45
CbmTrdHit.h
Class for hits in TRD detector.
CbmTrdModuleAbstract::SetDigiPar
virtual void SetDigiPar(const CbmTrdParModDigi *p)
Definition: CbmTrdModuleAbstract.h:72
CbmTrdGeoHandler::FillModuleMap
std::map< Int_t, TGeoPhysicalNode * > FillModuleMap()
Fill map with information of the gas volumes for each detector.
Definition: CbmTrdGeoHandler.cxx:214
CbmTrdParSetGeo
Definition: CbmTrdParSetGeo.h:9
CbmTrdModuleAbstract::SetChmbPar
virtual void SetChmbPar(const CbmTrdParModGas *p)
Definition: CbmTrdModuleAbstract.h:71
CbmTrdModuleRecR
Rectangular pad module; Cluster finding and hit reconstruction algorithms.
Definition: CbmTrdModuleRecR.h:14
CbmTrdHitProducer
Definition: CbmTrdHitProducer.h:15
CbmTrdHitProducer::Init
virtual InitStatus Init()
Inherited form FairTask.
Definition: CbmTrdHitProducer.cxx:133
CbmTrdParSetDigi.h
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmTrdModuleRecT
Triangular pad module; Cluster finding and hit reconstruction algorithms.
Definition: CbmTrdModuleRecT.h:16
CbmTrdDigi::GetType
CbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
Definition: CbmTrdDigi.h:137
CbmTrdModuleAbstract::SetGeoPar
virtual void SetGeoPar(const CbmTrdParModGeo *p)
Definition: CbmTrdModuleAbstract.h:74
CbmDigiManager.h
CbmTrdDigi::kSPADIC
@ kSPADIC
Definition: CbmTrdDigi.h:16
hits
static vector< vector< QAHit > > hits
Definition: CbmTofHitFinderTBQA.cxx:114
CbmTrdHitProducer::fGeoPar
CbmTrdParSetGeo * fGeoPar
parameter list for modules geometry
Definition: CbmTrdHitProducer.h:60
CbmTrdDigi
Definition: CbmTrdDigi.h:14
CbmTrdParSetDigi
Definition: CbmTrdParSetDigi.h:15
CbmTrdParSetGas.h
CbmTrdCluster.h
Data Container for TRD clusters.
CbmTrdModuleAbstract::SetGainPar
virtual void SetGainPar(const CbmTrdParModGain *p)
Definition: CbmTrdModuleAbstract.h:73
CbmTrdDigi::GetCharge
Double_t GetCharge() const
Charge getter for SPADIC.
Definition: CbmTrdDigi.cxx:133
CbmTrdHitProducer::SetParContainers
virtual void SetParContainers()
Definition: CbmTrdHitProducer.cxx:242
CbmTrdHitProducer::fClusters
TClonesArray * fClusters
Definition: CbmTrdHitProducer.h:51
CbmCluster::GetDigi
Int_t GetDigi(Int_t index) const
Get digi at position index.
Definition: CbmCluster.h:76
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
CbmTrdHitProducer::Exec
virtual void Exec(Option_t *option="")
Inherited from FairTask.
Definition: CbmTrdHitProducer.cxx:178
CbmTrdHitProducer.h