void runMC(Int_t field, TString gas, Int_t gain, TString outdir="./", int nEvents=5000, Int_t run = 1, unsigned int seed=4711) { // ------------------------------------------------------------------------ gRandom->SetSeed(seed); //gROOT->ProcessLine(".x $VMCWORKDIR/gconfig/rootlogon.C"); // ======================================================================== // Verbosity level (0=quiet, 1=event level, 2=track level, 3=debug) Int_t iVerbose = 1; FairRunSim *fRun = new FairRunSim(); // set the MC version used // -------------------------------------------------- TString mcMode = "TGeant3"; fRun->SetName(mcMode); TString jobdir=outdir; int length = jobdir.Length(); if(jobdir[length-1] != "/") jobdir.Append("/"); TString jobname=Form("Cosmics_FopiMC_%i%s%i_%i.mc.root",field,gas.Data(),gain,run); TString outfile = jobdir+jobname; std::cout<SetOutputFile(outfile); std::cout<<"Set output file to "<Getenv("VMCWORKDIR"); digifile += Form("/tpc/FOPI/par/tpc.%i%s%iMC_long.par",field,gas.Data(),gain); cout<GetRuntimeDb(); FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo(); parIo1->open(digifile.Data(),"in"); rtdb->setFirstInput(parIo1); Bool_t kParameterMerged=kTRUE; FairParRootFileIo* parOut=new FairParRootFileIo(kParameterMerged); parOut->open(parfile.Data()); rtdb->setOutput(parOut); TpcDigiPar* par = (TpcDigiPar*) rtdb->getContainer("TpcDigiPar"); par->setInputVersion(fRun->GetRunId(),1); par->setChanged(kTRUE); par->init(); //================================================================================ // build a run specific geometry // run the FopiGeom.C in a separate root session // // taroff: distance between target and center of magnet // targetpos: distance between real target position and nominal FOPI target // position // In experiment S339 the distance between the nominal FOPI target position // and the center of the magnet is 41 cm. /* Double_t taroff = -65; Double_t targetpos = taroff+41.; // possible materials: copper (default), lead, carbon TString targetmat = TString("copper"); TString alignmentFileName = par->getAlignmentFile(); TString geoFile; geoFile.Form("$VMCWORKDIR/geometry/FopiGeom_s339%5.1f.root",targetpos); TString geoFileName; geoFileName.Form("FopiGeom_s339%5.1f.root",targetpos); TString cmd; cmd.Form(".! root -b -q '$FOPI2ROOT/fopigeometry/FopiGeom.C(%f,\"%s\",\"%s\",\"%s\",kFALSE,kFALSE)'",targetpos,targetmat.Data(),alignmentFileName.Data(),geoFile.Data()); gROOT->ProcessLine(cmd);*/ // In general, the following parts need not be touched // ======================================================================== // ----- Timer -------------------------------------------------------- TStopwatch timer; timer.Start(); // ------------------------------------------------------------------------ // Set Material file Name //----------------------- fRun->SetMaterials("media_pnd.geo"); // Create and add detectors //------------------------- // FairModule *Cave= new FopiDetector("FOPI"); // Cave->SetGeometryFileName(geoFile); // fRun->AddModule(Cave); FairModule *Cave= new PndCave("CAVE"); Cave->SetGeometryFileName("pndcave.geo"); fRun->AddModule(Cave); TpcDetector *Tpc = new TpcDetector("TPC", kTRUE); Tpc->SetGeometryFileName("tpc_prototype_long_ArCO2.root"); Tpc->SetMixture("TPCFOPI_mix"); // TPCmixture: Neon CO2 (90/10); TPCFOPI_mix: Ar/CO2 (90/10) if(mcMode=="TGeant3") Tpc->SetAliMC(); fRun->AddModule(Tpc); FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); fRun->SetGenerator(primGen); FairBoxGeneratorMOD* boxGen = new FairBoxGeneratorMOD(13,1); //boxGen->SetDebug(kTRUE); boxGen->SetPRange(2,2); // GeV/c boxGen->SetPhiRange(270.,270.); // Azimuth angle range [degree] boxGen->SetThetaRange(90.,90.); // Polar angle in lab system range [degree] boxGen->SetBoxXYZ(-17,17, 17,17, -65, 440); primGen->AddGenerator(boxGen); // Create and Set Magnetic Field // -------------------- // Constant Field PndConstField *fMagField=new PndConstField(); fMagField->SetField(0., 0. , 6. ); // values are in kG fMagField->SetFieldRegion(-17, 17, -17, 17, -2000, 2000); // values are in cm fRun->SetField(fMagField); /**Initialize the session*/ fRun->Init(); // Initialize the Digimapper: // TpcDigiPar* tpcpar = FairRun::Instance()->GetRuntimeDb()->getContainer("TpcDigiPar"); // TpcDigiMapper::getInstance()->init(tpcpar); // //TpcDigiMapper::getInstance()->forceManualDriftVel(forceDriftVel); // TpcAlignmentManager::init(tpcpar->getAlignmentFile()); rtdb->saveOutput(); rtdb->print(); // Transport nEvents // ----------------- fRun->Run(nEvents); timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); cout << endl << endl; cout << "Macro finished succesfully." << endl; cout << "Output file is " << outfile << endl; cout << "Parameter file is " << parfile << endl; cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl; cout << endl; // ------------------------------------------------------------------------ }