c1c6153cffe3441e6e4fe72783f6dd0ff5f3a41d
[u/mrichter/AliRoot.git] / PWGCF / EBYE / BalanceFunctions / AliAnalysisTaskTriggeredBF.cxx
1 #include "TChain.h"\r
2 #include "TList.h"\r
3 #include "TCanvas.h"\r
4 #include "TLorentzVector.h"\r
5 #include "TGraphErrors.h"\r
6 #include "TH1F.h"\r
7 #include "TH2F.h"\r
8 #include "TArrayF.h"\r
9 #include "TF1.h"\r
10 #include "TRandom.h"\r
11 \r
12 #include "AliLog.h"\r
13 \r
14 #include "AliAnalysisTaskSE.h"\r
15 #include "AliAnalysisManager.h"\r
16 \r
17 #include "AliESDVertex.h"\r
18 #include "AliESDEvent.h"\r
19 #include "AliESDInputHandler.h"\r
20 #include "AliAODEvent.h"\r
21 #include "AliAODTrack.h"\r
22 #include "AliAODInputHandler.h"\r
23 #include "AliGenEventHeader.h"\r
24 #include "AliGenHijingEventHeader.h"\r
25 #include "AliMCEventHandler.h"\r
26 #include "AliMCEvent.h"\r
27 #include "AliMixInputEventHandler.h"\r
28 #include "AliStack.h"\r
29 \r
30 #include "TH2D.h"    \r
31 #include "AliTHn.h"             \r
32 \r
33 #include "AliEventPoolManager.h" \r
34 \r
35 #include "AliAnalysisTaskTriggeredBF.h"\r
36 #include "AliBalanceTriggered.h"\r
37 \r
38 \r
39 // Analysis task for the TriggeredBF code\r
40 // Authors: Panos.Christakoglou@nikhef.nl, m.weber@cern.ch\r
41 \r
42 ClassImp(AliAnalysisTaskTriggeredBF)\r
43 \r
44 //________________________________________________________________________\r
45 AliAnalysisTaskTriggeredBF::AliAnalysisTaskTriggeredBF(const char *name) \r
46 : AliAnalysisTaskSE(name), \r
47   fBalance(0),\r
48   fRunShuffling(kFALSE),\r
49   fShuffledBalance(0),\r
50   fRunMixing(kFALSE),\r
51   fMixingTracks(50000),\r
52   fMixedBalance(0),\r
53   fPoolMgr(0),\r
54   fList(0),\r
55   fListTriggeredBF(0),\r
56   fListTriggeredBFS(0),\r
57   fListTriggeredBFM(0),\r
58   fHistListPIDQA(0),\r
59   fHistEventStats(0),\r
60   fHistCentStats(0),\r
61   fHistTriggerStats(0),\r
62   fHistTrackStats(0),\r
63   fHistVx(0),\r
64   fHistVy(0),\r
65   fHistVz(0),\r
66   fHistClus(0),\r
67   fHistDCA(0),\r
68   fHistChi2(0),\r
69   fHistPt(0),\r
70   fHistEta(0),\r
71   fHistPhi(0),\r
72   fHistPhiBefore(0),\r
73   fHistPhiAfter(0),\r
74   fHistV0M(0),\r
75   fHistRefTracks(0),\r
76   fCentralityEstimator("V0M"),\r
77   fUseCentrality(kFALSE),\r
78   fCentralityPercentileMin(0.), \r
79   fCentralityPercentileMax(5.),\r
80   fImpactParameterMin(0.),\r
81   fImpactParameterMax(20.),\r
82   fUseMultiplicity(kFALSE),\r
83   fNumberOfAcceptedTracksMin(0),\r
84   fNumberOfAcceptedTracksMax(10000),\r
85   fHistNumberOfAcceptedTracks(0),\r
86   fUseOfflineTrigger(kFALSE),\r
87   fVxMax(0.3),\r
88   fVyMax(0.3),\r
89   fVzMax(10.),\r
90   nAODtrackCutBit(128),\r
91   fPtMin(0.3),\r
92   fPtMax(1.5),\r
93   fEtaMin(-0.8),\r
94   fEtaMax(-0.8),\r
95   fDCAxyCut(-1),\r
96   fDCAzCut(-1),\r
97   fTPCchi2Cut(-1),\r
98   fNClustersTPCCut(-1)\r
99 {\r
100   // Constructor\r
101   // Define input and output slots here\r
102   // Input slot #0 works with a TChain\r
103   DefineInput(0, TChain::Class());\r
104   // Output slot #0 writes into a TH1 container\r
105   DefineOutput(1, TList::Class());\r
106   DefineOutput(2, TList::Class());\r
107   DefineOutput(3, TList::Class());\r
108   DefineOutput(4, TList::Class());\r
109 }\r
110 \r
111 //________________________________________________________________________\r
112 AliAnalysisTaskTriggeredBF::~AliAnalysisTaskTriggeredBF() {\r
113 \r
114   // Destructor\r
115 \r
116 }\r
117 \r
118 //________________________________________________________________________\r
119 void AliAnalysisTaskTriggeredBF::UserCreateOutputObjects() {\r
120   // Create histograms\r
121   // Called once\r
122   if(!fBalance) {\r
123     fBalance = new AliBalanceTriggered();\r
124     fBalance->SetAnalysisLevel("AOD");\r
125   }\r
126   if(fRunShuffling) {\r
127     if(!fShuffledBalance) {\r
128       fShuffledBalance = new AliBalanceTriggered();\r
129       fShuffledBalance->SetAnalysisLevel("AOD");\r
130     }\r
131   }\r
132   if(fRunMixing) {\r
133     if(!fMixedBalance) {\r
134       fMixedBalance = new AliBalanceTriggered();\r
135       fMixedBalance->SetAnalysisLevel("AOD");\r
136     }\r
137   }\r
138 \r
139   //QA list\r
140   fList = new TList();\r
141   fList->SetName("listQA");\r
142   fList->SetOwner();\r
143 \r
144   //Balance Function list\r
145   fListTriggeredBF = new TList();\r
146   fListTriggeredBF->SetName("listTriggeredBF");\r
147   fListTriggeredBF->SetOwner();\r
148 \r
149   if(fRunShuffling) {\r
150     fListTriggeredBFS = new TList();\r
151     fListTriggeredBFS->SetName("listTriggeredBFShuffled");\r
152     fListTriggeredBFS->SetOwner();\r
153   }\r
154   if(fRunMixing) {\r
155     fListTriggeredBFM = new TList();\r
156     fListTriggeredBFM->SetName("listTriggeredBFMixed");\r
157     fListTriggeredBFM->SetOwner();\r
158   }\r
159   \r
160   \r
161   //Event stats.\r
162   TString gCutName[4] = {"Total","Offline trigger",\r
163                          "Vertex","Analyzed"};\r
164   fHistEventStats = new TH1F("fHistEventStats",\r
165                              "Event statistics;;N_{events}",\r
166                              4,0.5,4.5);\r
167   for(Int_t i = 1; i <= 4; i++)\r
168     fHistEventStats->GetXaxis()->SetBinLabel(i,gCutName[i-1].Data());\r
169   fList->Add(fHistEventStats);\r
170   \r
171   TString gCentName[9] = {"V0M","FMD","TRK","TKL","CL0","CL1","V0MvsFMD","TKLvsV0M","ZEMvsZDC"};\r
172   fHistCentStats = new TH2F("fHistCentStats",\r
173                             "Centrality statistics;;Cent percentile",\r
174                             9,-0.5,8.5,220,-5,105);\r
175   for(Int_t i = 1; i <= 9; i++)\r
176     fHistCentStats->GetXaxis()->SetBinLabel(i,gCentName[i-1].Data());\r
177   fList->Add(fHistCentStats);\r
178   \r
179   fHistTriggerStats = new TH1F("fHistTriggerStats","Trigger statistics;TriggerBit;N_{events}",130,0,130);\r
180   fList->Add(fHistTriggerStats);\r
181   \r
182   fHistTrackStats = new TH1F("fHistTrackStats","Event statistics;TrackFilterBit;N_{events}",130,0,130);\r
183   fList->Add(fHistTrackStats);\r
184 \r
185   fHistNumberOfAcceptedTracks = new TH1F("fHistNumberOfAcceptedTracks",";N_{acc.};Entries",4001,-0.5,4000.5);\r
186   fList->Add(fHistNumberOfAcceptedTracks);\r
187 \r
188   // Vertex distributions\r
189   fHistVx = new TH1F("fHistVx","Primary vertex distribution - x coordinate;V_{x} (cm);Entries",100,-0.5,0.5);\r
190   fList->Add(fHistVx);\r
191   fHistVy = new TH1F("fHistVy","Primary vertex distribution - y coordinate;V_{y} (cm);Entries",100,-0.5,0.5);\r
192   fList->Add(fHistVy);\r
193   fHistVz = new TH1F("fHistVz","Primary vertex distribution - z coordinate;V_{z} (cm);Entries",100,-20.,20.);\r
194   fList->Add(fHistVz);\r
195 \r
196   // QA histograms\r
197   fHistClus = new TH2F("fHistClus","# Cluster (TPC vs. ITS)",10,0,10,200,0,200);\r
198   fList->Add(fHistClus);\r
199   fHistChi2 = new TH1F("fHistChi2","Chi2/NDF distribution",200,0,10);\r
200   fList->Add(fHistChi2);\r
201   fHistDCA  = new TH2F("fHistDCA","DCA (xy vs. z)",400,-5,5,400,-5,5); \r
202   fList->Add(fHistDCA);\r
203   fHistPt   = new TH1F("fHistPt","p_{T} distribution",200,0,10);\r
204   fList->Add(fHistPt);\r
205   fHistEta  = new TH1F("fHistEta","#eta distribution",200,-2,2);\r
206   fList->Add(fHistEta);\r
207   fHistPhi  = new TH1F("fHistPhi","#phi distribution",200,-20,380);\r
208   fList->Add(fHistPhi);\r
209   fHistPhiBefore  = new TH1F("fHistPhiBefore","#phi distribution",200,0.,2*TMath::Pi());\r
210   fList->Add(fHistPhiBefore);\r
211   fHistPhiAfter  = new TH1F("fHistPhiAfter","#phi distribution",200,0.,2*TMath::Pi());\r
212   fList->Add(fHistPhiAfter);\r
213   fHistV0M  = new TH2F("fHistV0M","V0 Multiplicity C vs. A",500, 0, 20000, 500, 0, 20000);\r
214   fList->Add(fHistV0M);\r
215   TString gRefTrackName[6] = {"tracks","tracksPos","tracksNeg","tracksTPConly","clusITS0","clusITS1"};\r
216   fHistRefTracks  = new TH2F("fHistRefTracks","Nr of Ref tracks/event vs. ref track estimator;;Nr of tracks",6, 0, 6, 400, 0, 20000);\r
217   for(Int_t i = 1; i <= 6; i++)\r
218     fHistRefTracks->GetXaxis()->SetBinLabel(i,gRefTrackName[i-1].Data());\r
219   fList->Add(fHistRefTracks);\r
220 \r
221 \r
222 \r
223   // Balance function histograms\r
224   // Initialize histograms if not done yet\r
225   if(!fBalance->GetHistNp()){\r
226     AliWarning("Histograms not yet initialized! --> Will be done now");\r
227     AliWarning("--> Add 'gBalance->InitHistograms()' in your configBalanceFunction");\r
228     fBalance->InitHistograms();\r
229   }\r
230 \r
231   if(fRunShuffling) {\r
232     if(!fShuffledBalance->GetHistNp()) {\r
233       AliWarning("Histograms (shuffling) not yet initialized! --> Will be done now");\r
234       AliWarning("--> Add 'gBalance->InitHistograms()' in your configBalanceFunction");\r
235       fShuffledBalance->InitHistograms();\r
236     }\r
237   }\r
238 \r
239   if(fRunMixing) {\r
240     if(!fMixedBalance->GetHistNp()) {\r
241       AliWarning("Histograms (mixing) not yet initialized! --> Will be done now");\r
242       AliWarning("--> Add 'gBalance->InitHistograms()' in your configBalanceFunction");\r
243       fMixedBalance->InitHistograms();\r
244     }\r
245   }\r
246 \r
247   fListTriggeredBF->Add(fBalance->GetHistNp());\r
248   fListTriggeredBF->Add(fBalance->GetHistNn());\r
249   fListTriggeredBF->Add(fBalance->GetHistNpn());\r
250   fListTriggeredBF->Add(fBalance->GetHistNnn());\r
251   fListTriggeredBF->Add(fBalance->GetHistNpp());\r
252   fListTriggeredBF->Add(fBalance->GetHistNnp());\r
253   \r
254   if(fRunShuffling) {\r
255     fListTriggeredBFS->Add(fShuffledBalance->GetHistNp());\r
256     fListTriggeredBFS->Add(fShuffledBalance->GetHistNn());\r
257     fListTriggeredBFS->Add(fShuffledBalance->GetHistNpn());\r
258     fListTriggeredBFS->Add(fShuffledBalance->GetHistNnn());\r
259     fListTriggeredBFS->Add(fShuffledBalance->GetHistNpp());\r
260     fListTriggeredBFS->Add(fShuffledBalance->GetHistNnp());\r
261   }  \r
262 \r
263   if(fRunMixing) {\r
264     fListTriggeredBFM->Add(fMixedBalance->GetHistNp());\r
265     fListTriggeredBFM->Add(fMixedBalance->GetHistNn());\r
266     fListTriggeredBFM->Add(fMixedBalance->GetHistNpn());\r
267     fListTriggeredBFM->Add(fMixedBalance->GetHistNnn());\r
268     fListTriggeredBFM->Add(fMixedBalance->GetHistNpp());\r
269     fListTriggeredBFM->Add(fMixedBalance->GetHistNnp());\r
270   }  \r
271 \r
272 \r
273   // Event Mixing\r
274   Int_t trackDepth = fMixingTracks; \r
275   Int_t poolsize   = 1000;  // Maximum number of events, ignored in the present implemented of AliEventPoolManager\r
276    \r
277   Double_t centralityBins[] = {0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,15.,20.,25.,30.,35.,40.,45.,50.,55.,60.,65.,70.,75.,80.,90.,100.}; // SHOULD BE DEDUCED FROM CREATED ALITHN!!!\r
278   Double_t* centbins        = centralityBins;\r
279   Int_t nCentralityBins     = sizeof(centralityBins) / sizeof(Double_t) - 1;\r
280   \r
281   // bins for second buffer are shifted by 100 cm\r
282   Double_t vertexBins[] = {-10., -7., -5., -3., -1., 1., 3., 5., 7., 10.}; // SHOULD BE DEDUCED FROM CREATED ALITHN!!!\r
283   Double_t* vtxbins     = vertexBins;\r
284   Int_t nVertexBins     = sizeof(vertexBins) / sizeof(Double_t) - 1;\r
285   cout<<nCentralityBins<<" "<<nVertexBins<<endl;\r
286 \r
287   fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, centbins, nVertexBins, vtxbins);\r
288 \r
289 \r
290   // Post output data.\r
291   PostData(1, fList);\r
292   PostData(2, fListTriggeredBF);\r
293   if(fRunShuffling) PostData(3, fListTriggeredBFS);\r
294   if(fRunMixing) PostData(4, fListTriggeredBFM);\r
295 }\r
296 \r
297 //________________________________________________________________________\r
298 void AliAnalysisTaskTriggeredBF::UserExec(Option_t *) {\r
299   // Main loop\r
300   // Called for each event\r
301 \r
302   TString gAnalysisLevel = fBalance->GetAnalysisLevel();\r
303   Float_t fCentrality = 0.;  \r
304 \r
305   // -------------------------------------------------------------                   \r
306   // AOD analysis (vertex and track cuts also here!!!!)\r
307   if(gAnalysisLevel == "AOD") {\r
308     AliVEvent* eventMain = dynamic_cast<AliVEvent*>(InputEvent()); \r
309     if(!eventMain) {\r
310       AliError("eventMain not available");\r
311       return;\r
312     }\r
313 \r
314     // check event cuts and fill event histograms\r
315     if((fCentrality = IsEventAccepted(eventMain)) < 0){\r
316       return;\r
317     }\r
318     \r
319     // get the accepted tracks in main event\r
320     TObjArray *tracksMain = GetAcceptedTracks(eventMain);\r
321 \r
322     // store charges of all accepted tracks, shuffle and reassign (two extra loops!)\r
323     TObjArray* tracksShuffled = NULL;\r
324     if(fRunShuffling){\r
325       tracksShuffled = GetShuffledTracks(tracksMain);\r
326     }\r
327     \r
328     // Event mixing --> UPDATE POOL IS MISSING!!!\r
329     if (fRunMixing)\r
330       {\r
331         // 1. First get an event pool corresponding in mult (cent) and\r
332         //    zvertex to the current event. Once initialized, the pool\r
333         //    should contain nMix (reduced) events. This routine does not\r
334         //    pre-scan the chain. The first several events of every chain\r
335         //    will be skipped until the needed pools are filled to the\r
336         //    specified depth. If the pool categories are not too rare, this\r
337         //    should not be a problem. If they are rare, you could lose`\r
338         //    statistics.\r
339         \r
340         // 2. Collect the whole pool's content of tracks into one TObjArray\r
341         //    (bgTracks), which is effectively a single background super-event.\r
342         \r
343         // 3. The reduced and bgTracks arrays must both be passed into\r
344         //    FillCorrelations(). Also nMix should be passed in, so a weight\r
345         //    of 1./nMix can be applied.\r
346         \r
347         AliEventPool* pool = fPoolMgr->GetEventPool(fCentrality, eventMain->GetPrimaryVertex()->GetZ());\r
348         \r
349         if (!pool)\r
350           AliFatal(Form("No pool found for centrality = %f, zVtx = %f", fCentrality, eventMain->GetPrimaryVertex()->GetZ()));\r
351         \r
352         //pool->SetDebug(1);\r
353         \r
354         if (pool->IsReady() || pool->NTracksInPool() > fMixingTracks / 10 || pool->GetCurrentNEvents() >= 5) \r
355           {\r
356             \r
357             Int_t nMix = pool->GetCurrentNEvents();\r
358             //cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;\r
359             \r
360             //((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(2);\r
361             //((TH2F*) fListOfHistos->FindObject("mixedDist"))->Fill(centrality, pool->NTracksInPool());\r
362             //if (pool->IsReady())\r
363             //((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(3);\r
364             \r
365             // Fill mixed-event histos here  \r
366             for (Int_t jMix=0; jMix<nMix; jMix++) \r
367               {\r
368                 TObjArray* tracksMixed = pool->GetEvent(jMix);\r
369                 fMixedBalance->FillBalance(fCentrality,tracksMain,tracksMixed); \r
370               }\r
371           }\r
372 \r
373         // Update the Event pool\r
374         pool->UpdatePool(tracksMain);\r
375         //pool->PrintInfo();\r
376         \r
377       }//run mixing\r
378     \r
379     // calculate balance function\r
380     fBalance->FillBalance(fCentrality,tracksMain,NULL);\r
381     \r
382     // calculate shuffled balance function\r
383     if(fRunShuffling && tracksShuffled != NULL) {\r
384       fShuffledBalance->FillBalance(fCentrality,tracksShuffled,NULL);\r
385     }\r
386     \r
387   }//AOD analysis\r
388   else{\r
389     AliError("Triggered Balance Function analysis only for AODs!");\r
390   }\r
391 }     \r
392 \r
393 //________________________________________________________________________\r
394 Float_t AliAnalysisTaskTriggeredBF::IsEventAccepted(AliVEvent *event){\r
395   // Checks the Event cuts\r
396   // Fills Event statistics histograms\r
397   \r
398   // event selection done in AliAnalysisTaskSE::Exec() --> this is not used\r
399   fHistEventStats->Fill(1); //all events\r
400 \r
401   Bool_t isSelectedMain = kTRUE;\r
402   Float_t fCentrality = -1.;\r
403   TString gAnalysisLevel = fBalance->GetAnalysisLevel();\r
404   \r
405   if(fUseOfflineTrigger)\r
406     isSelectedMain = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();\r
407   \r
408   if(isSelectedMain) {\r
409     fHistEventStats->Fill(2); //triggered events\r
410     \r
411     //Centrality stuff \r
412     if(fUseCentrality) {\r
413       if(gAnalysisLevel == "AOD") { //centrality in AOD header\r
414         AliAODHeader *header = (AliAODHeader*) event->GetHeader();\r
415         fCentrality = header->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());\r
416 \r
417         // QA for centrality estimators\r
418         fHistCentStats->Fill(0.,header->GetCentralityP()->GetCentralityPercentile("V0M"));\r
419         fHistCentStats->Fill(1.,header->GetCentralityP()->GetCentralityPercentile("FMD"));\r
420         fHistCentStats->Fill(2.,header->GetCentralityP()->GetCentralityPercentile("TRK"));\r
421         fHistCentStats->Fill(3.,header->GetCentralityP()->GetCentralityPercentile("TKL"));\r
422         fHistCentStats->Fill(4.,header->GetCentralityP()->GetCentralityPercentile("CL0"));\r
423         fHistCentStats->Fill(5.,header->GetCentralityP()->GetCentralityPercentile("CL1"));\r
424         fHistCentStats->Fill(6.,header->GetCentralityP()->GetCentralityPercentile("V0MvsFMD"));\r
425         fHistCentStats->Fill(7.,header->GetCentralityP()->GetCentralityPercentile("TKLvsV0M"));\r
426         fHistCentStats->Fill(8.,header->GetCentralityP()->GetCentralityPercentile("ZEMvsZDC"));\r
427         \r
428         // centrality QA (V0M)\r
429         fHistV0M->Fill(event->GetVZEROData()->GetMTotV0A(), event->GetVZEROData()->GetMTotV0C());\r
430         \r
431         // centrality QA (reference tracks)\r
432         fHistRefTracks->Fill(0.,header->GetRefMultiplicity());\r
433         fHistRefTracks->Fill(1.,header->GetRefMultiplicityPos());\r
434         fHistRefTracks->Fill(2.,header->GetRefMultiplicityNeg());\r
435         fHistRefTracks->Fill(3.,header->GetTPConlyRefMultiplicity());\r
436         fHistRefTracks->Fill(4.,header->GetNumberOfITSClusters(0));\r
437         fHistRefTracks->Fill(5.,header->GetNumberOfITSClusters(1));\r
438         fHistRefTracks->Fill(6.,header->GetNumberOfITSClusters(2));\r
439         fHistRefTracks->Fill(7.,header->GetNumberOfITSClusters(3));\r
440         fHistRefTracks->Fill(8.,header->GetNumberOfITSClusters(4));\r
441       }\r
442     }\r
443     \r
444     \r
445     const AliVVertex *vertex = event->GetPrimaryVertex();\r
446     \r
447     if(vertex) {\r
448       Double32_t fCov[6];\r
449       vertex->GetCovarianceMatrix(fCov);\r
450       if(vertex->GetNContributors() > 0) {\r
451         if(fCov[5] != 0) {\r
452           fHistEventStats->Fill(3); //events with a proper vertex\r
453           if(TMath::Abs(vertex->GetX()) < fVxMax) {\r
454             if(TMath::Abs(vertex->GetY()) < fVyMax) {\r
455               if(TMath::Abs(vertex->GetZ()) < fVzMax) {\r
456                 fHistEventStats->Fill(4); //analyzed events\r
457                 fHistVx->Fill(vertex->GetX());\r
458                 fHistVy->Fill(vertex->GetY());\r
459                 fHistVz->Fill(vertex->GetZ());\r
460 \r
461                 // take only events inside centrality class\r
462                 if((fCentrality > fCentralityPercentileMin) && (fCentrality < fCentralityPercentileMax)){\r
463                   return fCentrality;           \r
464                 }//centrality class\r
465               }//Vz cut\r
466             }//Vy cut\r
467           }//Vx cut\r
468         }//proper vertex resolution\r
469       }//proper number of contributors\r
470     }//vertex object valid\r
471   }//triggered event \r
472   \r
473   // in all other cases return -1 (event not accepted)\r
474   return -1;\r
475 }\r
476 \r
477 //________________________________________________________________________\r
478 TObjArray* AliAnalysisTaskTriggeredBF::GetAcceptedTracks(AliVEvent *event){\r
479   // Returns TObjArray with tracks after all track cuts (only for AOD!)\r
480   // Fills QA histograms\r
481 \r
482   //output TObjArray holding all good tracks\r
483   TObjArray* tracksAccepted = new TObjArray;\r
484   tracksAccepted->SetOwner(kTRUE);\r
485 \r
486   Double_t v_charge;\r
487   Double_t v_eta;\r
488   Double_t v_phi;\r
489   Double_t v_pt;\r
490   \r
491   // Loop over tracks in event\r
492   for (Int_t iTracks = 0; iTracks < event->GetNumberOfTracks(); iTracks++) {\r
493     AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(event->GetTrack(iTracks));\r
494     if (!aodTrack) {\r
495       AliError(Form("Could not receive track %d", iTracks));\r
496       continue;\r
497     }\r
498     \r
499     // AOD track cuts\r
500     \r
501     // For ESD Filter Information: ANALYSIS/macros/AddTaskESDfilter.C\r
502     // take only TPC only tracks \r
503     fHistTrackStats->Fill(aodTrack->GetFilterMap());\r
504     if(!aodTrack->TestFilterBit(nAODtrackCutBit)) continue;\r
505     \r
506     v_charge = aodTrack->Charge();\r
507     v_eta    = aodTrack->Eta();\r
508     v_phi    = aodTrack->Phi() * TMath::RadToDeg();\r
509     v_pt     = aodTrack->Pt();\r
510     \r
511     Float_t DCAxy = aodTrack->DCA();      // this is the DCA from global track (not exactly what is cut on)\r
512     Float_t DCAz  = aodTrack->ZAtDCA();   // this is the DCA from global track (not exactly what is cut on)\r
513     \r
514     \r
515     // Kinematics cuts from ESD track cuts\r
516     if( v_pt < fPtMin || v_pt > fPtMax)      continue;\r
517     if( v_eta < fEtaMin || v_eta > fEtaMax)  continue;\r
518     \r
519     // Extra DCA cuts (for systematic studies [!= -1])\r
520     if( fDCAxyCut != -1 && fDCAzCut != -1){\r
521       if(TMath::Sqrt((DCAxy*DCAxy)/(fDCAxyCut*fDCAxyCut)+(DCAz*DCAz)/(fDCAzCut*fDCAzCut)) > 1 ){\r
522         continue;  // 2D cut\r
523       }\r
524     }\r
525     \r
526     // Extra TPC cuts (for systematic studies [!= -1])\r
527     if( fTPCchi2Cut != -1 && aodTrack->Chi2perNDF() > fTPCchi2Cut){\r
528       continue;\r
529     }\r
530     if( fNClustersTPCCut != -1 && aodTrack->GetTPCNcls() < fNClustersTPCCut){\r
531       continue;\r
532     }\r
533     \r
534     // fill QA histograms\r
535     fHistClus->Fill(aodTrack->GetITSNcls(),aodTrack->GetTPCNcls());\r
536     fHistDCA->Fill(DCAz,DCAxy);\r
537     fHistChi2->Fill(aodTrack->Chi2perNDF());\r
538     fHistPt->Fill(v_pt);\r
539     fHistEta->Fill(v_eta);\r
540     fHistPhi->Fill(v_phi);\r
541     \r
542     // add the track to the TObjArray\r
543     tracksAccepted->Add(new AliBFBasicParticle(v_eta, v_phi, v_pt, v_charge));\r
544   }\r
545 \r
546   return tracksAccepted;\r
547 }\r
548 \r
549 //________________________________________________________________________\r
550 TObjArray* AliAnalysisTaskTriggeredBF::GetShuffledTracks(TObjArray *tracks){\r
551   // Clones TObjArray and returns it with tracks after shuffling the charges\r
552 \r
553   TObjArray* tracksShuffled = new TObjArray;\r
554   tracksShuffled->SetOwner(kTRUE);\r
555 \r
556   vector<Short_t> *chargeVector = new vector<Short_t>;   //original charge of accepted tracks \r
557 \r
558   for (Int_t i=0; i<tracks->GetEntriesFast(); i++)\r
559   {\r
560     AliVParticle* track = (AliVParticle*) tracks->At(i);\r
561     chargeVector->push_back(track->Charge());\r
562   }  \r
563  \r
564   random_shuffle(chargeVector->begin(), chargeVector->end());\r
565   \r
566   for(Int_t i = 0; i < tracks->GetEntriesFast(); i++){\r
567     AliVParticle* track = (AliVParticle*) tracks->At(i);\r
568     tracksShuffled->Add(new AliBFBasicParticle(track->Eta(), track->Phi(), track->Pt(),chargeVector->at(i)));\r
569   }\r
570    \r
571   return tracksShuffled;\r
572 }\r
573 \r
574 //________________________________________________________________________\r
575 void  AliAnalysisTaskTriggeredBF::FinishTaskOutput(){\r
576 \r
577   if (!fBalance) {\r
578     AliError("fBalance not available");\r
579     return;\r
580   }  \r
581   if(fRunShuffling) {\r
582     if (!fShuffledBalance) {\r
583       AliError("fShuffledBalance not available");\r
584       return;\r
585     }\r
586   }\r
587 \r
588 }\r
589 \r
590 //________________________________________________________________________\r
591 void AliAnalysisTaskTriggeredBF::Terminate(Option_t *) {\r
592   // Called once at the end of the query\r
593 \r
594   // not implemented ...\r
595 \r
596 }\r
597 \r
598 void AliAnalysisTaskTriggeredBF::UserExecMix(Option_t *)\r
599 {\r
600 \r
601   // not yet done for event mixing!\r
602   return;\r
603 \r
604 }\r
605 \r