FairRoot/PandaRoot
PndEvtGenDirect.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndEvtGenDirect source file -----
3 // ----- -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include <iostream>
8 #include "TClonesArray.h"
9 #include "TFile.h"
10 #include "TLorentzVector.h"
11 #include "TTree.h"
12 #include "TMath.h"
13 #include "TVector3.h"
14 #include "TParticle.h"
15 #include "TRandom.h"
16 #include "TRandom3.h"
17 
18 #include "FairPrimaryGenerator.h"
19 
20 #include "PndEvtGenDirect.h"
21 
22 #include "EvtGen/EvtGen.hh"
23 
24 #include "EvtGenBase/EvtPatches.hh"
25 #include "EvtGenBase/EvtParticleFactory.hh"
26 #include "EvtGenBase/EvtStdHep.hh"
27 #include "EvtGenBase/EvtParticle.hh"
28 #include "EvtGenBase/EvtRandom.hh"
29 #include "EvtGenBase/EvtRandomEngine.hh"
30 #include "EvtGenBase/EvtReport.hh"
31 #include "EvtGenBase/EvtHepMCEvent.hh"
32 
34 #if EVTGEN_EXTERNAL
35 #include "EvtGenExternal/EvtExternalGenList.hh"
36 #include "EvtGenBase/EvtAbsRadCorr.hh"
37 #include "EvtGenBase/EvtDecayBase.hh"
38 #endif
39 
40 #include <string>
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 using namespace std;
45 
46 using std::endl;
47 using std::ofstream;
48 using std::cout;
49 
50 //define class for generating random nubers
51 class EvtRootRandomEngine:public EvtRandomEngine{
52 public:
54  double random();
55  int seed;
56 };
57 
59  static TRandom3 randengine(seed);
60  return randengine.Rndm();
61 }
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") && (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 
94 
95  //Initialize the generator - read in the decay table and particle properties
96 
97  EvtRandomEngine* myRandomEngine=0;
98 
99  // Make sure that the seed is always set if default value (-1) is used, JGM, August 2011
100  if (Seed<0)
101  {
102  Seed = gRandom->GetSeed();
103  cout << "<I> Rnd Seed changed to " << Seed << endl;
104  }
105  myRandomEngine=new EvtRootRandomEngine(Seed);
106 
107 
108  // Set up the default external generator list: Photos, Pythia and/or Tauola ONLY if available
109 #if EVTGEN_EXTERNAL
110  EvtExternalGenList genList;
111  EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
112  std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
113 
114  // Create the EvtGen generator object
115  myGenerator=new EvtGen(defaultDECAY,defaultPDL,myRandomEngine,
116  radCorrEngine, &extraModels);
117 #else
118  //If you don't want to use external generators, use the following:
119  myGenerator=new EvtGen(defaultDECAY,defaultPDL,myRandomEngine);
120 #endif
121 
122  //If I wanted a user decay file, I would read it in now.
123  if(decfile!="") myGenerator->readUDecay(decfile.Data());
124 
125  PART=EvtPDL::getId(std::string(particle.Data()));
126 
127  if ( (particle.Contains("pbarp") || particle.Contains("pbard") || particle.Contains("pbarA")) && Mom==0)
128  {
129  cerr <<"\033[5m\033[31m -E ****** FATAL ERROR: <particle> is '" << particle.Data() << "'; MUST give pbar momentum or cms energy!\033[0m"<<endl;
130  exit(0);
131  }
132 
133  double val=-3.0969;
134  fMomentum = 0.0;
135  fEnergy = 0.0;
136  double mp=0.938272;
137  double md=1.875613;
138  double mu=0.931494;
139  double mA=ATarg*mu;
140 
141  if ( (particle.Contains("pbarp") || particle.Contains("pbard") || particle.Contains("pbarA") ) && Mom!=0){
142  val=Mom;
143  }else{
144  if(PART.getId()==-1){
145  cerr << "Particle \""<<particle<<"\" is unknown!!!"<<endl<<"Check your Macro for spelling mistake."<<endl;
146  exit(0);
147  }
148  val=-EvtPDL::getMass(PART);
149  }
150 
151  // val is the momentum of the pbar beam
152  if (val>0){
153  fMomentum = val;
154  if ( particle.Contains("pbarpSystem") ) fEnergy = mp+sqrt(fMomentum*fMomentum+mp*mp);
155  if ( particle.Contains("pbardSystem") ) fEnergy = md+sqrt(fMomentum*fMomentum+mp*mp);
156  if ( particle.Contains("pbarASystem") ) fEnergy = mA+sqrt(fMomentum*fMomentum+mp*mp);
157  }
158  else //val is -E_cm
159  {
160  val=-val;
161  fEnergy = val*val/(2*mp);
162  fMomentum = sqrt(fEnergy*fEnergy-val*val);
163  }
164 
165  cout <<"\n############# Generating with following conditions:\n\n";
166  cout <<"incident 4-mom : ("<<fEnergy<<", 0, 0, "<<fMomentum<<"), m = "<<sqrt(fEnergy*fEnergy-fMomentum*fMomentum)<<endl;
167  cout <<"\n######################\n\n"<<endl;
168 
169 }
170 // ------------------------------------------------------------------------
171 
172 // ----- Destructor ---------------------------------------------------
174 
175 }
176 // ------------------------------------------------------------------------
177 
178 // ----- Public method ReadEvent --------------------------------------
179 Bool_t PndEvtGenDirect::ReadEvent(FairPrimaryGenerator* primGen) {
180  static Int_t evtnr=0;
181  // Loop to create nEvents, starting from an Upsilon(4S)
182  // Set up the parent particle
183  EvtParticle *parent;
184 
185  EvtVector4R pInit(fEnergy, 0.0000, -0.0000, fMomentum);
186  parent=EvtParticleFactory::particleFactory(PART,pInit);
187  parent->setDiagonalSpinDensity();
188 
189 
190  // Generate the event
191  myGenerator->generateDecay(parent);
192  // Write out the results
193 
194  // we should better use the EvtParticle properties here... and kick the evtstd structure!!!!
195  evtstdhep.init();
196  parent->makeStdHep(evtstdhep);
197 
198  Bool_t plotflag;
199  plotflag=false;
200  //print out some status info
201  if (verbose>1 ||(verbose==1 && (evtnr<10 || ((evtnr+1)%100)==0))){
202  cout << "PndEvtGenDirect::ReadEvent "<<evtnr <<" "<<fEnergy<<" "<<fMomentum << endl;
203  parent->printParticle();
204  // Write out the results
205  EvtHepMCEvent theEvent;
206  theEvent.constructEvent(parent);
207  HepMC::GenEvent* genEvent = theEvent.getEvent();
208  genEvent->print(std::cout);
209 
210 // report(INFO,"EvtGen") << "event Number\t"<< evtnr << evtstdhep << endl;
211 // cout << evtnr << "\t" << evtstdhep.getNPart();
212 // cout <<evtstdhep<<endl;
213 
214  cout <<"==== now compare ==="<<endl;
215  plotflag=true;
216  }
217 
218  // Write the output
219 
220  Int_t npart;
221  Double_t fX, fY, fZ, fT;
222  double Px,Py,Pz, fE; // ,Pm[1000],Wh[1000];
223  int Id;
224  npart=evtstdhep.getNPart();
225  EvtVector4R vxyz,pxyz;
226 
227  for(Int_t i=0; i<npart; i++){
228  Int_t nFD, nLD;
229  // add track
230  nFD=evtstdhep.getFirstDaughter(i);
231  nLD=evtstdhep.getLastDaughter(i);
232  if(fStoreTree ||(nFD==-1 && nLD==-1))
233  {
234  Id=evtstdhep.getStdHepID(i);
235  vxyz=evtstdhep.getX4(i);
236  pxyz=evtstdhep.getP4(i);
237  fT=vxyz.get(0)/(1000*TMath::C()); //mm - > s conversion
238  fX=vxyz.get(1)/10.; // mm -> cm conversion
239  fY=vxyz.get(2)/10.; // mm -> cm conversion
240  fZ=vxyz.get(3)/10.; // mm -> cm conversion
241  fE=pxyz.get(0);
242  Px=pxyz.get(1);
243  Py=pxyz.get(2);
244  Pz=pxyz.get(3);
245  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,
246  fX, fY, fZ, fT,Px, Py, Pz, fE, Id, nFD, nLD,evtstdhep.getFirstMother(i),evtstdhep.getLastMother(i));
247  if(fStoreTree){
248  primGen->AddTrack(Id, Px, Py, Pz, fX, fY, fZ, evtstdhep.getFirstMother(i),(nFD==-1 && nLD==-1),fE,fT);
249  }else{
250  primGen->AddTrack(Id, Px, Py, Pz, fX, fY, fZ,-1,true,fE,fT);// default -1, true
251  }
252  }
253  }
254  if(plotflag) cout <<"==== compare end ==="<<endl;
255 
256  parent->deleteTree();
257 
258  evtnr++;
259 
260  return kTRUE;
261 
262 }
263 // ------------------------------------------------------------------------
264 
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)