25#include <FairFileSource.h>
26#include <FairMCEventHeader.h>
27#include <FairMonitor.h>
28#include <FairParAsciiFileIo.h>
29#include <FairParRootFileIo.h>
30#include <FairRootFileSink.h>
31#include <FairRuntimeDb.h>
34#include <TClonesArray.h>
35#include <TGeoManager.h>
36#include <TObjString.h>
53 LOG(debug) <<
"Destructing " << fName;
55 if (it->second)
delete it->second;
65 if (gSystem->AccessPathName(fileName)) LOG(fatal) << fName <<
": input file " << fileName <<
" does not exist!";
67 LOG(fatal) << fName <<
": access modes other than kRegular are not yet supported!";
68 TChain* chain =
new TChain(
"cbmsim");
69 chain->Add(fileName.Data());
78 if (gSystem->AccessPathName(fileName.Data())) {
79 LOG(error) << fName <<
": Parameter file " << fileName <<
" does not exist!";
83 LOG(info) << fName <<
": Adding parameter file " << fileName;
99 LOG(info) << fName <<
": Found branch " << entry.second->GetBranchName() <<
" for system "
101 entry.second->SetPresent();
112 TFile* file = input->
GetChain()->GetFile();
114 TTree* tree = file->Get<TTree>(
"cbmsim");
116 FairMCEventHeader* header =
new FairMCEventHeader();
117 tree->SetBranchAddress(
"MCEventHeader.", &header);
119 fRun = header->GetRunID();
120 LOG(info) << fName <<
": Run id is " <<
fRun;
130 std::cout <<
"Create default digitisers" << std::endl;
132 std::stringstream ss;
134 ss << fName <<
": Create default digitisers: ";
139 if (!it->second->IsActive())
continue;
145 if (it->second->GetDigitizer() !=
nullptr)
continue;
155 LOG(info) <<
"system " << it->first;
204 default: LOG(fatal) << fName <<
": Unknown system " << system;
break;
207 LOG(info) << ss.str();
226 entry.second->SetActive(kFALSE);
235 if (gSystem->AccessPathName(fileName)) LOG(fatal) << fName <<
": input file " << fileName <<
" does not exist!";
236 TChain* chain =
new TChain(
"cbmsim");
237 chain->Add(fileName.Data());
250 Int_t sysLength = sysName.Length() + 1;
251 gGeoManager->CdTop();
252 TGeoNode* cave = gGeoManager->GetCurrentNode();
253 for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
254 TString volName = cave->GetDaughter(iNode)->GetVolume()->GetName();
255 if (volName.Contains(sysName.Data(), TString::kIgnoreCase)) {
256 geoTag = TString(volName(sysLength, volName.Length() - sysLength));
273 std::cout << std::endl << std::endl;
274 LOG(info) <<
"===================================================";
275 LOG(info) <<
"========== Initialize with default values =========";
278 TString word = (nBranches == 1 ?
"branch" :
"branches");
279 LOG(info) << fName <<
": " << nBranches <<
" input " << word <<
" found";
284 word = (nDigis == 1 ?
" digitiser" :
" digitisers");
285 LOG(info) << fName <<
": " << nDigis << word <<
" instantiated.";
289 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
290 FairParRootFileIo* parIoRoot =
new FairParRootFileIo();
292 rtdb->setFirstInput(parIoRoot);
296 rtdb->getContainer(
"FairGeoParSet");
297 rtdb->initContainers(
fRun);
303 TString srcDir = gSystem->Getenv(
"VMCWORKDIR");
305 if (trdGeo.Length() > 0) {
306 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".asic.par";
308 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".digi.par";
310 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".gain.par";
312 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".gas.par";
315 if (tofGeo.Length() > 0) {
316 parFile = srcDir +
"/parameters/tof/tof_" + tofGeo +
".digibdf.par";
319 if (fsdGeo.Length() > 0) {
320 parFile = srcDir +
"/parameters/fsd/fsd_" + fsdGeo +
".digi.par";
329 if (gROOT->GetVersionInt() >= 60602) {
330 gGeoManager->GetListOfVolumes()->Delete();
331 gGeoManager->GetListOfShapes()->Delete();
336 std::cout << std::endl << std::endl;
337 LOG(info) <<
"===================================================";
349 std::cout << std::endl << std::endl;
350 LOG(info) <<
"===================================================";
355 std::cout << std::endl;
359 if (
fGenerateRunInfo) LOG(info) << fName <<
": Run info will be generated.";
362 if (
fMode == Mode::EventByEvent)
376 run->SetSink(std::make_unique<FairRootFileSink>(
fOutFile).release());
377 LOG(info) << fName <<
": Output file is " <<
fOutFile;
382 FairMonitor::GetMonitor()->EnableMonitor(kTRUE,
fMoniFile);
383 LOG(info) << fName <<
": Monitor is enabled; monitor file is " <<
fMoniFile;
390 if (it->second->IsActive() && digitizer !=
nullptr) {
397 run->AddTask(digitizer);
398 LOG(info) << fName <<
": Added task " << digitizer->GetName();
412 LOG(info) << fName <<
": Setting runtime DB ";
414 FairRuntimeDb* rtdb = run->GetRuntimeDb();
415 FairParRootFileIo* parIoRoot =
new FairParRootFileIo();
418 LOG(info) << fName <<
": No ASCII input to parameter database";
419 rtdb->setFirstInput(parIoRoot);
422 FairParAsciiFileIo* parIoAscii =
new FairParAsciiFileIo();
424 rtdb->setFirstInput(parIoAscii);
425 rtdb->setSecondInput(parIoRoot);
427 LOG(info) <<
"===================================================";
431 std::cout << std::endl << std::endl;
432 LOG(info) <<
"===================================================";
433 LOG(info) << fName <<
": Initialising run...";
435 rtdb->setOutput(parIoRoot);
437 LOG(info) << fName <<
": Initialising run...finished";
438 LOG(info) <<
"===================================================";
442 std::cout << std::endl << std::endl << std::endl;
443 LOG(info) <<
"===================================================";
444 LOG(info) << fName <<
": Starting run...";
447 run->Run(0, event1 - 1);
452 if (event1 < 0) event1 = 0;
453 if (event1 <= event2)
454 run->Run(event1, event2);
456 run->Run(event1, event1);
458 std::cout << std::endl;
459 LOG(info) << fName <<
": Run finished.";
460 LOG(info) << fName <<
": Output file is " <<
fOutFile;
461 LOG(info) << fName <<
": Parameter file is " <<
fParRootFile;
464 LOG(info) <<
"===================================================";
468 std::cout << std::endl << std::endl;
469 LOG(info) << fName <<
": CPU consumption";
470 if (!
fMoniFile.IsNull()) FairMonitor::GetMonitor()->Print();
471 std::cout << std::endl;
481 if (gROOT->GetVersionInt() >= 60602) {
482 gGeoManager->GetListOfVolumes()->Delete();
483 gGeoManager->GetListOfShapes()->Delete();
488 TList* badlist = gROOT->GetListOfBrowsables();
489 badlist->Remove(badlist->FindObject(
"FairTaskList"));
518 if (oldDigitizer !=
nullptr) {
519 LOG(warn) << fName <<
": replacing " << oldDigitizer->GetName() <<
" by " << digitizer->GetName();
522 if (!branch.IsNull())
fDigitizers[system]->SetBranchName(branch);
540 if ((!gSystem->AccessPathName(path.Data())) && (!overwrite)) {
541 LOG(fatal) << fName <<
": output file " << path <<
" already exists!";
546 const char* directory = gSystem->DirName(path.Data());
547 if (gSystem->AccessPathName(directory)) {
548 Int_t success = gSystem->mkdir(directory, kTRUE);
550 LOG(fatal) << fName <<
": output directory " << directory <<
" does not exist and cannot be created!";
552 LOG(info) << fName <<
": created directory " << directory;
563 if (gSystem->AccessPathName(fileName)) LOG(fatal) << fName <<
": parameter file " << fileName <<
" does not exist!";
ECbmTreeAccess
Mode to read entries from a ROOT TTree.
@ kMvd
Micro-Vertex Detector.
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
ClassImp(CbmDigitization)
Class for producing RICH digis from from MCPoints.
TRD digitizer. Updated 24/04/2013 by Andrey Lebedev andrey.lebedev@gsi.de Updated 4/06/2018 by Alex B...
Task class for simulating the detector response of the t-zero detector.
CBM task class for filling digis into time slices.
void SetLatency(Double_t time)
Set the DAQ buffer latency.
void SetDigitizer(ECbmModuleId system, CbmDigitizeBase *digitizer)
Set the digitizer for a given system.
CbmMCInput * GetFirstInput()
First input from the first input set @value Pointer to first input.
const std::set< TString > & GetBranchList() const
List of branch names @value Reference to set of branch names.
Double_t GetStartTime()
Run start time.
void AddInput(UInt_t inputId, TChain *chain, cbm::sim::TimeDist dist, Double_t rate, ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Add a transport input.
void EmbedInput(UInt_t inputId, TChain *chain, UInt_t targetInputId, ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Embed a transport input.
void SetMode(cbm::sim::Mode mode)
Set event-by-event mode @value choice kTRUE if event-by-event mode.
void EmbedInput(UInt_t inputId, TString fileName, UInt_t targetInputId, ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Embed an input file into another one.
Int_t CheckInput()
Check the presence of input branches.
void SetParameterRootFile(TString fileName)
Set the parameter file name.
void DefaultInit()
Initialize the branches, digitizers and parameter files With default values.
void DeactivateAllBut(ECbmModuleId system)
Deactivate all systems except the specified one.
CbmDigitization()
Constructor.
Int_t CreateDefaultDigitizers()
Instantiate the default digitisers for the active systems.
TString fMoniFile
Resource monitoring information.
void Run()
Process all events from input.
void SetDigitizer(ECbmModuleId system, CbmDigitizeBase *digitizer, TString branch="", Bool_t persistent=kTRUE)
Set a digitizer explicitly.
void SetOutputFile(TString fileName, Bool_t overwrite=kFALSE)
Set the output file name.
CbmDigitizeBase * GetDigitizer(ECbmModuleId system)
Get the pointer on a given digitizer if existing.
std::map< ECbmModuleId, CbmDigitizeInfo * > fDigitizers
Bool_t AddParameterAsciiFile(TString fileName)
Add an ASCII parameter file.
TString fOutFile
Output data (digis)
TList fParAsciiFiles
ASCII parameter files.
void StoreAllTimeSlices(Bool_t choice=kTRUE)
Store all time-slices.
void Deactivate(ECbmModuleId system)
Deactivate a system for digitisation.
CbmDigitizationSource * fSource
Input source.
virtual ~CbmDigitization()
Destructor
TString GetGeoTag(ECbmModuleId system, TGeoManager *geo)
Get the geometry tag of a system from a TGeoManager.
Double_t fTimeSliceLength
TString fParRootFile
ROOT parameter file.
void SetDefaultBranches()
Default settings for digitizers.
void AddInput(UInt_t inputId, TString fileName, cbm::sim::TimeDist dist=cbm::sim::TimeDist::Poisson, Double_t eventRate=0., ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Add an input file.
Abstract base class for CBM digitisation tasks.
void SetRunStartTime(Double_t time)
Set the run start time.
virtual Double_t GetLatency() const =0
Detector system ID.
void SetCreateMatches(Bool_t choice=kTRUE)
Set creation of links to MC.
void SetProduceNoise(Bool_t choice=kTRUE)
Set production of inter-event noise.
void SetEventMode(Bool_t choice=kTRUE)
Set event-by-event mode.
Auxiliary class for CbmDigitize.
Class for the digitization of the CBM-FSD.
static TString GetModuleName(ECbmModuleId moduleId)
static TString GetModuleNameCaps(ECbmModuleId moduleId)
Class for producing RICH digis from from MCPoints.
void SetAsync(Bool_t async=kTRUE)
Task class for simulating the detector response of the STS.
CBM ToF digitizer using beam data distributions as hit/cluster models.