]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/AliAnalysisTaskProtons.cxx
Code organization - To come: corrections/container for antiprotons
[u/mrichter/AliRoot.git] / PWG2 / AliAnalysisTaskProtons.cxx
1 #include "TChain.h"
2 #include "TTree.h"
3 #include "TString.h"
4 #include "TList.h"
5 #include "TH2F.h"
6 #include "TH1I.h"
7 #include "TF1.h"
8 #include "TCanvas.h"
9 #include "TLorentzVector.h"
10
11 #include "AliAnalysisTask.h"
12 #include "AliAnalysisManager.h"
13
14 #include "AliESDEvent.h"
15 #include "AliESDInputHandler.h"
16 #include "AliAODEvent.h"
17 #include "AliAODInputHandler.h"
18 #include "AliMCEventHandler.h"
19 #include "AliMCEvent.h"
20 #include "AliStack.h"
21
22 #include "PWG2spectra/SPECTRA/AliProtonAnalysis.h"
23 #include "AliAnalysisTaskProtons.h"
24
25 // Analysis task creating a the 2d y-p_t spectrum of p and antip
26 // Author: Panos Cristakoglou
27
28 ClassImp(AliAnalysisTaskProtons)
29
30 //________________________________________________________________________ 
31 AliAnalysisTaskProtons::AliAnalysisTaskProtons()
32   : AliAnalysisTask(), fESD(0), fAOD(0), fMC(0), fAnalysisType("ESD"),
33     fList(0), fAnalysis(0),
34     fElectronFunction(0), fMuonFunction(0),
35     fPionFunction(0), fKaonFunction(0), fProtonFunction(0),
36     fFunctionUsed(kFALSE) {
37   //Dummy constructor
38                                                                                                    
39 }
40
41 //________________________________________________________________________
42 AliAnalysisTaskProtons::AliAnalysisTaskProtons(const char *name) 
43 : AliAnalysisTask(name, ""), fESD(0), fAOD(0), fMC(0), fAnalysisType("ESD"),
44   fList(0), fAnalysis(0), 
45   fElectronFunction(0), fMuonFunction(0),
46   fPionFunction(0), fKaonFunction(0), fProtonFunction(0),
47   fFunctionUsed(kFALSE) { 
48   // Constructor
49
50   // Define input and output slots here
51   // Input slot #0 works with a TChain
52   DefineInput(0, TChain::Class());
53   // Output slot #0 writes into a TList container
54   DefineOutput(0, TList::Class());
55 }
56
57 //________________________________________________________________________
58 void AliAnalysisTaskProtons::ConnectInputData(Option_t *) {
59   // Connect ESD or AOD here
60   // Called once
61
62   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
63   if (!tree) {
64     Printf("ERROR: Could not read chain from input slot 0");
65   } else {
66     if(fAnalysisType == "ESD") {
67       tree->SetBranchStatus("*", kFALSE);
68       tree->SetBranchStatus("Tracks.*", kTRUE);
69       
70       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
71      
72       if (!esdH) {
73         Printf("ERROR: Could not get ESDInputHandler");
74       } else
75         fESD = esdH->GetEvent();
76     }
77     else if(fAnalysisType == "AOD") {
78      AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
79      
80      if (!aodH) {
81        Printf("ERROR: Could not get AODInputHandler");
82      } else
83        fAOD = aodH->GetEvent();
84     }
85     else if(fAnalysisType == "MC") {
86      AliMCEventHandler* mcH = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
87      if (!mcH) {
88        Printf("ERROR: Could not retrieve MC event handler");
89      }
90      else
91        fMC = mcH->MCEvent();
92     }
93     else
94       Printf("Wrong analysis type: Only ESD, AOD and MC types are allowed!");
95   }
96 }
97
98 //________________________________________________________________________
99 void AliAnalysisTaskProtons::CreateOutputObjects() {
100   // Create histograms
101   // Called once
102   //Prior probabilities
103   Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
104   
105   //proton analysis object
106   fAnalysis = new AliProtonAnalysis();
107   fAnalysis->InitHistograms(10,-1.0,1.0,30,0.1,3.1);
108
109   if(fAnalysisType == "ESD") {
110     //Use of TPConly tracks                                                                                                                                                      
111     fAnalysis->UseTPCOnly();
112
113     //TPC related cuts       
114     fAnalysis->SetMinTPCClusters(50);
115     fAnalysis->SetMaxChi2PerTPCCluster(3.5);
116     fAnalysis->SetMaxCov11(2.0);
117     fAnalysis->SetMaxCov22(2.0);
118     fAnalysis->SetMaxCov33(0.5);
119     fAnalysis->SetMaxCov44(0.5);
120     fAnalysis->SetMaxCov55(2.0);
121     fAnalysis->SetMaxSigmaToVertex(2.5);
122     fAnalysis->SetTPCRefit();
123
124     //ITS related cuts - to be used in the case of the analysis of global tracks                                                                                                
125     //fAnalysis->SetMinITSClusters(5);                                                                                                                                          
126     //fAnalysis->SetITSRefit();                                                                                                                                                  
127   }
128
129   if(fFunctionUsed)
130     fAnalysis->SetPriorProbabilityFunctions(fElectronFunction,
131                                             fMuonFunction,
132                                             fPionFunction,
133                                             fKaonFunction,
134                                             fProtonFunction);
135   else
136     fAnalysis->SetPriorProbabilities(partFrac);
137
138   fList = new TList();
139   fList->Add(fAnalysis->GetProtonYPtHistogram());
140   fList->Add(fAnalysis->GetAntiProtonYPtHistogram());
141   fList->Add(fAnalysis->GetEventHistogram());
142 }
143
144 //________________________________________________________________________
145 void AliAnalysisTaskProtons::Exec(Option_t *) {
146   // Main loop
147   // Called for each event
148   
149   if(fAnalysisType == "ESD") {
150     if (!fESD) {
151       Printf("ERROR: fESD not available");
152       return;
153     }
154
155     Printf("Proton ESD analysis task: There are %d tracks in this event", fESD->GetNumberOfTracks());
156     fAnalysis->Analyze(fESD);
157   }//ESD analysis              
158   
159   else if(fAnalysisType == "AOD") {
160     if (!fAOD) {
161       Printf("ERROR: fAOD not available");
162       return;
163     }
164     
165     Printf("Proton AOD analysis task: There are %d tracks in this event", fAOD->GetNumberOfTracks());
166     fAnalysis->Analyze(fAOD);
167   }//AOD analysis                                                                                                                                                                
168   
169   else if(fAnalysisType == "MC") {
170     if (!fMC) {
171       Printf("ERROR: Could not retrieve MC event");
172       return;
173     }
174
175     AliStack* stack = fMC->Stack();
176     if (!stack) {
177       Printf("ERROR: Could not retrieve the stack");
178       return;
179     }
180     Printf("Proton MC analysis task: There are %d primaries in this event", stack->GetNprimary());
181     fAnalysis->Analyze(stack);
182   }//MC analysis                      
183
184   // Post output data.
185   PostData(0, fList);
186 }      
187
188 //________________________________________________________________________
189 void AliAnalysisTaskProtons::Terminate(Option_t *) {
190   // Draw result to the screen
191   // Called once at the end of the query
192   
193   fList = dynamic_cast<TList*> (GetOutputData(0));
194   if (!fList) {
195     Printf("ERROR: fList not available");
196     return;
197   }
198    
199   TH2F *fHistYPtProtons = (TH2F *)fList->At(0);
200   TH2F *fHistYPtAntiProtons = (TH2F *)fList->At(1);
201     
202   TCanvas *c1 = new TCanvas("c1","p-\bar{p}",200,0,800,400);
203   c1->SetFillColor(10); c1->SetHighLightColor(10); c1->Divide(2,1);
204
205   c1->cd(1)->SetLeftMargin(0.15); c1->cd(1)->SetBottomMargin(0.15);  
206   if (fHistYPtProtons) fHistYPtProtons->DrawCopy("colz");
207   c1->cd(2)->SetLeftMargin(0.15); c1->cd(2)->SetBottomMargin(0.15);  
208   if (fHistYPtAntiProtons) fHistYPtAntiProtons->DrawCopy("colz");
209 }
210
211