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)
80 if (fRadiator == NULL) fRadiator = make_shared<CbmTrdRadiator>(kTRUE,
"tdr18");
94 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++)
106 fAsicPar =
static_cast<CbmTrdParSetAsic*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetAsic"));
107 fGasPar =
static_cast<CbmTrdParSetGas*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGas"));
108 fDigiPar =
static_cast<CbmTrdParSetDigi*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetDigi"));
109 fGainPar =
static_cast<CbmTrdParSetGain*
>(FairRunAna::Instance()->GetRuntimeDb()->getContainer(
"CbmTrdParSetGain"));
116 FairRootManager* ioman = FairRootManager::Instance();
117 if (!ioman) LOG(fatal) <<
"CbmTrdDigitizer::Init: No FairRootManager";
119 fPoints = (TClonesArray*) ioman->GetObject(
"TrdPoint");
120 if (!
fPoints) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No TrdPoint array!";
122 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
123 if (!
fTracks) LOG(fatal) <<
"CbmTrdDigitizer::Init(): No MCTrack array!";
137 if (!result.second) {
138 LOG(error) << GetName() <<
": Error in reading from file! Task will be inactive.";
141 LOG(info) << GetName() <<
": " << std::get<0>(result) <<
" lines read from file, " <<
fInactiveChannels.size()
142 <<
" channels set inactive";
148 LOG(info) <<
"================ TRD Digitizer ===============";
149 LOG(info) <<
" Free streaming : " << (
IsTimeBased() ?
"yes" :
"no");
150 LOG(info) <<
" Add Noise : " << (
AddNoise() ?
"yes" :
"no");
151 LOG(info) <<
" Weighted distance : " << (
UseWeightedDist() ?
"yes" :
"no");
171 Int_t nofPoints =
fPoints->GetEntriesFast();
172 gGeoManager->CdTop();
173 for (Int_t iPoint = 0; iPoint < nofPoints; iPoint++) {
178 if (!point)
continue;
180 if (!track)
continue;
184 LOG(debug2) << GetName() <<
"::Exec: MC-track points towards target!";
189 map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.find(point->GetDetectorID());
195 gGeoManager->FindNode(meanX, meanY, meanZ);
196 if (!TString(gGeoManager->GetPath()).Contains(
"gas")) {
197 LOG(error) << GetName() <<
"::Exec: MC-track not in TRD! Node:" << TString(gGeoManager->GetPath()).Data()
198 <<
" gGeoManager->MasterToLocal() failed!";
206 Double_t gamma = TMath::Sqrt(1 + TMath::Power(track->
GetP() / (track->
GetMass()), 2));
213 Int_t nDigis(0), nofElectrons(0), nofLatticeHits(0), nofPointsAboveThreshold(0), n0, n1, n2;
214 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++) {
220 imod->second->GetCounters(n0, n1, n2);
222 nofLatticeHits += n1;
223 nofPointsAboveThreshold += n2;
224 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis = imod->second->GetDigiMap();
225 for (std::map<Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it = digis->begin(); it != digis->end(); it++) {
226 assert(it->second.second);
236 Double_t digisOverPoints = (nofPoints > 0) ? Double_t(nDigis) / Double_t(nofPoints) : 0;
237 Double_t latticeHitsOverElectrons = (nofElectrons > 0) ? (Double_t) nofLatticeHits / (Double_t) nofElectrons : 0;
238 LOG(debug) <<
"CbmTrdDigitizer::Exec Points: " << nofPoints;
239 LOG(debug) <<
"CbmTrdDigitizer::Exec PointsAboveThreshold: " << nofPointsAboveThreshold;
240 LOG(debug) <<
"CbmTrdDigitizer::Exec Digis: " << nDigis;
241 LOG(debug) <<
"CbmTrdDigitizer::Exec digis/points: " << digisOverPoints;
243 LOG(debug) <<
"CbmTrdDigitizer::Exec LatticeHits: " << nofLatticeHits;
244 LOG(debug) <<
"CbmTrdDigitizer::Exec Electrons: " << nofElectrons;
245 LOG(debug) <<
"CbmTrdDigitizer::Exec latticeHits/electrons:" << latticeHitsOverElectrons;
247 LOG(debug) <<
"CbmTrdDigitizer::Exec real time=" << timer.RealTime() <<
" CPU time=" << timer.CpuTime();
250 LOG(info) <<
"+ " << setw(15) << GetName() <<
": Event " << setw(6) << right <<
fCurrentEvent <<
" at " << fixed
251 << setprecision(3) <<
fCurrentEventTime <<
" ns, points: " << nofPoints <<
", digis: " << nDigis
252 <<
". Exec time " << setprecision(6) << timer.RealTime() <<
" s.";
258 LOG(info) << GetName() <<
": Processing analogue buffers";
260 for (map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++) {
261 nDigis += imod->second->FlushBuffer();
262 std::map<Int_t, std::pair<CbmTrdDigi*, CbmMatch*>>* digis = imod->second->GetDigiMap();
263 for (std::map<Int_t, pair<CbmTrdDigi*, CbmMatch*>>::iterator it = digis->begin(); it != digis->end(); it++) {
264 assert(it->second.second);
271 LOG(info) << GetName() <<
": " << nDigis << (nDigis == 1 ?
" digi " :
" digis ") <<
"created and sent to DAQ ";
278 LOG(info) <<
"=====================================";
279 LOG(info) << GetName() <<
": Finish run";
281 LOG(info) << GetName() <<
": Run summary ";
282 LOG(info) <<
"=====================================";
305 const TString& path = gGeoManager->
GetPath();
306 LOG(debug) << GetName() <<
"::AddModule(" << path <<
")"
307 <<
" det[" << detId <<
"]";
312 if (moduleAddress != detId) {
313 LOG(error) <<
"CbmTrdDigitizer::AddModule: MC module ID " << detId <<
" does not match geometry definition "
314 << moduleAddress <<
". Module init failed!";
320 LOG(error) << GetName() <<
"::AddModule : No Read-Out params for module " << detId <<
" @ " << path
321 <<
". Module init failed!";
330 trd2d = (moduleType >= 9);
331 LOG(debug) << GetName() <<
"::AddModule(" << path <<
" " << (trd2d ?
'2' :
'1') <<
"D] mod[" << moduleAddress;
335 if (moduleType == 10)
339 module = fModuleMap[moduleAddress] = new CbmTrdModuleSim2D(moduleAddress, lyId, orientation, UseFASP());
341 module->SetTimeSysOffset(-400);
346 const Char_t* ewin =
"Al;C;HC;C;Al";
364 fRadiator2D = make_shared<CbmTrdRadiator>(kTRUE,
"tdr18", ewin);
368 module->SetRadiator(fRadiator2D);
373 module = fModuleMap[moduleAddress] = new CbmTrdModuleSimR(moduleAddress, lyId, orientation);
374 module->SetMessageConverter(fConverter);
377 module->SetDigiPar(pDigi);
382 LOG(info) << GetName() <<
"::AddModule : No Geo params for module " << detId <<
" @ " << path <<
". Using default.";
383 module->SetGeoPar(new CbmTrdParModGeo(Form("TRD_%d", detId), path));
386 module->SetGeoPar(pGeo);
393 LOG(fatal) << GetName() <<
"::AddModule : No ASIC params for module " << detId <<
" @ " << path <<
". Abort.";
396 module->SetAsicPar(pAsic);
401 LOG(info) << GetName() <<
"::AddModule : No Gas params for module " << detId <<
" @ " << path
402 <<
". Using default.";
405 module->SetChmbPar(pChmb);
410 LOG(debug) << GetName() <<
"::AddModule : No Gain params for module " << detId <<
" @ " << path
411 <<
". Using default.";
414 module->SetGainPar(pGain);
417 if (
fRadiator)
module->SetRadiator(fRadiator);
420 module->SetDigitizer(this);
433 for (std::map<Int_t, CbmTrdModuleSim*>::iterator imod =
fModuleMap.begin(); imod !=
fModuleMap.end(); imod++)
434 imod->second->ResetCounters();
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()
Set of inactive channels, indicated by CbmAddress.
Int_t fCurrentEvent
Number of current input.
TString fInactiveChannelFileName
Time of current MC event [ns].
std::set< uint32_t > fInactiveChannels
Name of file with inactive channels.
void GetEventInfo()
Get event information.
Int_t fCurrentInput
Start time of run [ns].
Double_t fCurrentEventTime
Number of current MC entry.
Int_t fCurrentMCEntry
Number of current MC event.
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
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)
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const