FairRoot/PandaRoot
runLumiSimBox.cxx
Go to the documentation of this file.
1 /*
2  * runLumiSimBox.cxx
3  *
4  * Created on: Nov 28, 2012
5  * Author: jasinski
6  */
7 
8 
9 
10 // Panda FullSim macro
11 
12 /*
13 #include<TString.h>
14 #include<TStopwatch.h>
15 #include<TROOT.h>
16 #include<FairModule.h>
17 #include<PndCave.h>
18 #include<PndMagnet.h>
19 #include<PndPipe.h>
20 #include<PndMvdDetector.h>
21 #include<FairRunSim.h>
22 #include<PndLmdDetector.h>
23 #include<FairPrimaryGenerator.h>
24 #include<FairBoxGenerator.h>
25 #include<PndMultiField.h>
26 #include<PndTransMap.h>
27 #include<PndDipoleMap.h>
28 #include<PndSolenoidMap.h>
29 #include<FairParRootFileIo.h>
30 #include<PndMultiFieldPar.h>
31 // important for compiled version ****************
32 #include<PndSensorNameContFact.h>
33 #include<FairBaseContFact.h>
34 #include<PndFieldContFact.h>
35 #include <PndPassiveContFact.h>
36 #include <TSystem.h>
37 // ******************important for compiled version
38 */
39 //#include<.h>
40 
41 int nEvents = 1000000; // number of primary events
42 double mom = 15; // beam momentum
43 double mom_spread = 1e-4; // HESR momentum resolution (relative to mom)
44 double dx = -0.; // displacement of the primary vertex in x
45 double dy = -0.; // displacement of the primary vertex in y
46 double phi_low = 0;
47 double phi_high = 360.;
48 double theta_low = 3.e-3/3.141 *180.; //2.5 mrad
49 double theta_high = 10.e-3/3.141 *180.; //10 mrad
50 TString storePath="."; //tmpOutput";
51 const int particle=-2212; // particle id (-2212 = antiproton)
52 
53 //static TROOT* pROOT = gROOT;
54 
55 //void runLumi0SimBox(const int nEvents=10, const double mom=15, TString storePath="tmpOutput", const int verboseLevel=0, const int particle=-211)
57 {
58 
59 // cout << nEvents << " " << mom << " " << dx << " " << dy << " " << endl;
60  const int verboseLevel=0;//7;
61  TStopwatch timer;
62  timer.Start();
63  gDebug=0;
64 
65  //output1
66  TString simOutput=storePath+"/Lumi_MC.root";
67  TString parOutput=storePath+"/Lumi_Params.root";
68 
69  //Load basic libraries
70  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
71  gSystem->Load("libSds");
72  gSystem->Load("libLmd");
73  FairRunSim *fRun = new FairRunSim();
74  std::cout<<"All libraries successfully loaded!"<<std::endl;
75 
76  //set the MC version used
77  fRun->SetName("TGeant4");
78  //fRun->SetName("TGeant3");
79 
80  fRun->SetOutputFile(simOutput);
81 
82  //fRun->SetRadMapRegister(true);
83  //fRun->SetRadLenRegister(true);
84  std::cout << "$VMCWORKDIR is " << getenv("VMCWORKDIR") << " ." << std::endl;
85 
86  /*
87  // ************ important when running standalone *********************
88  // initialization of singleton classes
89  PndSensorNameContFact& sensornamecontfact = PndSensorNameContFact::gPndSensorNameContFact();
90  FairBaseContFact& basecontfact = FairBaseContFact::gFairBaseContFact();
91  PndFieldContFact& fieldcontfact = PndFieldContFact::gPndFieldContFact();
92  PndPassiveContFact& passivecontfact = PndPassiveContFact::gPndPassiveContFact();
93  // ***********************************************************************
94 */
95 
96  //set material
97  fRun->SetMaterials("media_pnd.geo");
98 
99  //create and add detectors
100  FairModule *Cave= new PndCave("CAVE");
101  Cave->SetGeometryFileName("pndcaveVAC.geo");
102  fRun->AddModule(Cave);
103 
104  FairModule *Magnet= new PndMagnet("MAGNET");
105  Magnet->SetGeometryFileName("FullSolenoid.root");
106  fRun->AddModule(Magnet);
107 
108  FairModule *Dipole= new PndMagnet("MAGNET");
109  Dipole->SetGeometryFileName("dipole.geo");
110  fRun->AddModule(Dipole);
111 
112  //FairModule *Pipe= new PndPipe("PIPE");
113  //Pipe->SetGeometryFileName("pipebeamtarget.geo");
114  //fRun->AddModule(Pipe);
115 
116  FairModule *Pipe= new PndPipe("PIPE");
117  Pipe->SetGeometryFileName("beampipe_201303.root");// with lumi beam pipe
118  //Pipe->SetGeometryFileName("beampipe_201202_no_lmd_pipe.root");
119  //Pipe->SetGeometryFileName("beampipe_201112.root");
120  //Pipe->SetGeometryFileName("../macro/lmd/geo/HV_MAPS-Design.root");
121  fRun->AddModule(Pipe);
122 
123  /*FairDetector *Stt= new PndStt("STT", kFALSE);
124  Stt->SetGeometryFileName("straws_skewed_blocks.geo");
125  fRun->AddModule(Stt);*/
126 
127  //FairDetector *Mvd = new PndMvdDetector("MVD", kFALSE);
128  //Mvd->SetGeometryFileName("MVD_v1.0_woPassiveTraps.root");
129  //fRun->AddModule(Mvd);
130 
131  /* PndEmc *Emc = new PndEmc("EMC",kFALSE);
132  Emc->SetGeometryFileNameDouble("emc_module1245.dat","emc_module3new.root"); // if you want to use new geometry for FwEndCap
133  fRun->AddModule(Emc);
134 
135  FairDetector *Tof = new PndTof("TOF",kFALSE);
136  Tof->SetGeometryFileName("tofbarrel.geo");
137  fRun->AddModule(Tof);
138 
139  FairDetector *Drc = new PndDrc("DIRC", kFALSE);
140  Drc->SetGeometryFileName("dirc.geo");
141  fRun->AddModule(Drc);
142 
143  PndMdt *Muo = new PndMdt("MDT",kFALSE);
144  Muo->SetGeometryFileName("muopars.root");
145  Muo->SetMdtVersion("torino");
146  fRun->AddModule(Muo);*/
147 
148 
149 
150  PndLmdDetector *Lum = new PndLmdDetector("LUM", kTRUE);
151  Lum->SetExclusiveSensorType("LumActive"); //ignore MVD
152  //Lum->SetGeometryFileName("../macro/lmd/geo/F0-Design.root"); //!!!
153  //Lum->SetGeometryFileName("HV_MAPS-Design_mod.root"); //!!!
154  Lum->SetGeometryFileName("HV_MAPS-Design_mod_cone.root");
155  //Lum->SetGeometryFileName("beampipe_201303_active.root");
156  //Lum->SetGeometryFileName("../macro/lmd/geo/beampipe_201205_w_sensors.root"); //!!!
157 
158  // Lum->SetGeometryFileName("../macro/lmd/geo/MyTest-Dipol-Design.root"); //!!!
159 
160  // Mvd->SetGeometryFileName("lumi.geo");
161  // Mvd->SetGeometryFileName("MVD14.root");
162  Lum->SetVerboseLevel(verboseLevel);
163  fRun->AddModule(Lum);
164 
165  // FairDetector *Stt= new CbmStt("STT", kTRUE);
166  // Stt->SetGeometryFileName("straws_axial.geo");
167  // fRun->AddModule(Stt);
168 
169  // FairDetector *Emc = new CbmEmc("EMC",kTRUE);
170  // Emc->SetGeometryFileName("emc_module12345.dat");
171  // fRun->AddModule(Emc);
172 
173  // FairDetector *Drc = new CbmDrc("DIRC", kTRUE);
174  // Drc->SetGeometryFileName("dirc.geo");
175  // fRun->AddModule(Drc);
176 
177 
178  //particle generator
179  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
180  fRun->SetGenerator(primGen);
181 
182  // Particle Generator (pdgid,mult, px,py,pz, vx,vy,vz)
183 
184  // single pions for testing
185  // FairParticleGenerator* partGenX = new FairParticleGenerator(211,1, 1.,0.,0., 0.,0.,0.);
186  // FairParticleGenerator* partGenY = new FairParticleGenerator(211,1, 0.,1.,0., 0.,0.,0.);
187  // FairParticleGenerator* partGenZ = new FairParticleGenerator(211,1, 0.,0.1,1., 0.,0.,0.);
188  // FairParticleGenerator* partGenXYZ = new FairParticleGenerator(211,1, 1.,1.,5., 0.,0.,0.);
189  // primGen->AddGenerator(partGenX);
190  // primGen->AddGenerator(partGenY);
191  // primGen->AddGenerator(partGenZ);
192  // primGen->AddGenerator(partGenXYZ);
193 
194  // Ion Generator
195  // FairIonGenerator *fIongen= new FairIonGenerator(79, 197,79,1, 0.,0., 25, 0.,0.,-1.);
196  // primGen->AddGenerator(fIongen);
197 
198  // Box Generator
199  FairBoxGenerator *fBox = new FairBoxGenerator(particle, 1);
200  //FairBoxGenerator *fBox = new FairBoxGenerator(0, 1);
201  fBox->SetPRange(mom-mom*mom_spread,mom+mom*mom_spread); // momentum +- 10e-4
202  //fBox->SetThetaRange(0.2,0.4); //3...8 mrad
203  // fBox->SetThetaRange(0.13,0.56);
204  // fBox->SetThetaRange(0.13,0.7); // 2... 12 mrad
205  // fBox->SetThetaRange(0.3,0.3);
206  // fBox->SetThetaRange(0.,0.7);
207  //fBox->SetThetaRange(1e-3/3.141 *180., 10e-3/3.141 *180.);
208  //fBox->SetThetaRange(1e-8/3.141 *180., 1e-3/3.141 *180.);
209  //fBox->SetThetaRange(4e-3/3.141 *180., 8e-3/3.141 *180.);
210  // fBox->SetThetaRange(0., 3.14);
211  // fBox->SetThetaRange(0.4, 0.46); //7-8 mrad
212  //fBox->SetThetaRange(0.257831, 0.315127); //4.5 ... 5.5 mrad
213  // fBox->SetThetaRange(0.257831, 0.257831); //4.5 mrad
214  // fBox->SetThetaRange(0., 90.);
215  // fBox->SetPhiRange(0.,360.);
216  //fBox->SetThetaRange(0., 0.);
217  //fBox->SetPhiRange(89.,91.);
218  // fBox->SetPhiRange(0.,20.);//TEST
219  // fBox->SetPhiRange(44.,46.);
220  //fBox->SetPhiRange(-90.,90.);
221  // fBox->SetPhiRange(22.5,22.5);
222 
223  fBox->SetThetaRange(theta_low, theta_high);
224  fBox->SetPhiRange(phi_low, phi_high);
225 
226  fBox->SetXYZ(dx, dy, 0.);
227 
228  //fBox->SetThetaRange(0.,0.); //3.5 ... 8.? mrad
229  //fBox->SetPhiRange(-90.,-90.);
230  //
231  // fBox->SetPhiRange(1*180./TMath::Pi(),2*180./TMath::Pi());
232  //fBox->SetPhiRange(80.,100.);
233  primGen->AddGenerator(fBox);
234 
235 
236  // //EvtGen Generator
237  // PndEvtGenDirect *EvtGen = new PndEvtGenDirect("pbarpSystem","PBARSYSTEMTO4PIPHSP.DEC",mom);
238  // primGen->AddGenerator(EvtGen);
239 
240 
241  // Urqmd Generator
242  // FairUrqmdGenerator* urqmdGen = new FairUrqmdGenerator("../../input/00-03fm.100ev.f14");
243  // primGen->AddGenerator(urqmdGen);
244 
245  // DPM Generator
246  // PndDpmGenerator* dpmGen = new PndDpmGenerator("DpmInput/el_100k_aida/el_6_2GeV.root");
247  // primGen->AddGenerator(dpmGen);
248 
249 
250  //reading the new field map in the old format
251  fRun->SetBeamMom(mom);
253 
254  PndTransMap *map_t = new PndTransMap("TransMap", "R");
255  PndDipoleMap *map_d1 = new PndDipoleMap("DipoleMap1", "R");
256  PndDipoleMap *map_d2 = new PndDipoleMap("DipoleMap2", "R");
257  //PndTransMap *map_t = new PndTransMap("TransMap", "R");
258  //PndDipoleMap *map_d1 = new PndDipoleMap("DipoleMap1", "R");
259  //PndDipoleMap *map_d2 = new PndDipoleMap("DipoleMap2", "R");
260  PndSolenoidMap *map_s1 = new PndSolenoidMap("SolenoidMap1", "R");
261  PndSolenoidMap *map_s2 = new PndSolenoidMap("SolenoidMap2", "R");
262  PndSolenoidMap *map_s3 = new PndSolenoidMap("SolenoidMap3", "R");
263  PndSolenoidMap *map_s4 = new PndSolenoidMap("SolenoidMap4", "R");
264 
265  fField->AddField(map_t);
266  fField->AddField(map_d1);
267  fField->AddField(map_d2);
268  fField->AddField(map_s1);
269  fField->AddField(map_s2);
270  fField->AddField(map_s3);
271  fField->AddField(map_s4);
272 
273  fRun->SetField(fField);
274 
275  if(nEvents<101)
276  fRun->SetStoreTraj(kTRUE); // toggle this for use with EVE
277  else
278  fRun->SetStoreTraj(kFALSE);
279 
280 
281  fRun->Init();
282 
283  // -Trajectories Visualization (TGeoManager Only )
284  // -----------------------------------------------
285 
286  // Set cuts for storing the trajectpries
287 // FairTrajFilter* trajFilter = FairTrajFilter::Instance();
288 // trajFilter->SetStepSizeCut(0.01); // 1 cm
289 // trajFilter->SetVertexCut(-200., -200., -200, 200., 200., 200.);
290 // trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
291 // trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
292 // trajFilter->SetStorePrimaries(kTRUE);
293 // trajFilter->SetStoreSecondaries(kTRUE);
294 
295 
296  // Fill the Parameter containers for this run
297  //-------------------------------------------
298  FairRuntimeDb *rtdb=fRun->GetRuntimeDb();
299  Bool_t kParameterMerged=kTRUE;
300  FairParRootFileIo* output=new FairParRootFileIo(kParameterMerged);
301  output->open(parOutput.Data(),"RECREATE");
302  rtdb->setOutput(output);
303  PndMultiFieldPar* Par = (PndMultiFieldPar*) rtdb->getContainer("PndMultiFieldPar");
304  if (fField) { Par->SetParameters(fField); }
305  Par->setInputVersion(fRun->GetRunId(),1);
306  Par->setChanged();
307 
308  // Transport nEvents
309  // -----------------
310 
311  fRun->Run(nEvents);
312 
313  rtdb->saveOutput();
314  rtdb->print();
315 
316 
317  timer.Stop();
318  Double_t rtime = timer.RealTime();
319  Double_t ctime = timer.CpuTime();
320  printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
321 }
322 
323 #include<TApplication.h>
324 #include<iostream>
325 
326 using namespace std;
327 
328 /* arguments
329  * 1: total number of events to simulate
330  * 2: energy of anti protons
331  * 3: displacement of the vertex in x [cm]
332  * 4: displacement of the vertex in y [cm]
333  */
334 
335 
336 int main(int argc, char **argv){
337  cout << " running box generator " << endl;
338  if (argc > 1){
339  nEvents = atoi(argv[1]);
340  cout << " generating " << nEvents << " anti protons " << endl;
341  }
342  if (argc > 2){
343  mom = atof(argv[2]);
344  cout << " with a momentum of " << mom << " GeV/c " << endl;
345  }
346  if (argc > 3){
347  dx = atof(argv[3]);
348  cout << " a displacement of " << dx << " [cm] in x " << endl;
349  }
350  if (argc > 4){
351  dy = atof(argv[4]);
352  cout << " a displacement of " << dy << " [cm] in y " << endl;
353  }
354  //TApplication myapp("runLumi0SimBox",0,0);
355  runLumiSimBox();// 8.9);
356  //myapp.Run();
357  return 0;
358 }
359 
PndMultiField * fField
Definition: sim_emc_apd.C:97
int main(int argc, char **argv)
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
double dy
double theta_high
int verboseLevel
Definition: Lars/runMvdSim.C:7
Bool_t kParameterMerged
Definition: sim_emc_apd.C:113
void SetExclusiveSensorType(const TString sens)
void SetParameters(FairField *field)
TString storePath
Double_t mom
Definition: plot_dirc.C:14
PndDipoleMap * map_d2
Definition: sim_hit_emc.C:111
PndSolenoidMap * map_s1
Definition: sim_hit_emc.C:112
FairBoxGenerator * fBox
double theta_low
double phi_high
FairParRootFileIo * output
Definition: sim_emc_apd.C:120
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
const int particle
TString parOutput
FairRunAna * fRun
Definition: hit_dirc.C:58
Double_t
FairModule * Dipole
Definition: sim_emc_apd.C:40
FairModule * Cave
Definition: sim_emc_apd.C:32
PndSolenoidMap * map_s3
Definition: sim_hit_emc.C:114
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
gDebug
Definition: sim_emc_apd.C:6
PndSolenoidMap * map_s2
Definition: sim_hit_emc.C:113
Double_t ctime
Definition: hit_dirc.C:114
double dx
void runLumiSimBox()
double phi_low
TString simOutput
PndMultiFieldPar * Par
Definition: sim_emc_apd.C:115
void AddField(FairField *field)
double mom_spread
void SetVerboseLevel(Int_t level)
PndDipoleMap * map_d1
Definition: sim_hit_emc.C:110
PndTransMap * map_t
Definition: sim_hit_emc.C:109
FairModule * Pipe
Definition: sim_emc_apd.C:44
Double_t rtime
Definition: hit_dirc.C:113
FairModule * Magnet
Definition: sim_emc_apd.C:36
PndSolenoidMap * map_s4
Definition: sim_hit_emc.C:115
Definition: PndCave.h:8