18 #include "FairFileSource.h"
19 #include "FairLogger.h"
20 #include "FairMCEventHeader.h"
21 #include "FairMonitor.h"
22 #include "FairParAsciiFileIo.h"
23 #include "FairParRootFileIo.h"
24 #include "FairRuntimeDb.h"
25 #include "TClonesArray.h"
26 #include "TGeoManager.h"
33 : TNamed(
"CbmDigitization",
"Digitisation Run")
36 , fTimeSliceLength(-1.)
37 , fProduceNoise(kTRUE)
38 , fCreateMatches(kTRUE)
46 , fOverwriteOutput(kFALSE)
47 , fGenerateRunInfo(kTRUE)
56 LOG(debug) <<
"Destructing " << fName;
58 if (it->second)
delete it->second;
71 if (gSystem->AccessPathName(fileName))
72 LOG(fatal) << fName <<
": input file " << fileName <<
" does not exist!";
73 TChain* chain =
new TChain(
"cbmsim");
74 chain->Add(fileName.Data());
82 if (gSystem->AccessPathName(fileName.Data())) {
83 LOG(error) << fName <<
": Parameter file " << fileName
84 <<
" does not exist!";
88 LOG(info) << fName <<
": Adding parameter file " << fileName;
103 LOG(info) << fName <<
": Found branch " << entry.second->GetBranchName()
106 entry.second->SetPresent();
117 TFile* file = input->
GetChain()->GetFile();
119 TTree* tree =
dynamic_cast<TTree*
>(file->Get(
"cbmsim"));
121 FairMCEventHeader* header =
new FairMCEventHeader();
122 tree->SetBranchAddress(
"MCEventHeader.", &header);
124 fRun = header->GetRunID();
125 LOG(info) << fName <<
": Run id is " <<
fRun;
134 std::cout <<
"Create default digitisers" << std::endl;
138 ss << fName <<
": Create default digitisers: ";
143 if (!it->second->IsActive())
continue;
146 if (!it->second->IsPresent())
continue;
149 if (it->second->GetDigitizer() !=
nullptr)
continue;
153 LOG(info) <<
"MVD digitizer is not available "
154 <<
"in time-based mode. ";
157 LOG(info) <<
"system " << it->first;
196 default: LOG(fatal) << fName <<
": Unknown system " << system;
break;
199 LOG(info) << ss.str();
217 entry.second->SetActive(kFALSE);
227 UInt_t targetInputId,
229 if (gSystem->AccessPathName(fileName))
230 LOG(fatal) << fName <<
": input file " << fileName <<
" does not exist!";
231 TChain* chain =
new TChain(
"cbmsim");
232 chain->Add(fileName.Data());
244 Int_t sysLength = sysName.Length() + 1;
245 gGeoManager->CdTop();
246 TGeoNode* cave = gGeoManager->GetCurrentNode();
247 for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
248 TString volName = cave->GetDaughter(iNode)->GetVolume()->GetName();
249 if (volName.Contains(sysName.Data(), TString::kIgnoreCase)) {
250 geoTag = TString(volName(sysLength, volName.Length() - sysLength));
266 std::cout << std::endl << std::endl;
267 LOG(info) <<
"===================================================";
268 LOG(info) <<
"========== Initialize with default values =========";
271 TString word = (nBranches == 1 ?
"branch" :
"branches");
272 LOG(info) << fName <<
": " << nBranches <<
" input " << word <<
" found";
277 word = (nDigis == 1 ?
" digitiser" :
" digitisers");
278 LOG(info) << fName <<
": " << nDigis << word <<
" instantiated.";
282 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
283 FairParRootFileIo* parIoRoot =
new FairParRootFileIo();
285 rtdb->setFirstInput(parIoRoot);
289 rtdb->getContainer(
"FairGeoParSet");
290 rtdb->initContainers(
fRun);
295 TString srcDir = gSystem->Getenv(
"VMCWORKDIR");
297 if (trdGeo.Length() > 0) {
298 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".asic.par";
300 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".digi.par";
302 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".gain.par";
304 parFile = srcDir +
"/parameters/trd/trd_" + trdGeo +
".gas.par";
307 if (tofGeo.Length() > 0) {
308 parFile = srcDir +
"/parameters/tof/tof_" + tofGeo +
".digi.par";
310 parFile = srcDir +
"/parameters/tof/tof_" + tofGeo +
".digibdf.par";
319 if (gROOT->GetVersionInt() >= 60602) {
320 gGeoManager->GetListOfVolumes()->Delete();
321 gGeoManager->GetListOfShapes()->Delete();
326 std::cout << std::endl << std::endl;
327 LOG(info) <<
"===================================================";
338 std::cout << std::endl << std::endl;
339 LOG(info) <<
"===================================================";
344 std::cout << std::endl;
348 if (
fGenerateRunInfo) LOG(info) << fName <<
": Run info will be generated.";
364 LOG(info) << fName <<
": Output file is " <<
fOutFile;
369 FairMonitor::GetMonitor()->EnableMonitor(kTRUE,
fMoniFile);
370 LOG(info) << fName <<
": Monitor is enabled; monitor file is " <<
fMoniFile;
377 if (it->second->IsActive() && digitizer !=
nullptr) {
382 run->AddTask(digitizer);
383 LOG(info) << fName <<
": Added task " << digitizer->GetName();
397 LOG(info) << fName <<
": Setting runtime DB ";
399 FairRuntimeDb* rtdb = run->GetRuntimeDb();
400 FairParRootFileIo* parIoRoot =
new FairParRootFileIo();
403 LOG(info) << fName <<
": No ASCII input to parameter database";
404 rtdb->setFirstInput(parIoRoot);
407 FairParAsciiFileIo* parIoAscii =
new FairParAsciiFileIo();
409 rtdb->setFirstInput(parIoAscii);
410 rtdb->setSecondInput(parIoRoot);
412 LOG(info) <<
"===================================================";
416 std::cout << std::endl << std::endl;
417 LOG(info) <<
"===================================================";
418 LOG(info) << fName <<
": Initialising run...";
420 rtdb->setOutput(parIoRoot);
422 LOG(info) << fName <<
": Initialising run...finished";
423 LOG(info) <<
"===================================================";
427 std::cout << std::endl << std::endl << std::endl;
428 LOG(info) <<
"===================================================";
429 LOG(info) << fName <<
": Starting run...";
432 run->Run(0, event1 - 1);
436 if (event1 < 0) event1 = 0;
437 if (event1 <= event2)
438 run->Run(event1, event2);
440 run->Run(event1, event1);
442 std::cout << std::endl;
443 LOG(info) << fName <<
": Run finished.";
444 LOG(info) << fName <<
": Output file is " <<
fOutFile;
445 LOG(info) << fName <<
": Parameter file is " <<
fParRootFile;
447 LOG(info) << fName <<
": Monitor file is " <<
fMoniFile;
449 LOG(info) <<
"===================================================";
453 std::cout << std::endl << std::endl;
454 LOG(info) << fName <<
": CPU consumption";
455 if (!
fMoniFile.IsNull()) FairMonitor::GetMonitor()->Print();
456 std::cout << std::endl;
466 if (gROOT->GetVersionInt() >= 60602) {
467 gGeoManager->GetListOfVolumes()->Delete();
468 gGeoManager->GetListOfShapes()->Delete();
506 if (oldDigitizer !=
nullptr) {
507 LOG(warn) << fName <<
": replacing " << oldDigitizer->GetName() <<
" by "
508 << digitizer->GetName();
511 if (!branch.IsNull())
fDigitizers[system]->SetBranchName(branch);
520 new CbmDigitizeInfo(system, branch, digitizer, kFALSE, kTRUE, persistent);
529 if ((!gSystem->AccessPathName(path.Data())) && (!overwrite)) {
530 LOG(fatal) << fName <<
": output file " << path <<
" already exists!";
535 const char* directory = gSystem->DirName(path.Data());
536 if (gSystem->AccessPathName(directory)) {
537 Int_t success = gSystem->mkdir(directory, kTRUE);
539 LOG(fatal) << fName <<
": output directory " << directory
540 <<
" does not exist and cannot be created!";
542 LOG(info) << fName <<
": created directory " << directory;
552 if (gSystem->AccessPathName(fileName))
553 LOG(fatal) << fName <<
": parameter file " << fileName
554 <<
" does not exist!";