// ----------------------------------------------------------------------------- // ----- run_digi_tb_hic.C ----- // ----- ----- // ----- created by C. Simon on 2018-02-17 ----- // ----- ----- // ----------------------------------------------------------------------------- void run_digi_tb_hic(Int_t nEvents = 2, const char* setupName = "sps_nov15", UInt_t uSeedIncrement = 1, Double_t dBeamIntensity = 1.e6, Double_t dInteractionProb = 0.01, Int_t iNThreads = 1, Double_t dSpillLength = 1., Double_t dSpillBreakLength = 0., Bool_t bAverageSpills = kFALSE, Int_t iNSerialSpills = 1, Bool_t bSingleTimeSlice = kFALSE, Bool_t bCalibrateDigis = kFALSE, const char* inputFilePath = "", Int_t nFiles = 1, Bool_t bRunWithMemory = kTRUE, Bool_t bEnforceTwoSidedReadout = kFALSE, Bool_t bGenerateDarkRate = kTRUE, Bool_t bIgnoreSignalInterference = kFALSE, Bool_t bIgnoreChannelDeadTime = kFALSE, Bool_t bStorePointsInTS = kFALSE, Bool_t bAlternativeBranchNames = kFALSE) { // TODO: Should the index range of simulated MC files ever exceed the current // interval [1,99999] which is represented by 5 consecutive digits in // the file name, the following lines need to be adapted accordingly. const char* cIndexRegexp = "[0-9][0-9][0-9][0-9][0-9]"; const char* cIndexFormat = "%05d"; // ======================================================================== // Adjust this part according to your requirements TString outDir = "data/"; TString parFile = outDir + setupName + "_params.root"; // Parameter file TString outFile = outDir + setupName + "_test.raw.root"; // Output file delete gRandom; gRandom = new TRandomMixMax(uSeedIncrement + 4357); // Specify log level (INFO, DEBUG, DEBUG1, ...) TString logLevel = "ERROR"; TString logVerbosity = "LOW"; gErrorIgnoreLevel = kWarning; TString inDir = gSystem->Getenv("VMCWORKDIR"); TString paramDir = inDir + "/parameters/"; // In general, the following parts need not be touched // ======================================================================== // ---- Set the log level FairLogger::GetLogger()->SetLogScreenLevel(logLevel.Data()); FairLogger::GetLogger()->SetLogVerbosityLevel(logVerbosity.Data()); TString setupFile = inDir + "/geometry/setup/setup_" + setupName + ".C"; TString setupFunct = TString("setup_") + setupName + "()"; gROOT->LoadMacro(setupFile); gInterpreter->ProcessLine(setupFunct); TList *parFileList = new TList(); TString geoTag; CbmSetup* setup = CbmSetup::Instance(); // - TOF digitisation parameters setup->GetGeoTag(kTof, geoTag); TObjString* tofDigiTbFile = new TObjString(paramDir + "tof/tof_"+ geoTag + ".digitb.par"); parFileList->Add(tofDigiTbFile); // ---- Debug option ------------------------------------------------- gDebug = 0; // ------------------------------------------------------------------------ // ----- Timer -------------------------------------------------------- TStopwatch timer; timer.Start(); // ------------------------------------------------------------------------ // ----- Reconstruction run ------------------------------------------- TString tFileNameEnd("/" + outDir + setupName + "_test.mc.root"); TString tFirstInputFileName(inputFilePath); tFirstInputFileName += tFileNameEnd; if(!tFirstInputFileName.EndsWith(".root")) { std::cout << "-E- run_digi_tb_hic: No valid input file name!" << std::endl; return; } TRegexp tRegexp(cIndexRegexp); TString tFirstInputFileIndexString(tFirstInputFileName(tRegexp)); if(!tFirstInputFileIndexString.IsDec()) { std::cout << "-E- run_digi_tb_hic: Index string not found in input file name!" << std::endl; return; } Int_t iFirstInputFileIndex = tFirstInputFileIndexString.Atoi(); TString tFileNameStart(tFirstInputFileName(0, tFirstInputFileName.Index(tRegexp))); CbmFileSource* source = new CbmFileSource(tFirstInputFileName); for(Int_t iIndex = iFirstInputFileIndex + 1; iIndex < iFirstInputFileIndex + nFiles; iIndex++) { TString tFileName = tFileNameStart + TString::Format(cIndexFormat, iIndex) + tFileNameEnd; source->AddFile(tFileName); } Double_t dMeanEventInterval = 1.e9/dBeamIntensity/dInteractionProb; // [ns] cout << "beam intensity: " << dBeamIntensity << " Hz" << endl; cout << "interaction probability: " << dInteractionProb << endl; cout << "mean time between events: " << dMeanEventInterval << " ns" << endl; /* TVectorD* InteractionProb(NULL); (source->GetInFile())->GetObject("InteractionProb", InteractionProb); if(InteractionProb) { if(0. < (*InteractionProb)[0]) { cout << "beam intensity: " << dBeamIntensity << " Hz" << endl; cout << "interaction probability: " << (*InteractionProb)[0] << endl; dMeanEventInterval = 1.e9/dBeamIntensity/(*InteractionProb)[0]; cout << "mean time between events: " << dMeanEventInterval << " ns" << endl; } } else { std::cout << "-E- run_digi_tb_hic: Interaction probability not found in input file!" << std::endl; return; } */ source->SetEventMeanTime(dMeanEventInterval); source->SetBeamTime(dSpillLength*1e9, dSpillBreakLength*1e9); source->SetMaxSpillNo(iNSerialSpills); source->SetEventTimeOffset((dSpillLength + dSpillBreakLength)*iNSerialSpills*(uSeedIncrement - 1)*1e9); // Specify duration of timeslices in output [ns] Double_t timeSliceSize = 0.; if(bSingleTimeSlice) { // calculated from spill properties timeSliceSize = ((dSpillLength + dSpillBreakLength)*iNSerialSpills + 0.5)*1e9; } else { // coupled to the mean time between two consecutive events timeSliceSize = 1000.*dMeanEventInterval; } CbmRunAna *run = new CbmRunAna(); source->SetFileHeader(run->GetFileHeader()); run->SetAsync(); // asynchroneous mode run->SetSource(source); run->SetOutputFile(outFile); // run->SetEventHeaderPersistence(kFALSE); // TODO: requires FairRoot v-17.03 FairRootManager::Instance()->SetUseFairLinks(kFALSE); /* FairMonitor::GetMonitor()->EnableMonitor(kTRUE); */ // ------------------------------------------------------------------------ // ---- MC point time ordering as required for the time-based ToF digitizer CbmMCTimeSim* timeSim = new CbmMCTimeSim(1.); timeSim->BufferSubDetector(kTof); if(bStorePointsInTS) { timeSim->IndexDetectorPoints(kTof); } run->AddTask(timeSim); CbmTofCounter::SetEnforceTwoSidedReadout(bEnforceTwoSidedReadout); CbmTofCounter::SetIgnoreSignalInterference(bIgnoreSignalInterference); CbmTofCounter::SetIgnoreChannelDeadTime(bIgnoreChannelDeadTime); CbmTofDigitizeDev* tofDigi = new CbmTofDigitizeDev(); tofDigi->SetMemorizeCharges(bRunWithMemory); tofDigi->SetGenerateDarkRate(bGenerateDarkRate); tofDigi->SetCalibrateDigis(bCalibrateDigis); tofDigi->SetNThreads(iNThreads); tofDigi->SetRemoveHitsFromMemory(kFALSE); tofDigi->SetHitRemovalCriterion(0.01); // FIXME if(bStorePointsInTS) { tofDigi->SetSendPointsToDAQ(kTRUE); } if(bAverageSpills) { tofDigi->SetClearMemoryInSpillBreak(kTRUE); } else { tofDigi->SetClearMemoryInSpillBreak(kFALSE); } tofDigi->SetSpillBreakLength(dSpillBreakLength); tofDigi->SetEventTimeOffset((dSpillLength + dSpillBreakLength)*iNSerialSpills*(uSeedIncrement - 1)*1e9); tofDigi->SetAlternativeBranchNames(bAlternativeBranchNames); tofDigi->SetFileIndex((Int_t)uSeedIncrement - 1); run->AddTask(tofDigi); // ----- DAQ CbmDaq* daq = new CbmDaq(timeSliceSize); daq->SetEventMode(kFALSE); daq->StoreAllTimeSlices(kTRUE); daq->SetDigitizer(kTof, tofDigi); daq->SetStartTimeOffset((dSpillLength + dSpillBreakLength)*iNSerialSpills*(uSeedIncrement - 1)*1e9); daq->SetDigiLinkRegistration(!bStorePointsInTS); run->AddTask(daq); // ----- Parameter database -------------------------------------------- FairRuntimeDb* rtdb = run->GetRuntimeDb(); FairParRootFileIo* parIo1 = new FairParRootFileIo(); FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo(); parIo1->open(parFile.Data(),"UPDATE"); parIo2->open(parFileList, "in"); rtdb->setFirstInput(parIo1); rtdb->setSecondInput(parIo2); rtdb->print(); // ------------------------------------------------------------------------ // ----- Intialise and run -------------------------------------------- rtdb->getListOfContainers()->Print(); run->Init(); rtdb->setOutput(parIo1); rtdb->closeOutput(); // rtdb->saveOutput(); rtdb->print(); cout << "Starting run" << endl; run->Run(0, nEvents); // ------------------------------------------------------------------------ // ----- Finish ------------------------------------------------------- timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); cout << endl << endl; cout << "Macro finished successfully." << endl; cout << "Output file is " << outFile << endl; cout << "Parameter file is " << parFile << endl; cout << "Digi Real time " << rtime << " s, CPU time " << ctime << " s" << endl; cout << Form("%2d %7.0f. %7.0f.", iNThreads, rtime, ctime) << endl; cout << endl; // ------------------------------------------------------------------------ // ----- Resource monitoring ------------------------------------------ FairSystemInfo sysInfo; Float_t maxMemory=sysInfo.GetMaxMemory(); std::cout << ""; std::cout << maxMemory; std::cout << "" << std::endl; Float_t cpuUsage=ctime/rtime; std::cout << ""; std::cout << cpuUsage; std::cout << "" << std::endl; /* FairMonitor* tempMon = FairMonitor::GetMonitor(); tempMon->Print(); */ cout << " Test passed" << endl; cout << " All ok " << endl; RemoveGeoManager(); // ------------------------------------------------------------------------ }