AliPhysics  8d00e07 (8d00e07)
AliAnalysisTaskStudentsML.cxx
Go to the documentation of this file.
1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
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 * template class for student projects *
18 * Marcel Lesch (marcel.lesch@cern.ch) *
19 **********************************************/
20 
21 #include "Riostream.h"
23 #include "AliLog.h"
24 #include "AliAODEvent.h"
25 #include "AliAODInputHandler.h"
26 #include "AliAnalysisManager.h"
27 #include "AliMultSelection.h"
28 #include "TRandom.h"
29 #include "TComplex.h"
30 #include "TProfile.h"
31 #include "TStyle.h"
32 #include "TFile.h"
33 #include "TH1F.h"
34 
35 using std::cout;
36 using std::endl;
37 
39 
40 //================================================================================================================
41 
42 AliAnalysisTaskStudentsML::AliAnalysisTaskStudentsML(const char *name, Bool_t useParticleWeights):
43  AliAnalysisTaskSE(name),
44  fHistList(NULL),
45  // Control histograms:
46  fControlHistogramsList(NULL),
47  fPtHist(NULL),
48  fNbins(1000),
49  fMinBin(0.),
50  fMaxBin(10.),
51  fPhiHist(NULL),
52  fEtaHist(NULL),
53  fMultiHisto(NULL),
54  fMaxCorrelator(8),
55  // Final results:
56  fFinalResultsList(NULL)
57  {
58  // Constructor.
59 
60  AliDebug(2,"AliAnalysisTaskStudentsML::AliAnalysisTaskStudentsML(const char *name, Bool_t useParticleWeights)");
61 
62  // Base list:
63  fHistList = new TList();
64  fHistList->SetName("outputStudentAnalysis");
65  fHistList->SetOwner(kTRUE);
66 
67  // Initialize all arrays:
68  this->InitializeArrays();
69 
70  // Define input and output slots here
71  // Input slot #0 works with an AliFlowEventSimple
72  //DefineInput(0, AliFlowEventSimple::Class());
73  // Input slot #1 is needed for the weights input file:
74  //if(useParticleWeights)
75  //{
76  // DefineInput(1, TList::Class());
77  //}
78  // Output slot #0 is reserved
79  // Output slot #1 writes into a TList container
80 
81  DefineOutput(1, TList::Class());
82 
83  if(useParticleWeights)
84  {
85  // not needed for the time being
86  }
87 
88 } // AliAnalysisTaskStudentsML::AliAnalysisTaskStudentsML(const char *name, Bool_t useParticleWeights):
89 
90 //================================================================================================================
91 
94  fHistList(NULL),
95  // Control histograms:
96  fControlHistogramsList(NULL),
97  fPtHist(NULL),
98  fNbins(1000),
99  fMinBin(0.),
100  fMaxBin(10.),
101  fPhiHist(NULL),
102  fEtaHist(NULL),
103  fMultiHisto(NULL),
104  fMaxCorrelator(8),
105  // Final results:
106  fFinalResultsList(NULL)
107 {
108  // Dummy constructor.
109 
110  AliDebug(2,"AliAnalysisTaskStudentsML::AliAnalysisTaskStudentsML()");
111 
112 } // AliAnalysisTaskStudentsML::AliAnalysisTaskStudentsML():
113 
114 //================================================================================================================
115 
117 {
118  // Destructor.
119 
120  if(fHistList) delete fHistList;
121 
122 } // AliAnalysisTaskStudentsML::~AliAnalysisTaskStudentsML()
123 
124 //================================================================================================================
125 
127 {
128  // Called at every worker node to initialize.
129 
130  // a) Trick to avoid name clashes, part 1;
131  // b) Book and nest all lists;
132  // c) Book all objects;
133  // *) Trick to avoid name clashes, part 2.
134 
135  // a) Trick to avoid name clashes, part 1:
136  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
137  TH1::AddDirectory(kFALSE);
138 
139  // b) Book and nest all lists:
140  this->BookAndNestAllLists();
141 
142  // c) Book all objects:
143  this->BookControlHistograms();
145 
146  // *) Trick to avoid name clashes, part 2:
147  TH1::AddDirectory(oldHistAddStatus);
148 
149  PostData(1,fHistList);
150 
151 } // void AliAnalysisTaskStudentsML::UserCreateOutputObjects()
152 
153 //================================================================================================================
154 
156 {
157  // Main loop (called for each event).
158 
159  // a) Get pointer to AOD event:
160  // b) Start analysis over AODs;
161  // c) Reset event-by-event objects;
162  // d) PostData.
163 
164  // a) Get pointer to AOD event:
165  AliAODEvent *aAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
166  if(!aAOD){return;}
167 
168 
169 
170 
171 
172  // b) Start analysis over AODs:
173  Int_t nTracks = aAOD->GetNumberOfTracks(); // number of all tracks in current event
174  fMultiHisto->Fill(nTracks);
175 
176  for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
177  {
178  AliAODTrack *aTrack = dynamic_cast<AliAODTrack*>(aAOD->GetTrack(iTrack)); // getting a pointer to a track
179  if(!aTrack){continue;} // protection against NULL pointers
180  if(!aTrack->TestFilterBit(128)){continue;} // filter bit 128 denotes TPC-only tracks, use only them for the analysis
181 
182  // example variables for each track:
183  Double_t px = aTrack->Px(); // x-component of momenta
184  Double_t py = aTrack->Py(); // y-component of momenta
185  Double_t pz = aTrack->Pz(); // z-component of momenta
186  Double_t e = aTrack->E(); // energy
187  Double_t phi = aTrack->Phi(); // azimuthal angle
188  Double_t eta = aTrack->Eta(); // pseudorapidity
189  Double_t charge = aTrack->Charge(); // charge
190  Double_t pt = aTrack->Pt(); // Pt (transverse momentum)
191 
192 
193  // apply some cuts: e.g. take for the analysis only particles in -0.8 < eta < 0.8, and 0.2 < pT < 5.0
194  // ... implementation of particle cuts ...
195  if( (-0.8 < eta) && (eta < 0.8) && (0.2 < pt) && (pt < 5.0) )
196  {
197  // Fill some control histograms with the particles which passed cuts:
198  fPtHist->Fill(pt);
199  fPhiHist->Fill(phi);
200  fEtaHist->Fill(eta);
201 
202 
203  // Do some analysis only with the particles which passed the cuts
204  // ... your analysis code ...
205 
206  //fill arrays for angles (weights and bin)
207 
208  } // if( (-0.8 < eta) && (eta < 0.8) && (0.2 < pt) && (pt < 5.0) )
209  } // for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
210 
211  // c) Reset event-by-event objects:
212  // ...
213 
214 
215  // d) PostData:
216  PostData(1,fHistList);
217 
218 } // void AliAnalysisTaskStudentsML::UserExec(Option_t *)
219 
220 //================================================================================================================
221 
223 {
224  // Accessing the merged output list.
225 
226  fHistList = (TList*)GetOutputData(1);
227  if(!fHistList){exit(1);}
228 
229  // Do some calculation in offline mode here:
230  // ...
231 
232  TFile *f = new TFile("AnalysisResults.root","RECREATE");
233  fHistList->Write(fHistList->GetName(),TObject::kSingleKey);
234 
235  delete f;
236 
237 } // end of void AliAnalysisTaskStudentsML::Terminate(Option_t *)
238 
239 //================================================================================================================
240 
242 {
243  // Initialize all data members which are arrays in this method.
244 
245  // ...
246 
247 } // void AliAnalysisTaskStudentsML::InitializeArrays()
248 
249 //=======================================================================================================================
250 
252 {
253  // Book and nest all lists nested in the base list fHistList.
254 
255  // a) Book and nest lists for control histograms;
256  // b) Book and nest lists for final results.
257 
258  TString sMethodName = "void AliAnalysisTaskStudentsML::BookAndNestAllLists()";
259  if(!fHistList){Fatal(sMethodName.Data(),"fHistList is NULL");}
260 
261  // a) Book and nest lists for control histograms:
263  fControlHistogramsList->SetName("ControlHistograms");
264  fControlHistogramsList->SetOwner(kTRUE);
265  fHistList->Add(fControlHistogramsList);
266 
267  // b) Book and nest lists for final results:
268  fFinalResultsList = new TList();
269  fFinalResultsList->SetName("FinalResults");
270  fFinalResultsList->SetOwner(kTRUE);
272 
273 } // void AliAnalysisTaskStudentsML::BookAndNestAllLists()
274 
275 //=======================================================================================================================
276 
278 {
279  // Book all control histograms.
280 
281  // a) Book histogram to hold pt distribution;
282  // b) Book histogram to hold phi distribution;
283  // c) Book histogram to hold eta distribution;
284  // d) Book histogam to hold multiplicty distribution;
285  // e) ...
286 
287 
288 
289 
290  // a) Book histogram to hold pt spectra:
291  fPtHist = new TH1F("fPtHist","atrack->Pt()",fNbins,fMinBin,fMaxBin);
292  fPtHist->SetStats(kFALSE);
293  fPtHist->SetFillColor(kBlue-10);
294  fPtHist->GetXaxis()->SetTitle("p_{t}");
296 
297  // b) Book histogram to hold phi distribution:
298  fPhiHist = new TH1F("fPhiHist","Phi Distribution",1000,0.,6.3);
299  fPhiHist->GetXaxis()->SetTitle("Phi");
300  fPhiHist->SetLineColor(4);
302 
303  // c) Book histogram to hold eta distribution:
304  fEtaHist = new TH1F("fEtaHist","Eta Distribution",1000,-1.,1.);
305  fEtaHist->GetXaxis()->SetTitle("Eta");
306  fEtaHist->SetLineColor(4);
308 
309  // d) Book histogam to hold multiplicty distribution:
310  fMultiHisto = new TH1F("fMultiHisto","Multiplicity",300,0.,3.); //histogram for multiplicity
311  fMultiHisto->GetXaxis()->SetTitle("Multiplicity M");
313 
314  // e) ...
315 
316 } // void AliAnalysisTaskStudentsML::BookControlHistograms()
317 
318 //=======================================================================================================================
319 
321 {
322  // Book all histograms to hold the final results.
323 
324  // fFinalResultsList->Add(...);
325 
326 } // void AliAnalysisTaskStudentsML::BookFinalResultsHistograms()
327 
328 //=======================================================================================================================
329 
Int_t charge
double Double_t
Definition: External.C:58
virtual void Terminate(Option_t *)
int Int_t
Definition: External.C:63
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53