1 /**************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-----------------------------------------------------------------
17 // AliAnalysisTaskSpectraBoth class
18 //-----------------------------------------------------------------
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"
43 #include "AliVEvent.h"
44 #include "AliESDEvent.h"
45 #include "AliPIDResponse.h"
47 #include "AliSpectraBothPID.h"
48 #include "AliGenEventHeader.h"
49 #include <TMCProcess.h>
56 using namespace AliSpectraNameSpaceBoth;
59 ClassImp(AliAnalysisTaskSpectraBoth)
61 //________________________________________________________________________
62 AliAnalysisTaskSpectraBoth::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)
65 // Default constructor
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());
75 //________________________________________________________________________
76 //________________________________________________________________________
77 void AliAnalysisTaskSpectraBoth::UserCreateOutputObjects()
79 // create output objects
80 fHistMan = new AliSpectraBothHistoManager("SpectraHistos",fNRebin,fmakePIDQAhisto);
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();
89 PostData(1, fHistMan );
90 PostData(2, fEventCuts);
91 PostData(3, fTrackCuts);
94 //________________________________________________________________________
95 void AliAnalysisTaskSpectraBoth::UserExec(Option_t *)
98 Int_t ifAODEvent=AliSpectraBothTrackCuts::kotherobject;
99 fAOD = dynamic_cast<AliVEvent*>(InputEvent());
100 // AliESDEvent* esdevent=0x0;
101 // AliAODEvent* aodevent=0x0;
103 TString nameoftrack(fAOD->ClassName());
104 if(!nameoftrack.CompareTo("AliESDEvent"))
106 ifAODEvent=AliSpectraBothTrackCuts::kESDobject;
107 //esdevent=dynamic_cast<AliESDEvent*>(fAOD);
109 else if(!nameoftrack.CompareTo("AliAODEvent"))
111 ifAODEvent=AliSpectraBothTrackCuts::kAODobject;
112 //aodevent=dynamic_cast<AliAODEvent*>(fAOD);
115 AliFatal("Not processing AODs or ESDS") ;
118 if(!fEventCuts->CheckMCProcessType(MCEvent()))
123 if(fdotheMCLoopAfterEventCuts)
124 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,-100,fHistMan->GetEventStatHist()))
125 return;//event selection
126 TClonesArray *arrayMC = 0;
134 mcVertex[0]=9999.; mcVertex[1]=9999.; mcVertex[2]=9999.;
135 AliMCEvent* mcEvent=(AliMCEvent*)MCEvent();
138 AliFatal("Error: MC particles branch not found!\n");
140 AliHeader* header = mcEvent->Header();
143 AliDebug(AliLog::kError, "Header not available");
147 AliGenEventHeader* genHeader = header->GenEventHeader();
150 genHeader->PrimaryVertex(mcVertex);
153 if(ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
155 arrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
158 AliFatal("Error: MC particles branch not found!\n");
160 Int_t nMC = arrayMC->GetEntries();
161 for (Int_t iMC = 0; iMC < nMC; iMC++)
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());
170 if(partMC->Y() > fTrackCuts->GetYMax()|| partMC->Y() < fTrackCuts->GetYMin() )
172 if(partMC->IsPhysicalPrimary())
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)
179 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
183 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
185 stack = mcEvent->Stack();
186 Int_t nMC = stack->GetNtrack();
187 for (Int_t iMC = 0; iMC < nMC; iMC++)
190 TParticle *partMC = stack->Particle(iMC);
195 if(!partMC->GetPDG(0))
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() )
203 if(stack->IsPhysicalPrimary(iMC))
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)
210 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
215 if(!fdotheMCLoopAfterEventCuts)
216 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,mcZ,fHistMan->GetEventStatHist()))
217 return;//event selection
218 //main loop on tracks
220 //cout<<fAOD->GetNumberOfTracks()<<endl;
221 for (Int_t iTracks = 0; iTracks < fAOD->GetNumberOfTracks(); iTracks++)
223 AliVTrack* track = dynamic_cast<AliVTrack*>(fAOD->GetTrack(iTracks));
224 AliAODTrack* aodtrack=0;
225 AliESDtrack* esdtrack=0;
229 Float_t chi2perndf=-1.0;
230 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
232 esdtrack=dynamic_cast<AliESDtrack*>(track);
235 esdtrack->GetImpactParameters(dca,dcaz);
236 ncls=esdtrack->GetTPCNcls();
238 chi2perndf=(esdtrack->GetTPCchi2()/Float_t(ncls - 5));
244 else if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
246 aodtrack=dynamic_cast<AliAODTrack*>(track);
250 dcaz=aodtrack->ZAtDCA();
251 ncls=aodtrack->GetTPCNcls();
252 chi2perndf=aodtrack->Chi2perNDF();
256 if (!fTrackCuts->IsSelected(track,kTRUE))
261 fPID->FillQAHistos(fHistMan, track, fTrackCuts);
263 //calculate DCA for AOD track
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);
276 fHistMan->GetPtHistogram(kHistPtRec)->Fill(track->Pt(),dca); // PT histo
277 // get identity and charge
278 Bool_t rec[3]={false,false,false};
279 Bool_t sel[3]={false,false,false};
280 Int_t idRec = fPID->GetParticleSpecie(fHistMan,track, fTrackCuts,rec);
281 for(int irec=kSpPion;irec<kNSpecies;irec++)
292 idRec = kSpUndefined;
297 Int_t charge = track->Charge() > 0 ? kChPos : kChNeg;
299 // Fill histograms, only if inside y and nsigma acceptance
300 if(idRec != kSpUndefined && fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec))
302 fHistMan->GetHistogram2D(kHistPtRecSigma,idRec,charge)->Fill(track->Pt(),dca);
303 if(fTrackCuts->GetMakeQAhisto())
305 fTrackCuts->GetHistoDCAzQA()->Fill(idRec,track->Pt(),dcaz);
306 fTrackCuts->GetHistoNclustersQA()->Fill(idRec,track->Pt(),ncls);
307 fTrackCuts->GetHistochi2perNDFQA()->Fill(idRec,track->Pt(),chi2perndf);
311 //can't put a continue because we still have to fill allcharged primaries, done later
316 Bool_t isPrimary = kFALSE;
317 Bool_t isSecondaryMaterial = kFALSE;
318 Bool_t isSecondaryWeak = kFALSE;
319 Int_t idGen =kSpUndefined;
322 if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
324 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(TMath::Abs(track->GetLabel()));
327 AliError("Cannot get MC particle");
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;
336 if(!isPrimary&&!isSecondaryWeak&&!isSecondaryMaterial)//old tagging for old AODs
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()
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))));
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("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
352 isSecondaryWeak = kTRUE; // add if(partMC->GetStatus() & kPDecay)? FIXME
354 isSecondaryMaterial = kTRUE;
356 //cout<<"AOD 2 tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
359 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
362 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
364 motherpdg=TMath::Abs(moth->GetPdgCode());
368 idGen = fPID->GetParticleSpecie(partMC);
369 pdgcode=partMC->GetPdgCode();
371 else if (ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
373 TParticle *partMC =stack->Particle(TMath::Abs(track->GetLabel()));
376 AliError("Cannot get MC particle");
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;
387 TParticle* moth=stack->Particle(TMath::Abs(partMC->GetFirstMother()));
389 motherpdg = TMath::Abs(moth->GetPdgCode());
394 idGen = fPID->GetParticleSpecie(partMC);
395 pdgcode=partMC->GetPdgCode();
400 // cout<<isPrimary<<" "<<isSecondaryWeak<<" "<<isSecondaryMaterial<<endl;
401 // cout<<" functions "<<partMC->IsPhysicalPrimary()<<" "<<partMC->IsSecondaryFromWeakDecay()<<" "<<partMC->IsSecondaryFromMaterial()<<endl;
403 if (isPrimary&&irec==kSpPion)
404 fHistMan->GetPtHistogram(kHistPtRecPrimaryAll)->Fill(track->Pt(),dca); // PT histo of reconstrutsed primaries in defined eta
406 //nsigma cut (reconstructed nsigma)
407 if(idRec == kSpUndefined)
410 // rapidity cut (reconstructed pt and identity)
411 if(!fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec)) continue;
416 if (idRec == idGen) fHistMan->GetHistogram2D(kHistPtRecTrue, idGen, charge)->Fill(track->Pt(),dca);
420 fHistMan->GetHistogram2D(kHistPtRecSigmaPrimary, idRec, charge)->Fill(track->Pt(),dca);
421 if(idGen != kSpUndefined)
423 fHistMan->GetHistogram2D(kHistPtRecPrimary, idGen, charge)->Fill(track->Pt(),dca);
425 fHistMan->GetHistogram2D(kHistPtRecTruePrimary, idGen, charge)->Fill(track->Pt(),dca);
428 //25th Apr - Muons are added to Pions -- FIXME
429 if ( pdgcode == 13 && idRec == kSpPion)
431 fHistMan->GetPtHistogram(kHistPtRecTrueMuonPlus)->Fill(track->Pt(),dca);
433 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonPlus)->Fill(track->Pt(),dca);
435 if ( pdgcode == -13 && idRec == kSpPion)
437 fHistMan->GetPtHistogram(kHistPtRecTrueMuonMinus)->Fill(track->Pt(),dca);
440 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonMinus)->Fill(track->Pt(),dca);
449 if(fMotherWDPDGcode>0)
451 if(motherpdg==fMotherWDPDGcode)
452 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
455 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
457 if(isSecondaryMaterial)
458 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryMaterial , idRec, charge)->Fill(track->Pt(),dca);
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);
473 } // end loop on tracks
475 // cout<< ntracks<<endl;
476 fHistMan->GetGenMulvsRawMulHistogram("hHistGenMulvsRawMul")->Fill(npar,ntracks);
477 PostData(1, fHistMan );
478 PostData(2, fEventCuts);
479 PostData(3, fTrackCuts);
483 //_________________________________________________________________
484 void AliAnalysisTaskSpectraBoth::Terminate(Option_t *)