1 #include "AliGenExtFile.h"
2 #include "AliGenMUONlib.h"
5 #include <TDirectory.h>
9 ClassImp(AliGenExtFile)
10 AliGenExtFile::AliGenExtFile()
15 fTitle="Primaries from ext. File";
16 fFileName="dtujet93.root";
24 AliGenExtFile::AliGenExtFile(Int_t npart)
29 fTitle="Primaries from ext. File";
30 fFileName="dtujet93.root";
35 //____________________________________________________________
36 AliGenExtFile::~AliGenExtFile()
41 //____________________________________________________________
42 void AliGenExtFile::NtupleInit()
45 // reset the existing file environment and open a new root file if
46 // the pointer to the Fluka tree is null
51 File = new TFile(fFileName);
53 cout<<"I have opened "<<fFileName<<" file "<<endl;
55 // get the tree address in the Fluka boundary source file
56 fTreeNtuple = (TTree*)gDirectory->Get("h888");
58 File = fTreeNtuple->GetCurrentFile();
62 TTree *h2=fTreeNtuple;
63 //Set branch addresses
64 //Set branch addresses
65 h2->SetBranchAddress("Nihead",&Nihead);
66 h2->SetBranchAddress("Ihead",Ihead);
67 h2->SetBranchAddress("Nrhead",&Nrhead);
68 h2->SetBranchAddress("Rhead",Rhead);
69 h2->SetBranchAddress("Idpart",&Idpart);
70 h2->SetBranchAddress("Theta",&Theta);
71 h2->SetBranchAddress("Phi",&Phi);
72 h2->SetBranchAddress("P",&P);
73 h2->SetBranchAddress("E",&E);
77 //____________________________________________________________
78 void AliGenExtFile::Generate()
81 AliMC* pMC = AliMC::GetMC();
83 Float_t polar[3]= {0,0,0};
85 Float_t origin[3]={0,0,0};
90 Float_t amass, charge, tlife;
92 Int_t i, j, nt, Ntracks=0;
95 TTree *h2=fTreeNtuple;
96 Int_t nentries = (Int_t) h2->GetEntries();
97 // loop over number of particles
98 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
102 for (j=0;j<3;j++) origin[j]=fOrigin[j];
103 if(fVertexSmear==perEvent) {
106 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
107 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
111 if (fNcurrent >= nentries) {
112 printf("\n No more entries !!! !\n");
118 printf("\n This should never happen !\n");
120 printf("\n Next event contains %d tracks! \n", i6);
123 for (i=0; i<Ntracks; i++) {
125 pMC->Gfpart(Idpart, name, itrtyp,amass, charge, tlife);
126 prwn=sqrt((E+amass)*(E-amass));
128 Theta *= TMath::Pi()/180.;
129 Phi = (Phi-180)*TMath::Pi()/180.;
130 if(Theta<fThetaMin || Theta>fThetaMax ||
131 Phi<fPhiMin || Phi>fPhiMax ||
132 prwn<fPMin || prwn>fPMax)
136 p[0]=prwn*TMath::Sin(Theta)*TMath::Cos(Phi);
137 p[1]=prwn*TMath::Sin(Theta)*TMath::Sin(Phi);
138 p[2]=prwn*TMath::Cos(Theta);
140 if(fVertexSmear==perTrack) {
144 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
145 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
148 gAlice->SetTrack(fTrackIt,-1,Idpart,p,origin,polar,0,"Primary",nt);
151 nb = (Int_t)h2->GetEvent(fNcurrent);
155 // Get AliRun object or create it
157 gAlice = (AliRun*)File->Get("gAlice");
158 if (gAlice) printf("AliRun object found on file\n");
159 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
161 TTree *fAli=gAlice->TreeK();
162 if (fAli) File =fAli->GetCurrentFile();