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)
64 // Default constructor
66 DefineInput(0, TChain::Class());
67 DefineOutput(1, AliSpectraBothHistoManager::Class());
68 DefineOutput(2, AliSpectraBothEventCuts::Class());
69 DefineOutput(3, AliSpectraBothTrackCuts::Class());
70 DefineOutput(4, AliSpectraBothPID::Class());
74 //________________________________________________________________________
75 //________________________________________________________________________
76 void AliAnalysisTaskSpectraBoth::UserCreateOutputObjects()
78 // create output objects
79 fHistMan = new AliSpectraBothHistoManager("SpectraHistos",fNRebin);
81 if (!fTrackCuts) AliFatal("Track Cuts should be set in the steering macro");
82 if (!fEventCuts) AliFatal("Event Cuts should be set in the steering macro");
83 if (!fPID) AliFatal("PID object should be set in the steering macro");
84 fTrackCuts->SetAliESDtrackCuts(fCuts);
85 fEventCuts->InitHisto();
86 fTrackCuts->InitHisto();
88 PostData(1, fHistMan );
89 PostData(2, fEventCuts);
90 PostData(3, fTrackCuts);
93 //________________________________________________________________________
94 void AliAnalysisTaskSpectraBoth::UserExec(Option_t *)
97 Int_t ifAODEvent=AliSpectraBothTrackCuts::kotherobject;
98 fAOD = dynamic_cast<AliVEvent*>(InputEvent());
99 // AliESDEvent* esdevent=0x0;
100 // AliAODEvent* aodevent=0x0;
102 TString nameoftrack(fAOD->ClassName());
103 if(!nameoftrack.CompareTo("AliESDEvent"))
105 ifAODEvent=AliSpectraBothTrackCuts::kESDobject;
106 //esdevent=dynamic_cast<AliESDEvent*>(fAOD);
108 else if(!nameoftrack.CompareTo("AliAODEvent"))
110 ifAODEvent=AliSpectraBothTrackCuts::kAODobject;
111 //aodevent=dynamic_cast<AliAODEvent*>(fAOD);
114 AliFatal("Not processing AODs or ESDS") ;
115 if(fdotheMCLoopAfterEventCuts)
116 if(!fEventCuts->IsSelected(fAOD,fTrackCuts))return;//event selection
117 TClonesArray *arrayMC = 0;
125 mcVertex[0]=9999.; mcVertex[1]=9999.; mcVertex[2]=9999.;
126 AliMCEvent* mcEvent=(AliMCEvent*)MCEvent();
129 AliFatal("Error: MC particles branch not found!\n");
131 AliHeader* header = mcEvent->Header();
134 AliDebug(AliLog::kError, "Header not available");
138 AliGenEventHeader* genHeader = header->GenEventHeader();
141 genHeader->PrimaryVertex(mcVertex);
144 if(ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
146 arrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
149 AliFatal("Error: MC particles branch not found!\n");
151 Int_t nMC = arrayMC->GetEntries();
152 for (Int_t iMC = 0; iMC < nMC; iMC++)
154 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(iMC);
155 if(!partMC->Charge()) continue;//Skip neutrals
156 //if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax()){//charged hadron are filled inside the eta acceptance
157 //Printf("%f %f-%f",partMC->Eta(),fTrackCuts->GetEtaMin(),fTrackCuts->GetEtaMax());
158 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
159 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
161 if(partMC->Y() > fTrackCuts->GetYMax()|| partMC->Y() < fTrackCuts->GetYMin() )
163 if(partMC->IsPhysicalPrimary())
165 // check for true PID + and fill P_t histos
166 Int_t charge = partMC->Charge() > 0 ? kChPos : kChNeg ;
167 Int_t id = fPID->GetParticleSpecie(partMC);
168 if(id != kSpUndefined)
170 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),partMC->IsPhysicalPrimary());
174 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
176 stack = mcEvent->Stack();
177 Int_t nMC = stack->GetNtrack();
178 for (Int_t iMC = 0; iMC < nMC; iMC++)
181 TParticle *partMC = stack->Particle(iMC);
186 if(!partMC->GetPDG(0))
188 if(TMath::Abs(partMC->GetPDG(0)->Charge()/3.0)<0.01)
189 continue;//Skip neutrals
190 if(partMC->Eta() > fTrackCuts->GetEtaMin() && partMC->Eta() < fTrackCuts->GetEtaMax())
191 fHistMan->GetPtHistogram(kHistPtGen)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
192 if(partMC->Y() > fTrackCuts->GetYMax() ||partMC->Y() < fTrackCuts->GetYMin() )
194 if(stack->IsPhysicalPrimary(iMC))
196 // check for true PID + and fill P_t histos
197 Int_t charge = partMC->GetPDG(0)->Charge()/3.0 > 0 ? kChPos : kChNeg ;
198 Int_t id = fPID->GetParticleSpecie(partMC);
199 if(id != kSpUndefined)
201 fHistMan->GetHistogram2D(kHistPtGenTruePrimary,id,charge)->Fill(partMC->Pt(),stack->IsPhysicalPrimary(iMC));
206 if(!fdotheMCLoopAfterEventCuts)
207 if(!fEventCuts->IsSelected(fAOD,fTrackCuts,fIsMC,mcZ))return;//event selection
208 //main loop on tracks
210 //cout<<fAOD->GetNumberOfTracks()<<endl;
211 for (Int_t iTracks = 0; iTracks < fAOD->GetNumberOfTracks(); iTracks++)
213 AliVTrack* track = dynamic_cast<AliVTrack*>(fAOD->GetTrack(iTracks));
214 AliAODTrack* aodtrack=0;
215 AliESDtrack* esdtrack=0;
219 Float_t chi2perndf=-1.0;
220 if(ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
222 esdtrack=dynamic_cast<AliESDtrack*>(track);
225 esdtrack->GetImpactParameters(dca,dcaz);
226 ncls=esdtrack->GetTPCNcls();
228 chi2perndf=(esdtrack->GetTPCchi2()/Float_t(ncls - 5));
234 else if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
236 aodtrack=dynamic_cast<AliAODTrack*>(track);
240 dcaz=aodtrack->ZAtDCA();
241 ncls=aodtrack->GetTPCNcls();
242 chi2perndf=aodtrack->Chi2perNDF();
246 if (!fTrackCuts->IsSelected(track,kTRUE))
249 fPID->FillQAHistos(fHistMan, track, fTrackCuts);
251 //calculate DCA for AOD track
253 {// track->DCA() does not work in old AOD production
254 Double_t d[2], covd[3];
255 AliVTrack* track_clone=(AliVTrack*)track->Clone("track_clone"); // need to clone because PropagateToDCA updates the track parameters
256 Bool_t isDCA = track_clone->PropagateToDCA(fAOD->GetPrimaryVertex(),fAOD->GetMagneticField(),9999.,d,covd);
264 fHistMan->GetPtHistogram(kHistPtRec)->Fill(track->Pt(),dca); // PT histo
265 // get identity and charge
266 Bool_t rec[3]={false,false,false};
267 Int_t idRec = fPID->GetParticleSpecie(fHistMan,track, fTrackCuts,rec);
268 for(int irec=kSpPion;irec<kNSpecies;irec++)
279 idRec = kSpUndefined;
284 Int_t charge = track->Charge() > 0 ? kChPos : kChNeg;
286 // Fill histograms, only if inside y and nsigma acceptance
287 if(idRec != kSpUndefined && fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec))
289 fHistMan->GetHistogram2D(kHistPtRecSigma,idRec,charge)->Fill(track->Pt(),dca);
290 fTrackCuts->GetHistoDCAzQA()->Fill(idRec,track->Pt(),dcaz);
291 fTrackCuts->GetHistoNclustersQA()->Fill(idRec,track->Pt(),ncls);
292 fTrackCuts->GetHistochi2perNDFQA()->Fill(idRec,track->Pt(),chi2perndf);
294 //can't put a continue because we still have to fill allcharged primaries, done later
299 Bool_t isPrimary = kFALSE;
300 Bool_t isSecondaryMaterial = kFALSE;
301 Bool_t isSecondaryWeak = kFALSE;
302 Int_t idGen =kSpUndefined;
304 if (ifAODEvent==AliSpectraBothTrackCuts::kAODobject)
306 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(TMath::Abs(track->GetLabel()));
309 AliError("Cannot get MC particle");
312 // Check if it is primary, secondary from material or secondary from weak decay
313 isPrimary = partMC->IsPhysicalPrimary();
314 isSecondaryWeak = partMC->IsSecondaryFromWeakDecay();
315 isSecondaryMaterial = partMC->IsSecondaryFromMaterial();
316 //cout<<"AOD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
318 if(!isPrimary&&!isSecondaryWeak&&!isSecondaryMaterial)
320 AliError("old tagging");
321 Int_t mfl=-999,codemoth=-999;
322 Int_t indexMoth=partMC->GetMother(); // FIXME ignore fakes? TO BE CHECKED, on ESD is GetFirstMother()
325 AliAODMCParticle* moth = (AliAODMCParticle*) arrayMC->At(indexMoth);
326 codemoth = TMath::Abs(moth->GetPdgCode());
327 mfl = Int_t (codemoth/ TMath::Power(10, Int_t(TMath::Log10(codemoth))));
329 //Int_t uniqueID = partMC->GetUniqueID();
330 //cout<<"uniqueID: "<<partMC->GetUniqueID()<<" "<<kPDecay<<endl;
331 //cout<<"status: "<<partMC->GetStatus()<<" "<<kPDecay<<endl;
332 // if(uniqueID == kPDecay)Printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
334 isSecondaryWeak = kTRUE; // add if(partMC->GetStatus() & kPDecay)? FIXME
336 isSecondaryMaterial = kTRUE;
338 //cout<<"AOD 2 tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<" "<<partMC->GetMCProcessCode()<<endl;
341 idGen = fPID->GetParticleSpecie(partMC);
342 pdgcode=partMC->GetPdgCode();
344 else if (ifAODEvent==AliSpectraBothTrackCuts::kESDobject)
346 TParticle *partMC =stack->Particle(TMath::Abs(track->GetLabel()));
349 AliError("Cannot get MC particle");
352 isPrimary = stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()));
353 isSecondaryWeak = stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()));
354 isSecondaryMaterial = stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()));
355 //cout<<"ESD tagging "<<isPrimary<<" "<<isSecondaryWeak<<isSecondaryMaterial<<endl;
357 idGen = fPID->GetParticleSpecie(partMC);
358 pdgcode=partMC->GetPdgCode();
363 // cout<<isPrimary<<" "<<isSecondaryWeak<<" "<<isSecondaryMaterial<<endl;
364 // cout<<" functions "<<partMC->IsPhysicalPrimary()<<" "<<partMC->IsSecondaryFromWeakDecay()<<" "<<partMC->IsSecondaryFromMaterial()<<endl;
366 if (isPrimary&&irec==kSpPion)
367 fHistMan->GetPtHistogram(kHistPtRecPrimaryAll)->Fill(track->Pt(),dca); // PT histo of reconstrutsed primaries in defined eta
369 //nsigma cut (reconstructed nsigma)
370 if(idRec == kSpUndefined)
373 // rapidity cut (reconstructed pt and identity)
374 if(!fTrackCuts->CheckYCut ((BothParticleSpecies_t)idRec)) continue;
379 if (idRec == idGen) fHistMan->GetHistogram2D(kHistPtRecTrue, idGen, charge)->Fill(track->Pt(),dca);
383 fHistMan->GetHistogram2D(kHistPtRecSigmaPrimary, idRec, charge)->Fill(track->Pt(),dca);
384 if(idGen != kSpUndefined)
386 fHistMan->GetHistogram2D(kHistPtRecPrimary, idGen, charge)->Fill(track->Pt(),dca);
388 fHistMan->GetHistogram2D(kHistPtRecTruePrimary, idGen, charge)->Fill(track->Pt(),dca);
391 //25th Apr - Muons are added to Pions -- FIXME
392 if ( pdgcode == 13 && idRec == kSpPion)
394 fHistMan->GetPtHistogram(kHistPtRecTrueMuonPlus)->Fill(track->Pt(),dca);
396 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonPlus)->Fill(track->Pt(),dca);
398 if ( pdgcode == -13 && idRec == kSpPion)
400 fHistMan->GetPtHistogram(kHistPtRecTrueMuonMinus)->Fill(track->Pt(),dca);
403 fHistMan->GetPtHistogram(kHistPtRecTruePrimaryMuonMinus)->Fill(track->Pt(),dca);
411 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryWeakDecay, idRec, charge)->Fill(track->Pt(),dca);
412 if(isSecondaryMaterial)
413 fHistMan->GetHistogram2D(kHistPtRecSigmaSecondaryMaterial , idRec, charge)->Fill(track->Pt(),dca);
419 } // end loop on tracks
421 // cout<< ntracks<<endl;
422 fHistMan->GetGenMulvsRawMulHistogram("hHistGenMulvsRawMul")->Fill(npar,ntracks);
423 PostData(1, fHistMan );
424 PostData(2, fEventCuts);
425 PostData(3, fTrackCuts);
429 //_________________________________________________________________
430 void AliAnalysisTaskSpectraBoth::Terminate(Option_t *)