// ----------------------------------------------------------------------------- // ----- run_mc_hic.C ----- // ----- ----- // ----- created by C. Simon on 2018-01-15 ----- // ----- ----- // ----------------------------------------------------------------------------- void run_mc_hic(Int_t nEvents = 2, const char* setupName = "sps_nov15", UInt_t uSeedIncrement = 0, const char* inputFile = "", Int_t nFiles = 1, Bool_t bNoTransportPhysics = kFALSE, Double_t dInteractionProb = 0.01) { // FIXME: tells ROOT not to trap SIGSEGV to prevent it from getting stuck // if an incorrect Geant3 memory layout occurs gSystem->IgnoreSignal(kSigSegmentationViolation, kTRUE); // 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 // --- Logger settings ---------------------------------------------------- TString logLevel = "ERROR"; TString logVerbosity = "LOW"; gErrorIgnoreLevel = kWarning; // ------------------------------------------------------------------------ // ----- Environment -------------------------------------------------- TString myName = "run_mc_hic"; // this macro's name for screen output TString srcDir = gSystem->Getenv("VMCWORKDIR"); // top source directory if(bNoTransportPhysics) { gSystem->Setenv("CONFIG_DIR", (srcDir + "/macro/tof/digitizer/gconfig/nophys").Data()); } else { gSystem->Setenv("CONFIG_DIR", (srcDir + "/macro/tof/digitizer/gconfig/real").Data()); } // ------------------------------------------------------------------------ // ----- In- and output file names ------------------------------------ TString outDir = "data/"; TString outFile = outDir + setupName + "_test.mc.root"; TString parFile = outDir + setupName + "_params.root"; TString geoFile = outDir + setupName + "_geofile_full.root"; // ------------------------------------------------------------------------ delete gRandom; gRandom = new TRandomMixMax(uSeedIncrement + 4357); // --- Define the target geometry ----------------------------------------- // // The target is not part of the setup, since one and the same setup can // and will be used with different targets. // The target is constructed as a tube in z direction with the specified // diameter (in x and y) and thickness (in z). It will be placed at the // specified position as daughter volume of the volume present there. It is // in the responsibility of the user that no overlaps or extrusions are // created by the placement of the target. // Double_t targetDiameter = 2.0; // diameter in cm (diamond dimensions: 2 x 2 cm^2) Double_t targetPosX = 0.; // target x position in global c.s. [cm] Double_t targetPosY = 0.; // target y position in global c.s. [cm] Double_t targetPosZ = 0.; // target z position in global c.s. [cm] // ------------------------------------------------------------------------ // --- Define the creation of the primary vertex ------------------------ // // The primary vertex point can be sampled in x and y either from a Gaussian // distribution or from a rectangular uniform distribution with the specified // beam profile widthes. In z, either a uniform distribution over the extension // of the target or a more physical exponential distribution parametrized with // the geometric mean free path of the beam particles in the target medium can // be chosen from. // By setting the respective flags to kFALSE, the primary vertex will always be // at the (0., 0.) in x and y and in the z centre of the target, respectively. // // Please note that the last smearing flag of a certain type in the list will // determine the behavior of the algorithm! // // If 'autoCorrectBeam' is true, then the beam profile is guaranteed to // be fully contained (up to +/- 5 sigma in the Gaussian case) in the target // profile. Bool_t smearVertexXY = kFALSE; Bool_t smearVertexZ = kFALSE; Bool_t smearGausVertexXY = kTRUE; Bool_t smearExpVertexZ = kTRUE; Bool_t autoCorrectBeam = kTRUE; Double_t beamWidthX = 1.; // Gaussian sigma of the beam profile in x [cm] Double_t beamWidthY = 1.; // Gaussian sigma of the beam profile in y [cm] // ------------------------------------------------------------------------ // In general, the following parts need not be touched // ======================================================================== // ----- Timer -------------------------------------------------------- TStopwatch timer; timer.Start(); // ------------------------------------------------------------------------ // ---- Debug option ------------------------------------------------- gDebug = 0; // ------------------------------------------------------------------------ // ----- Logger settings ---------------------------------------------- FairLogger::GetLogger()->SetLogScreenLevel(logLevel.Data()); FairLogger::GetLogger()->SetLogVerbosityLevel(logVerbosity.Data()); // ------------------------------------------------------------------------ // ----- Remove old CTest runtime dependency file --------------------- TString depFile = Remove_CTest_Dependency_File(outDir, "run_mc_hic" , setupName); // ------------------------------------------------------------------------ // ----- Create simulation run ---------------------------------------- FairRunSim* run = new FairRunSim(); run->SetName("TGeant3"); // Transport engine run->SetOutputFile(outFile); // Output file run->SetGenerateRunInfo(kFALSE); // Create FairRunInfo file // FIXME: 2019-08-24 disabled due to a // 'gFile' segfault in // 'FairRunInfo::WriteHistosToFile' // ------------------------------------------------------------------------ FairRootManager::Instance()->SetUseFairLinks(kFALSE); // ----- Load the geometry setup ------------------------------------- std::cout << std::endl; TString setupFile = srcDir + "/geometry/setup/setup_" + setupName + ".C"; TString setupFunct = "setup_"; setupFunct = setupFunct + setupName + "()"; std::cout << "-I- " << myName << ": Loading macro " << setupFile << std::endl; gROOT->LoadMacro(setupFile); gROOT->ProcessLine(setupFunct); // ------------------------------------------------------------------------ // ----- Create media ------------------------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Setting media file" << std::endl; run->SetMaterials("media.geo"); // Materials // ------------------------------------------------------------------------ // ----- Create and register modules ---------------------------------- std::cout << std::endl; TString macroName = gSystem->Getenv("VMCWORKDIR"); macroName += "/macro/run/modules/registerSetup.C"; std::cout << "Loading macro " << macroName << std::endl; gROOT->LoadMacro(macroName); gROOT->ProcessLine("registerSetup()"); // ------------------------------------------------------------------------ // ----- Create and register the target ------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Registering target" << std::endl; CbmTarget* target = new CbmTarget(); target->SetDiameter(targetDiameter); target->SetPosition(targetPosX, targetPosY, targetPosZ); run->AddModule(target); // ------------------------------------------------------------------------ // ----- Create magnetic field ---------------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Registering magnetic field" << std::endl; CbmFieldMap* magField = CbmSetup::Instance()->CreateFieldMap(); if ( ! magField ) { std::cout << "-E- run_mc_hic: No valid field!"; return; } run->SetField(magField); // ------------------------------------------------------------------------ // ----- Create PrimaryGenerator -------------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Registering event generators" << std::endl; FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); // --- Uniform distribution of event plane angle primGen->SetEventPlane(0., 2.*TMath::Pi()); // ------------------------------------------------------------------------ TString tFirstInputFileName(inputFile); if(!tFirstInputFileName.EndsWith(".root")) { std::cout << "-E- run_mc_hic: No valid input file name!" << std::endl; return; } TRegexp tRegexp(cIndexRegexp); TString tFirstInputFileIndexString(tFirstInputFileName(tRegexp)); if(!tFirstInputFileIndexString.IsDec()) { std::cout << "-E- run_mc_hic: Index string not found in input file name!" << std::endl; return; } Int_t iFirstInputFileIndex = tFirstInputFileIndexString.Atoi(); TString tFileNameStart(tFirstInputFileName(0, tFirstInputFileName.Index(tRegexp))); TString tFileNameEnd(".root"); // Use the CbmTofUnigenGenerator for the input CbmTofUnigenGenerator* uniGen = new CbmTofUnigenGenerator(tFirstInputFileName); for(Int_t iIndex = iFirstInputFileIndex + 1; iIndex < iFirstInputFileIndex + nFiles; iIndex++) { TString tFileName = tFileNameStart + TString::Format(cIndexFormat, iIndex) + tFileNameEnd; uniGen->AddFile(tFileName); } uniGen->SetTarget(target); uniGen->SetBeamSigmaX(beamWidthX); uniGen->SetBeamSigmaY(beamWidthY); uniGen->SetCollisionProbabilityZ(dInteractionProb); uniGen->SmearVertexXY(smearVertexXY); uniGen->SmearGausVertexXY(smearGausVertexXY); uniGen->SmearVertexZ(smearVertexZ); uniGen->SmearExpVertexZ(smearExpVertexZ); uniGen->SetAutoCorrectBeam(autoCorrectBeam); primGen->AddGenerator(uniGen); run->SetGenerator(primGen); // ------------------------------------------------------------------------ CbmTof* tTofDetector = dynamic_cast(run->GetListOfModules()->FindObject("TOF")); if(tTofDetector) { std::cout << std::endl; std::cout << "-I- " << myName << ": ToF detector found." << std::endl; tTofDetector->GenerateOnePointPerTrack(kTRUE); if(bNoTransportPhysics) { tTofDetector->SetProcessAnyTrack(kTRUE); } } else { std::cout << std::endl; std::cout << "-E- " << myName << ": ToF detector not found!" << std::endl; return; } // ----- Load the ToF counter setup ------------------------------------ std::cout << std::endl; setupFile = srcDir + "/macro/tof/setup/counters_" + setupName + ".C"; setupFunct = "counters_"; setupFunct = setupFunct + setupName + "()"; std::cout << "-I- " << myName << ": Loading macro " << setupFile << std::endl; if(-1 != gROOT->LoadMacro(setupFile)) { if(!gROOT->ProcessLine(setupFunct)) { std::cout << std::endl; std::cout << "-E- " << myName << ": ToF counter setup failed!" << std::endl; return; } } // ------------------------------------------------------------------------ // ----- Run initialisation ------------------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Initialise run" << std::endl; run->Init(); // ------------------------------------------------------------------------ // ----- Runtime database --------------------------------------------- std::cout << std::endl << std::endl; std::cout << "-I- " << myName << ": Set runtime DB" << std::endl; FairRuntimeDb* rtdb = run->GetRuntimeDb(); CbmFieldPar* fieldPar = (CbmFieldPar*) rtdb->getContainer("CbmFieldPar"); fieldPar->SetParameters(magField); fieldPar->setChanged(); fieldPar->setInputVersion(run->GetRunId(),1); Bool_t kParameterMerged = kTRUE; FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged); parOut->open(parFile.Data()); rtdb->setOutput(parOut); // rtdb->saveOutput(); rtdb->closeOutput(); rtdb->print(); // ------------------------------------------------------------------------ // ----- Start run ---------------------------------------------------- std::cout << std::endl << std::endl; std::cout << "-I- " << myName << ": Starting run" << std::endl; run->Run(nEvents); // ------------------------------------------------------------------------ // ----- Finish ------------------------------------------------------- run->CreateGeometryFile(geoFile); timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); std::cout << std::endl << std::endl; std::cout << "Macro finished successfully." << std::endl; std::cout << "Output file is " << outFile << std::endl; std::cout << "Parameter file is " << parFile << std::endl; std::cout << "Geometry file is " << geoFile << std::endl; std::cout << "MC Real time " << rtime << " s, CPU time " << ctime << "s" << std::endl << std::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; std::cout << " Test passed" << std::endl; std::cout << " All ok " << std::endl; // Function needed for CTest runtime dependency Generate_CTest_Dependency_File(depFile); RemoveGeoManager(); // ------------------------------------------------------------------------ }