25 #include <FairBaseParSet.h>
26 #include <FairEventHeader.h>
27 #include <FairLogger.h>
28 #include <FairRootManager.h>
29 #include <FairRunAna.h>
30 #include <FairRunSim.h>
31 #include <FairRuntimeDb.h>
35 #include <TClonesArray.h>
37 #include <TStopwatch.h>
58 , nofBackwardTracks(0)
63 , fDigiMatches(nullptr)
85 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin();
99 FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetAsic"));
101 FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGas"));
103 FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetDigi"));
105 FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGain"));
111 FairRootManager* ioman = FairRootManager::Instance();
112 if (!ioman) LOG(fatal) <<
"CbmTrdDigitizer::Init: No FairRootManager";
114 fPoints = (TClonesArray*) ioman->GetObject(
"TrdPoint");
115 if (!
fPoints) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No TrdPoint array!";
117 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
118 if (!
fTracks) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No MCTrack array!";
131 LOG(info) <<
"================ TRD Digitizer ===============";
132 LOG(info) <<
" Free streaming : " << (
IsTimeBased() ?
"yes" :
"no");
133 LOG(info) <<
" Add Noise : " << (
AddNoise() ?
"yes" :
"no");
134 LOG(info) <<
" Weighted distance : " << (
UseWeightedDist() ?
"yes" :
"no");
153 Int_t nofPoints =
fPoints->GetEntriesFast();
154 gGeoManager->CdTop();
155 for (Int_t iPoint = 0; iPoint < nofPoints; iPoint++) {
160 if (!point)
continue;
163 if (!track)
continue;
167 LOG(debug2) << GetName() <<
"::Exec: MC-track points towards target!";
172 map<Int_t, CbmTrdModuleSim*>::iterator imod =
179 gGeoManager->FindNode(meanX, meanY, meanZ);
180 if (!TString(gGeoManager->GetPath()).Contains(
"gas")) {
181 LOG(error) << GetName() <<
"::Exec: MC-track not in TRD! Node:"
182 << TString(gGeoManager->GetPath()).Data()
183 <<
" gGeoManager->MasterToLocal() failed!";
190 Double_t gamma = TMath::Sqrt(
191 1 + TMath::Power(track->
GetP() / (3.e8 * track->
GetMass()), 2));
199 Int_t nDigis(0), nofElectrons(0), nofLatticeHits(0),
200 nofPointsAboveThreshold(0), n0, n1, n2;
201 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin();
209 imod->second->GetCounters(n0, n1, n2);
211 nofLatticeHits += n1;
212 nofPointsAboveThreshold += n2;
213 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis =
214 imod->second->GetDigiMap();
216 for (std::map<Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it =
220 assert(it->second.second);
221 SendData(it->second.first, it->second.second);
229 Double_t digisOverPoints =
230 (nofPoints > 0) ? Double_t(nDigis) / Double_t(nofPoints) : 0;
231 Double_t latticeHitsOverElectrons =
232 (nofElectrons > 0) ? (Double_t) nofLatticeHits / (Double_t) nofElectrons
234 LOG(debug) <<
"CbmTrdDigitizer::Exec Points: " << nofPoints;
235 LOG(debug) <<
"CbmTrdDigitizer::Exec PointsAboveThreshold: "
236 << nofPointsAboveThreshold;
237 LOG(debug) <<
"CbmTrdDigitizer::Exec Digis: " << nDigis;
238 LOG(debug) <<
"CbmTrdDigitizer::Exec digis/points: "
240 LOG(debug) <<
"CbmTrdDigitizer::Exec BackwardTracks: "
242 LOG(debug) <<
"CbmTrdDigitizer::Exec LatticeHits: "
244 LOG(debug) <<
"CbmTrdDigitizer::Exec Electrons: " << nofElectrons;
245 LOG(debug) <<
"CbmTrdDigitizer::Exec latticeHits/electrons:"
246 << latticeHitsOverElectrons;
248 LOG(debug) <<
"CbmTrdDigitizer::Exec real time=" << timer.RealTime()
249 <<
" CPU time=" << timer.CpuTime();
252 LOG(info) <<
"+ " << setw(15) << GetName() <<
": Event " << setw(6) << right
255 <<
", digis: " << nDigis <<
". Exec time " << setprecision(6)
256 << timer.RealTime() <<
" s.";
261 LOG(info) << GetName() <<
": Processing analogue buffers";
263 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin();
266 nDigis += imod->second->FlushBuffer();
267 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis =
268 imod->second->GetDigiMap();
269 for (std::map<Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it =
273 assert(it->second.second);
274 SendData(it->second.first, it->second.second);
279 LOG(info) << GetName() <<
": " << nDigis
280 << (nDigis == 1 ?
" digi " :
" digis ")
281 <<
"created and sent to DAQ ";
287 LOG(info) <<
"=====================================";
288 LOG(info) << GetName() <<
": Finish run";
290 LOG(info) << GetName() <<
": Run summary ";
291 LOG(info) <<
"=====================================";
313 const char* path = gGeoManager->
GetPath();
319 if (moduleAddress != detId) {
320 LOG(error) <<
"CbmTrdDigitizer::AddModule: MC module ID " << detId
321 <<
" does not match geometry definition " << moduleAddress
322 <<
". Module init failed!";
325 LOG(debug) << GetName() <<
"::AddModule(" << path <<
" "
326 << (moduleType < 9 ?
'R' :
'T') <<
"] mod[" << moduleAddress
327 <<
"] ly[" << lyId <<
"] det[" << detId <<
"]";
329 if (moduleType >= 9) {
343 LOG(debug) << GetName() <<
"::AddModule : No Geo params for module @ "
344 << path <<
". Using default.";
347 module->SetGeoPar(pGeo);
353 LOG(debug) << GetName() <<
"::AddModule : No Read-Out params for module @ "
354 << path <<
". Using default.";
356 module->SetDigiPar(pDigi);
359 if (moduleType >= 9) {
364 LOG(debug) << GetName() <<
"::AddModule : No ASIC params for module @ "
365 << path <<
". Using default.";
369 module->SetAsicPar(pAsic);
375 LOG(debug) << GetName() <<
"::AddModule : No Gas params for module @ "
376 << path <<
". Using default.";
378 module->SetChmbPar(pChmb);
384 LOG(debug) << GetName() <<
"::AddModule : No Gain params for module @ "
385 << path <<
". Using default.";
387 module->SetGainPar(pGain);
393 module->SetDigitizer(
this);
405 for (std::map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin();
408 imod->second->ResetCounters();