6 #include "AliAODEvent.h"
7 #include "AliAODRecoDecay.h"
8 #include "AliAODTrack.h"
11 #include "AliAnalysisTaskSE.h"
12 #include "AliMCEvent.h"
13 #include "AliAODMCParticle.h"
17 #include "AliAnalysisTaskAODFilterBitQA.h"
19 // Analysis task for the QA of AOD track filter bits
20 // Authors: m.weber@cern.ch
22 ClassImp(AliAnalysisTaskAODFilterBitQA)
24 //________________________________________________________________________
25 AliAnalysisTaskAODFilterBitQA::AliAnalysisTaskAODFilterBitQA(const char *name)
26 : AliAnalysisTaskSE(name),
29 useCentrality(kFALSE),
30 fillOnlySecondaries(kFALSE),
31 fillHFVertexingTracks(kFALSE),
32 fHFBranchName("D0toKpi"),
35 fCentralityPercentileMin(0.),
36 fCentralityPercentileMax(80.),
44 for(Int_t iCharge = 0; iCharge < gNCharge; iCharge++){
45 for(Int_t iTrackBit = 0; iTrackBit < gBitMax; iTrackBit++){
46 fHistKinematics[iCharge][iTrackBit] = NULL;
47 fHistDCAconstrained[iCharge][iTrackBit] = NULL;
48 fHistDCAglobal[iCharge][iTrackBit] = NULL;
49 fHistChiClus[iCharge][iTrackBit] = NULL;
53 DefineInput(0, TChain::Class());
54 // Output slot #0 writes into a TH1 container
55 DefineOutput(1, TList::Class());
59 //________________________________________________________________________
60 AliAnalysisTaskAODFilterBitQA::~AliAnalysisTaskAODFilterBitQA() {
62 // ... not implemented
65 //________________________________________________________________________
66 void AliAnalysisTaskAODFilterBitQA::UserCreateOutputObjects() {
70 // global switch disabling the reference
71 // (to avoid "Replacing existing TH1" if several wagons are created in train)
72 Bool_t oldStatus = TH1::AddDirectoryStatus();
73 TH1::AddDirectory(kFALSE);
76 fListQA = new TList();
77 fListQA->SetName("listQA");
81 fHistTrackStats = new TH2D("fHistTrackStats","Track statistics;Centrality;TrackFilterBit;N_{events}",100,0,100,gBitMax,0,gBitMax);
82 fListQA->Add(fHistTrackStats);
84 TString sCharge[gNCharge] = {"Plus","Minus"};
86 for(Int_t iCharge = 0; iCharge < gNCharge; iCharge++){
87 for(Int_t iTrackBit = 0; iTrackBit < gBitMax; iTrackBit++){
88 fHistKinematics[iCharge][iTrackBit] = new TH3D(Form("Bit%d_%s_Kinematics",iTrackBit,sCharge[iCharge].Data()),Form("Bit%d_%s_Kinematics;#eta;#varphi (rad);p_{T} (GeV/c)",iTrackBit,sCharge[iCharge].Data()),100,-1.0,1.0,100,0,TMath::Pi()*2,100,0,10);
89 fHistDCAconstrained[iCharge][iTrackBit] = new TH2D(Form("Bit%d_%s_DCAconstrained",iTrackBit,sCharge[iCharge].Data()),Form("Bit%d_%s_DCAconstrained;DCA XY [Constrained] (cm);DCA Z [Constrained] (cm)",iTrackBit,sCharge[iCharge].Data()),100,-5.0,5.0,100,-5.0,5.0);
90 fHistDCAglobal[iCharge][iTrackBit] = new TH3D(Form("Bit%d_%s_DCAglobal",iTrackBit,sCharge[iCharge].Data()),Form("Bit%d_%s_DCAglobal;DCA X [Global] (cm);DCA Y [Global] (cm);DCA Z [Global] (cm)",iTrackBit,sCharge[iCharge].Data()),100,-5.0,5.0,100,-5.0,5.0,100,-5.0,5.0);
91 fHistChiClus[iCharge][iTrackBit] = new TH2D(Form("Bit%d_%s_ChiClus",iTrackBit,sCharge[iCharge].Data()),Form("Bit%d_%s_ChiClus;#chi^{2} [Fit];N_{clus} [TPC]",iTrackBit,sCharge[iCharge].Data()),100,-1.0,5.0,160,0,160.0);
92 fListQA->Add(fHistKinematics[iCharge][iTrackBit]);
93 fListQA->Add(fHistDCAconstrained[iCharge][iTrackBit]);
94 fListQA->Add(fHistDCAglobal[iCharge][iTrackBit]);
95 fListQA->Add(fHistChiClus[iCharge][iTrackBit]);
100 PostData(1, fListQA);
102 AliInfo("Finished setting up the Output");
103 TH1::AddDirectory(oldStatus);
106 //________________________________________________________________________
107 void AliAnalysisTaskAODFilterBitQA::UserExec(Option_t *) {
109 // Called for each event
111 AliVEvent* event = dynamic_cast<AliVEvent*>(InputEvent());
113 AliError("event not available");
117 // MC information (set if available)
118 fArrayMC = dynamic_cast<TClonesArray*>(event->FindListObject(AliAODMCParticle::StdBranchName()));
121 Double_t lMultiplicityVar = -1;
122 if((lMultiplicityVar = IsEventAccepted(event)) < 0){
126 // fill HF vertexing tracks
127 if(fillHFVertexingTracks){
128 GetAcceptedHFVertexingTracks(event,lMultiplicityVar);
131 // get the accepted tracks in main event
132 GetAcceptedTracks(event,lMultiplicityVar);
136 //________________________________________________________________________
137 void AliAnalysisTaskAODFilterBitQA::FinishTaskOutput(){
138 // Finish task output
139 // not implemented ...
143 //________________________________________________________________________
144 void AliAnalysisTaskAODFilterBitQA::Terminate(Option_t *) {
145 // Draw result to the screen
146 // Called once at the end of the query
147 // not implemented ...
152 //________________________________________________________________________
153 Double_t AliAnalysisTaskAODFilterBitQA::IsEventAccepted(AliVEvent *event){
154 // Checks the Event cuts
157 Double_t fVxMax = 0.5;
158 Double_t fVyMax = 0.5;
159 Double_t fVzMax = 10.0;
160 TString fCentralityEstimator = "V0M";
162 Float_t gCentrality = -1.;
163 const AliVVertex *vertex = event->GetPrimaryVertex();
167 vertex->GetCovarianceMatrix(fCov);
168 if(vertex->GetNContributors() > 0) {
170 if(TMath::Abs(vertex->GetX()) < fVxMax) {
171 if(TMath::Abs(vertex->GetY()) < fVyMax) {
172 if(TMath::Abs(vertex->GetZ()) < fVzMax) {
174 // get the reference multiplicty or centrality (if required)
177 AliAODHeader *header = (AliAODHeader*) event->GetHeader();
178 gCentrality = header->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());
180 if((gCentrality > fCentralityPercentileMin) && (gCentrality < fCentralityPercentileMax)){
188 // if not using centrality/multiplicty, return 1
194 }//proper vertex resolution
195 }//proper number of contributors
196 }//vertex object valid
198 // in all other cases return -1 (event not accepted)
202 //________________________________________________________________________
203 void AliAnalysisTaskAODFilterBitQA::GetAcceptedTracks(AliVEvent *event, Double_t gCentrality){
204 // Checks track cuts (filter bits)
205 // Fills QA histograms
211 Double_t vDCAconstrainedxy;
212 Double_t vDCAconstrainedz;
213 Double_t vDCAglobalx;
214 Double_t vDCAglobaly;
215 Double_t vDCAglobalz;
222 const AliVVertex *vertex = event->GetPrimaryVertex();
225 // Loop over tracks in event
226 for (Int_t iTracks = 0; iTracks < event->GetNumberOfTracks(); iTracks++) {
227 AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(event->GetTrack(iTracks));
229 AliError(Form("Could not receive track %d", iTracks));
233 // get MC information (if available)
234 if(fArrayMC && fillOnlySecondaries){
236 Int_t label = aodTrack->GetLabel();
237 AliAODMCParticle *mcTrack = (AliAODMCParticle *)fArrayMC->At(TMath::Abs(label));
239 if(mcTrack->IsPhysicalPrimary())
244 vEta = aodTrack->Eta();
245 vPhi = aodTrack->Phi();// * TMath::RadToDeg();
246 vPt = aodTrack->Pt();
247 vDCAconstrainedxy = aodTrack->DCA();
248 vDCAconstrainedz = aodTrack->ZAtDCA();
249 vChi2 = aodTrack->Chi2perNDF();
250 vClus = aodTrack->GetTPCNcls();
253 if( vPt > fPtMax || vPt < fPtMin )
255 if( vEta > fEtaMax || vEta < fEtaMin )
258 // if not constrained track the position is stored (primary vertex to be subtracted)
259 aodTrack->GetXYZ(pos);
260 vDCAglobalx = pos[0] - v[0];
261 vDCAglobaly = pos[1] - v[1];
262 vDCAglobalz = pos[2] - v[2];
264 // fill for separately for positive and negative charges
267 if(aodTrack->Charge() > 0)
269 else if(aodTrack->Charge() < 0)
272 AliError("Charge==0?");
279 for(Int_t iTrackBit = 0; iTrackBit < gBitMax-1; iTrackBit++){
280 fHistTrackStats->Fill(gCentrality,iTrackBit,aodTrack->TestFilterBit(1<<iTrackBit));
282 if(aodTrack->TestFilterBit(1<<iTrackBit)){
283 fHistKinematics[iCharge][iTrackBit]->Fill(vEta,vPhi,vPt);
284 fHistDCAconstrained[iCharge][iTrackBit]->Fill(vDCAconstrainedxy,vDCAconstrainedz);
285 fHistDCAglobal[iCharge][iTrackBit]->Fill(vDCAglobalx,vDCAglobaly,vDCAglobalz);
286 fHistChiClus[iCharge][iTrackBit]->Fill(vChi2,vClus);
290 // fill all tracks in last bit
291 fHistTrackStats->Fill(gCentrality,gBitMax-1,1);
292 fHistKinematics[iCharge][gBitMax-1]->Fill(vEta,vPhi,vPt);
293 fHistDCAconstrained[iCharge][gBitMax-1]->Fill(vDCAconstrainedxy,vDCAconstrainedz);
294 fHistDCAglobal[iCharge][gBitMax-1]->Fill(vDCAglobalx,vDCAglobaly,vDCAglobalz);
295 fHistChiClus[iCharge][gBitMax-1]->Fill(vChi2,vClus);
297 }//charge positive or negative
304 //________________________________________________________________________
305 void AliAnalysisTaskAODFilterBitQA::GetAcceptedHFVertexingTracks(AliVEvent *event, Double_t gCentrality){
306 // Checks track cuts (filter bits)
307 // from daughters of HF candidates
308 // Fills QA histograms
313 Double_t vDCAconstrainedxy;
314 Double_t vDCAconstrainedz;
315 Double_t vDCAglobalx;
316 Double_t vDCAglobaly;
317 Double_t vDCAglobalz;
325 Int_t IDListLength = 0;
326 for(Int_t i = 0; i < 1000; i++){
330 const AliVVertex *vertex = event->GetPrimaryVertex();
333 // =================================================================================
334 // HF part (taken from AliAnalysisTaskSEDmesonsFilterCJ)
336 TClonesArray *arrayDStartoD0pi = (TClonesArray*)event->GetList()->FindObject(fHFBranchName.Data());
338 if (!arrayDStartoD0pi) {
339 AliInfo(Form("Could not find array %s, skipping the event",fHFBranchName.Data()));
342 AliDebug(2, Form("Found %d vertices",arrayDStartoD0pi->GetEntriesFast()));
346 const Int_t NVertices = arrayDStartoD0pi->GetEntriesFast();
348 for (Int_t iVertex = 0; iVertex < NVertices; ++iVertex) {
350 AliAODRecoDecay *HFvertex = static_cast<AliAODRecoDecay*>(arrayDStartoD0pi->At(iVertex));
352 // Loop over tracks (daughters of D candidates)
353 for (Int_t iProng = 0; iProng<HFvertex->GetNProngs(); iProng++) {
355 AliAODTrack *daughter = (AliAODTrack*)HFvertex->GetDaughter(iProng);
357 AliError(Form("Could not receive track %d %d", iVertex, iProng));
362 // get MC information (if available)
363 if(fArrayMC && fillOnlySecondaries){
365 Int_t label = daughter->GetLabel();
366 AliAODMCParticle *mcTrack = (AliAODMCParticle *)fArrayMC->At(TMath::Abs(label));
368 if(mcTrack->IsPhysicalPrimary())
373 vEta = daughter->Eta();
374 vPhi = daughter->Phi();// * TMath::RadToDeg();
375 vPt = daughter->Pt();
376 vDCAconstrainedxy = daughter->DCA();
377 vDCAconstrainedz = daughter->ZAtDCA();
378 vChi2 = daughter->Chi2perNDF();
379 vClus = daughter->GetTPCNcls();
382 if( vPt > fPtMax || vPt < fPtMin )
384 if( vEta > fEtaMax || vEta < fEtaMin )
387 // avoid double counting (can be optimized)
388 Bool_t doubleCount = kFALSE;
389 Int_t daughterID = daughter->GetID();
390 for(Int_t idx = 0; idx < IDListLength; idx++){
391 if(IDList[idx]==daughterID){
397 IDList[IDListLength] = daughterID;
405 // if not constrained track the position is stored (primary vertex to be subtracted)
406 daughter->GetXYZ(pos);
407 vDCAglobalx = pos[0] - v[0];
408 vDCAglobaly = pos[1] - v[1];
409 vDCAglobalz = pos[2] - v[2];
411 // fill for separately for positive and negative charges
414 if(daughter->Charge() > 0)
416 else if(daughter->Charge() < 0)
419 AliError("Charge==0?");
427 // if some filter bits should be ignored, skip them here
428 if(fBitIgnore1 > -1 && daughter->TestFilterBit(1<<fBitIgnore1))
430 if(fBitIgnore2 > -1 && daughter->TestFilterBit(1<<fBitIgnore2))
433 for(Int_t iTrackBit = 0; iTrackBit < gBitMax; iTrackBit++){
434 fHistTrackStats->Fill(gCentrality,iTrackBit,daughter->TestFilterBit(1<<iTrackBit));
436 if(daughter->TestFilterBit(1<<iTrackBit)){
437 fHistKinematics[iCharge][iTrackBit]->Fill(vEta,vPhi,vPt);
438 fHistDCAconstrained[iCharge][iTrackBit]->Fill(vDCAconstrainedxy,vDCAconstrainedz);
439 fHistDCAglobal[iCharge][iTrackBit]->Fill(vDCAglobalx,vDCAglobaly,vDCAglobalz);
440 fHistChiClus[iCharge][iTrackBit]->Fill(vChi2,vClus);
444 // fill all tracks in last bit
445 fHistTrackStats->Fill(gCentrality,gBitMax-1,1);
446 fHistKinematics[iCharge][gBitMax-1]->Fill(vEta,vPhi,vPt);
447 fHistDCAconstrained[iCharge][gBitMax-1]->Fill(vDCAconstrainedxy,vDCAconstrainedz);
448 fHistDCAglobal[iCharge][gBitMax-1]->Fill(vDCAglobalx,vDCAglobaly,vDCAglobalz);
449 fHistChiClus[iCharge][gBitMax-1]->Fill(vChi2,vClus);
451 }//charge positive or negative