// -----------------------------------------------------------------------------
// ----- run_digi_tb_flood.C -----
// ----- -----
// ----- created by C. Simon on 2017-08-25 -----
// ----- -----
// -----------------------------------------------------------------------------
void run_digi_tb_flood(Int_t nEvents = 2, const char* setupName = "sps_nov15", UInt_t uSeedIncrement = 0,
Double_t dMeanEventInterval = 1000., 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 bRunWithMemory = kTRUE,
Bool_t bEquidistantEvents = kFALSE, Bool_t bAlternativeBranchNames = kFALSE,
Bool_t bEnforceTwoSidedReadout = kFALSE, Bool_t bCalibrateDigis = kFALSE,
Bool_t bStorePointsInTS = kFALSE, Bool_t bSingleCounter = kTRUE)
{
// ========================================================================
// Adjust this part according to your requirements
TString outDir = "data/";
TString inFile = outDir + setupName + "_test.mc.root"; // Input file (MC events)
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/";
TString setupFile = inDir + "/geometry/setup/setup_" + setupName + ".C";
TString setupFunct = TString("setup_") + setupName + "()";
gROOT->LoadMacro(setupFile);
gInterpreter->ProcessLine(setupFunct);
// In general, the following parts need not be touched
// ========================================================================
// ---- Set the log level
FairLogger::GetLogger()->SetLogScreenLevel(logLevel.Data());
FairLogger::GetLogger()->SetLogVerbosityLevel(logVerbosity.Data());
TList *parFileList = new TList();
TString geoTag;
CbmSetup* setup = CbmSetup::Instance();
// - TOF digitisation parameters
setup->GetGeoTag(kTof, geoTag);
TObjString* tofDigiTbFile = new TObjString("tof_" + geoTag + ".digitb.par");
parFileList->Add(tofDigiTbFile);
// ---- Debug option -------------------------------------------------
gDebug = 0;
// ------------------------------------------------------------------------
// ----- Timer --------------------------------------------------------
TStopwatch timer;
timer.Start();
// ------------------------------------------------------------------------
// ----- Reconstruction run -------------------------------------------
CbmFileSource* source = new CbmFileSource(inFile);
cout << "mean time between events: " << dMeanEventInterval << " ns" << endl;
if(bEquidistantEvents)
{
source->SetEventTimeInterval(dMeanEventInterval, dMeanEventInterval);
}
else
{
source->SetEventMeanTime(dMeanEventInterval);
}
source->SetBeamTime(dSpillLength*1e9, dSpillBreakLength*1e9);
source->SetMaxSpillNo(iNSerialSpills);
if(!bSingleCounter)
{
source->SetEventTimeOffset((dSpillLength + dSpillBreakLength)*iNSerialSpills*(uSeedIncrement - 1)*1e9);
}
// Specify duration of time slices 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);
CbmTofDigitizeDev* tofDigi = new CbmTofDigitizeDev();
tofDigi->SetMemorizeCharges(bRunWithMemory);
tofDigi->SetGenerateDarkRate(kFALSE);
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);
if(!bSingleCounter)
{
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);
if(!bSingleCounter)
{
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();
// ------------------------------------------------------------------------
}