AliPhysics  63e47e1 (63e47e1)
AliAnalysisTaskStudentsCM.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 **************************************/
19 
20 #include "Riostream.h"
22 #include "AliLog.h"
23 #include "AliAODEvent.h"
24 #include "AliAODInputHandler.h"
25 #include "AliAnalysisManager.h"
26 #include "AliMultSelection.h"
27 #include "TRandom.h"
28 #include "TComplex.h"
29 #include "TProfile.h"
30 #include "TStyle.h"
31 #include "TFile.h"
32 
33 using std::cout;
34 using std::endl;
35 
37 
38 //================================================================================================================
39 
40 AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM(const char *name, Bool_t useParticleWeights): // {Definition of the constructor of the class}
41  AliAnalysisTaskSE(name),
42  fHistList(NULL), // {These are pointers. There is no address to point to when they are initialise by default, so NULL}
43  // Control histograms:
44  fControlHistogramsList(NULL),
45  fTestHistogramsList(NULL), // {TEST}
46  fPtHistNoCut(NULL),
47  fPtHist(NULL),
48  fNbins(1000),
49  fMinBin(0.),
50  fMaxBin(20.),
51  fPhiHist(NULL),
52  fEtaHist(NULL),
53  fEnergyHist(NULL), // TEST
54  fEnergyHistNoCut(NULL),
55  fPtPhiHist(NULL), // TEST
56  fMassSquareHist(NULL), // TEST
57  // Final results:
58  fFinalResultsList(NULL),
59  fEtaMassSquareHist(NULL)
60  {
61  // Constructor. {The data members must initialise in the EXACT SAME order than they are declared in the header file ! If a data member is added, it must be put at the same place in the list in the .h and the .cxx}
62 
63  AliDebug(2,"AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM(const char *name, Bool_t useParticleWeights)");
64 
65  // Base list:
66  fHistList = new TList();
67  fHistList->SetName("outputStudentAnalysis");
68  fHistList->SetOwner(kTRUE);
69 
70  // Initialize all arrays:
71  this->InitializeArrays();
72 
73  // Define input and output slots here
74  // Input slot #0 works with an AliFlowEventSimple
75  //DefineInput(0, AliFlowEventSimple::Class());
76  // Input slot #1 is needed for the weights input file:
77  //if(useParticleWeights)
78  //{
79  // DefineInput(1, TList::Class());
80  //}
81  // Output slot #0 is reserved
82  // Output slot #1 writes into a TList container
83 
84  DefineOutput(1, TList::Class());
85 
86  if(useParticleWeights)
87  {
88  // not needed for the time being
89  }
90 
91 } // AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM(const char *name, Bool_t useParticleWeights):
92 
93 //================================================================================================================
94 
95 AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM(): // {Dummy constructor. Simply paste the initialised data members again here.}
97  fHistList(NULL),
98  // Control histograms:
99  fControlHistogramsList(NULL),
100  fTestHistogramsList(NULL), // {TEST}
101  fPtHistNoCut(NULL),
102  fPtHist(NULL),
103  fNbins(1000),
104  fMinBin(0.),
105  fMaxBin(20.),
106  fPhiHist(NULL),
107  fEtaHist(NULL),
108  fEnergyHist(NULL), // {TEST}
109  fEnergyHistNoCut(NULL),
110  fPtPhiHist(NULL), // TEST
111  fMassSquareHist(NULL), // TEST
112  // Final results:
113  fFinalResultsList(NULL),
114  fEtaMassSquareHist(NULL)
115 {
116  // Dummy constructor.
117 
118  AliDebug(2,"AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM()");
119 
120 } // AliAnalysisTaskStudentsCM::AliAnalysisTaskStudentsCM():
121 
122 //================================================================================================================
123 
125 {
126  // Destructor. {Delete the main TList deletes everything in it automatically}
127 
128  if(fHistList) delete fHistList;
129 
130 } // AliAnalysisTaskStudentsCM::~AliAnalysisTaskStudentsCM()
131 
132 //================================================================================================================
133 
135 {
136  // Called at every worker node to initialize.
137 
138  // a) Trick to avoid name clashes, part 1;
139  // b) Book and nest all lists;
140  // c) Book all objects;
141  // *) Trick to avoid name clashes, part 2.
142 
143  // a) Trick to avoid name clashes, part 1:
144  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
145  TH1::AddDirectory(kFALSE);
146 
147  // b) Book and nest all lists:
148  this->BookAndNestAllLists();
149 
150  // c) Book all objects:
151  this->BookControlHistograms();
152  this->BookTestHistograms(); // {TEST}
154 
155  // *) Trick to avoid name clashes, part 2:
156  TH1::AddDirectory(oldHistAddStatus);
157 
158  PostData(1,fHistList);
159 
160 } // void AliAnalysisTaskStudentsCM::UserCreateOutputObjects()
161 
162 //================================================================================================================
163 
165 {
166  // Main loop (called for each event). {Put the tasks that are applied to each event there.}
167 
168  // a) Get pointer to AOD event:
169  // b) Start analysis over AODs;
170  // c) Reset event-by-event objects;
171  // d) PostData.
172 
173  // a) Get pointer to AOD event:
174  AliAODEvent *aAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
175  if(!aAOD){return;}
176 
177  // b) Start analysis over AODs:
178  Int_t nTracks = aAOD->GetNumberOfTracks(); // number of all tracks in current event
179  for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
180  {
181  AliAODTrack *aTrack = dynamic_cast<AliAODTrack*>(aAOD->GetTrack(iTrack)); // getting a pointer to a track
182  if(!aTrack){continue;} // protection against NULL pointers
183  if(!aTrack->TestFilterBit(128)){continue;} // filter bit 128 denotes TPC-only tracks, use only them for the analysis
184 
185  // example variables for each track:
186  Double_t px = aTrack->Px(); // x-component of momenta
187  Double_t py = aTrack->Py(); // y-component of momenta
188  Double_t pz = aTrack->Pz(); // z-component of momenta
189  Double_t e = aTrack->E(); // energy
190  Double_t phi = aTrack->Phi(); // azimuthal angle
191  Double_t eta = aTrack->Eta(); // pseudorapidity
192  Double_t charge = aTrack->Charge(); // charge
193  Double_t pt = aTrack->Pt(); // Pt (transverse momentum)
194  Double_t mSquare = 0.; // mass^2
195 
196  // Fill the control histogram containing the transverse momentum before the application of any cut
197  fPtHistNoCut->Fill(pt);
198  fEnergyHistNoCut->Fill(e);
199 
200  // apply some cuts: e.g. take for the analysis only particles in -0.8 < eta < 0.8, and 0.2 < pT < 5.0
201  // ... implementation of particle cuts ...
202  if( (-0.8 < eta) && (eta < 0.8) && (0.2 < pt) && (pt < 5.0) )
203  {
204  // Fill some control histograms with the particles which passed cuts:
205  fPtHist->Fill(pt);
206  fPhiHist->Fill(phi);
207  //fEtaHist->Fill(eta); // moved to final results as a test
208 
209  // Fill the personal histograms into the test subfolder of the output
210  fEnergyHist->Fill(e); // {TEST}
211  fPtPhiHist->Fill(pt,phi); // TEST
212 
213 
214  // Do some analysis only with the particles which passed the cuts
215  // ... your analysis code ...
216  // TEST
217  mSquare = e*e - (px*px + py*py + pz*pz);
218 
219  // Fill some final histograms
220  fEtaHist->Fill(eta);
221  fMassSquareHist->Fill(mSquare);
222  fEtaMassSquareHist->Fill(eta,mSquare);
223 
224  } // if( (-0.8 < eta) && (eta < 0.8) && (0.2 < pt) && (pt < 5.0) )
225  } // for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
226 
227  // c) Reset event-by-event objects:
228  // ...
229 
230  // d) PostData:
231  PostData(1,fHistList);
232 
233 } // void AliAnalysisTaskStudentsCM::UserExec(Option_t *)
234 
235 //================================================================================================================
236 
238 {
239  // Accessing the merged output list.
240 
241  fHistList = (TList*)GetOutputData(1);
242  if(!fHistList){exit(1);}
243 
244  // Do some calculation in offline mode here: {i.e. once the run over the events has been done}
245  // ...
246 
247 
248  TFile *f = new TFile("AnalysisResults.root","RECREATE"); // {Name of the output file}
249  fHistList->Write(fHistList->GetName(),TObject::kSingleKey); // {Writing of the main TList in the output file}
250 
251  delete f;
252 
253 } // end of void AliAnalysisTaskStudentsCM::Terminate(Option_t *)
254 
255 //================================================================================================================
256 
258 {
259  // Initialize all data members which are arrays in this method.
260 
261  // ...
262 
263 } // void AliAnalysisTaskStudentsCM::InitializeArrays()
264 
265 //=======================================================================================================================
266 
268 {
269  // Book and nest all lists nested in the base list fHistList.
270 
271  // a) Book and nest lists for control histograms;
272  // b) Book and nest lists for final results.
273 
274  TString sMethodName = "void AliAnalysisTaskStudentsCM::BookAndNestAllLists()";
275  if(!fHistList){Fatal(sMethodName.Data(),"fHistList is NULL");}
276 
277  // a) Book and nest lists for control histograms:
279  fControlHistogramsList->SetName("ControlHistograms");
280  fControlHistogramsList->SetOwner(kTRUE);
281  fHistList->Add(fControlHistogramsList);
282 
283  // {TEST} Book and nest lists for personal test histograms:
284  fTestHistogramsList = new TList();
285  fTestHistogramsList->SetName("TestHistograms");
286  fTestHistogramsList->SetOwner(kTRUE);
288 
289  // b) Book and nest lists for final results:
290  fFinalResultsList = new TList();
291  fFinalResultsList->SetName("FinalResults");
292  fFinalResultsList->SetOwner(kTRUE);
294 
295 } // void AliAnalysisTaskStudentsCM::BookAndNestAllLists()
296 
297 //=======================================================================================================================
298 
300 {
301  // Book all control histograms.
302 
303  // a) Book histogram to hold pt distribution before the application of cuts;
304  // b) Book histogram to hold pt distribution;
305  // c) Book histogram to hold phi distribution;
306  // d) Book histogram to hold eta distribution
307  // e) ...
308 
309 
310  // a) Book histogram to hold pt distribution before the application of cuts;
311  fPtHistNoCut = new TH1F("fPtHistNoCut", "atrack->Pt()", fNbins, fMinBin, fMaxBin);
312  fPtHistNoCut->SetStats(kTRUE);
313  fPtHistNoCut->SetFillColor(kRed);
314  fPtHistNoCut->GetXaxis()->SetTitle("p_{t}");
316 
317  // b) Book histogram to hold pt spectra:
318  fPtHist = new TH1F("fPtHist","atrack->Pt()",fNbins,fMinBin,fMaxBin);
319  fPtHist->SetStats(kTRUE);
320  fPtHist->SetFillColor(kBlue-10);
321  fPtHist->GetXaxis()->SetTitle("p_{t}");
323 
324  // c) Book histogram to hold phi distribution:
325  fPhiHist = new TH1F("fPhiHist","Phi Distribution",1000,0.,6.3);
326  fPhiHist->GetXaxis()->SetTitle("Phi");
327  fPhiHist->SetLineColor(4);
329 
330  // c) Book histogram to hold eta distribution:
331  /*fEtaHist = new TH1F("fEtaHist","Eta Distribution",1000,-1.,1.);
332  fEtaHist->GetXaxis()->SetTitle("Eta");
333  fEtaHist->SetLineColor(4);
334  fControlHistogramsList->Add(fEtaHist);*/
335 
336 } // void AliAnalysisTaskStudentsCM::BookControlHistograms()
337 
338 //=======================================================================================================================
339 
341 {
342  // Book all personal histograms.
343 
344  // a) Book histogram to hold energy distribution
345  // b) Book histogram to hold energy distribution before the application of cuts
346  // c) Book 2D histogram to hold (pt, phi) distribution
347 
348  // a) Book histogram to hold energy distribution {TEST}
349  fEnergyHist = new TH1F("fEnergyHist", "Energy Distribution",fNbins,fMinBin,fMaxBin);
350  fEnergyHist->SetStats(kTRUE);
351  fEnergyHist->SetLineColor(3);
352  fEnergyHist->GetXaxis()->SetTitle("E");
354 
355  // b) Book histogram to hold energy distribution before the application of cuts
356  fEnergyHistNoCut = new TH1F("fEnergyHistNoCut", "Energy distribution before cuts", fNbins, fMinBin, fMaxBin);
357  fEnergyHistNoCut->SetStats(kTRUE);
358  fEnergyHistNoCut->GetXaxis()->SetTitle("E");
360 
361  // c) Book 2D histogram to hold (pt, phi) distribution TEST
362  fPtPhiHist = new TH2F("fPtPhiHist", "(Pt, Phi) Distribution", fNbins,fMinBin,fMaxBin,1000,0.,6.3);
363  fPtPhiHist->SetStats(kFALSE);
364  fPtPhiHist->GetXaxis()->SetTitle("p_{t}");
365  fPtPhiHist->GetYaxis()->SetTitle("Phi");
367 
368 } // void AliAnalysisTaskStudentsCM::BookTestHistograms()
369 
370 // ======================================================================================================================
371 
373 {
374  // Book all histograms to hold the final results.
375 
376  // a) Book histogram to hold eta (previously into control histogram) TEST
377  // b) Book histogram to hold mSquare TEST
378  // c) Book histogram to hold mSquare as a function of eta TEST
379 
380  // a) Book histogram to hold eta (previously into control histogram) TEST
381  fEtaHist = new TH1F("fEtaHist","Eta Distribution",1000,-1.,1.);
382  fEtaHist->GetXaxis()->SetTitle("Eta");
383  fEtaHist->SetLineColor(4);
385 
386  // b) Book histogram to hold mSquare TEST
387  fMassSquareHist = new TH1F("fMassSquareHist", "Mass squared distribution",1000,0.,15.);
388  fMassSquareHist->GetXaxis()->SetTitle("m^{2}");
389  fMassSquareHist->SetLineColor(1);
391 
392  // c) Book histogram to hold mSquare as a function of eta TEST
393  fEtaMassSquareHist = new TH2F("fEtaMassSquareHist", "(eta, m^2) distribution",1000,-1.,1.,1000,0.,5.);
394  fEtaMassSquareHist->GetXaxis()->SetTitle("Eta");
395  fEtaMassSquareHist->GetYaxis()->SetTitle("m^2");
397 
398  // fFinalResultsList->Add(...);
399 
400 } // void AliAnalysisTaskStudentsCM::BookFinalResultsHistograms()
401 
402 //=======================================================================================================================
403 
Int_t charge
double Double_t
Definition: External.C:58
Definition: External.C:236
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