]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskMCParticleFilter.cxx
MCEvent and MCEventHandler can be used as containers. This allows us to compose MC...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskMCParticleFilter.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 //  Analysis task for Kinematic filtering
18 //  Fill AODtrackMC tracks from Kinematic stack
19 //
20  
21 #include <TChain.h>
22 #include <TFile.h>
23 #include "TParticle.h"
24 #include "TString.h"
25
26 #include "AliAnalysisTaskMCParticleFilter.h"
27 #include "AliAnalysisManager.h"
28 #include "AliAnalysisFilter.h"
29 #include "AliHeader.h"
30 #include "AliStack.h"
31 #include "AliMCEvent.h"
32 #include "AliMCEventHandler.h"
33 #include "AliAODEvent.h"
34 #include "AliAODHeader.h"
35 #include "AliAODMCHeader.h"
36 #include "AliAODHandler.h"
37 #include "AliAODVertex.h"
38 #include "AliAODMCParticle.h"
39
40
41 #include "AliLog.h"
42
43 ClassImp(AliAnalysisTaskMCParticleFilter)
44
45 ////////////////////////////////////////////////////////////////////////
46
47 //____________________________________________________________________
48 AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter():
49 AliAnalysisTaskSE(),
50   fTrackFilterMother(0x0)
51 {
52   // Default constructor
53 }
54
55 //____________________________________________________________________
56 AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter(const char* name):
57     AliAnalysisTaskSE(name),
58     fTrackFilterMother(0x0)
59 {
60   // Default constructor
61 }
62
63
64 //____________________________________________________________________
65 AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter(const AliAnalysisTaskMCParticleFilter& obj):
66     AliAnalysisTaskSE(obj),
67     fTrackFilterMother(obj.fTrackFilterMother)
68 {
69   // Copy constructor
70 }
71
72 //____________________________________________________________________
73 AliAnalysisTaskMCParticleFilter::~AliAnalysisTaskMCParticleFilter()
74 {
75   //  if( fTrackFilterMother ) delete fTrackFilterMother;
76 }
77
78
79 //____________________________________________________________________
80 AliAnalysisTaskMCParticleFilter& AliAnalysisTaskMCParticleFilter::operator=(const AliAnalysisTaskMCParticleFilter& other)
81 {
82 // Assignment
83   if(this!=&other) {
84     AliAnalysisTaskSE::operator=(other);
85     fTrackFilterMother = other.fTrackFilterMother;
86   }
87   return *this;
88 }
89
90 //____________________________________________________________________
91 void AliAnalysisTaskMCParticleFilter::UserCreateOutputObjects()
92 {
93   // Create the output container
94     if (OutputTree()&&fTrackFilterMother) 
95         OutputTree()->GetUserInfo()->Add(fTrackFilterMother);
96
97     // this part is mainly needed to set the MCEventHandler
98     // to the AODHandler, this will not be needed when
99     // AODHandler goes to ANALYSISalice
100     // setting in the steering macro will not work on proof :(
101     // so we have to do it in a task
102
103     // the branch booking can also go into the AODHandler then
104
105
106     // mcparticles
107     TClonesArray *tca = new TClonesArray("AliAODMCParticle", 0);
108     tca->SetName(AliAODMCParticle::StdBranchName());
109     AddAODBranch("TClonesArray",&tca);
110
111     // MC header...
112     AliAODMCHeader *mcHeader = new AliAODMCHeader();
113     Printf("AODMCHeader %p",mcHeader);
114     Printf("AODMCHeader ** %p",&mcHeader);
115     mcHeader->SetName(AliAODMCHeader::StdBranchName());
116     AddAODBranch("AliAODMCHeader",&mcHeader);    
117
118     
119
120     AliMCEventHandler *mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
121     AliAODHandler *aodH = dynamic_cast<AliAODHandler*> ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
122     if(!aodH){
123       Printf("%s:&d Could not get AODHandler",(char*)__FILE__,__LINE__);
124       return;
125     }
126     aodH->SetMCEventHandler(mcH);
127
128     
129 }
130
131 //____________________________________________________________________
132 void AliAnalysisTaskMCParticleFilter::UserExec(Option_t */*option*/)
133 {
134 // Execute analysis for current event
135 //
136
137 // Fill AOD tracks from Kinematic stack
138     
139   // get AliAOD Event 
140   AliAODEvent* aod = AODEvent();
141   if (!aod) {
142       AliWarning("No Output Handler connected, doing nothing !") ;
143       return;
144   }
145
146   AliMCEventHandler *mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
147   if(!mcH){ 
148     AliWarning("No MC handler Found");
149     return;
150   }
151
152
153   // fetch the output 
154   // Fill control histos
155
156   // tmp array for holding the mctracks
157   // need to set mother and duagther __before__
158   // filling in the tree
159
160   AliMCEvent *mcE = MCEvent();
161
162   if(!mcE){
163     AliWarning("No MC event Found");
164     return;
165   }
166
167   Int_t np    = mcE->GetNumberOfTracks();
168   Int_t nprim = mcE->GetNumberOfPrimaries();
169   // TODO ADD MC VERTEX
170   
171   // We take all real primaries
172
173
174   Int_t j=0;
175   for (Int_t ip = 0; ip < np; ip++){
176     AliMCParticle* mcpart =  mcE->GetTrack(ip);
177     TParticle* part = mcpart->Particle();
178     Float_t xv = part->Vx();
179     Float_t yv = part->Vy();
180     Float_t zv = part->Vz();
181     Float_t rv = TMath::Sqrt(xv * xv + yv * yv);
182       
183     Bool_t write = kFALSE;
184     
185     if (ip < nprim) {
186       // Select the primary event
187       write = kTRUE;
188     } else if (part->GetUniqueID() == 4) {
189       // Particles from decay
190       // Check that the decay chain ends at a primary particle
191       AliMCParticle* mother = mcpart;
192       Int_t imo = mcpart->GetMother();
193       while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
194         mother = mcE->GetTrack(imo);
195         imo =  mother->GetMother();
196       }
197       // Select according to pseudorapidity and production point of primary ancestor
198       if (imo < nprim && Select(mcE->GetTrack(imo)->Particle(), rv, zv))write = kTRUE;         
199     } else if (part->GetUniqueID() == 5) {
200       // Now look for pair production
201       Int_t imo = mcpart->GetMother();
202       if (imo < nprim) {
203         // Select, if the gamma is a primary
204         write = kTRUE;
205       } else {
206         // Check if the gamma comes from the decay chain of a primary particle
207         AliMCParticle* mother = mcE->GetTrack(imo);
208         imo = mother->GetMother();
209         while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
210           mother =  mcE->GetTrack(imo);
211           imo =  mother->GetMother();
212         }
213         // Select according to pseudorapidity and production point 
214         if (imo < nprim && Select(mother->Particle(), rv, zv)) 
215           write = kTRUE;
216       }
217     }
218     /*
219     else if (part->GetUniqueID() == 13){
220       // Evaporation
221       // Check that we end at a primary particle
222       TParticle* mother = part;
223       Int_t imo = part->GetFirstMother();
224       while((imo >= nprim) && ((mother->GetUniqueID() == 4 ) || ( mother->GetUniqueID() == 13))) {
225         mother =  mcE->Stack()->Particle(imo);
226         imo =  mother->GetFirstMother();
227       }
228       // Select according to pseudorapidity and production point 
229         if (imo < nprim && Select(mother, rv, zv)) 
230           write = kTRUE;
231     }
232     */    
233     if (write) {
234       if(mcH)mcH->SelectParticle(ip);
235       j++;
236     }
237   }
238
239
240     // check for charm daughters
241   static int  iTaken = 0;
242   static int  iAll = 0;
243   static int  iCharm = 0;
244   for (Int_t ip = 0; ip < np; ip++){
245     AliMCParticle* mcpart =  mcE->GetTrack(ip);
246     TParticle* part = mcpart->Particle();
247
248     //    if((TMath::Abs(part->GetPdgCode())/400)==1){
249     if((TMath::Abs(part->GetPdgCode()))==411){
250       // cases 
251       iCharm++;
252       Printf("Decay Mother %s",part->GetPDG()->GetName());
253       Int_t d0 =  mcpart->GetFirstDaughter();
254       Int_t d1 =  mcpart->GetLastDaughter();
255       if(d0>0&&d1>0){
256         for(int id = d0;id <= d1;id++){
257           AliMCParticle* daughter =  mcE->GetTrack(id);
258           Printf("Decay Daughter %s",daughter->Particle()->GetPDG()->GetName());
259           iAll++;
260           if(mcH->IsParticleSelected(id))iTaken++;
261         }
262       }
263     }
264   }
265   Printf("Taken daughters %d/%d of %d charm",iTaken,iAll,iCharm);
266
267
268   return;
269 }
270
271 Bool_t AliAnalysisTaskMCParticleFilter::Select(TParticle* part, Float_t rv, Float_t zv)
272 {
273   // Selection accoring to eta of the mother and production point
274   // This has to be refined !!!!!!
275
276   // Esp if we don't have collisison in the central barrel but e.g. beam gas
277   //  return kTRUE;
278
279   Float_t eta = part->Eta();
280
281   // central barrel consider everything in the ITS...
282   // large eta window for smeared vertex and SPD acceptance (2 at z = 0)
283   // larger for V0s in the TPC
284   //  if (TMath::Abs(eta) < 2.5 && rv < 250. && TMath::Abs(zv)<255)return kTRUE;
285
286   if (TMath::Abs(eta) < 2.5 && rv < 170)return kTRUE;   
287
288   // Andreas' Cuts
289   //  if (TMath::Abs(eta) < 1. && rv < 170)return kTRUE;   
290
291
292
293   // Muon arm
294   if(eta > -4.2 && eta < -2.3 && zv > -500.)return kTRUE; // Muon arms
295
296   // PMD acceptance 2.3 <= eta < = 3.5
297   //  if(eta>2.0&&eta<3.7)return kTRUE; 
298
299   return kFALSE;
300  
301 }
302