/** * \file global_sim.C * * \brief Simulation macro for tutorial on the CBM Software Workshop. * * \author Andrey Lebedev * \date 2011 **/ void global_sim(Int_t nEvents = 100) { // Take SCRIPT environment variable // If script == "yes" than macro is executed via bash script. TString script = TString(gSystem->Getenv("SCRIPT")); // Files // This file names we will change for each simulation run via bash script. TString dir = "/data.local1/andrey/events/trd_v11a/"; //directory for output simulation files TString mcFile = dir + "mc.0000.root"; //MC file name TString parFile = dir + "param.0000.root"; //Parameter file name // Geometries TString caveGeom = "cave.geo"; TString targetGeom = "target_au_250mu.geo"; TString pipeGeom = "pipe_standard.geo"; TString mvdGeom = "";//"mvd_v07a.geo"; // This STS geometry we will change via bash script. TString stsGeom = "sts/sts_v11a.geo"; TString richGeom = "rich/rich_v08a.geo"; TString trdGeom = "trd/trd_v10b.geo"; TString tofGeom = "tof/tof_v07a.geo"; TString ecalGeom = "";//"ecal_FastMC.geo"; TString fieldMap = "field_v10e"; TString magnetGeom = "passive/magnet_v09e.geo"; // If SCRIPT environment variable is set to "yes", i.e. macro is run via script if (script == "yes") { dir = TString(gSystem->Getenv("OUTPUT_DIR")); mcFile = dir + "mc.0000.root"; parFile = dir + "param.0000.root"; stsGeom = TString(gSystem->Getenv("STS_GEOM")); } // ----- Magnetic field ----------------------------------------------- Double_t fieldZ = 50.; // field center z position Double_t fieldScale = 1.; // field scaling factor TStopwatch timer; timer.Start(); gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C"); basiclibs(); gROOT->LoadMacro("$VMCWORKDIR/macro/littrack/cbmrootlibs.C"); cbmrootlibs(); FairRunSim* fRun = new FairRunSim(); fRun->SetName("TGeant3"); // Transport engine fRun->SetOutputFile(mcFile); // Output file FairRuntimeDb* rtdb = fRun->GetRuntimeDb(); fRun->SetMaterials("media.geo"); // Materials if ( caveGeom != "" ) { FairModule* cave = new CbmCave("CAVE"); cave->SetGeometryFileName(caveGeom); fRun->AddModule(cave); cout << " --- " << caveGeom << endl; } if ( pipeGeom != "" ) { FairModule* pipe = new CbmPipe("PIPE"); pipe->SetGeometryFileName(pipeGeom); fRun->AddModule(pipe); cout << " --- " << pipeGeom << endl; } if ( targetGeom != "" ) { FairModule* target = new CbmTarget("Target"); target->SetGeometryFileName(targetGeom); fRun->AddModule(target); cout << " --- " << targetGeom << endl; } if ( magnetGeom != "" ) { FairModule* magnet = new CbmMagnet("MAGNET"); magnet->SetGeometryFileName(magnetGeom); fRun->AddModule(magnet); cout << " --- " << magnetGeom << endl; } if ( mvdGeom != "" ) { FairDetector* mvd = new CbmMvd("MVD", kTRUE); mvd->SetGeometryFileName(mvdGeom); fRun->AddModule(mvd); } if ( stsGeom != "" ) { FairDetector* sts = new CbmSts("STS", kTRUE); sts->SetGeometryFileName(stsGeom); fRun->AddModule(sts); cout << " --- " << stsGeom << endl; } if ( richGeom != "" ) { FairDetector* rich = new CbmRich("RICH", kTRUE); rich->SetGeometryFileName(richGeom); fRun->AddModule(rich); } if ( trdGeom != "" ) { FairDetector* trd = new CbmTrd("TRD",kTRUE ); trd->SetGeometryFileName(trdGeom); fRun->AddModule(trd); cout << " --- " << trdGeom << endl; } if ( tofGeom != "" ) { FairDetector* tof = new CbmTof("TOF", kTRUE); tof->SetGeometryFileName(tofGeom); fRun->AddModule(tof); cout << " --- " << tofGeom << endl; } if ( ecalGeom != "" ) { FairDetector* ecal = new CbmEcal("ECAL", kTRUE, ecalGeom.Data()); fRun->AddModule(ecal); } // ------------------------------------------------------------------------ // ----- Create magnetic field ---------------------------------------- std::cout << "FIELD MAP " << fieldMap << std::endl; CbmFieldMap* magField = NULL; if (fieldMap == "field_electron_standard" || fieldMap == "field_v10e") magField = new CbmFieldMapSym2(fieldMap); else if (fieldMap == "field_muon_standard" ) magField = new CbmFieldMapSym2(fieldMap); else if (fieldMap == "FieldMuonMagnet" ) magField = new CbmFieldMapSym3(fieldMap); else { cout << "===> ERROR: Unknown field map " << fieldMap << endl; exit; } magField->SetPosition(0., 0., fieldZ); magField->SetScale(fieldScale); fRun->SetField(magField); // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); FairBoxGenerator* boxGen1 = new FairBoxGenerator(11, 5); boxGen1->SetPtRange(0.,3.); boxGen1->SetPhiRange(0.,360.); boxGen1->SetThetaRange(2.5,25.); boxGen1->SetCosTheta(); boxGen1->Init(); primGen->AddGenerator(boxGen1); FairBoxGenerator* boxGen2 = new FairBoxGenerator(-11, 5); boxGen2->SetPtRange(0.,3.);; boxGen2->SetPhiRange(0.,360.); boxGen2->SetThetaRange(2.5,25.); boxGen2->SetCosTheta(); boxGen2->Init(); primGen->AddGenerator(boxGen2); fRun->SetGenerator(primGen); fRun->Init(); // ----- Runtime database --------------------------------------------- CbmFieldPar* fieldPar = (CbmFieldPar*) rtdb->getContainer("CbmFieldPar"); fieldPar->SetParameters(magField); fieldPar->setChanged(); fieldPar->setInputVersion(fRun->GetRunId(),1); Bool_t kParameterMerged = kTRUE; FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged); parOut->open(parFile.Data()); rtdb->setOutput(parOut); rtdb->saveOutput(); rtdb->print(); // ------------------------------------------------------------------------ // ----- Start run ---------------------------------------------------- fRun->Run(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 " << mcFile << endl; cout << "Real time used: " << rtime << "s " << endl; cout << "CPU time used : " << ctime << "s " << endl << endl << endl; // ------------------------------------------------------------------------ }