Update of the tag system. 1. Correct implementation of the event ID - period, orbit...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskMCParticleFilter.cxx
CommitLineData
da97a08a 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"
dce1b636 35#include "AliAODMCHeader.h"
da97a08a 36#include "AliAODHandler.h"
37#include "AliAODVertex.h"
38#include "AliAODMCParticle.h"
39
40
41#include "AliLog.h"
42
43ClassImp(AliAnalysisTaskMCParticleFilter)
44
45////////////////////////////////////////////////////////////////////////
46
47//____________________________________________________________________
48AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter():
49AliAnalysisTaskSE(),
50 fTrackFilterMother(0x0)
51{
52 // Default constructor
53}
54
55//____________________________________________________________________
56AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter(const char* name):
57 AliAnalysisTaskSE(name),
58 fTrackFilterMother(0x0)
59{
60 // Default constructor
61}
62
63
64//____________________________________________________________________
65AliAnalysisTaskMCParticleFilter::AliAnalysisTaskMCParticleFilter(const AliAnalysisTaskMCParticleFilter& obj):
66 AliAnalysisTaskSE(obj),
67 fTrackFilterMother(obj.fTrackFilterMother)
68{
69 // Copy constructor
70}
71
72//____________________________________________________________________
73AliAnalysisTaskMCParticleFilter::~AliAnalysisTaskMCParticleFilter()
74{
75 // if( fTrackFilterMother ) delete fTrackFilterMother;
76}
77
78
79//____________________________________________________________________
80AliAnalysisTaskMCParticleFilter& 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//____________________________________________________________________
91void AliAnalysisTaskMCParticleFilter::UserCreateOutputObjects()
92{
93 // Create the output container
94 if (OutputTree()&&fTrackFilterMother)
95 OutputTree()->GetUserInfo()->Add(fTrackFilterMother);
d2740fba 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
dce1b636 105
106 // mcparticles
da97a08a 107 TClonesArray *tca = new TClonesArray("AliAODMCParticle", 0);
108 tca->SetName(AliAODMCParticle::StdBranchName());
109 AddAODBranch("TClonesArray",&tca);
da97a08a 110
dce1b636 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());
da97a08a 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);
dce1b636 127
da97a08a 128
129}
130
131//____________________________________________________________________
132void 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 AliStack* stack = mcE->Stack();
168 Int_t np = mcE->GetNumberOfTracks();
169 Int_t nprim = stack->GetNprimary();
170 // TODO ADD MC VERTEX
171
172 // We take all real primaries
173
174
175
176 Int_t j=0;
177 for (Int_t ip = 0; ip < np; ip++){
178 AliMCParticle* mcpart = mcE->GetTrack(ip);
179 TParticle* part = mcpart->Particle();
180
181 Float_t xv = part->Vx();
182 Float_t yv = part->Vy();
183 Float_t zv = part->Vz();
184 Float_t rv = TMath::Sqrt(xv * xv + yv * yv);
185
186 Bool_t write = kFALSE;
da97a08a 187
da97a08a 188 if (ip < nprim) {
189 // Select the primary event
190 write = kTRUE;
191 } else if (part->GetUniqueID() == 4) {
192 // Particles from decay
193 // Check that the decay chain ends at a primary particle
194 TParticle* mother = part;
195 Int_t imo = part->GetFirstMother();
196 while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
197 mother = mcE->Stack()->Particle(imo);
198 imo = mother->GetFirstMother();
199 }
200 // Select according to pseudorapidity and production point
201 if (imo < nprim && Select(mother, rv, zv))
202 write = kTRUE;
203 } else if (part->GetUniqueID() == 5) {
204 // Now look for pair production
205 continue;
206 Int_t imo = part->GetFirstMother();
207 if (imo < nprim) {
208 // Select, if the gamma is a primary
209 write = kTRUE;
210 } else {
211 // Check if the gamma comes from the decay chain of a primary particle
212 TParticle* mother = mcE->Stack()->Particle(imo);
213 imo = mother->GetFirstMother();
214 while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
215 mother = mcE->Stack()->Particle(imo);
216 imo = mother->GetFirstMother();
217 }
218 // Select according to pseudorapidity and production point
219 if (imo < nprim && Select(mother, rv, zv))
220 write = kTRUE;
221 }
222 }
223 /*
224 else if (part->GetUniqueID() == 13){
225 // Evaporation
226 // Check that we end at a primary particle
227 TParticle* mother = part;
228 Int_t imo = part->GetFirstMother();
229 while((imo >= nprim) && ((mother->GetUniqueID() == 4 ) || ( mother->GetUniqueID() == 13))) {
230 mother = mcE->Stack()->Particle(imo);
231 imo = mother->GetFirstMother();
232 }
233 // Select according to pseudorapidity and production point
234 if (imo < nprim && Select(mother, rv, zv))
235 write = kTRUE;
236 }
237 */
238 if (write) {
239 if(mcH)mcH->SelectParticle(ip);
240 j++;
241 }
242 }
243
244 return;
245}
246
247Bool_t AliAnalysisTaskMCParticleFilter::Select(TParticle* part, Float_t rv, Float_t zv)
248{
249 // Selection accoring to eta of the mother and production point
250 // This has to be refined !!!!!!
251
252 // Esp if we don't have collisison in the central barrel but e.g. beam gas
253 // return kTRUE;
254
255 Float_t eta = part->Eta();
256
257 // central barrel consider everything in the ITS...
258 // large eta window for smeared vertex and SPD acceptance (2 at z = 0)
259 // larger for V0s in the TPC
260 // if (TMath::Abs(eta) < 2.5 && rv < 250. && TMath::Abs(zv)<255)return kTRUE;
261
262 // Andreas' Cuts
263 if (TMath::Abs(eta) < 1. && rv < 170)return kTRUE;
264
265 // Muon arm
266 if(eta > -4.2 && eta < -2.3 && zv > -500.)return kTRUE; // Muon arms
267
268 // PMD acceptance 2.3 <= eta < = 3.5
269 // if(eta>2.0&&eta<3.7)return kTRUE;
270
271 return kFALSE;
272
273}
274