]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/Fluctuations/AliEbyEHigherMomentsTask.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGCF / EBYE / Fluctuations / AliEbyEHigherMomentsTask.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: Satyajit Jena.                                                 *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16
17 //=========================================================================//
18 //                                                                         //
19 //           Analysis Task for Net-Charge Higher Moment Analysis           //
20 //              Author: Satyajit Jena || Nirbhay K. Behera                 //
21 //                      sjena@cern.ch || nbehera@cern.ch                   //
22 //           Last Modified: 30/01/2014: only for net-charge part           //
23 //=========================================================================//
24 #include "TChain.h"
25 #include "TList.h"
26 #include "TFile.h"
27 #include "TTree.h"
28 #include "TH1D.h"
29 #include "TH2D.h"
30 #include "TH3D.h"
31 #include "THnSparse.h"
32 #include "TCanvas.h"
33
34 #include "AliAnalysisTaskSE.h"
35 #include "AliAnalysisManager.h"
36 #include "AliAODEvent.h"
37 #include "AliVTrack.h"
38 #include "AliAODTrack.h"
39 #include "AliAODInputHandler.h"
40 #include "AliAODEvent.h"
41 #include "AliStack.h"
42 #include "AliAODMCHeader.h"
43 #include "AliAODMCParticle.h"
44 #include "AliMCEventHandler.h"
45 #include "AliMCEvent.h"
46 #include "AliStack.h"
47 #include "AliGenHijingEventHeader.h"
48 #include "AliGenEventHeader.h"
49 #include "AliPID.h"
50 #include "AliAODPid.h"                
51 #include "AliPIDResponse.h"
52 #include "AliAODpidUtil.h"        
53 #include "AliPIDCombined.h"
54 #include "AliHelperPID.h"
55
56 #include "AliEbyEHigherMomentsTask.h"
57
58 using std::cout;
59 using std::endl;
60
61 ClassImp(AliEbyEHigherMomentsTask)
62
63
64 //-----------------------------------------------------------------------
65 AliEbyEHigherMomentsTask::AliEbyEHigherMomentsTask( const char *name )
66 : AliAnalysisTaskSE( name ),
67   fListOfHistos(0),
68   fArrayMC(0),
69   fAnalysisType(0),
70   fCentralityEstimator("V0M"),
71   fCentrality(0),
72   fVxMax(3.),
73   fVyMax(3.),
74   fVzMax(10.),
75   fPtLowerLimit(0.3),
76   fPtHigherLimit(1.5),
77   fNptBins(0),
78   fBin(0),
79   fEtaLowerLimit(-0.8),
80   fEtaHigherLimit(0.8),
81   fAODtrackCutBit(128),
82   fEventCounter(0),
83   fHistVxVy(0),
84   fTHnCentNplusNminusCh(0),
85   fTHnCentNplusNminusChTruth(0),
86   fPtBinNplusNminusCh(0),
87   fPtBinNplusNminusChTruth(0)
88
89   
90   for ( Int_t i = 0; i < 4; i++) { 
91     fHistQA[i] = NULL;
92   }
93  
94   DefineOutput(1, TList::Class()); // Outpput....
95   //DefineOutput(2, TList::Class()); 
96 }
97
98 AliEbyEHigherMomentsTask::~AliEbyEHigherMomentsTask() {
99
100   if(fListOfHistos) delete fListOfHistos;
101 }
102
103 //---------------------------------------------------------------------------------
104 void AliEbyEHigherMomentsTask::UserCreateOutputObjects() {
105   
106   fListOfHistos = new TList();
107   fListOfHistos->SetOwner(kTRUE);
108   
109   fEventCounter = new TH1D("fEventCounter","EventCounter", 10, 0.5,10.5);
110   fEventCounter->GetXaxis()->SetBinLabel(1,"Event Accesed");
111   fEventCounter->GetXaxis()->SetBinLabel(2,"Within 0-80% centrality");
112   fEventCounter->GetXaxis()->SetBinLabel(5,"Have a vertex");
113   fEventCounter->GetXaxis()->SetBinLabel(6,"After vertex Cut");
114   fEventCounter->GetXaxis()->SetBinLabel(7,"Event Analyzed");
115   fListOfHistos->Add(fEventCounter);
116   
117   //For QA-Histograms
118   fHistQA[0] = new TH1D("fHistQAvz", "Histo Vz After Cut", 500, -25., 25.);  
119   fHistQA[1] = new TH1D("fHistQAPt","p_{T} distribution",600,0,6);
120   fHistQA[2] = new TH1D("fHistQAEta","#eta distribution",240,-1.2,1.2);
121   fHistQA[3] = new TH1D("fHistQAPhi","#phi distribution",340,0,6.8);
122  
123   for(Int_t i = 0; i < 4; i++)
124     {
125       fListOfHistos->Add(fHistQA[i]);
126     }
127   
128   fHistVxVy = new TH2D("fHistVxVy","Vertex-x Vs Vertex-y", 200, -1., 1., 200, -1., 1.);
129   fListOfHistos->Add(fHistVxVy);
130  
131  
132   const Int_t nDim = 3;
133   
134   Int_t fBinsCh[nDim] = {100, 1500, 1500};
135   Double_t fMinCh[nDim] = { -0.5, -0.5, -0.5 };
136   Double_t fMaxCh[nDim] = { 99.5, 1499.5, 1499.5};
137   
138   const Int_t dim = fNptBins*2 + 1;
139   //const Int_t dim = ;
140   Int_t bin[dim];
141   Double_t min[dim];
142   Double_t max[dim];
143   bin[0] = 100; min[0] = -0.5; max[0] = 99.5;
144
145   for(Int_t i = 1; i < dim; i++){
146     
147     bin[i] = 900;
148     min[i] = -0.5;
149     max[i] = 899.5;
150  
151   } 
152   
153   fTHnCentNplusNminusCh = new THnSparseD("fTHnCentNplusNminusCh","Cent-NplusChrg-NminusChrg", nDim, fBinsCh, fMinCh, fMaxCh); 
154   fTHnCentNplusNminusCh->GetAxis(0)->SetTitle("Centrality");
155   fTHnCentNplusNminusCh->GetAxis(1)->SetTitle("Nplus");
156   fTHnCentNplusNminusCh->GetAxis(2)->SetTitle("Nminus");
157   fListOfHistos->Add(fTHnCentNplusNminusCh);
158
159   fPtBinNplusNminusCh = new THnSparseI("fPtBinNplusNminusCh","cent-nplus-nminus", dim, bin, min, max);
160   
161   fListOfHistos->Add(fPtBinNplusNminusCh);
162   
163   if( fAnalysisType == "MCAOD" ){   
164     
165     fTHnCentNplusNminusChTruth = new THnSparseD("fTHnCentNplusNminusChTruth","Cent-NplusChrg-NminusChrg", nDim, fBinsCh, fMinCh, fMaxCh); 
166     fTHnCentNplusNminusChTruth->GetAxis(0)->SetTitle("Centrality");
167     fTHnCentNplusNminusChTruth->GetAxis(1)->SetTitle("Nplus");
168     fTHnCentNplusNminusChTruth->GetAxis(2)->SetTitle("Nminus");
169     fListOfHistos->Add(fTHnCentNplusNminusChTruth);
170     
171     fPtBinNplusNminusChTruth = new THnSparseI("fPtBinNplusNminusChTruth","cent-nplus-nminus", dim, bin, min, max);
172     fListOfHistos->Add(fPtBinNplusNminusChTruth);
173     
174   }//MCAOD---
175   
176  
177   
178   //PostData(1, fListOfHistosQA);
179   PostData(1, fListOfHistos);   
180   
181   
182 }
183
184
185 //----------------------------------------------------------------------------------
186 void AliEbyEHigherMomentsTask::UserExec( Option_t * ){
187   
188   fEventCounter->Fill(1);
189   
190   if(fAnalysisType == "AOD") {
191     
192     doAODEvent();
193     
194   }//AOD--analysis-----
195   
196   else if(fAnalysisType == "MCAOD") {
197     
198     doMCAODEvent();
199     
200   }
201   
202   else return;
203  
204   
205   
206 }
207
208 //--------------------------------------------------------------------------------------
209 void AliEbyEHigherMomentsTask::doAODEvent(){
210   
211   Double_t positiveSum = 0.;
212   Double_t negativeSum = 0.;
213   const Int_t dim = fNptBins*2;
214   Double_t PtCh[dim];
215
216   for(Int_t idx = 0; idx < dim; idx++){
217     PtCh[idx] = 0.;
218   }
219
220
221   AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
222   if (!manager) {
223     cout<<"ERROR: Analysis manager not found."<<endl;
224     return;
225   }
226   //coneect to the inputHandler------------
227   AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
228   if (!inputHandler) {
229     cout<<"ERROR: Input handler not found."<<endl;
230     return;
231   }
232   
233   AliAODEvent *fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
234
235   if (!fAOD)
236     {
237       cout<< "ERROR: AOD not found " <<endl;
238       return;
239     }
240   
241   if(!ProperVertex(fAOD)) return;   
242   
243   AliAODHeader *aodHeader = fAOD->GetHeader();
244   
245   fCentrality = (Int_t)aodHeader->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());
246   
247   if(fCentrality < 0 || fCentrality >= 81) return;
248   
249   fEventCounter->Fill(2);
250   
251   Int_t nTracks = fAOD->GetNumberOfTracks();
252   
253   for(Int_t i = 0; i < nTracks; i++) {
254     
255     AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i)); 
256     
257     if(!aodTrack) {
258       AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
259       continue;
260     }
261     
262     if(!AcceptTrack(aodTrack) ) continue;
263
264     
265     fBin = GetPtBin(aodTrack->Pt());
266     
267     Short_t gCharge = aodTrack->Charge();
268     if(gCharge > 0){
269       positiveSum += 1.;
270       PtCh[fBin] += 1;
271     }
272     if(gCharge < 0){
273       negativeSum += 1.;
274       PtCh[fNptBins+fBin] += 1;
275     }
276    
277    
278   }//--------- Track Loop to select with filterbit
279   
280   Double_t fContainerCh[3] = { static_cast<Double_t>(fCentrality), positiveSum, negativeSum};
281   
282   fTHnCentNplusNminusCh->Fill(fContainerCh);
283
284   //cout << fCentrality << " " << positiveSum <<" " << negativeSum << endl;
285   
286   Double_t ptContainer[dim+1];
287
288   ptContainer[0] = fCentrality;
289
290   for(Int_t i = 1; i <= dim; i++){
291     ptContainer[i] = PtCh[i-1];
292     //cout << PtCh[i-1] <<" ,";
293   }
294   //cout << endl;
295
296   fPtBinNplusNminusCh->Fill(ptContainer);
297   
298   
299   fEventCounter->Fill(7);
300   PostData(1, fListOfHistos);
301   return;
302   
303 }
304 //--------------------------------------------------------------------------------------
305 //--------------------------------------------------------------------------------------
306 void AliEbyEHigherMomentsTask::doMCAODEvent(){
307   
308   
309   //---------
310   Double_t positiveSumMCRec = 0.;
311   Double_t negativeSumMCRec = 0.;
312  
313   Double_t positiveSumMCTruth = 0.;
314   Double_t negativeSumMCTruth = 0.;
315  
316   const Int_t dim = fNptBins*2;
317   Double_t PtCh[dim];
318   Double_t ptChMC[dim];
319   for(Int_t idx = 0; idx < dim; idx++){
320     PtCh[idx] = 0;
321     ptChMC[idx] = 0;
322   }
323   
324   //Connect to Anlaysis manager------
325   AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager();
326   if (!manager) {
327     cout<<"ERROR: Analysis manager not found."<<endl;
328     return;
329   }
330   
331   AliAODInputHandler* inputHandler = dynamic_cast<AliAODInputHandler*> (manager->GetInputEventHandler());
332   if (!inputHandler) {
333     cout<<"ERROR: Input handler not found."<<endl;
334     return;
335   }
336   
337   //AOD event------
338   AliAODEvent *fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
339   
340   if (!fAOD)
341     {
342       cout<< "ERROR: AOD not found " <<endl;
343       return;
344     }
345
346   // -- Get MC header
347   // ------------------------------------------------------------------
348   
349   fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
350   if (!fArrayMC) {
351     AliFatal("Error: MC particles branch not found!\n");
352     return;
353   }
354   
355   AliAODMCHeader *mcHdr=NULL;
356   mcHdr=(AliAODMCHeader*)fAOD->GetList()->FindObject(AliAODMCHeader::StdBranchName());  
357   if(!mcHdr) {
358     printf("MC header branch not found!\n");
359     return;
360   }
361   
362   if(!ProperVertex(fAOD)) return;
363
364   AliAODHeader *aodHeader = fAOD->GetHeader();
365   
366   fCentrality = (Int_t)aodHeader->GetCentralityP()->GetCentralityPercentile(fCentralityEstimator.Data());
367
368   if( fCentrality < 0 || fCentrality >= 81) return;
369   
370   fEventCounter->Fill(2);
371  
372   Int_t nTracks = fAOD->GetNumberOfTracks();
373   
374   for(Int_t i = 0; i < nTracks; i++) {
375     
376     AliAODTrack* aodTrack = dynamic_cast<AliAODTrack *>(fAOD->GetTrack(i)); 
377     
378     if(!aodTrack) {
379       AliError(Form("ERROR: Could not retrieve AODtrack %d",i));
380       continue;
381     }
382     
383     if(!AcceptTrack(aodTrack) ) continue;
384
385     
386     fBin = GetPtBin(aodTrack->Pt());
387     
388     //cout << "Pt Bin " << fBin << endl;
389
390     Short_t gCharge = aodTrack->Charge();
391     if(gCharge > 0){
392       positiveSumMCRec += 1.;
393      PtCh[fBin] += 1;
394     }
395     if(gCharge < 0){
396       negativeSumMCRec += 1.;    
397       PtCh[fNptBins+fBin] += 1;
398     }
399    
400   }//--------- Track Loop to select with filterbit
401   
402   //===============================================================================
403   //---------------------MC Truth--------------------------------------------------
404   //===============================================================================
405   
406   Int_t nMCTrack = fArrayMC->GetEntriesFast();
407   
408   for (Int_t iMC = 0; iMC < nMCTrack; iMC++) {
409     
410     AliAODMCParticle *partMC = (AliAODMCParticle*) fArrayMC->At(iMC);
411     
412     if(!partMC){
413       AliError(Form("ERROR: Could not retrieve AODMCtrack %d",iMC));
414       continue;
415     }
416     
417     if(partMC->Charge() == 0) continue;
418     if(!partMC->IsPhysicalPrimary()) continue;
419     
420     if (partMC->Eta() < fEtaLowerLimit || partMC->Eta() > fEtaHigherLimit) continue;
421     if (partMC->Pt() < fPtLowerLimit ||  partMC->Pt() > fPtHigherLimit) continue;
422     
423     Short_t gCharge = partMC->Charge();
424     Int_t mcbin = GetPtBin(partMC->Pt());
425     
426     if(gCharge > 0){
427       positiveSumMCTruth += 1.;
428       ptChMC[mcbin] += 1.;
429     }
430     if(gCharge < 0){
431       negativeSumMCTruth += 1.;
432       ptChMC[fNptBins+mcbin] += 1.;
433     }
434    
435    
436   }//MC-Truth Track loop--
437
438   Double_t fContainerCh[3] = { static_cast<Double_t>(fCentrality), positiveSumMCRec, negativeSumMCRec};//Reco. values ch. hadrons
439   Double_t fContainerChTruth[3] = { static_cast<Double_t>(fCentrality), positiveSumMCTruth, negativeSumMCTruth};  
440  
441   fTHnCentNplusNminusCh->Fill(fContainerCh);//Fill the rec. ch. particles---
442   fTHnCentNplusNminusChTruth->Fill(fContainerChTruth);//MC -Truth ch. particles
443   
444   //cout << fCentrality << " " << positiveSumMCRec << " " << negativeSumMCRec <<endl;
445   //cout <<fCentrality<<"   " << positiveSumMCTruth << " " << negativeSumMCTruth << endl;
446   //cout <<"   " << posPidSumMCRec << " " << negPidSumMCRec << endl;
447   //cout <<"   " << posPidSumMCTruth << " " << negPidSumMCTruth << endl;
448   //cout <<"---------------------------------" << endl;
449   
450   Double_t ptContainer[dim+1];
451   Double_t ptContainerMC[dim+1];
452   ptContainer[0] = fCentrality;
453   ptContainerMC[0] = fCentrality;
454
455   for(Int_t i = 1; i <= dim; i++){
456     ptContainer[i] = PtCh[i-1];
457     ptContainerMC[i] = ptChMC[i-1];
458     //cout <<" "<< PtCh[i-1]<<endl;
459     //  cout<< " MC=" << ptChMC[i-1];
460   }
461
462   //cout << endl;
463
464   fPtBinNplusNminusCh->Fill(ptContainer);
465   fPtBinNplusNminusChTruth->Fill(ptContainerMC);
466
467   fEventCounter->Fill(7);
468   PostData(1, fListOfHistos);
469   return;
470   
471 }
472
473 //---------------------------------------------------------------------------------------
474 Bool_t AliEbyEHigherMomentsTask::ProperVertex(AliAODEvent *fAOD) const{
475   
476   Bool_t IsVtx = kFALSE;
477   
478   const AliAODVertex *vertex = fAOD->GetPrimaryVertex();
479   
480   if(vertex) {
481     Double32_t fCov[6];
482     vertex->GetCovarianceMatrix(fCov);
483     if(vertex->GetNContributors() > 0) {
484       if(fCov[5] != 0) {
485         
486         Double_t lvx = vertex->GetX();
487         Double_t lvy = vertex->GetY();
488         Double_t lvz = vertex->GetZ();
489         
490         fEventCounter->Fill(5);
491       
492         if(TMath::Abs(lvx) < fVxMax) {
493           if(TMath::Abs(lvy) < fVyMax) {
494             if(TMath::Abs(lvz) < fVzMax) {
495               
496               fEventCounter->Fill(6);
497               fHistQA[0]->Fill(lvz);
498               fHistVxVy->Fill(lvx,lvy);
499               IsVtx = kTRUE; 
500               
501             }//Z-Vertex cut---
502           }//Y-vertex cut--
503         }//X-vertex cut---
504       }//Covariance------
505     }//Contributors check---
506   }//If vertex-----------
507
508   AliCentrality *centrality = fAOD->GetCentrality();
509   if (centrality->GetQuality() != 0) IsVtx = kFALSE;
510   
511   return IsVtx;
512 }
513 //---------------------------------------------------------------------------------------
514
515 //---------------------------------------------------------------------------------------
516 Bool_t AliEbyEHigherMomentsTask::AcceptTrack(AliAODTrack* track) const{
517   
518   if(!track) return kFALSE;
519   if( track->Charge() == 0 ) return kFALSE;
520
521   Double_t pt = track->Pt();
522   Double_t eta = track->Eta();
523   if(!track->TestFilterBit(fAODtrackCutBit)) return kFALSE;
524   if( pt < fPtLowerLimit || pt > fPtHigherLimit ) return kFALSE;
525   if( eta < fEtaLowerLimit || eta > fEtaHigherLimit ) return kFALSE;
526   
527   fHistQA[1]->Fill(pt);
528   fHistQA[2]->Fill(eta);
529   fHistQA[3]->Fill(track->Phi());
530  
531   return kTRUE;
532 }
533 //------------------------------------------------------------------------
534
535 //------------------------------------------------------------------------
536 Int_t AliEbyEHigherMomentsTask::GetPtBin(Double_t pt){
537   
538   Int_t bin = 0;
539
540   Double_t BinSize = (fPtHigherLimit - fPtLowerLimit)/fNptBins;
541   
542   for(Int_t iBin = 0; iBin < fNptBins; iBin++){
543     
544     Double_t xLow = fPtLowerLimit + iBin*BinSize;
545     Double_t xHigh = fPtLowerLimit + (iBin+1)*BinSize;
546     
547     if( pt >= xLow && pt < xHigh){
548       bin = iBin;
549       //cout << "Pt Bin #" << bin <<"pt=" << pt << endl;
550       break;
551     }
552     
553   }//for 
554   
555   
556   return bin;
557 }
558 //------------------------------------------------------------------------
559 //------------------------------------------------------------------------
560 void AliEbyEHigherMomentsTask::Terminate( Option_t * ){
561   
562   Info("AliEbyEHigherMomentTask"," Task Successfully finished");
563   
564 }
565
566 //------------------------------------------------------------------------