AliPhysics  master (3d17d9d)
AliAnalysisTaskNBodyFemtoscopy.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 * Femtoscopy task for N bodies *
18 *Laura Serksnyte
19 *laura.serksnyte@cern.ch
20 **************************************/
21 
22 #include "Riostream.h"
24 #include "AliLog.h"
25 #include "AliAODEvent.h"
26 #include "AliAODInputHandler.h"
27 #include "TFile.h"
28 
29 using std::cout;
30 using std::endl;
31 
33 
34 //================================================================================================================
35 
37  AliAnalysisTaskSE(name),
38  fHistList(NULL),
39  // Control histograms:
40  fControlHistogramsList(NULL),
41  fPtHist(NULL),
42  fNbinsPt(1000),
43  fMinBinPt(0.),
44  fMaxBinPt(10.),
45  // Final results:
46  fFinalResultsList(NULL)
47  {
48  // Constructor.
49 
50  AliDebug(2,"AliAnalysisTaskNBodyFemtoscopy::AliAnalysisTaskNBodyFemtoscopy(const char *name, Bool_t useParticleWeights)");
51 
52  // Base list:
53  fHistList = new TList();
54  fHistList->SetName("outputStudentAnalysis");
55  fHistList->SetOwner(kTRUE);
56 
57  // Initialize all arrays:
58  this->InitializeArrays();
59 
60  // Define input and output slots here
61  // Input slot #0 works with an AliFlowEventSimple
62  //DefineInput(0, AliFlowEventSimple::Class());
63  // Input slot #1 is needed for the weights input file:
64  //if(useParticleWeights)
65  //{
66  // DefineInput(1, TList::Class());
67  //}
68  // Output slot #0 is reserved
69  // Output slot #1 writes into a TList container
70 
71  DefineOutput(1, TList::Class());
72 
73  if(useParticleWeights)
74  {
75  // not needed for the time being
76  }
77 
78 } // AliAnalysisTaskNBodyFemtoscopy::AliAnalysisTaskNBodyFemtoscopy(const char *name, Bool_t useParticleWeights):
79 
80 //================================================================================================================
81 
84  fHistList(NULL),
85  // Control histograms:
86  fControlHistogramsList(NULL),
87  fPtHist(NULL),
88  fNbinsPt(1000),
89  fMinBinPt(0.),
90  fMaxBinPt(10.),
91  // Final results:
92  fFinalResultsList(NULL)
93 {
94  // Dummy constructor.
95 
96  AliDebug(2,"AliAnalysisTaskNBodyFemtoscopy::AliAnalysisTaskNBodyFemtoscopy()");
97 
98 } // AliAnalysisTaskNBodyFemtoscopy::AliAnalysisTaskNBodyFemtoscopy():
99 
100 //================================================================================================================
101 
103 {
104  // Destructor.
105 
106  if(fHistList) delete fHistList;
107 
108 } // AliAnalysisTaskNBodyFemtoscopy::~AliAnalysisTaskNBodyFemtoscopy()
109 
110 //================================================================================================================
111 
113 {
114  // Called at every worker node to initialize.
115 
116  // a) Trick to avoid name clashes, part 1;
117  // b) Book and nest all lists;
118  // c) Book all objects;
119  // *) Trick to avoid name clashes, part 2.
120 
121  // a) Trick to avoid name clashes, part 1:
122  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
123  TH1::AddDirectory(kFALSE);
124 
125  // b) Book and nest all lists:
126  this->BookAndNestAllLists();
127 
128  // c) Book all objects:
129  this->BookControlHistograms();
131 
132  // *) Trick to avoid name clashes, part 2:
133  TH1::AddDirectory(oldHistAddStatus);
134 
135  PostData(1,fHistList);
136 
137 } // void AliAnalysisTaskNBodyFemtoscopy::UserCreateOutputObjects()
138 
139 //================================================================================================================
140 
142 {
143  // Main loop (called for each event).
144  // a) Get pointer to AOD event:
145  // b) Start analysis over AODs;
146  // c) Reset event-by-event objects;
147  // d) PostData.
148 
149  // a) Get pointer to AOD event:
150  AliAODEvent *aAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
151  if(!aAOD){return;}
152 
153  // b) Start analysis over AODs:
154  Int_t nTracks = aAOD->GetNumberOfTracks(); // number of all tracks in current event
155  for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
156  {
157  AliAODTrack *aTrack = dynamic_cast<AliAODTrack*>(aAOD->GetTrack(iTrack)); // getting a pointer to a track
158  if(!aTrack){continue;} // protection against NULL pointers
159  if(!aTrack->TestFilterBit(128)){continue;} // filter bit 128 denotes TPC-only tracks, use only them for the analysis
160 
161  // example variables for each track: (for more options, please see class STEER/AOD/AliAODTrack.h)
162  Double_t pt = aTrack->Pt(); // Pt
163  //Double_t px = aTrack->Px(); // x-component of momenta
164  //Double_t py = aTrack->Py(); // y-component of momenta
165  //Double_t pz = aTrack->Pz(); // z-component of momenta
166  //Double_t e = aTrack->E(); // energy
167  //Double_t phi = aTrack->Phi(); // azimuthal angle
168  //Double_t eta = aTrack->Eta(); // pseudorapidity
169  //Double_t charge = aTrack->Charge(); // charge
170 
171  // apply some cuts: e.g. take for the analysis only particles in 0.2 < pT < 5.0 GeV
172  if( (0.2 < pt) && (pt < 5.0) ) // example cuts
173  {
174  // fill some control histograms:
175  fPtHist->Fill(pt); // filling pt distribution
176 
177  // do some analysis only with the particles which passed the cuts
178  // ... your analysis code ...
179 
180  } // if( (0.2 < pT) && (pT < 5.0) )
181 
182  } // for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
183 
184  // c) Reset event-by-event objects:
185  // ...
186 
187  // d) PostData:
188  PostData(1,fHistList);
189 
190 } // void AliAnalysisTaskNBodyFemtoscopy::UserExec(Option_t *)
191 
192 //================================================================================================================
193 
195 {
196  // Accessing the merged output list.
197 
198  fHistList = (TList*)GetOutputData(1);
199  if(!fHistList){exit(1);}
200 
201  // Do some calculation in offline mode here:
202 
203  // ... your code for offline calculations ...
204 
205  // Update the output file with new results:
206  TFile *f = new TFile("AnalysisResults.root","RECREATE");
207  fHistList->Write(fHistList->GetName(),TObject::kSingleKey);
208 
209  delete f;
210 
211 } // end of void AliAnalysisTaskNBodyFemtoscopy::Terminate(Option_t *)
212 
213 //================================================================================================================
214 
216 {
217  // Initialize all data members which are arrays in this method.
218 
219 } // void AliAnalysisTaskNBodyFemtoscopy::InitializeArrays()
220 
221 //=======================================================================================================================
222 
224 {
225  // Book and nest all lists nested in the base list fHistList.
226 
227  // a) Book and nest lists for control histograms;
228  // b) Book and nest lists for final results.
229 
230  TString sMethodName = "void AliAnalysisTaskNBodyFemtoscopy::BookAndNestAllLists()";
231  if(!fHistList){Fatal(sMethodName.Data(),"fHistList is NULL");}
232 
233  // a) Book and nest lists for control histograms:
235  fControlHistogramsList->SetName("ControlHistograms");
236  fControlHistogramsList->SetOwner(kTRUE);
237  fHistList->Add(fControlHistogramsList);
238 
239  // b) Book and nest lists for final results:
240  fFinalResultsList = new TList();
241  fFinalResultsList->SetName("FinalResults");
242  fFinalResultsList->SetOwner(kTRUE);
244 
245 } // void AliAnalysisTaskNBodyFemtoscopy::BookAndNestAllLists()
246 
247 //=======================================================================================================================
248 
250 {
251  // Book all control histograms.
252 
253  // a) Book histogram to hold pt spectra;
254  // b) ...
255 
256  // a) Book histogram to hold pt spectra:
257  fPtHist = new TH1F("fPtHist","atrack->Pt()",fNbinsPt,fMinBinPt,fMaxBinPt);
258  fPtHist->SetStats(kFALSE);
259  fPtHist->SetFillColor(kBlue-10);
260  fPtHist->GetXaxis()->SetTitle("p_{t}");
262 
263  // b) ...
264 
265 } // void AliAnalysisTaskNBodyFemtoscopy::BookControlHistograms()
266 
267 //=======================================================================================================================
268 
270 {
271  // Book all histograms to hold the final results.
272 
273 } // void AliAnalysisTaskNBodyFemtoscopy::BookFinalResultsHistograms()
274 
275 //=======================================================================================================================
276 
double Double_t
Definition: External.C:58
int Int_t
Definition: External.C:63
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53