32#include <FairBaseParSet.h>
33#include <FairEventHeader.h>
34#include <FairRootManager.h>
35#include <FairRunAna.h>
36#include <FairRunSim.h>
37#include <FairRuntimeDb.h>
40#include <TClonesArray.h>
42#include <TStopwatch.h>
61 , nofBackwardTracks(0)
66 , fDigiMatches(nullptr)
93 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++)
105 fAsicPar =
static_cast<CbmTrdParSetAsic*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetAsic"));
106 fGasPar =
static_cast<CbmTrdParSetGas*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGas"));
107 fDigiPar =
static_cast<CbmTrdParSetDigi*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetDigi"));
108 fGainPar =
static_cast<CbmTrdParSetGain*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGain"));
115 FairRootManager* ioman = FairRootManager::Instance();
116 if (!ioman) LOG(fatal) <<
"CbmTrdDigitizer::Init: No FairRootManager";
118 fPoints = (TClonesArray*) ioman->GetObject(
"TrdPoint");
119 if (!
fPoints) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No TrdPoint array!";
121 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
122 if (!
fTracks) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No MCTrack array!";
126 fRadiator = make_shared<CbmTrdRadiator>(kTRUE,
"tdr18_25cm");
128 fRadiator = make_shared<CbmTrdRadiator>(kTRUE,
"tdr18");
143 if (!result.second) {
144 LOG(error) << GetName() <<
": Error in reading from file! Task will be inactive.";
147 LOG(info) << GetName() <<
": " << std::get<0>(result) <<
" lines read from file, " <<
fInactiveChannels.size()
148 <<
" channels set inactive";
154 LOG(info) <<
"================ TRD Digitizer ===============";
155 LOG(info) <<
" Free streaming : " << (
IsTimeBased() ?
"yes" :
"no");
156 LOG(info) <<
" Add Noise : " << (
AddNoise() ?
"yes" :
"no");
157 LOG(info) <<
" Weighted distance : " << (
UseWeightedDist() ?
"yes" :
"no");
178 gGeoManager->CdTop();
179 for (
Int_t iPoint = 0; iPoint < nofPoints; iPoint++) {
184 if (!point)
continue;
186 if (!track)
continue;
190 LOG(debug2) << GetName() <<
"::Exec: MC-track points towards target!";
195 map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.find(point->GetDetectorID());
201 gGeoManager->FindNode(meanX, meanY, meanZ);
202 if (!TString(gGeoManager->GetPath()).Contains(
"gas")) {
203 LOG(error) << GetName() <<
"::Exec: MC-track not in TRD! Node:" << TString(gGeoManager->GetPath()).Data()
204 <<
" gGeoManager->MasterToLocal() failed!";
212 Double_t gamma = TMath::Sqrt(1 + TMath::Power(track->
GetP() / (track->
GetMass()), 2));
219 Int_t nDigis(0), nofElectrons(0), nofLatticeHits(0), nofPointsAboveThreshold(0), n0, n1, n2;
220 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++) {
226 imod->second->GetCounters(n0, n1, n2);
228 nofLatticeHits += n1;
229 nofPointsAboveThreshold += n2;
230 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis = imod->second->GetDigiMap();
231 for (std::map<
Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it = digis->begin(); it != digis->end(); it++) {
232 assert(it->second.second);
247 Double_t digisOverPoints = (nofPoints > 0) ? Double_t(nDigis) / Double_t(nofPoints) : 0;
248 Double_t latticeHitsOverElectrons = (nofElectrons > 0) ? (Double_t) nofLatticeHits / (Double_t) nofElectrons : 0;
249 LOG(debug) <<
"CbmTrdDigitizer::Exec Points: " << nofPoints;
250 LOG(debug) <<
"CbmTrdDigitizer::Exec PointsAboveThreshold: " << nofPointsAboveThreshold;
251 LOG(debug) <<
"CbmTrdDigitizer::Exec Digis: " << nDigis;
252 LOG(debug) <<
"CbmTrdDigitizer::Exec digis/points: " << digisOverPoints;
254 LOG(debug) <<
"CbmTrdDigitizer::Exec LatticeHits: " << nofLatticeHits;
255 LOG(debug) <<
"CbmTrdDigitizer::Exec Electrons: " << nofElectrons;
256 LOG(debug) <<
"CbmTrdDigitizer::Exec latticeHits/electrons:" << latticeHitsOverElectrons;
258 LOG(debug) <<
"CbmTrdDigitizer::Exec real time=" << timer.RealTime() <<
" CPU time=" << timer.CpuTime();
261 LOG(info) <<
"+ " << setw(15) << GetName() <<
": Event " << setw(6) << right <<
fCurrentEvent <<
" at " << fixed
262 << setprecision(3) <<
fCurrentEventTime <<
" ns, points: " << nofPoints <<
", digis: " << nDigis
263 <<
". Exec time " << setprecision(6) << timer.RealTime() <<
" s.";
269 LOG(info) << GetName() <<
": Processing analogue buffers";
271 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++) {
272 nDigis += imod->second->FlushBuffer();
273 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis = imod->second->GetDigiMap();
274 for (std::map<
Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it = digis->begin(); it != digis->end(); it++) {
275 assert(it->second.second);
287 LOG(info) << GetName() <<
": " << nDigis << (nDigis == 1 ?
" digi " :
" digis ") <<
"created and sent to DAQ ";
294 LOG(info) <<
"=====================================";
295 LOG(info) << GetName() <<
": Finish run";
297 LOG(info) << GetName() <<
": Run summary ";
298 LOG(info) <<
"=====================================";
321 const TString& path = gGeoManager->
GetPath();
322 LOG(debug) << GetName() <<
"::AddModule(" << path <<
")"
323 <<
" det[" << detId <<
"]";
328 if (moduleAddress != detId) {
329 LOG(error) <<
"CbmTrdDigitizer::AddModule: MC module ID " << detId <<
" does not match geometry definition "
330 << moduleAddress <<
". Module init failed!";
336 LOG(error) << GetName() <<
"::AddModule : No Read-Out params for module " << detId <<
" @ " << path
337 <<
". Module init failed!";
346 trd2d = (moduleType >= 9);
347 LOG(debug) << GetName() <<
"::AddModule(" << path <<
" " << (trd2d ?
'2' :
'1') <<
"D] mod[" << moduleAddress;
351 if (moduleType == 10)
355 module = fModuleMap[moduleAddress] = new CbmTrdModuleSim2D(moduleAddress, lyId, orientation, UseFASP());
357 module->SetTimeSysOffset(-400);
362 const Char_t* ewin =
"Al;C;HC;C;Al";
380 fRadiator2D = make_shared<CbmTrdRadiator>(kTRUE,
"tdr18", ewin);
384 module->SetRadiator(fRadiator2D);
389 module = fModuleMap[moduleAddress] = new CbmTrdModuleSimR(moduleAddress, lyId, orientation);
390 module->SetMessageConverter(fConverter);
393 module->SetDigiPar(pDigi);
398 LOG(info) << GetName() <<
"::AddModule : No Geo params for module " << detId <<
" @ " << path <<
". Using default.";
399 module->SetGeoPar(new CbmTrdParModGeo(Form("TRD_%d", detId), path));
402 module->SetGeoPar(pGeo);
409 LOG(fatal) << GetName() <<
"::AddModule : No ASIC params for module " << detId <<
" @ " << path <<
". Abort.";
412 module->SetAsicPar(pAsic);
417 LOG(info) << GetName() <<
"::AddModule : No Gas params for module " << detId <<
" @ " << path
418 <<
". Using default.";
421 module->SetChmbPar(pChmb);
426 LOG(debug) << GetName() <<
"::AddModule : No Gain params for module " << detId <<
" @ " << path
427 <<
". Using default.";
430 module->SetGainPar(pGain);
433 if (
fRadiator)
module->SetRadiator(fRadiator);
436 module->SetDigitizer(this);
449 for (std::map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++)
450 imod->second->ResetCounters();
465 TString sysName =
"trd";
466 Int_t sysLength = sysName.Length() + 1;
467 gGeoManager->CdTop();
468 TGeoNode* cave = gGeoManager->GetCurrentNode();
469 for (
Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
470 TString volName = cave->GetDaughter(iNode)->GetVolume()->GetName();
471 if (volName.Contains(sysName.Data(), TString::kIgnoreCase)) {
472 geoTag = TString(volName(sysLength, volName.Length() - sysLength));
ClassImp(CbmConverterManager)
Helper class to convert unique channel ID back and forth.
TRD digitizer. Updated 24/04/2013 by Andrey Lebedev andrey.lebedev@gsi.de Updated 4/06/2018 by Alex B...
Helper class to extract information from the GeoManager.
virtual std::pair< size_t, bool > ReadInactiveChannels()
TString fInactiveChannelFileName
std::set< uint32_t > fInactiveChannels
Double_t fCurrentEventTime
Base class template for CBM digitisation tasks.
void SendData(Double_t time, CbmTrdDigi *digi, CbmMatch *match=nullptr)
double GetMass() const
Mass of the associated particle.
int32_t GetPdgCode() const
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
double GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
virtual void Exec(Option_t *option)
Inherited from FairTask.
CbmTrdParSetAsic * fAsicPar
parameter list for ASIC characterization
std::shared_ptr< CbmTrdRadiator > fRadiator2D
parametrization of 2D radiator TR yield
static void SetTimeBased(Bool_t set=kTRUE)
virtual void SetParContainers()
Inherited from FairTask.
CbmTrdRawToDigiR * fConverter
virtual InitStatus Init()
Inherited from FairTask.
CbmTrdParSetGas * fGasPar
parameter list for HV status
void ResetCounters()
Recursive reset all private monitoring counters.
CbmTrdParSetGain * fGainPar
parameter list for keV->ADC gain conversion
virtual void Finish()
Inherited from FairTask.
std::shared_ptr< CbmTrdRadiator > fRadiator
parametrization of radiator TR yield
TString GetGeoTag()
Get the TRD geo tag curently used.
static Bool_t UseWeightedDist()
Double_t fLastEventTime
time of last event [ns]
CbmTrdModuleSim * AddModule(Int_t detId)
Create module for current MC point.
static void SetUseFASP(Bool_t set=kTRUE)
CbmTrdDigitizer(std::shared_ptr< CbmTrdRadiator > radiator=nullptr)
Constructor.
std::map< Int_t, CbmTrdModuleSim * > fModuleMap
list of modules being processed
TClonesArray * fTracks
MC Track information.
virtual void ResetArrays()
Clear data arrays.
CbmTrdParSetDigi * fDigiPar
parameter list for read-out geometry
std::vector< CbmTrdDigi > * fDigis
Output CbmTrdDigi array.
std::vector< CbmMatch > * fDigiMatches
Output CbmMatch array.
TClonesArray * fPoints
Trd MC points.
static Bool_t IsTimeBased()
void FlushBuffers()
Flush local digi buffers to CbmDaqBuffer.
CbmTrdParSetGeo * fGeoPar
parameter list for geometry definitions
virtual ~CbmTrdDigitizer()
Destructor.
static Int_t fConfig
Configuration map for the digitizer. See CbmTrdSimDef for details.
Int_t GetModuleType(const TString &path)
Int_t GetRadiatorType(const TString &path)
Navigate to node and return the radiator type build in the geometry based on the naming convention.
Int_t GetModuleOrientation(const TString &path)
Return pad orientation of the current node in the TGeoManager.
Int_t GetModuleAddress()
Return module address calculated based on the current node in the TGeoManager.
virtual const Char_t * GetPath() const
Abstract class for module wise digitization and raw format producing.
virtual Bool_t MakeDigi(CbmTrdPoint *p, Double_t time, Bool_t TR=kFALSE)=0
Steering routine for converting MC point to digits.
virtual void SetLinkId(Int_t input, Int_t event=-1, Int_t point=-1)
virtual void SetGamma(Double_t gamma=0.)=0
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition of chamber gain conversion for one TRD module.
int GetPadPlaneType() const
Access the basic type of pad plane topology. For convenience also specific accessors are added for ea...
bool IsPadPlane2D() const
Definition of gain parameters for one TRD module.
Definition of gas parameters for one TRD module.
Definition of geometry for one TRD module.
Describe TRD module ASIC settings (electronic gain, delays, etc)
Describe TRD module working settings (HV, etc)