// ----------------------------------------------------------------------------- // ----- run_mc_flood.C ----- // ----- ----- // ----- created by C. Simon on 2017-08-25 ----- // ----- ----- // ----------------------------------------------------------------------------- void run_mc_flood(Int_t nEvents = 2, const char* setupName = "sps_nov15", UInt_t uSeedIncrement = 0, Int_t iModuleType = 9, Int_t iModuleIndex = 2, Int_t iCounterIndex = 1, Bool_t bSpotResponse = kFALSE, Bool_t bSingleCounter = kTRUE, Bool_t bXYPlaneVertex = kTRUE, Bool_t bNoTransportPhysics = kTRUE) { // FIXME: tells ROOT not to trap SIGSEGV to prevent it from getting stuck // if an incorrect Geant3 memory layout occurs gSystem->IgnoreSignal(kSigSegmentationViolation, kTRUE); // ======================================================================== // Adjust this part according to your requirement // --- Logger settings ---------------------------------------------------- TString logLevel = "ERROR"; TString logVerbosity = "LOW"; gErrorIgnoreLevel = kWarning; // ------------------------------------------------------------------------ // ----- Environment -------------------------------------------------- TString myName = "run_mc_flood"; // 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. // TString targetElement = "Lead"; Double_t targetThickness = 0.1; // full thickness in cm Double_t targetDiameter = 2.0; // diameter in cm 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] // ------------------------------------------------------------------------ // 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_flood" , 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(targetElement.Data(), targetThickness, 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_sim_new: 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(); CbmTofFloodIlluminator* floodGen = new CbmTofFloodIlluminator(); // floodGen->SetPDGType(0); // floodGen->SetMomentum(10.); floodGen->SetPDGType(13); floodGen->SetMomentum(3.); floodGen->SetCounter(iModuleType, iModuleIndex, iCounterIndex); if(bSpotResponse) { floodGen->SetWindow(0.5, 0.5, 0.5, 0.5); // 1cm^2 about the counter center // floodGen->SetWindow(1.0, 1.0, 1.0, 1.0); // 4cm^2 about the counter center (7-0-0) } else { floodGen->SetWindow(); // default: illuminate the full counter surface } if(!bSingleCounter) { floodGen->SetXYPlaneVertex(bXYPlaneVertex); floodGen->SetOriginVertex(!bXYPlaneVertex); floodGen->SetShiftWindowToYZPlane(kTRUE); floodGen->SetSmearGausBeamOnTarget(kTRUE); } floodGen->SetTarget(target); primGen->AddGenerator(floodGen); 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); } if(bSingleCounter) { tTofDetector->SetAllCountersInactive(kTRUE); tTofDetector->SetCounterActive(iModuleType, iModuleIndex, iCounterIndex); } else { // ----- 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; } } // ------------------------------------------------------------------------ } } else { std::cout << std::endl; std::cout << "-I- " << myName << ": ToF detector not found!" << std::endl; return; } // ----- Run initialisation ------------------------------------------- std::cout << std::endl; std::cout << "-I- " << myName << ": Initialise run" << std::endl; run->Init(); run->GetPrimaryGenerator()->Init(); // ABSOLUTELY necessary here!!! // ------------------------------------------------------------------------ // ----- 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(); // ------------------------------------------------------------------------ }