FairRoot/PandaRoot
PndEvtGenDirect.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndEvtGenDirect source file -----
3 // ----- -----
4 // -------------------------------------------------------------------------
5 
6 #include <iostream>
7 #include "TClonesArray.h"
8 #include "TFile.h"
9 #include "TLorentzVector.h"
10 #include "TTree.h"
11 #include "TMath.h"
12 #include "TVector3.h"
13 #include "TParticle.h"
14 #include "TRandom.h"
15 #include "TRandom3.h"
16 
17 #include "FairPrimaryGenerator.h"
18 
19 #include "PndEvtGenDirect.h"
20 
21 #include "EvtGen/EvtGen.hh"
22 
23 #include "EvtGenBase/EvtPatches.hh"
24 #include "EvtGenBase/EvtParticleFactory.hh"
25 #include "EvtGenBase/EvtStdHep.hh"
26 #include "EvtGenBase/EvtParticle.hh"
27 #include "EvtGenBase/EvtRandom.hh"
28 #include "EvtGenBase/EvtRandomEngine.hh"
29 #include "EvtGenBase/EvtReport.hh"
30 #include "EvtGenBase/EvtHepMCEvent.hh"
31 
33 #if EVTGEN_EXTERNAL
34 #include "EvtGenExternal/EvtExternalGenList.hh"
35 #include "EvtGenBase/EvtAbsRadCorr.hh"
36 #include "EvtGenBase/EvtDecayBase.hh"
37 #endif
38 
39 #include <string>
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 using namespace std;
44 
45 using std::endl;
46 using std::ofstream;
47 using std::cout;
48 
49 //define class for generating random nubers
50 class EvtRootRandomEngine:public EvtRandomEngine {
51  public:
53  seed=s;
54  }
55  double random();
56  int seed;
57 };
58 
60  static TRandom3 randengine(seed);
61  return randengine.Rndm();
62 }
63 
64 // ----- Default constructor ------------------------------------------
66  SetName("PndEvtGenDirect");
67  fStoreTree=false;
68  verbose=0;
69 }
70 // ------------------------------------------------------------------------
71 
72 // ----- Standard constructor -----------------------------------------
73 PndEvtGenDirect::PndEvtGenDirect(TString particle,TString decfile,Double_t Mom,Long_t Seed,TString defaultDECAY,TString defaultPDL,Double_t ATarg) {
75 
76  cout << "<I> PndEvtGenDirect"<<endl;
77  cout << "<I> Particle: "<<particle<<endl;
78  cout << "<I> decfile: "<<decfile<<endl;
79  if(Mom>0) cout << "<I> pbar-Momentum: "<<Mom<<endl;
80  if(Mom==0) cout << "<I> Momentum: "<<Mom<<endl;
81  if(Mom<0) cout << "<I> CMS energy: "<<Mom<<endl;
82  cout << "<I> Rnd Seed: "<<Seed<<endl;
83  TString work = getenv("VMCWORKDIR");
84  if (defaultDECAY=="") defaultDECAY = work + "/pgenerators/EvtGen/EvtGen/Private/DECAY.DEC";
85  if (defaultPDL=="") defaultPDL = work + "/pgenerators/EvtGen/EvtGen/Private/evt.pdl";
86 
87  if ( (particle.Contains("pbarASystem") || particle.Contains("pASystem")) && (ATarg<3.||ATarg>238.))
88  {
89  cerr <<"****** FATAL ERROR: nuclear target mass number MUST be between 3 and 238! ******"<<endl;
90  exit(0);
91  }
92 
93  //Initialize the generator - read in the decay table and particle properties
94 
95  EvtRandomEngine* myRandomEngine=0;
96 
97  // Make sure that the seed is always set if default value (-1) is used, JGM, August 2011
98  if (Seed<0)
99  {
100  Seed = gRandom->GetSeed();
101  cout << "<I> Rnd Seed changed to " << Seed << endl;
102  }
103  myRandomEngine=new EvtRootRandomEngine(Seed);
104 
105 
106  // Set up the default external generator list: Photos, Pythia and/or Tauola ONLY if available
107 #if EVTGEN_EXTERNAL
108  EvtExternalGenList genList;
109  EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
110  std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
111 
112  // Create the EvtGen generator object
113  myGenerator=new EvtGen(defaultDECAY,defaultPDL,myRandomEngine,
114  radCorrEngine, &extraModels);
115 #else
116  //If you don't want to use external generators, use the following:
117  myGenerator=new EvtGen(defaultDECAY,defaultPDL,myRandomEngine);
118 #endif
119 
120  //If I wanted a user decay file, I would read it in now.
121  if(decfile!="") myGenerator->readUDecay(decfile.Data());
122 
123  PART=EvtPDL::getId(std::string(particle.Data()));
124 
125  double val=-3.0969;
126  fMomentum = 0.0;
127  fEnergy = 0.0;
128  double mp=0.938272;
129  double md=1.875613;
130  double mu=0.931494;
131  double mA=ATarg*mu;
132 
133  if ( particle.Contains("pbarp") || particle.Contains("pbard") || particle.Contains("pbarA") || particle.Contains("pp") || particle.Contains("pd") || particle.Contains("pA") ) {
134  if (Mom==0) {
135  cerr <<"\033[5m\033[31m -E ****** FATAL ERROR: <particle> is '" << particle.Data() << "'; MUST give pbar momentum or cms energy!\033[0m"<<endl;
136  exit(0);
137  } else {
138  val=Mom;
139  }
140  } else {
141  if(PART.getId()==-1) {
142  cerr << "Particle \""<<particle<<"\" is unknown!!!"<<endl<<"Check your Macro for spelling mistake."<<endl;
143  exit(0);
144  }
145  val=-EvtPDL::getMass(PART);
146  }
147 
148  // val is the momentum of the beam
149  if (val>0) {
150  fMomentum = val;
151  if ( particle.Contains("pbarpSystem") || particle.Contains("ppSystem")) fEnergy = mp+sqrt(fMomentum*fMomentum+mp*mp);
152  if ( particle.Contains("pbardSystem") || particle.Contains("pdSystem")) fEnergy = md+sqrt(fMomentum*fMomentum+mp*mp);
153  if ( particle.Contains("pbarASystem") || particle.Contains("pASystem")) fEnergy = mA+sqrt(fMomentum*fMomentum+mp*mp);
154  } else { //val is -E_cm
155  val=-val;
156  fEnergy = val*val/(2*mp);
157  fMomentum = sqrt(fEnergy*fEnergy-val*val);
158  }
159 
160  cout <<"\n############# Generating with following conditions:\n\n";
161  cout <<"incident 4-mom : ("<<fEnergy<<", 0, 0, "<<fMomentum<<"), m = "<<sqrt(fEnergy*fEnergy-fMomentum*fMomentum)<<endl;
162  cout <<"\n######################\n\n"<<endl;
163 
164 }
165 // ------------------------------------------------------------------------
166 
167 // ----- Destructor ---------------------------------------------------
169 
170 }
171 // ------------------------------------------------------------------------
172 
173 // ----- Public method ReadEvent --------------------------------------
174 Bool_t PndEvtGenDirect::ReadEvent(FairPrimaryGenerator* primGen) {
175  static Int_t evtnr=0;
176  // Loop to create nEvents, starting from an Upsilon(4S)
177  // Set up the parent particle
178  EvtParticle *parent;
179 
180  EvtVector4R pInit(fEnergy, 0.0000, -0.0000, fMomentum);
181  parent=EvtParticleFactory::particleFactory(PART,pInit);
182  parent->setDiagonalSpinDensity();
183 
184  // Generate the event
185  myGenerator->generateDecay(parent);
186  // Write out the results
187 
188  // we should better use the EvtParticle properties here... and kick the evtstd structure!!!!
189  evtstdhep.init();
190  parent->makeStdHep(evtstdhep);
191 
192  Bool_t plotflag;
193  plotflag=false;
194  //print out some status info
195  if (verbose>1 ||(verbose==1 && (evtnr<10 || ((evtnr+1)%100)==0))) {
196  cout << "PndEvtGenDirect::ReadEvent "<<evtnr <<" "<<fEnergy<<" "<<fMomentum << endl;
197  parent->printParticle();
198  // Write out the results
199  EvtHepMCEvent theEvent;
200  theEvent.constructEvent(parent);
201  HepMC::GenEvent* genEvent = theEvent.getEvent();
202  genEvent->print(std::cout);
203 
204  // report(INFO,"EvtGen") << "event Number\t"<< evtnr << evtstdhep << endl;
205  // cout << evtnr << "\t" << evtstdhep.getNPart();
206  // cout <<evtstdhep<<endl;
207 
208  cout <<"==== now compare ==="<<endl;
209  plotflag=true;
210  }
211 
212  // Write the output
213 
214  Int_t npart;
215  Double_t fX, fY, fZ, fT;
216  double Px,Py,Pz, fE; // ,Pm[1000],Wh[1000];
217  int Id;
218  npart=evtstdhep.getNPart();
219  EvtVector4R vxyz,pxyz;
220 
221  for(Int_t i=0; i<npart; i++) {
222  Int_t nFD, nLD;
223  // add track
224  nFD=evtstdhep.getFirstDaughter(i);
225  nLD=evtstdhep.getLastDaughter(i);
226  if(fStoreTree ||(nFD==-1 && nLD==-1))
227  {
228  Id=evtstdhep.getStdHepID(i);
229  vxyz=evtstdhep.getX4(i);
230  pxyz=evtstdhep.getP4(i);
231  fT=vxyz.get(0)/(1000*TMath::C()); //mm - > s conversion
232  fX=vxyz.get(1)/10.; // mm -> cm conversion
233  fY=vxyz.get(2)/10.; // mm -> cm conversion
234  fZ=vxyz.get(3)/10.; // mm -> cm conversion
235  fE=pxyz.get(0);
236  Px=pxyz.get(1);
237  Py=pxyz.get(2);
238  Pz=pxyz.get(3);
239  if(plotflag) printf("- I -: new particle %d at: %f, %f, %f (%f)-> %f %f %f (%f) ID %d ##Daughters %d %d Mothers %d %d\n", i,
240  fX, fY, fZ, fT,Px, Py, Pz, fE, Id, nFD, nLD,evtstdhep.getFirstMother(i),evtstdhep.getLastMother(i));
241  if(fStoreTree) {
242  primGen->AddTrack(Id, Px, Py, Pz, fX, fY, fZ, evtstdhep.getFirstMother(i),(nFD==-1 && nLD==-1),fE,fT);
243  } else {
244  primGen->AddTrack(Id, Px, Py, Pz, fX, fY, fZ,-1,true,fE,fT);// default -1, true
245  }
246  }
247  }
248  if(plotflag) cout <<"==== compare end ==="<<endl;
249 
250  parent->deleteTree();
251 
252  evtnr++;
253 
254  return kTRUE;
255 
256 }
257 // ------------------------------------------------------------------------
258 
260 
261 
262 
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
virtual ~PndEvtGenDirect()
cout<< "-----------------------------------------------> Quarter VOLUME<<endl;name="QuarterShape";QuarterShape=newTGeoArb8(name,dz,vertQuar);name="Quarter4Vol";TStringmedium="air";QuarterVol=newTGeoVolumeAssembly(name);name="SubunitShape";SubunitShape=newTGeoArb8(name,dz,vertSub);TStringmedium="air";name="SubunitVol";name1="SubunitVol1";name2="SubunitVol2";name3="SubunitVol3";name4="SubunitVol4";name5="SubunitVol5";name6="SubunitVol6";name7="SubunitVol7";name8="SubunitVol8";name9="SubunitVol9";SubunitVol=newTGeoVolumeAssembly(name);SubunitVol1=newTGeoVolumeAssembly(name1);SubunitVol2=newTGeoVolumeAssembly(name2);SubunitVol3=newTGeoVolumeAssembly(name3);SubunitVol4=newTGeoVolumeAssembly(name4);SubunitVol5=newTGeoVolumeAssembly(name5);SubunitVol6=newTGeoVolumeAssembly(name6);SubunitVol7=newTGeoVolumeAssembly(name7);SubunitVol8=newTGeoVolumeAssembly(name8);SubunitVol9=newTGeoVolumeAssembly(name9);name="BoxShape";BoxShape=newTGeoArb8(name,dz,vertBox);TStringmedium="air";name="BoxVol";BoxVol=newTGeoVolumeAssembly(name);name1="BoxVol1";name2="BoxVol2";name3="BoxVol3";name4="BoxVol4";BoxVol1=newTGeoVolumeAssembly(name1);BoxVol2=newTGeoVolumeAssembly(name2);BoxVol3=newTGeoVolumeAssembly(name3);BoxVol4=newTGeoVolumeAssembly(name4);for(Int_tb=0;b<kNumOfBoxes;b++){cout<<""<<endl;cout<<"---------------->BOXnumber:"<<b<<endl;if(b==0){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(-0.465518);}if(b==1){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(0.465518);}if(b==2){trBox=newTGeoTranslation(tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(-0.465518);rotBox.RotateY(-0.465518);}if(b==3){trBox=newTGeoTranslation(-tr-kSpaceInSub-kAlveoleThickness-0.5*kSpaceInBox,tr+kSpaceInSub+kAlveoleThickness+0.5*kSpaceInBox,0.);rotBox=newTGeoRotation();rotBox.RotateX(0.465518);rotBox.RotateY(0.465518);}TGeoCombiTrans*trrotBox=newTGeoCombiTrans(trBox,rotBox);name="BoxVol";name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol->AddNode(BoxVol,b,trrotBox);if(b==1){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol1->AddNode(BoxVol,b,trrotBox);}if(b==2){name+=b;trrotBox->SetName(name);trrotBox->RegisterYourself();SubunitVol2->AddNode(BoxVol1,b,trrotBox);}if(b==0){name+=b;trrotBox-> SetName(name)
Int_t i
Definition: run_full.C:25
TClonesArray * fT
Definition: drawGLTracks.C:13
exit(0)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
#define verbose
TLorentzVector s
Definition: Pnd2DStar.C:50
Double_t fX
Definition: PndCaloDraw.cxx:34
Double_t fZ
Definition: PndCaloDraw.cxx:34
static const double mp
Definition: mzparameters.h:11
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
const int particle
int Pic_FED Eff_lEE C()
Double_t
unsigned int seed
Double_t fY
Definition: PndCaloDraw.cxx:34
ClassImp(PndAnaContFact)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)