]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/SPECTRA/ChargedHadrons/dNdPt/AlidNdPtTask.cxx
PWGUD/dNdPt -> PWGLF/SPECTRA/ChargedHadrons/dNdPt
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / ChargedHadrons / dNdPt / AlidNdPtTask.cxx
1 /**************************************************************************\r
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
3 *                                                                        *\r
4 * Author: The ALICE Off-line Project.                                    *\r
5 * Contributors are mentioned in the code where appropriate.              *\r
6 *                                                                        *\r
7 * Permission to use, copy, modify and distribute this software and its   *\r
8 * documentation strictly for non-commercial purposes is hereby granted   *\r
9 * without fee, provided that the above copyright notice appears in all   *\r
10 * copies and that both the copyright notice and this permission notice   *\r
11 * appear in the supporting documentation. The authors make no claims     *\r
12 * about the suitability of this software for any purpose. It is          *\r
13 * provided "as is" without express or implied warranty.                  *\r
14 **************************************************************************/\r
15 \r
16 #include "iostream"\r
17 \r
18 #include "TChain.h"\r
19 #include "TTree.h"\r
20 #include "TH1F.h"\r
21 #include "TCanvas.h"\r
22 #include "TList.h"\r
23 #include "TFile.h"\r
24 \r
25 #include "AliAnalysisTask.h"\r
26 #include "AliAnalysisManager.h"\r
27 #include "AliESDEvent.h"\r
28 #include "AliESDInputHandler.h"\r
29 #include "AliESDVertex.h"\r
30 #include "AliTracker.h"\r
31 #include "AliGeomManager.h"\r
32 \r
33 #include "AliCentrality.h"\r
34 #include "AliESDVZERO.h"\r
35 #include "AliMultiplicity.h"\r
36 \r
37 #include "AliESDtrackCuts.h"\r
38 #include "AliMCEventHandler.h"\r
39 #include "dNdPt/AlidNdPt.h"\r
40 #include "dNdPt/AlidNdPtEventCuts.h"\r
41 #include "dNdPt/AlidNdPtAcceptanceCuts.h"\r
42 \r
43 #include "dNdPt/AlidNdPtTask.h"\r
44 \r
45 using namespace std;\r
46 \r
47 ClassImp(AlidNdPtTask)\r
48 \r
49 //_____________________________________________________________________________\r
50 AlidNdPtTask::AlidNdPtTask(const char *name) \r
51   : AliAnalysisTaskSE(name)\r
52   , fESD(0)\r
53   , fMC(0)\r
54   , fOutput(0)\r
55   , fPitList(0)\r
56   , fCompList(0)\r
57   , fUseMCInfo(kFALSE)\r
58 {\r
59   // Constructor\r
60 \r
61   // Define input and output slots here\r
62   DefineOutput(1, TList::Class());\r
63 \r
64   // create the list for comparison objects\r
65   fCompList = new TList;\r
66 }\r
67 \r
68 //_____________________________________________________________________________\r
69 AlidNdPtTask::~AlidNdPtTask()\r
70 {\r
71   if(fOutput) delete fOutput;  fOutput =0; \r
72   if(fCompList) delete fCompList;  fCompList =0; \r
73 }\r
74 \r
75 //____________________________________________________________________________\r
76 Bool_t AlidNdPtTask::Notify()\r
77 {\r
78   static Int_t count = 0;\r
79   count++;\r
80   //Printf("Processing %d. file: %s", count, ((TTree*) GetInputData(0))->GetCurrentFile()->GetName());\r
81   TTree *chain = (TChain*)GetInputData(0);\r
82   if(chain)\r
83     Printf("Processing %d. file: %s", count, chain->GetCurrentFile()->GetName());\r
84 \r
85   /*\r
86   TChain *chain = (TChain*)GetInputData(0);\r
87   AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
88   if (!esdH) {\r
89     Printf("ERROR: Could not get ESDInputHandler");\r
90     return kFALSE;\r
91   } else {\r
92     if(chain)\r
93     Printf("chain->GetCurrentFile()->GetName() %s", chain->GetCurrentFile()->GetName());\r
94   }\r
95   */\r
96 \r
97 return kTRUE;\r
98 }\r
99 \r
100 //_____________________________________________________________________________\r
101 Bool_t AlidNdPtTask::AddAnalysisObject(AlidNdPt *pObj) \r
102 {\r
103   // add analysis object to the list\r
104   if(pObj == 0) {\r
105     Printf("ERROR: Could not add comparison object");\r
106     return kFALSE;\r
107   }\r
108 \r
109   // add object to the list\r
110   fCompList->AddLast(pObj);\r
111        \r
112 return kTRUE;\r
113 }\r
114 \r
115 //_____________________________________________________________________________\r
116 void AlidNdPtTask::UserCreateOutputObjects()\r
117 {\r
118   // Create histograms\r
119   // Called once\r
120 \r
121   OpenFile(1, "RECREATE");\r
122 \r
123   //\r
124   // create output list\r
125   //\r
126   fOutput = new TList;\r
127   fOutput->SetOwner();\r
128   fPitList = fOutput->MakeIterator();\r
129 \r
130   // add dNdPt analysis objects to the output\r
131   AlidNdPt *pObj=0;\r
132   Int_t count=0;\r
133   TIterator *pitCompList = fCompList->MakeIterator();\r
134   pitCompList->Reset();\r
135   while(( pObj = (AlidNdPt *)pitCompList->Next()) != NULL) {\r
136     fOutput->Add(pObj);\r
137     count++;\r
138   }\r
139   Printf("UserCreateOutputObjects(): Number of output objects: %d \n", count);\r
140 \r
141   PostData(1, fOutput);\r
142 }\r
143 \r
144 //_____________________________________________________________________________\r
145 void AlidNdPtTask::UserExec(Option_t *) \r
146 {\r
147   //\r
148   // Called for each event\r
149   //\r
150 \r
151   // ESD event\r
152   fESD = (AliESDEvent*) (InputEvent());\r
153   if (!fESD) {\r
154     Printf("ERROR: ESD event not available");\r
155     return;\r
156   }\r
157 \r
158   // MC event\r
159   if(fUseMCInfo) {\r
160     fMC = MCEvent();\r
161     if (!fMC) {\r
162       Printf("ERROR: MC event not available");\r
163       return;\r
164     }\r
165   }\r
166 \r
167 \r
168     AlidNdPt *pObj = 0;\r
169     fPitList->Reset();\r
170     while((pObj = (AlidNdPt *)fPitList->Next()) != NULL) {\r
171       pObj->Process(fESD,fMC);\r
172     }\r
173 \r
174 \r
175   // Post output data.\r
176   PostData(1, fOutput);\r
177 }\r
178 \r
179 //_____________________________________________________________________________\r
180 void AlidNdPtTask::FinishTaskOutput() \r
181 {\r
182   //\r
183   // Called one at the end \r
184   // locally on working node\r
185   //\r
186    // check output data\r
187   fOutput = dynamic_cast<TList*> (GetOutputData(1));\r
188   if (!fOutput) {\r
189     Printf("ERROR: AlidNdPtTask::FinishTaskOutput(): Output data not avaiable GetOutputData(1)==0x0 ..." );\r
190     return;\r
191   }\r
192 \r
193   AlidNdPt* pObj=0;\r
194   TIterator* itOut = fOutput->MakeIterator();\r
195   itOut->Reset();\r
196   while(( pObj = dynamic_cast<AlidNdPt*>(itOut->Next())) != NULL) {\r
197     if(pObj->GetAnalyseOutput()) { \r
198       pObj->Analyse();\r
199     }\r
200   }\r
201 \r
202   // Post output data.\r
203   PostData(1, fOutput);\r
204 }\r
205 \r
206 //_____________________________________________________________________________\r
207 void AlidNdPtTask::Terminate(Option_t *) \r
208 {\r
209   // Called one at the end \r
210   \r
211   // check output data\r
212   fOutput = dynamic_cast<TList*> (GetOutputData(1));\r
213   if (!fOutput) {\r
214     Printf("ERROR: AlidNdPtTask::Terminate(): Output data not avaiable GetOutputData(0)==0x0 ..." );\r
215     return;\r
216   }\r
217 }\r