]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/DEV/AliJetFillCalTrkTrackMC.cxx
adding JETAN and FASTJETAN development libs for new i/o of tracks/particles for the...
[u/mrichter/AliRoot.git] / JETAN / DEV / AliJetFillCalTrkTrackMC.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 /* $Id$ */
17
18 //--------------------------------------------------
19 // Filling of CalTrkTrack objects in the MC reader task
20 //
21 // Author: magali.estienne@subatech.in2p3.fr
22 //         alexandre.shabetai@cern.ch
23 //-------------------------------------------------
24
25 // --- ROOT system ---
26 #include <TDatabasePDG.h>
27 #include <TRandom.h>
28 #include <TPDGCode.h>
29
30 // --- AliRoot system ---
31 #include "AliJetFillCalTrkTrackMC.h"
32 #include "AliAODMCParticle.h"
33 #include "AliJetKineReaderHeader.h"
34 #include "AliVEvent.h"
35 #include "AliMCEvent.h"
36
37 ClassImp(AliJetFillCalTrkTrackMC)
38
39 /////////////////////////////////////////////////////////////////////////
40
41 AliJetFillCalTrkTrackMC::AliJetFillCalTrkTrackMC(): 
42   AliJetFillCalTrkEvent(),
43   fHadCorr(0),
44   fApplyMIPCorrection(kTRUE),
45   fVEvt(0x0),
46   fMCEvent(0x0)
47 {
48   // constructor
49 }
50
51 //-----------------------------------------------------------------------
52 AliJetFillCalTrkTrackMC::AliJetFillCalTrkTrackMC(AliVEvent* evt): 
53   AliJetFillCalTrkEvent(),
54   fHadCorr(0),
55   fApplyMIPCorrection(kTRUE),
56   fVEvt(evt),
57   fMCEvent(0x0)
58 {
59   // constructor
60 }
61
62 //-----------------------------------------------------------------------
63 AliJetFillCalTrkTrackMC::AliJetFillCalTrkTrackMC(const AliJetFillCalTrkTrackMC &det): 
64   AliJetFillCalTrkEvent(det),
65   fHadCorr(det.fHadCorr),
66   fApplyMIPCorrection(det.fApplyMIPCorrection),
67   fVEvt(det.fVEvt),
68   fMCEvent(det.fMCEvent)
69 {
70   // Copy constructor
71 }
72
73 //-----------------------------------------------------------------------
74 AliJetFillCalTrkTrackMC& AliJetFillCalTrkTrackMC::operator=(const AliJetFillCalTrkTrackMC& other)
75 {
76   // Assignment
77   if (this != &other) { 
78    fHadCorr = other.fHadCorr;
79    fApplyMIPCorrection = other.fApplyMIPCorrection;
80    fVEvt = other.fVEvt;
81    fMCEvent = other.fMCEvent;
82   }
83  
84   return (*this);
85
86 }
87
88 //-----------------------------------------------------------------------
89 AliJetFillCalTrkTrackMC::~AliJetFillCalTrkTrackMC()
90 {
91   // destructor
92 }
93
94 //-----------------------------------------------------------------------
95 void AliJetFillCalTrkTrackMC::Exec(Option_t* const /*option*/)
96 {
97   // Main method.
98   // Fill AliJetFillCalTrkTrackMC the with the charged particle information
99
100   fDebug = fReaderHeader->GetDebug();
101   fOpt = fReaderHeader->GetDetector();
102   TString datatype = fReaderHeader->GetDataType();
103   datatype.ToUpper();
104
105   Int_t type=0;
106
107   if      (datatype.Contains("AODMC2B")) { type=kTrackAODMCChargedAcceptance; }
108   else if (datatype.Contains("AODMC2"))  { type=kTrackAODMCCharged; }
109   else if (datatype.Contains("AODMC"))   { type=kTrackAODMCAll; }
110  
111   else if (!datatype.Contains("AOD") && datatype.Contains("MC2")) {type=kTrackKineCharged;} 
112   else if (!datatype.Contains("AOD") && datatype.Contains("MC"))  {type=kTrackKineAll;}
113   
114   else { cout<< "Unknown Data type !" << endl; }
115
116   // temporary storage of signal and pt cut flag
117   Bool_t sflag = 0;
118   Bool_t cflag = 0;
119
120   // get cuts set by user
121   Float_t ptMin  = fReaderHeader->GetPtCut();
122   Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
123   Float_t etaMax = fReaderHeader->GetFiducialEtaMax();
124   Float_t phiMin = fReaderHeader->GetFiducialPhiMin();
125   Float_t phiMax = fReaderHeader->GetFiducialPhiMax();
126
127   if(fDebug>2) Printf("%s:%d Selecting tracks with %d",(char*)__FILE__,__LINE__,type);
128
129   Int_t goodTrackStd = 0;
130   Int_t goodTrackNonStd = 0;
131
132   if (type == kTrackKineAll || type == kTrackKineCharged){
133
134     FillKine();
135   } // Kine
136
137   else if (type == kTrackAODMCCharged || type == kTrackAODMCAll || type == kTrackAODMCChargedAcceptance) {
138     if(!fVEvt) return; 
139     TClonesArray *mcArray = dynamic_cast<TClonesArray*>(fVEvt->FindListObject(AliAODMCParticle::StdBranchName()));
140     if(!mcArray) {
141       Printf("%s:%d No MC particle branch found",(char*)__FILE__,__LINE__);
142       return; 
143     }
144     for(int it = 0;it < mcArray->GetEntriesFast();++it){
145       cflag=sflag=0;
146       AliAODMCParticle *part = (AliAODMCParticle*)(mcArray->At(it));
147       if(!part->IsPhysicalPrimary())continue;
148       Int_t   pdg     = TMath::Abs(part->GetPdgCode());
149       // exclude neutrinos anyway
150       if((pdg == 12 || pdg == 14 || pdg == 16)) continue;
151       cflag = ( part->Pt()>ptMin ) ? 1 : 0;
152       sflag = ( TMath::Abs(part->GetLabel()) < 10000 ) ? 1 : 0;
153       if(type == kTrackAODMCAll){
154         fCalTrkEvent->AddCalTrkTrack(part,cflag,sflag);
155         goodTrackStd++;
156       }
157       else if (type == kTrackAODMCCharged || type == kTrackAODMCChargedAcceptance ){
158         if(part->Charge()==0)continue;
159         if(kTrackAODMCCharged){
160           fCalTrkEvent->AddCalTrkTrack(part,cflag,sflag);
161           goodTrackStd++;
162         }
163         else {
164           if((part->Eta()>etaMax) || (part->Eta()<etaMin)) continue;
165           Float_t phi = ( (part->Phi()) < 0) ? (part->Phi()) + 2. * TMath::Pi() : (part->Phi());
166           if((phi>phiMax) || (phi<phiMin)) continue;
167           fCalTrkEvent->AddCalTrkTrack(part,cflag,sflag);
168           goodTrackStd++;
169         }
170       }
171     }
172    if(fDebug>0) printf("Number of good tracks selected: %5d \n", goodTrackStd+goodTrackNonStd); 
173   } // AODMCparticle
174
175 }
176
177 //-----------------------------------------------------------------------
178 Bool_t AliJetFillCalTrkTrackMC::FillKine()
179 {
180   // Fill event
181   Int_t goodTrack = 0;
182   
183   // Get the stack
184   if(!fMCEvent) {cout<<"could not get MCEvent!"<<endl; return kFALSE;}
185   
186   Int_t nt = fMCEvent->GetNumberOfTracks();
187   
188   // Get cuts set by user and header
189   Double_t ptMin = ((AliJetKineReaderHeader*) fReaderHeader)->GetPtCut();
190   Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
191   Float_t etaMax = fReaderHeader->GetFiducialEtaMax();
192   
193   TLorentzVector p4;
194   // Loop over particles
195   for (Int_t it = 0; it < nt; it++) {
196     if(!fMCEvent->IsPhysicalPrimary(it)) continue;
197     AliVParticle* part = fMCEvent->GetTrack(it);
198     Int_t   pdg    = TMath::Abs(part->PdgCode());
199     Float_t pt     = part->Pt();
200     
201     if( (pdg == 12 || pdg == 14 || pdg == 16)) continue;
202     
203     Float_t p      = part->P();
204     Float_t p0     = p;
205     Float_t eta    = part->Eta();
206     Float_t phi    = part->Phi();
207     Float_t charge = part->Charge();
208     
209     if (((AliJetKineReaderHeader*)fReaderHeader)->ChargedOnly()) {
210       if (charge == 0) continue;
211     } // End charged only
212     
213     // Fast simulation of EMCAL if requested
214     if (((AliJetKineReaderHeader*)fReaderHeader)->FastSimEMCAL()) {
215       // Charged particles only
216       if (charge != 0){
217         // Simulate efficiency
218         if (!Efficiency(p0, eta, phi)) continue;
219         // Simulate resolution
220         p = SmearMomentum(4, p0);
221       } // end "if" charged particles
222       // Neutral particles (exclude K0L, n, nbar)
223       if (pdg == kNeutron || pdg == kK0Long) continue;
224     } // End fast EMCAL
225     
226     // Fast simulation of TPC if requested
227     if (((AliJetKineReaderHeader*)fReaderHeader)->FastSimTPC()) {
228       // Charged particles only
229       if (charge == 0)               continue;
230       // Simulate efficiency
231       if (!Efficiency(p0, eta, phi)) continue;
232       // Simulate resolution
233       p = SmearMomentum(4, p0);
234     } // End fast TPC
235
236     // Fill momentum array
237     Float_t r  = p/p0;
238     Float_t px = r * part->Px();
239     Float_t py = r * part->Py();
240     Float_t pz = r * part->Pz();
241     Float_t m =  part->M();
242     
243     Float_t e  = TMath::Sqrt(px * px + py * py + pz * pz + m * m);
244     p4 = TLorentzVector(px, py, pz, e);
245     if ((p4.Eta()>etaMax) || (p4.Eta()<etaMin)) continue;
246
247     // Flag used to store the r factor
248     Float_t ptReso = r;
249     Bool_t cflag = kFALSE, sflag = kTRUE;
250     if (pt > ptMin) cflag = kTRUE; // track surviving pt cut
251
252     fCalTrkEvent->AddCalTrkTrackKine(part,cflag,sflag,ptReso);
253
254     goodTrack++;
255
256   } // track loop
257
258   if(fDebug>0) printf(" Number of good tracks %d \n", goodTrack);
259
260   return kTRUE;
261
262 }
263
264 //-----------------------------------------------------------------------
265 Float_t AliJetFillCalTrkTrackMC::SmearMomentum(Int_t ind, Float_t p)
266 {
267   //  The relative momentum error, i.e.
268   //  (delta p)/p = sqrt (a**2 + (b*p)**2) * 10**-2,
269   //  where typically a = 0.75 and b = 0.16 - 0.24 depending on multiplicity
270   //  (the lower value is for dn/d(eta) about 2000, and the higher one for 8000)
271   //
272   //  If we include information from TRD, b will be a factor 2/3 smaller.
273   //
274   //  ind = 1: high multiplicity
275   //  ind = 2: low  multiplicity
276   //  ind = 3: high multiplicity + TRD
277   //  ind = 4: low  multiplicity + TRD
278
279   Float_t pSmeared;
280   Float_t a = 0.75;
281   Float_t b = 0.12;
282
283   if (ind == 1) b = 0.12;
284   if (ind == 2) b = 0.08;
285   if (ind == 3) b = 0.12;
286   if (ind == 4) b = 0.08;
287
288   Float_t sigma =  p * TMath::Sqrt(a * a + b * b * p * p)*0.01;
289   pSmeared = p + gRandom->Gaus(0., sigma);
290   return pSmeared;
291
292 }
293
294 //-----------------------------------------------------------------------
295 Bool_t AliJetFillCalTrkTrackMC::Efficiency(Float_t p, Float_t /*eta*/, Float_t phi)
296 {
297   // Fast simulation of geometrical acceptance and tracking efficiency
298   
299   //  Tracking
300   Float_t eff = 0.99;
301   if (p < 0.5) eff -= (0.5-p)*0.2/0.3;
302   // Geometry
303   if (p > 0.5) {
304     phi *= 180. / TMath::Pi();
305     // Sector number 0 - 17
306     Int_t isec  = Int_t(phi / 20.);
307     // Sector centre
308     Float_t phi0 = isec * 20. + 10.;
309     Float_t phir = TMath::Abs(phi-phi0);
310     // 2 deg of dead space
311     if (phir > 9.) eff = 0.;
312   }
313   
314   if (gRandom->Rndm() > eff) {
315     return kFALSE;
316   } else {
317     return kTRUE;
318   }
319   
320 }
321
322