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),
63 fmakePIDQAhisto(1),fMotherWDPDGcode(-1)
66 // Default constructor
68 DefineInput(0, TChain::Class());
69 DefineOutput(1, AliSpectraBothHistoManager::Class());
70 DefineOutput(2, AliSpectraBothEventCuts::Class());
71 DefineOutput(3, AliSpectraBothTrackCuts::Class());
72 DefineOutput(4, AliSpectraBothPID::Class());
76 //________________________________________________________________________
77 //________________________________________________________________________
78 void AliAnalysisTaskSpectraBoth::UserCreateOutputObjects()
80 // create output objects
81 fHistMan = new AliSpectraBothHistoManager("SpectraHistos",fNRebin,fmakePIDQAhisto);
83 if (!fTrackCuts) AliFatal("Track Cuts should be set in the steering macro");
84 if (!fEventCuts) AliFatal("Event Cuts should be set in the steering macro");
85 if (!fPID) AliFatal("PID object should be set in the steering macro");
86 fTrackCuts->SetAliESDtrackCuts(fCuts);
87 fEventCuts->InitHisto();
88 fTrackCuts->InitHisto();
90 PostData(1, fHistMan );
91 PostData(2, fEventCuts);
92 PostData(3, fTrackCuts);
95 //________________________________________________________________________
96 void AliAnalysisTaskSpectraBoth::UserExec(Option_t *)
99 Int_t ifAODEvent=AliSpectraBothTrackCuts::kotherobject;
100 fAOD = dynamic_cast<AliVEvent*>(InputEvent());
101 // AliESDEvent* esdevent=0x0;
102 // AliAODEvent* aodevent=0x0;
104 TString nameoftrack(fAOD->ClassName());
105 if(!nameoftrack.CompareTo("AliESDEvent"))
107 ifAODEvent=AliSpectraBothTrackCuts::kESDobject;
108 //esdevent=dynamic_cast<AliESDEvent*>(fAOD);
110 else if(!nameoftrack.CompareTo("AliAODEvent"))
112 ifAODEvent=AliSpectraBothTrackCuts::kAODobject;
113 //aodevent=dynamic_cast<AliAODEvent*>(fAOD);
116 AliFatal("Not processing AODs or ESDS") ;
117 if(fdotheMCLoopAfterEventCuts)
118 if(!fEventCuts->IsSelected(fAOD,fTrackCuts))return;//event selection
119 TClonesArray *arrayMC = 0;
127 mcVertex[0]=9999.; mcVertex[1]=9999.; mcVertex[2]=9999.;
128 AliMCEvent* mcEvent=(AliMCEvent*)MCEvent();
131 AliFatal("Error: MC particles branch not found!\n");
133 AliHeader* header = mcEvent->Header();
136 AliDebug(AliLog::kError, "Header not available");
140 AliGenEventHeader* genHeader = header->GenEventHeader();
143 genHeader->PrimaryVertex(mcVertex);
146 if(ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
148 arrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
151 AliFatal("Error: MC particles branch not found!\n");
153 Int_t nMC = arrayMC->GetEntries();
154 for (Int_t iMC = 0; iMC < nMC; iMC++)
156 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(iMC);
157 if(!partMC->Charge()) continue;//Skip neutrals
158 //if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax()){//charged hadron are filled inside the eta acceptance
159 //Printf("%f %f-%f",partMC->Eta(),fTrackCuts->GetEtaMin(),fTrackCuts->GetEtaMax());
160 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
161 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
163 if(partMC->Y() > fTrackCuts->GetYMax()|| partMC->Y() < fTrackCuts->GetYMin() )
165 if(partMC->IsPhysicalPrimary())
167 // check for true PID + and fill P_t histos
168 Int_t charge = partMC->Charge() > 0 ? kChPos : kChNeg ;
169 Int_t id = fPID->GetParticleSpecie(partMC);
170 if(id != kSpUndefined)
172 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
176 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
178 stack = mcEvent->Stack();
179 Int_t nMC = stack->GetNtrack();
180 for (Int_t iMC = 0; iMC < nMC; iMC++)
183 TParticle *partMC = stack->Particle(iMC);
188 if(!partMC->GetPDG(0))
190 if(TMath::Abs(partMC->GetPDG(0)->Charge()/3.0)<0.01)
191 continue;//Skip neutrals
192 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
193 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
194 if(partMC->Y() > fTrackCuts->GetYMax() ||partMC->Y() < fTrackCuts->GetYMin() )
196 if(stack->IsPhysicalPrimary(iMC))
198 // check for true PID + and fill P_t histos
199 Int_t charge = partMC->GetPDG(0)->Charge()/3.0 > 0 ? kChPos : kChNeg ;
200 Int_t id = fPID->GetParticleSpecie(partMC);
201 if(id != kSpUndefined)
203 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
208 if(!fdotheMCLoopAfterEventCuts)
209 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,mcZ))return;//event selection
210 //main loop on tracks
212 //cout<<fAOD->GetNumberOfTracks()<<endl;
213 for (Int_t iTracks = 0; iTracks < fAOD->GetNumberOfTracks(); iTracks++)
215 AliVTrack* track = dynamic_cast<AliVTrack*>(fAOD->GetTrack(iTracks));
216 AliAODTrack* aodtrack=0;
217 AliESDtrack* esdtrack=0;
221 Float_t chi2perndf=-1.0;
222 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
224 esdtrack=dynamic_cast<AliESDtrack*>(track);
227 esdtrack->GetImpactParameters(dca,dcaz);
228 ncls=esdtrack->GetTPCNcls();
230 chi2perndf=(esdtrack->GetTPCchi2()/Float_t(ncls - 5));
236 else if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
238 aodtrack=dynamic_cast<AliAODTrack*>(track);
242 dcaz=aodtrack->ZAtDCA();
243 ncls=aodtrack->GetTPCNcls();
244 chi2perndf=aodtrack->Chi2perNDF();
248 if (!fTrackCuts->IsSelected(track,kTRUE))
252 fPID->FillQAHistos(fHistMan, track, fTrackCuts);
254 //calculate DCA for AOD track
256 {// track->DCA() does not work in old AOD production
257 Double_t d[2], covd[3];
258 AliVTrack* track_clone=(AliVTrack*)track->Clone("track_clone"); // need to clone because PropagateToDCA updates the track parameters
259 Bool_t isDCA = track_clone->PropagateToDCA(fAOD->GetPrimaryVertex(),fAOD->GetMagneticField(),9999.,d,covd);
267 fHistMan->GetPtHistogram(kHistPtRec)->Fill(track->Pt(),dca); // PT histo
268 // get identity and charge
269 Bool_t rec[3]={false,false,false};
270 Int_t idRec = fPID->GetParticleSpecie(fHistMan,track, fTrackCuts,rec);
271 for(int irec=kSpPion;irec<kNSpecies;irec++)
282 idRec = kSpUndefined;
287 Int_t charge = track->Charge() > 0 ? kChPos : kChNeg;
289 // Fill histograms, only if inside y and nsigma acceptance
290 if(idRec != kSpUndefined && fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec))
292 fHistMan->GetHistogram2D(kHistPtRecSigma,idRec,charge)->Fill(track->Pt(),dca);
293 fTrackCuts->GetHistoDCAzQA()->Fill(idRec,track->Pt(),dcaz);
294 fTrackCuts->GetHistoNclustersQA()->Fill(idRec,track->Pt(),ncls);
295 fTrackCuts->GetHistochi2perNDFQA()->Fill(idRec,track->Pt(),chi2perndf);
297 //can't put a continue because we still have to fill allcharged primaries, done later
302 Bool_t isPrimary = kFALSE;
303 Bool_t isSecondaryMaterial = kFALSE;
304 Bool_t isSecondaryWeak = kFALSE;
305 Int_t idGen =kSpUndefined;
308 if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
310 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(TMath::Abs(track->GetLabel()));
313 AliError("Cannot get MC particle");
316 // Check if it is primary, secondary from material or secondary from weak decay
317 isPrimary = partMC->IsPhysicalPrimary();
318 isSecondaryWeak = partMC->IsSecondaryFromWeakDecay();
319 isSecondaryMaterial = partMC->IsSecondaryFromMaterial();
320 //cout<<"AOD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
322 if(!isPrimary&&!isSecondaryWeak&&!isSecondaryMaterial)//old tagging for old AODs
324 AliError("old tagging");
325 Int_t mfl=-999,codemoth=-999;
326 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
329 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
330 codemoth = TMath::Abs(moth->GetPdgCode());
331 mfl = Int_t (codemoth/ TMath::Power(10, Int_t(TMath::Log10(codemoth))));
333 //Int_t uniqueID = partMC->GetUniqueID();
334 //cout<<"uniqueID: "<<partMC->GetUniqueID()<<" "<<kPDecay<<endl;
335 //cout<<"status: "<<partMC->GetStatus()<<" "<<kPDecay<<endl;
336 // if(uniqueID == kPDecay)Printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
338 isSecondaryWeak = kTRUE; // add if(partMC->GetStatus() & kPDecay)? FIXME
340 isSecondaryMaterial = kTRUE;
342 //cout<<"AOD 2 tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
345 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
348 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
350 motherpdg=TMath::Abs(moth->GetPdgCode());
354 idGen = fPID->GetParticleSpecie(partMC);
355 pdgcode=partMC->GetPdgCode();
357 else if (ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
359 TParticle *partMC =stack->Particle(TMath::Abs(track->GetLabel()));
362 AliError("Cannot get MC particle");
365 isPrimary = stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()));
366 isSecondaryWeak = stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()));
367 isSecondaryMaterial = stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()));
368 //cout<<"ESD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<endl;
373 TParticle* moth=stack->Particle(TMath::Abs(partMC->GetFirstMother()));
375 motherpdg = TMath::Abs(moth->GetPdgCode());
380 idGen = fPID->GetParticleSpecie(partMC);
381 pdgcode=partMC->GetPdgCode();
386 // cout<<isPrimary<<" "<<isSecondaryWeak<<" "<<isSecondaryMaterial<<endl;
387 // cout<<" functions "<<partMC->IsPhysicalPrimary()<<" "<<partMC->IsSecondaryFromWeakDecay()<<" "<<partMC->IsSecondaryFromMaterial()<<endl;
389 if (isPrimary&&irec==kSpPion)
390 fHistMan->GetPtHistogram(kHistPtRecPrimaryAll)->Fill(track->Pt(),dca); // PT histo of reconstrutsed primaries in defined eta
392 //nsigma cut (reconstructed nsigma)
393 if(idRec == kSpUndefined)
396 // rapidity cut (reconstructed pt and identity)
397 if(!fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec)) continue;
402 if (idRec == idGen) fHistMan->GetHistogram2D(kHistPtRecTrue, idGen, charge)->Fill(track->Pt(),dca);
406 fHistMan->GetHistogram2D(kHistPtRecSigmaPrimary, idRec, charge)->Fill(track->Pt(),dca);
407 if(idGen != kSpUndefined)
409 fHistMan->GetHistogram2D(kHistPtRecPrimary, idGen, charge)->Fill(track->Pt(),dca);
411 fHistMan->GetHistogram2D(kHistPtRecTruePrimary, idGen, charge)->Fill(track->Pt(),dca);
414 //25th Apr - Muons are added to Pions -- FIXME
415 if ( pdgcode == 13 && idRec == kSpPion)
417 fHistMan->GetPtHistogram(kHistPtRecTrueMuonPlus)->Fill(track->Pt(),dca);
419 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonPlus)->Fill(track->Pt(),dca);
421 if ( pdgcode == -13 && idRec == kSpPion)
423 fHistMan->GetPtHistogram(kHistPtRecTrueMuonMinus)->Fill(track->Pt(),dca);
426 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonMinus)->Fill(track->Pt(),dca);
435 if(fMotherWDPDGcode>0)
437 if(motherpdg==fMotherWDPDGcode)
438 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
441 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
443 if(isSecondaryMaterial)
444 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryMaterial , idRec, charge)->Fill(track->Pt(),dca);
450 } // end loop on tracks
452 // cout<< ntracks<<endl;
453 fHistMan->GetGenMulvsRawMulHistogram("hHistGenMulvsRawMul")->Fill(npar,ntracks);
454 PostData(1, fHistMan );
455 PostData(2, fEventCuts);
456 PostData(3, fTrackCuts);
460 //_________________________________________________________________
461 void AliAnalysisTaskSpectraBoth::Terminate(Option_t *)