// -----------------------------------------------------------------------------
// ----- build_events.C -----
// ----- -----
// ----- created by C. Simon on 2018-05-24 -----
// ----- -----
// -----------------------------------------------------------------------------
void build_events(Int_t iNEvents, const TString& tInputFilePath, const TString& tInputFileName,
Int_t iNInputFiles, const TString& tMCLinkFileName, Int_t iNLinkFiles,
Double_t dEventWindow, Int_t iTriggerSet, Int_t iMultiplicity,
Bool_t bIgnoreCounterSides, Bool_t bHeavyIonCollisions, Bool_t bSimData)
{
// ---------------------------------------------------------------------------
TString tLogLevel = "ERROR";
TString tLogVerbosity = "LOW";
gErrorIgnoreLevel = kWarning;
gDebug = 0;
TTree::SetMaxTreeSize(1000000000000LL); // [B] here: 1 TB
// ---------------------------------------------------------------------------
TStopwatch tTimer;
tTimer.Start();
// ---------------------------------------------------------------------------
FairLogger::GetLogger()->SetLogScreenLevel(tLogLevel.Data());
FairLogger::GetLogger()->SetLogVerbosityLevel(tLogVerbosity.Data());
// ---------------------------------------------------------------------------
FairFileSource* tFileSource(NULL);
if(bSimData)
{
tFileSource = new FairFileSource(tInputFilePath + "/001/data/" + tInputFileName);
for(Int_t iInputFile = 2; iInputFile <= iNInputFiles; iInputFile++)
{
tFileSource->AddFile(tInputFilePath + TString::Format("/%03d/data/", iInputFile) + tInputFileName);
}
}
else
{
tFileSource = new FairFileSource("data/raw.out.root");
}
// ---------------------------------------------------------------------------
CbmRunAna* tRun = new CbmRunAna();
tRun->SetAsync(kTRUE);
tRun->SetContainerStatic(kTRUE);
tRun->SetSource(tFileSource);
tRun->SetOutputFile("data/unpack.out.root");
/*
FairMonitor::GetMonitor()->EnableMonitor(kTRUE);
*/
// ---------------------------------------------------------------------------
CbmMCDataManager* tDataManager = new CbmMCDataManager("MCManager");
if(bSimData)
{
if(bHeavyIonCollisions)
{
for(Int_t iInputFile = 1; iInputFile <= iNInputFiles; iInputFile++)
{
for(Int_t iLinkFile = 1; iLinkFile <= iNLinkFiles; iLinkFile++)
{
tDataManager->AddFileToChain(tInputFilePath + TString::Format("/%03d/data", iInputFile)
+ TString::Format("/mc/%05d/data/", iLinkFile)
+ tMCLinkFileName,
iInputFile - 1);
}
}
}
else
{
for(Int_t iInputFile = 1; iInputFile <= iNInputFiles; iInputFile++)
{
tDataManager->AddFileToChain(tInputFilePath + TString::Format("/%03d/data/", iInputFile)
+ tMCLinkFileName,
iInputFile - 1);
}
}
}
// ---------------------------------------------------------------------------
CbmTofBuildDigiEvents* tEventBuilder = new CbmTofBuildDigiEvents();
tEventBuilder->SetEventWindow(dEventWindow*(bSimData ? 1. : 1000.));
switch(iTriggerSet)
{
case 0:
// tEventBuilder->SetTriggerCounter(5, 1, 0, 1, -1, kTRUE);
tEventBuilder->SetTriggerCounter(5, 2, 0, 1, -1, kTRUE);
break;
case 1:
tEventBuilder->SetTriggerCounter(5, 1, 0, 1, 0, kTRUE);
tEventBuilder->SetTriggerCounter(5, 2, 0, 1, 0, kTRUE);
tEventBuilder->SetTriggerCounter(3, 0, 0, 2, -1, kFALSE);
// tEventBuilder->SetTriggerCounter(9, 0, 0, 2, -1, kFALSE);
// tEventBuilder->SetTriggerCounter(7, 0, 0, 2, -1, kFALSE);
// tEventBuilder->SetTriggerCounter(4, 0, 0, 2, -1, kFALSE);
break;
default:
std::cout << "-E- build_events: trigger set not implemented!" << std::endl;
return;
}
if(bIgnoreCounterSides)
{
tEventBuilder->SetIgnoreCounterSide(5, 1, 0, 1);
tEventBuilder->SetIgnoreCounterSide(5, 2, 0, 1);
}
tEventBuilder->SetTriggerMultiplicity(iMultiplicity);
tEventBuilder->SetPreserveMCBacklinks(kFALSE);
if(bSimData)
{
tEventBuilder->SetDigiTotOffset(10.);
}
else
{
tEventBuilder->SetPreserveMCBacklinks(kFALSE);
tEventBuilder->SetDigiTotOffset(-20000.); // in [ps]
}
tEventBuilder->SetRealData(!bSimData);
// ---------------------------------------------------------------------------
if(bSimData)
{
tRun->AddTask(tDataManager);
}
tRun->AddTask(tEventBuilder);
// ---------------------------------------------------------------------------
std::cout << "-I- build_events: initializing run..." << std::endl;
tRun->Init();
std::cout << "-I- build_events: starting run..." << std::endl;
tRun->Run(0, iNEvents);
// ---------------------------------------------------------------------------
tTimer.Stop();
Double_t dRealTime = tTimer.RealTime();
Double_t dCPUTime = tTimer.CpuTime();
std::cout << std::endl << std::endl;
std::cout << "Macro finished successfully." << std::endl;
std::cout << "Real time " << dRealTime << " s, CPU time " << dCPUTime << " s" << std::endl;
std::cout << std::endl;
// ---------------------------------------------------------------------------
// Extract the maximal used memory an add is as Dart measurement
// This line is filtered by CTest and the value send to CDash
FairSystemInfo tSysInfo;
Float_t fMaxMemory = tSysInfo.GetMaxMemory();
std::cout << "";
std::cout << fMaxMemory;
std::cout << "" << endl;
Float_t fCPUUsage = dCPUTime/dRealTime;
std::cout << "";
std::cout << fCPUUsage;
std::cout << "" << endl;
/*
FairMonitor::GetMonitor()->Print();
*/
// ---------------------------------------------------------------------------
FairRootManager::Instance()->CloseSink();
// ---------------------------------------------------------------------------
}