]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetKineReader.cxx
Protection added.
[u/mrichter/AliRoot.git] / JETAN / AliJetKineReader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-------------------------------------------------------------------------
17 // Jet kinematics reader 
18 // MC reader for jet analysis
19 // Author: Andreas Morsch (andreas.morsch@cern.ch)
20 //-------------------------------------------------------------------------
21
22 // From root ...
23 #include <TClonesArray.h>
24 #include <TPDGCode.h>
25 #include <TParticle.h>
26 #include <TParticlePDG.h>
27 #include <TLorentzVector.h>
28 #include <TSystem.h>
29 #include <TDatabasePDG.h>
30 #include <TRandom.h>
31 // From AliRoot ...
32 #include "AliAODJet.h"
33 #include "AliPDG.h"
34 #include "AliJetKineReaderHeader.h"
35 #include "AliJetKineReader.h"
36 #include "AliMCEventHandler.h"
37 #include "AliMCEvent.h"
38 #include "AliStack.h"
39 #include "AliHeader.h"
40 #include "AliGenPythiaEventHeader.h"
41 #include "AliLog.h"
42
43 ClassImp(AliJetKineReader)
44
45 AliJetKineReader::AliJetKineReader():
46     AliJetReader(),  
47     fAliHeader(0),
48     fMCEvent(0),
49     fGenJets(0)
50 {
51   // Default constructor
52 }
53
54 //____________________________________________________________________________
55
56 AliJetKineReader::~AliJetKineReader()
57 {
58   // Destructor
59   delete fAliHeader;
60 }
61
62 //____________________________________________________________________________
63
64 void AliJetKineReader::OpenInputFiles()
65 {
66   // Opens the input file using the run loader
67   // Not used anymore   
68 }
69
70 //____________________________________________________________________________
71
72 Bool_t AliJetKineReader::FillMomentumArray()
73 {
74   // Fill momentum array for event
75     Int_t goodTrack = 0;
76     // Clear array
77     // temporary storage of signal and cut flags
78     Int_t* sflag  = new Int_t[50000];
79     Int_t* cflag  = new Int_t[50000];
80   
81     ClearArray();
82     // Get the stack
83     AliStack* stack = fMCEvent->Stack();
84     // Number of primaries
85     Int_t nt = stack->GetNprimary();
86       
87     // Get cuts set by user and header
88     Double_t ptMin = ((AliJetKineReaderHeader*) fReaderHeader)->GetPtCut();
89     Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
90     Float_t etaMax = fReaderHeader->GetFiducialEtaMax();  
91     fAliHeader = fMCEvent->Header();
92       
93     
94     TLorentzVector p4;
95     // Loop over particles
96     for (Int_t it = 0; it < nt; it++) {
97         TParticle *part = stack->Particle(it);
98         Int_t   status  = part->GetStatusCode();
99         Int_t   pdg     = TMath::Abs(part->GetPdgCode());
100         Float_t pt      = part->Pt(); 
101           
102         // Skip non-final state particles, neutrinos 
103         // and particles with pt < pt_min 
104         if ((status != 1)            
105             || (pdg == 12 || pdg == 14 || pdg == 16)) continue; 
106         
107         Float_t p       = part->P();
108         Float_t p0      = p;
109         Float_t eta     = part->Eta();
110         Float_t phi     = part->Phi();
111         
112         // Fast simulation of TPC if requested
113         if (((AliJetKineReaderHeader*)fReaderHeader)->FastSimTPC()) {
114             // Charged particles only
115             Float_t charge = 
116                 TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
117             if (charge == 0)               continue;
118             // Simulate efficiency
119             if (!Efficiency(p0, eta, phi)) continue;
120             // Simulate resolution
121             p = SmearMomentum(4, p0);
122         } // End fast TPC
123           
124           // Fast simulation of EMCAL if requested
125         if (((AliJetKineReaderHeader*)fReaderHeader)->FastSimEMCAL()) {
126             Float_t charge = 
127                 TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
128             // Charged particles only
129             if (charge != 0){
130                 // Simulate efficiency
131                 if (!Efficiency(p0, eta, phi)) continue;
132                 // Simulate resolution
133                 p = SmearMomentum(4, p0);
134             } // end "if" charged particles
135               // Neutral particles (exclude K0L, n, nbar)
136             if (pdg == kNeutron || pdg == kK0Long) continue;
137         } // End fast EMCAL
138         
139           // Fill momentum array
140         Float_t r  = p/p0;
141         Float_t px = r * part->Px(); 
142         Float_t py = r * part->Py(); 
143         Float_t pz = r * part->Pz();
144         TParticlePDG *pPDG = part->GetPDG();
145         Float_t m = 0;
146         if(!pPDG){
147           // this is very rare...
148           // Is avoided by AliPDG::AddParticlesToPdgDataBase();
149           // but this should be called only once... (how in proof?)
150           // Calucluate mass with unsmeared momentum values
151           m  = part->Energy()*part->Energy() - 
152             (px * px + py * py + pz * pz)/r/r; 
153           if(m>0)m = TMath::Sqrt(m);
154           else m = 0;
155           AliInfo(Form("Unknown Particle using %d calculated mass m = %3.3f",part->GetPdgCode(),m));
156
157         }
158         else{
159           m  = pPDG->Mass();
160         }
161         Float_t e  = TMath::Sqrt(px * px + py * py + pz * pz + m * m);
162         p4 = TLorentzVector(px, py, pz, e);
163         if ( (p4.Eta()>etaMax) || (p4.Eta()<etaMin)) continue;
164         new ((*fMomentumArray)[goodTrack]) TLorentzVector(p4);
165         
166         // all tracks are signal ... ?
167         sflag[goodTrack]=1;
168         cflag[goodTrack]=0;
169         if (pt > ptMin) cflag[goodTrack] = 1; // track surviving pt cut
170         goodTrack++;
171     } // track loop
172
173 // set the signal flags
174     fSignalFlag.Set(goodTrack, sflag);
175     fCutFlag.Set(goodTrack, cflag);
176     AliInfo(Form(" Number of good tracks %d \n", goodTrack));
177     
178     delete[] sflag;
179     delete[] cflag;
180     
181     return kTRUE;
182 }
183
184
185 Float_t AliJetKineReader::SmearMomentum(Int_t ind, Float_t p)
186 {
187   //  The relative momentum error, i.e. 
188   //  (delta p)/p = sqrt (a**2 + (b*p)**2) * 10**-2,
189   //  where typically a = 0.75 and b = 0.16 - 0.24 depending on multiplicity
190   //  (the lower value is for dn/d(eta) about 2000, and the higher one for 8000)
191   //
192   //  If we include information from TRD, b will be a factor 2/3 smaller.
193   //
194   //  ind = 1: high multiplicity
195   //  ind = 2: low  multiplicity
196   //  ind = 3: high multiplicity + TRD
197   //  ind = 4: low  multiplicity + TRD
198   
199   Float_t pSmeared;
200   Float_t a = 0.75;
201   Float_t b = 0.12;
202   
203   if (ind == 1) b = 0.12;
204   if (ind == 2) b = 0.08;
205   if (ind == 3) b = 0.12;    
206   if (ind == 4) b = 0.08;    
207   
208   Float_t sigma =  p * TMath::Sqrt(a * a + b * b * p * p)*0.01;
209   pSmeared = p + gRandom->Gaus(0., sigma);
210   return pSmeared;
211 }
212
213
214 Bool_t AliJetKineReader::Efficiency(Float_t p, Float_t /*eta*/, Float_t phi)
215 {
216   // Fast simulation of geometrical acceptance and tracking efficiency
217  
218   //  Tracking
219   Float_t eff = 0.99;
220   if (p < 0.5) eff -= (0.5-p)*0.2/0.3;
221   // Geometry
222   if (p > 0.5) {
223     phi *= 180. / TMath::Pi();
224     // Sector number 0 - 17
225     Int_t isec  = Int_t(phi / 20.);
226     // Sector centre
227     Float_t phi0 = isec * 20. + 10.;
228     Float_t phir = TMath::Abs(phi-phi0);
229     // 2 deg of dead space
230     if (phir > 9.) eff = 0.;
231   }
232
233   if (gRandom->Rndm() > eff) {
234     return kFALSE;
235   } else {
236     return kTRUE;
237   }
238
239 }
240
241 TClonesArray*  AliJetKineReader::GetGeneratedJets()
242 {
243     //
244     // Get generated jets from mc header
245     //
246     if (!fGenJets) {
247         fGenJets = new TClonesArray("AliAODJets", 100);
248     } else {
249         fGenJets->Clear();
250     }
251     
252     
253     AliHeader* alih = GetAliHeader(); 
254     if (alih == 0) return 0;
255     AliGenEventHeader * genh = alih->GenEventHeader();
256     if (genh == 0) return 0;
257
258     Int_t nj =((AliGenPythiaEventHeader*)genh)->NTriggerJets(); 
259     for (Int_t i = 0; i < nj; i++) {
260         Float_t p[4];
261         ((AliGenPythiaEventHeader*)genh)->TriggerJet(i,p);
262         new ((*fGenJets)[i]) AliAODJet(p[0], p[1], p[2], p[3]);
263     }
264
265     return fGenJets;
266 }
267
268 void AliJetKineReader::SetInputEvent(TObject* /*esd*/, TObject* /*aod*/, TObject* mc)
269 {
270     // Connect the input event
271     fMCEvent = (AliMCEvent*) mc;
272 }