]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/SPECTRA/PiKaPr/TestAOD/AliAnalysisTaskSpectraBoth.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / AliAnalysisTaskSpectraBoth.cxx
CommitLineData
c683985a 1/**************************************************************************
2 * Copyright(c) 1998-2009, 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// AliAnalysisTaskSpectraBoth class
18//-----------------------------------------------------------------
19
20#include "TChain.h"
21#include "TTree.h"
22#include "TLegend.h"
23#include "TH1F.h"
24#include "TH2F.h"
25#include "TH3F.h"
26#include "TCanvas.h"
27#include "AliAnalysisTask.h"
28#include "AliAnalysisManager.h"
29#include "AliAODTrack.h"
30#include "AliAODMCParticle.h"
31#include "AliVParticle.h"
32#include "AliAODEvent.h"
33#include "AliAODInputHandler.h"
34#include "AliAnalysisTaskSpectraBoth.h"
35#include "AliAnalysisTaskESDfilter.h"
36#include "AliAnalysisDataContainer.h"
37#include "AliSpectraBothHistoManager.h"
38#include "AliSpectraBothTrackCuts.h"
39#include "AliSpectraBothEventCuts.h"
40#include "AliCentrality.h"
41#include "TProof.h"
42#include "AliPID.h"
43#include "AliVEvent.h"
44#include "AliESDEvent.h"
45#include "AliPIDResponse.h"
46#include "AliStack.h"
47#include "AliSpectraBothPID.h"
48#include "AliGenEventHeader.h"
49#include <TMCProcess.h>
50
51#include <iostream>
52
53
54
55
56using namespace AliSpectraNameSpaceBoth;
57using namespace std;
58
59ClassImp(AliAnalysisTaskSpectraBoth)
60
61//________________________________________________________________________
bc701102 62AliAnalysisTaskSpectraBoth::AliAnalysisTaskSpectraBoth(const char *name) : AliAnalysisTaskSE(name), fAOD(0), fHistMan(0), fTrackCuts(0), fEventCuts(0), fPID(0), fIsMC(0), fNRebin(0),fUseMinSigma(0),fCuts(0),fdotheMCLoopAfterEventCuts(0),fmakePIDQAhisto(1),fMotherWDPDGcode(-1)
be25efef 63
c683985a 64{
65 // Default constructor
66
67 DefineInput(0, TChain::Class());
68 DefineOutput(1, AliSpectraBothHistoManager::Class());
69 DefineOutput(2, AliSpectraBothEventCuts::Class());
70 DefineOutput(3, AliSpectraBothTrackCuts::Class());
71 DefineOutput(4, AliSpectraBothPID::Class());
72 fNRebin=0;
73
74}
75//________________________________________________________________________
76//________________________________________________________________________
77void AliAnalysisTaskSpectraBoth::UserCreateOutputObjects()
78{
79 // create output objects
be25efef 80 fHistMan = new AliSpectraBothHistoManager("SpectraHistos",fNRebin,fmakePIDQAhisto);
c683985a 81
82 if (!fTrackCuts) AliFatal("Track Cuts should be set in the steering macro");
83 if (!fEventCuts) AliFatal("Event Cuts should be set in the steering macro");
84 if (!fPID) AliFatal("PID object should be set in the steering macro");
85 fTrackCuts->SetAliESDtrackCuts(fCuts);
86 fEventCuts->InitHisto();
87 fTrackCuts->InitHisto();
88
89 PostData(1, fHistMan );
90 PostData(2, fEventCuts);
91 PostData(3, fTrackCuts);
92 PostData(4, fPID );
93}
94//________________________________________________________________________
95void AliAnalysisTaskSpectraBoth::UserExec(Option_t *)
96{
97 // main event loop
98 Int_t ifAODEvent=AliSpectraBothTrackCuts::kotherobject;
99 fAOD = dynamic_cast<AliVEvent*>(InputEvent());
100 // AliESDEvent* esdevent=0x0;
101 // AliAODEvent* aodevent=0x0;
102
103 TString nameoftrack(fAOD->ClassName());
104 if(!nameoftrack.CompareTo("AliESDEvent"))
105 {
106 ifAODEvent=AliSpectraBothTrackCuts::kESDobject;
107 //esdevent=dynamic_cast<AliESDEvent*>(fAOD);
108 }
109 else if(!nameoftrack.CompareTo("AliAODEvent"))
110 {
111 ifAODEvent=AliSpectraBothTrackCuts::kAODobject;
112 //aodevent=dynamic_cast<AliAODEvent*>(fAOD);
113 }
114 else
115 AliFatal("Not processing AODs or ESDS") ;
21e4a3cd 116 if(fIsMC)
117 {
118 if(!fEventCuts->CheckMCProcessType(MCEvent()))
119 return ;
120 }
121
122
c683985a 123 if(fdotheMCLoopAfterEventCuts)
34347952 124 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,-100,fHistMan->GetEventStatHist()))
4954491e 125 return;//event selection
c683985a 126 TClonesArray *arrayMC = 0;
127 Int_t npar=0;
128 AliStack* stack=0x0;
129 Double_t mcZ=-100;
130
131 if (fIsMC)
132 {
133 TArrayF mcVertex(3);
134 mcVertex[0]=9999.; mcVertex[1]=9999.; mcVertex[2]=9999.;
135 AliMCEvent* mcEvent=(AliMCEvent*)MCEvent();
136 if (!mcEvent)
137 {
138 AliFatal("Error: MC particles branch not found!\n");
139 }
140 AliHeader* header = mcEvent->Header();
141 if (!header)
142 {
143 AliDebug(AliLog::kError, "Header not available");
144 return;
145 }
146
147 AliGenEventHeader* genHeader = header->GenEventHeader();
148 if(genHeader)
149 {
150 genHeader->PrimaryVertex(mcVertex);
151 mcZ=mcVertex[2];
152 }
153 if(ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
154 {
155 arrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
156 if (!arrayMC)
157 {
158 AliFatal("Error: MC particles branch not found!\n");
159 }
160 Int_t nMC = arrayMC->GetEntries();
161 for (Int_t iMC = 0; iMC < nMC; iMC++)
162 {
163 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(iMC);
164 if(!partMC->Charge()) continue;//Skip neutrals
165 //if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax()){//charged hadron are filled inside the eta acceptance
166 //Printf("%f %f-%f",partMC->Eta(),fTrackCuts->GetEtaMin(),fTrackCuts->GetEtaMax());
167 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
168 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
169 //rapidity cut
170 if(partMC->Y() > fTrackCuts->GetYMax()|| partMC->Y() < fTrackCuts->GetYMin() )
171 continue;
172 if(partMC->IsPhysicalPrimary())
173 npar++;
174 // check for true PID + and fill P_t histos
175 Int_t charge = partMC->Charge() > 0 ? kChPos : kChNeg ;
176 Int_t id = fPID->GetParticleSpecie(partMC);
177 if(id != kSpUndefined)
178 {
179 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
180 }
181 }
182 }
183 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
184 {
185 stack = mcEvent->Stack();
186 Int_t nMC = stack->GetNtrack();
187 for (Int_t iMC = 0; iMC < nMC; iMC++)
188 {
189
190 TParticle *partMC = stack->Particle(iMC);
191
192 if(!partMC)
193 continue;
194
195 if(!partMC->GetPDG(0))
196 continue;
197 if(TMath::Abs(partMC->GetPDG(0)->Charge()/3.0)<0.01)
198 continue;//Skip neutrals
199 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
200 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
201 if(partMC->Y() > fTrackCuts->GetYMax() ||partMC->Y() < fTrackCuts->GetYMin() )
202 continue;
203 if(stack->IsPhysicalPrimary(iMC))
204 npar++;
205 // check for true PID + and fill P_t histos
206 Int_t charge = partMC->GetPDG(0)->Charge()/3.0 > 0 ? kChPos : kChNeg ;
207 Int_t id = fPID->GetParticleSpecie(partMC);
208 if(id != kSpUndefined)
209 {
210 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
211 }
212 }
213 }
214 }
215 if(!fdotheMCLoopAfterEventCuts)
34347952 216 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,mcZ,fHistMan->GetEventStatHist()))
0ab8c127 217 return;//event selection
c683985a 218 //main loop on tracks
219 Int_t ntracks=0;
220 //cout<<fAOD->GetNumberOfTracks()<<endl;
221 for (Int_t iTracks = 0; iTracks < fAOD->GetNumberOfTracks(); iTracks++)
222 {
223 AliVTrack* track = dynamic_cast<AliVTrack*>(fAOD->GetTrack(iTracks));
224 AliAODTrack* aodtrack=0;
225 AliESDtrack* esdtrack=0;
226 Float_t dca=-999.;
227 Float_t dcaz=-999.;
228 Short_t ncls=-1;
229 Float_t chi2perndf=-1.0;
230 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
231 {
232 esdtrack=dynamic_cast<AliESDtrack*>(track);
233 if(!esdtrack)
234 continue;
235 esdtrack->GetImpactParameters(dca,dcaz);
236 ncls=esdtrack->GetTPCNcls();
237 if ( ncls > 5)
238 chi2perndf=(esdtrack->GetTPCchi2()/Float_t(ncls - 5));
239
240 else
241 chi2perndf=-1;
242
243 }
244 else if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
245 {
246 aodtrack=dynamic_cast<AliAODTrack*>(track);
247 if(!aodtrack)
248 continue;
249 dca=aodtrack->DCA();
250 dcaz=aodtrack->ZAtDCA();
251 ncls=aodtrack->GetTPCNcls();
252 chi2perndf=aodtrack->Chi2perNDF();
253 }
254 else
255 continue;
256 if (!fTrackCuts->IsSelected(track,kTRUE))
0ab8c127 257 continue;
258
c683985a 259 ntracks++;
be25efef 260 if(fmakePIDQAhisto)
261 fPID->FillQAHistos(fHistMan, track, fTrackCuts);
c683985a 262
263 //calculate DCA for AOD track
264 if(dca==-999.)
265 {// track->DCA() does not work in old AOD production
266 Double_t d[2], covd[3];
267 AliVTrack* track_clone=(AliVTrack*)track->Clone("track_clone"); // need to clone because PropagateToDCA updates the track parameters
268 Bool_t isDCA = track_clone->PropagateToDCA(fAOD->GetPrimaryVertex(),fAOD->GetMagneticField(),9999.,d,covd);
269 delete track_clone;
270 if(!isDCA)
271 d[0]=-999.;
272 dca=d[0];
273 dcaz=d[1];
274 }
275
276 fHistMan->GetPtHistogram(kHistPtRec)->Fill(track->Pt(),dca); // PT histo
277 // get identity and charge
278 Bool_t rec[3]={false,false,false};
bc701102 279 Bool_t sel[3]={false,false,false};
c683985a 280 Int_t idRec = fPID->GetParticleSpecie(fHistMan,track, fTrackCuts,rec);
281 for(int irec=kSpPion;irec<kNSpecies;irec++)
282 {
283
284 if(fUseMinSigma)
285 {
286 if(irec>kSpPion)
287 break;
288 }
289 else
290 {
291 if(!rec[irec])
292 idRec = kSpUndefined;
293 else
294 idRec=irec;
295 }
296
297 Int_t charge = track->Charge() > 0 ? kChPos : kChNeg;
298
299 // Fill histograms, only if inside y and nsigma acceptance
300 if(idRec != kSpUndefined && fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec))
301 {
302 fHistMan->GetHistogram2D(kHistPtRecSigma,idRec,charge)->Fill(track->Pt(),dca);
34347952 303 if(fTrackCuts->GetMakeQAhisto())
304 {
305 fTrackCuts->GetHistoDCAzQA()->Fill(idRec,track->Pt(),dcaz);
306 fTrackCuts->GetHistoNclustersQA()->Fill(idRec,track->Pt(),ncls);
307 fTrackCuts->GetHistochi2perNDFQA()->Fill(idRec,track->Pt(),chi2perndf);
308 }
bc701102 309 sel[idRec]=true;
c683985a 310 }
311 //can't put a continue because we still have to fill allcharged primaries, done later
312
313 /* MC Part */
314 if (arrayMC||stack)
315 {
316 Bool_t isPrimary = kFALSE;
317 Bool_t isSecondaryMaterial = kFALSE;
318 Bool_t isSecondaryWeak = kFALSE;
319 Int_t idGen =kSpUndefined;
320 Int_t pdgcode=0;
be25efef 321 Int_t motherpdg=-1;
c683985a 322 if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
323 {
324 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(TMath::Abs(track->GetLabel()));
325 if (!partMC)
326 {
327 AliError("Cannot get MC particle");
328 continue;
329 }
330 // Check if it is primary, secondary from material or secondary from weak decay
331 isPrimary = partMC->IsPhysicalPrimary();
332 isSecondaryWeak = partMC->IsSecondaryFromWeakDecay();
333 isSecondaryMaterial = partMC->IsSecondaryFromMaterial();
334 //cout<<"AOD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
335
be25efef 336 if(!isPrimary&&!isSecondaryWeak&&!isSecondaryMaterial)//old tagging for old AODs
c683985a 337 {
338 AliError("old tagging");
339 Int_t mfl=-999,codemoth=-999;
340 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
341 if(indexMoth>=0)
342 {//is not fake
343 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
344 codemoth = TMath::Abs(moth->GetPdgCode());
345 mfl = Int_t (codemoth/ TMath::Power(10, Int_t(TMath::Log10(codemoth))));
346 }
347 //Int_t uniqueID = partMC->GetUniqueID();
348 //cout<<"uniqueID: "<<partMC->GetUniqueID()<<" "<<kPDecay<<endl;
349 //cout<<"status: "<<partMC->GetStatus()<<" "<<kPDecay<<endl;
350 // if(uniqueID == kPDecay)Printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
351 if(mfl==3)
352 isSecondaryWeak = kTRUE; // add if(partMC->GetStatus() & kPDecay)? FIXME
353 else
354 isSecondaryMaterial = kTRUE;
355 }
356 //cout<<"AOD 2 tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
be25efef 357 if(isSecondaryWeak)
358 {
359 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
360 if(indexMoth>=0)
361 {
362 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
93f027ac 363 if(moth)
be25efef 364 motherpdg=TMath::Abs(moth->GetPdgCode());
365 }
366 }
c683985a 367
368 idGen = fPID->GetParticleSpecie(partMC);
369 pdgcode=partMC->GetPdgCode();
370 }
371 else if (ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
372 {
373 TParticle *partMC =stack->Particle(TMath::Abs(track->GetLabel()));
374 if (!partMC)
375 {
376 AliError("Cannot get MC particle");
377 continue;
378 }
379 isPrimary = stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()));
380 isSecondaryWeak = stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()));
381 isSecondaryMaterial = stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()));
382 //cout<<"ESD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<endl;
383
be25efef 384 if(isSecondaryWeak)
385 {
386
387 TParticle* moth=stack->Particle(TMath::Abs(partMC->GetFirstMother()));
388 if(moth)
389 motherpdg = TMath::Abs(moth->GetPdgCode());
390
391 }
392
393
c683985a 394 idGen = fPID->GetParticleSpecie(partMC);
395 pdgcode=partMC->GetPdgCode();
396 }
397 else
398 return;
399
400 // cout<<isPrimary<<" "<<isSecondaryWeak<<" "<<isSecondaryMaterial<<endl;
401 // cout<<" functions "<<partMC->IsPhysicalPrimary()<<" "<<partMC->IsSecondaryFromWeakDecay()<<" "<<partMC->IsSecondaryFromMaterial()<<endl;
402
403 if (isPrimary&&irec==kSpPion)
404 fHistMan->GetPtHistogram(kHistPtRecPrimaryAll)->Fill(track->Pt(),dca); // PT histo of reconstrutsed primaries in defined eta
405
406 //nsigma cut (reconstructed nsigma)
407 if(idRec == kSpUndefined)
408 continue;
409
410 // rapidity cut (reconstructed pt and identity)
411 if(!fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec)) continue;
412
413 // Get true ID
bc701102 414
c683985a 415
416 if (idRec == idGen) fHistMan->GetHistogram2D(kHistPtRecTrue, idGen, charge)->Fill(track->Pt(),dca);
417
418 if (isPrimary)
419 {
420 fHistMan->GetHistogram2D(kHistPtRecSigmaPrimary, idRec, charge)->Fill(track->Pt(),dca);
421 if(idGen != kSpUndefined)
422 {
423 fHistMan->GetHistogram2D(kHistPtRecPrimary, idGen, charge)->Fill(track->Pt(),dca);
424 if (idRec == idGen)
425 fHistMan->GetHistogram2D(kHistPtRecTruePrimary, idGen, charge)->Fill(track->Pt(),dca);
426 }
427 }
428 //25th Apr - Muons are added to Pions -- FIXME
429 if ( pdgcode == 13 && idRec == kSpPion)
430 {
431 fHistMan->GetPtHistogram(kHistPtRecTrueMuonPlus)->Fill(track->Pt(),dca);
432 if(isPrimary)
433 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonPlus)->Fill(track->Pt(),dca);
434 }
435 if ( pdgcode == -13 && idRec == kSpPion)
436 {
437 fHistMan->GetPtHistogram(kHistPtRecTrueMuonMinus)->Fill(track->Pt(),dca);
438 if (isPrimary)
439 {
440 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonMinus)->Fill(track->Pt(),dca);
441 }
442 }
443
444 ///..... END FIXME
445
446 // Fill secondaries
be25efef 447 if(isSecondaryWeak)
448 {
449 if(fMotherWDPDGcode>0)
450 {
451 if(motherpdg==fMotherWDPDGcode)
452 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
453 }
454 else
455 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
456 }
c683985a 457 if(isSecondaryMaterial)
458 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryMaterial , idRec, charge)->Fill(track->Pt(),dca);
459
460 }//end if(arrayMC)
461 }
bc701102 462 if(sel[0]&&sel[1]&&sel[2])//pi+k+p
463 fHistMan->GetPtHistogram("hHistDoubleCounts")->Fill(track->Pt(),0);
464 else if(sel[0]&&sel[1]) //pi+k
465 fHistMan->GetPtHistogram("hHistDoubleCounts")->Fill(track->Pt(),1);
466 else if(sel[0]&&sel[2]) //pi+k
467 fHistMan->GetPtHistogram("hHistDoubleCounts")->Fill(track->Pt(),2);
468 else if(sel[1]&&sel[2]) //p+k
469 fHistMan->GetPtHistogram("hHistDoubleCounts")->Fill(track->Pt(),3);
470
c683985a 471
472
473 } // end loop on tracks
474
475 // cout<< ntracks<<endl;
476 fHistMan->GetGenMulvsRawMulHistogram("hHistGenMulvsRawMul")->Fill(npar,ntracks);
477 PostData(1, fHistMan );
478 PostData(2, fEventCuts);
479 PostData(3, fTrackCuts);
480 PostData(4, fPID );
481}
482
483//_________________________________________________________________
484void AliAnalysisTaskSpectraBoth::Terminate(Option_t *)
485{
486 // Terminate
487}