AliPhysics  b555aef (b555aef)
AliAnalysisTaskForStudents.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 "TLegend.h"
28 
29 #include "TCanvas.h" // TBI
30 #include "TFile.h" // TBI
31 #include "TRandom.h"
32 #include "TGraphErrors.h"
33 #include "TComplex.h"
34 #include "TProfile.h"
35 #include "TStyle.h"
36 
37 using std::cout;
38 using std::endl;
39 
41 
42 //================================================================================================================
43 
44 AliAnalysisTaskForStudents::AliAnalysisTaskForStudents(const char *name, Bool_t useParticleWeights):
45  AliAnalysisTaskSE(name),
46  fHistList(NULL),
47  // Control histograms:
48  fControlHistogramsList(NULL),
49  fPtHist(NULL),
50  fNbins(1000),
51  fMinBin(0.),
52  fMaxBin(10.),
53  fCentralityHist(NULL),
54  fNCentralityBins(10),
55  fMinCentrality(0.),
56  fMaxCentrality(100.),
57  fMultHist(NULL),
58  fPhiHist(NULL),
59  fEtaHist(NULL),
60  fhf(NULL),
61  fhf2(NULL),
62  leg_hist(NULL),
63  // Final results:
64  fFinalResultsList(NULL),
65  num(0),
66  fhr2bin(0), // me
67  fsize(9),
68  fbinnum(0),
69  fcounter1(0),
70  fcounter2(0),
71  fcounter3(0),
72  fmult(0),
73  c2(0.),
74  fhr2min(0.),
75  fhr2max(0.),
76  fper2(0.),
77  fper3(0.),
78  fper4(0.),
79  fvarb(0.),
80  fmu(0.),
81  fymin(0.), // me
82  fymax(0.), // me
83  fc4(0.),
84  fc3(0.),
85  fc22(0.),
86  fc24(0.),
87  fc23(0.),
88  fhr2(NULL),
89  fhr3(NULL),
90  fhrc22(NULL),
91  fhrc23(NULL),
92  fhrc24(NULL),
93  fhrc3(NULL),
94  fhrc4(NULL),
95  fgr(NULL),
96  fq6(0.,0.),
97  fq4(0.,0.),
98  fq(0.,0.),
99  fq2(0.,0.),
100  fqq(0.,0.),
101  fq5(0.,0.),
102  fq3(0.,0.),
103  fq1(0.,0.),
104  fq3x(0.,0.),
105  fqq3(0.,0.)
106  {
107  // Constructor.
108 
109  AliDebug(2,"AliAnalysisTaskForStudents::AliAnalysisTaskForStudents(const char *name, Bool_t useParticleWeights)");
110 
111  // Base list:
112  fHistList = new TList();
113  fHistList->SetName("outputStudentAnalysis");
114  fHistList->SetOwner(kTRUE);
115 
116  // Initialize all arrays:
117  this->InitializeArrays();
118 
119  // Define input and output slots here
120  // Input slot #0 works with an AliFlowEventSimple
121  //DefineInput(0, AliFlowEventSimple::Class());
122  // Input slot #1 is needed for the weights input file:
123  //if(useParticleWeights)
124  //{
125  // DefineInput(1, TList::Class());
126  //}
127  // Output slot #0 is reserved
128  // Output slot #1 writes into a TList container
129 
130  //num =1;
131 
132  DefineOutput(1, TList::Class());
133 
134  if(useParticleWeights)
135  {
136  // not needed for the time being
137  }
138 
139 } // AliAnalysisTaskForStudents::AliAnalysisTaskForStudents(const char *name, Bool_t useParticleWeights):
140 
141 //================================================================================================================
142 
145  fHistList(NULL),
146  // Control histograms:
147  fControlHistogramsList(NULL),
148  fPtHist(NULL),
149  fNbins(1000),
150  fMinBin(0.),
151  fMaxBin(10.),
152  fCentralityHist(NULL),
153  fNCentralityBins(10),
154  fMinCentrality(0.),
155  fMaxCentrality(100.),
156  fMultHist(NULL),
157  fPhiHist(NULL),
158  fEtaHist(NULL),
159  fhf(NULL),
160  fhf2(NULL),
161  leg_hist(NULL),
162  // Final results:
163  fFinalResultsList(NULL),
164  num(0),
165  fhr2bin(0),
166  fsize(9),
167  fbinnum(0),
168  fcounter1(0),
169  fcounter2(0),
170  fcounter3(0),
171  fmult(0),
172  c2(0.),
173  fhr2min(0.),
174  fhr2max(0.),
175  fper2(0.),
176  fper3(0.),
177  fper4(0.),
178  fvarb(0.),
179  fmu(0.),
180  fymin(0.), // me
181  fymax(0.), // me
182  fc4(0.),
183  fc3(0.),
184  fc22(0.),
185  fc24(0.),
186  fc23(0.),
187  fhr2(NULL),
188  fhr3(NULL),
189  fhrc22(NULL),
190  fhrc23(NULL),
191  fhrc24(NULL),
192  fhrc3(NULL),
193  fhrc4(NULL),
194  fgr(NULL),
195  fq6(0.,0.),
196  fq4(0.,0.),
197  fq(0.,0.),
198  fq2(0.,0.),
199  fqq(0.,0.),
200  fq5(0.,0.),
201  fq3(0.,0.),
202  fq1(0.,0.),
203  fq3x(0.,0.),
204  fqq3(0.,0.)
205 {
206  // Dummy constructor.
207 
208  AliDebug(2,"AliAnalysisTaskForStudents::AliAnalysisTaskForStudents()");
209 
210 } // AliAnalysisTaskForStudents::AliAnalysisTaskForStudents():
211 
212 //================================================================================================================
213 
215 {
216  // Destructor.
217 
218  if(fHistList) delete fHistList;
219 
220 } // AliAnalysisTaskForStudents::~AliAnalysisTaskForStudents()
221 
222 //================================================================================================================
223 
225 {
226  // Called at every worker node to initialize.
227 
228  // a) Trick to avoid name clashes, part 1;
229  // b) Book and nest all lists;
230  // c) Book all objects;
231  // *) Trick to avoid name clashes, part 2.
232 
233  // a) Trick to avoid name clashes, part 1:
234  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
235  TH1::AddDirectory(kFALSE);
236 
237  // b) Book and nest all lists:
238  this->BookAndNestAllLists();
239 
240  // c) Book all objects:
241  this->BookControlHistograms();
243 
244  // *) Trick to avoid name clashes, part 2:
245  TH1::AddDirectory(oldHistAddStatus);
246 
247  PostData(1,fHistList);
248 
249 } // void AliAnalysisTaskForStudents::UserCreateOutputObjects()
250 
251 //================================================================================================================
252 
254 {
255  Int_t im=0, jm=0;
256 
257  fq6 = TComplex(0.,0.);
258  fq4 = TComplex(0.,0.);
259  fq2 = TComplex(0.,0.);
260  fq5 = TComplex(0.,0.);
261  fq3 = TComplex(0.,0.);
262  fq1 = TComplex(0.,0.);
263 
264  // Main loop (called for each event).
265 
266  // a) Get pointer to AOD event:
267  // b) Start analysis over AODs;
268  // c) Reset event-by-event objects;
269  // d) PostData.
270 
271 
272  // a) Get pointer to AOD event:
273  AliAODEvent *aAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
274  if(!aAOD){return;}
275 
276  AliMultSelection *ams = (AliMultSelection*)aAOD->FindListObject("MultSelection");
277  if(!ams){return;}
278  if(ams->GetMultiplicityPercentile("V0M") >= fMinCentrality && ams->GetMultiplicityPercentile("V0M") < fMaxCentrality)
279  {
280  fCentralityHist->Fill(ams->GetMultiplicityPercentile("V0M"));
281  }
282  else
283  {
284  return; // this event do not belong to the centrality class specified for this particular analysis
285  }
286 
287 
288  // b) Start analysis over AODs:
289  Int_t nTracks = aAOD->GetNumberOfTracks(); // number of all tracks in current event
290  for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
291  {
292  AliAODTrack *aTrack = dynamic_cast<AliAODTrack*>(aAOD->GetTrack(iTrack)); // getting a pointer to a track
293  if(!aTrack){continue;} // protection against NULL pointers
294  if(!aTrack->TestFilterBit(128)){continue;} // filter bit 128 denotes TPC-only tracks, use only them for the analysis
295 
296  // example variables for each track: (for more options, please see class /home/deniz/alicesw/aliroot/v5-07-20/src/STEER/AOD/AliAODTrack.h )
297  Double_t px = aTrack->Px(); // x-component of momenta
298  Double_t py = aTrack->Py(); // y-component of momenta
299  Double_t pz = aTrack->Pz(); // z-component of momenta
300  Double_t e = aTrack->E(); // energy
301  Double_t phi = aTrack->Phi(); // azimuthal angle
302  Double_t eta = aTrack->Eta(); // pseudorapidity
303  Double_t charge = aTrack->Charge(); // charge
304  Double_t pt = aTrack->Pt(); // Pt
305 
306  // apply some cuts: e.g. take for the analysis only particles in -0.8 < eta < 0.8, and 0.2 < pT < 5.0
307  // ... implementation of particle cuts ...
308  if ( (-0.8 < eta) && (eta < 0.8) && (0.2 < pt) && (pt < 5.0) ) {
309 
310  fq2 += TComplex(cos(2.*phi),sin(2.*phi));
311  fq4 += TComplex(cos(4.*phi),sin(4.*phi));
312  fq6 += TComplex(cos(6.*phi),sin(6.*phi));
313  fq1 += TComplex(cos(phi),sin(phi));
314  fq3 += TComplex(cos(3.*phi),sin(3.*phi));
315  fq5 += TComplex(cos(5.*phi),sin(5.*phi));
316 
317  im++;
318 
319  fPtHist->Fill(pt);
320  fPhiHist->Fill(phi);
321  fEtaHist->Fill(eta);
322 
323  } // if ( (-0.8 < eta) && (eta < 0.8) && (0.2 < pT) && (pT < 5.0) )
324 
325 
326  // do some analysis only with the particles which passed the cuts
327  // ... your analysis code ...
328 
329  } // for(Int_t iTrack=0;iTrack<nTracks;iTrack++) // starting a loop over all tracks
330 
331  fmult = im;
332 
333  fMultHist->Fill(fmult);
334 
335  if ( fmult > 3) {
336  fper2 = fmult*(fmult-1.);
337  fper4 = fmult*(fmult-1.)*(fmult-2.)*(fmult-3.);
338  //fper3 = fmult*(fmult-1)*(fmult-2);
339 
340  fc22=(fq2.Rho2()-fmult)/fper2;
341  fhr2->Fill(0.1,fc22,fper2);
342 
343  fc24=(fq4.Rho2()-fmult)/fper2;
344  fhr2->Fill(1.1,fc24,fper2);
345 
346  fq=fq6*TComplex::Conjugate(fq2)*TComplex::Conjugate(fq4);
347  fqq=fq4*TComplex::Conjugate(fq2)*TComplex::Conjugate(fq2);
348 
349  fc4=(fq2.Rho2()*fq4.Rho2() - 2.*fq.Re() - 2.*fqq.Re() + fq6.Rho2()+fq2.Rho2()-(fmult-4.)*(fq2.Rho2()+fq4.Rho2())+fmult*(fmult-6.))/fper4;
350  fhr2->Fill(2.1,fc4,fper4);
351 
352  fc23=(fq3.Rho2()-fmult)/fper2;
353  fhr3->Fill(0.1,fc23,fper2);
354 
355  fq3x=fq5*TComplex::Conjugate(fq2)*TComplex::Conjugate(fq3);
356  fqq3=fq3*TComplex::Conjugate(fq1)*TComplex::Conjugate(fq2);
357 
358  fc3=(fq2.Rho2()*fq3.Rho2() - 2.*fq3x.Re() - 2.*fqq3.Re() + fq5.Rho2()+fq2.Rho2()-(fmult-4.)*(fq2.Rho2()+fq3.Rho2())+fmult*(fmult-6.))/fper4;
359  fhr3->Fill(0.6,fc3,fper4);
360 
361  //cout<<endl<<"Aod disinda "<<fcounter1++<<" "<<fc3<<" "<<fc23<<" "<<fc22<<" "<< fc23*fc22<<endl;
362  //cout<<endl<<"Aod disinda "<<fcounter1++<<" "<<fc3<<" "<<fc23<<" "<<fc22<<" "<< fc23*fc22<<endl;
363 
364  fbinnum = gRandom->Uniform(0,10);
365  fhrc22->Fill(fbinnum,fc22,fper2);
366  fhrc24->Fill(fbinnum,fc24,fper2);
367  fhrc4->Fill(fbinnum,fc4,fper4);
368 
369  fhrc23->Fill(fbinnum,fc23,fper2);
370  fhrc3->Fill(fbinnum,fc3,fper4);
371  } // if ( fmult > 3)
372 
373 
374  // c) Reset event-by-event objects:
375  // ...
376 
377  // d) PostData:
378  PostData(1,fHistList);
379 
380 } // void AliAnalysisTaskForStudents::UserExec(Option_t *)
381 
382 //================================================================================================================
383 
385 {
386 
387  Double_t varb4=0., mu4=0., varb3=0., mu3=0., sc42=0., sc32=0.;
388 
389  sc42 = fhr2->GetBinContent(3)-fhr2->GetBinContent(1)*fhr2->GetBinContent(2);
390  sc32 = fhr3->GetBinContent(2)-fhr2->GetBinContent(1)*fhr3->GetBinContent(1);
391  // Accessing the merged output list.
392 
393 
394  // access average two particle correlation from TProfile, that you have filled in UserExec
395  // raise that two particle correlation to power 7
396  // store that information in the histogram holding final results
397 
398  cout<<endl<<" fhr2(3) "<<fhr2->GetBinContent(3)<<" "<<fhr2->GetBinContent(2)<<" "<<fhr2->GetBinContent(1)<<" sc(4,2) "<<sc42<<endl;
399  fhf->SetBinContent(1, sc32);
400  fhf->SetBinContent(2,sc42);
401 
402  for (Int_t i=1;i<11;i++) { mu4 +=fhrc4->GetBinContent(i)-fhrc24->GetBinContent(i)*fhrc22->GetBinContent(i); }
403  for (Int_t s=1;s<11;s++) {
404  varb4+= pow(fhrc4->GetBinContent(s)-fhrc24->GetBinContent(s)*fhrc22->GetBinContent(s) - mu4/10.,2);
405  }
406  fhf->SetBinError(2, sqrt(varb4/9.));
407 
408  for (Int_t i=1;i<11;i++) { mu3 +=fhrc3->GetBinContent(i)-fhrc23->GetBinContent(i)*fhrc22->GetBinContent(i); }
409  for (Int_t s=1;s<11;s++) {
410  varb3+= pow(fhrc3->GetBinContent(s)-fhrc23->GetBinContent(s)*fhrc22->GetBinContent(s) - mu3/10.,2);
411  }
412  fhf->SetBinError(1,sqrt(varb3/9.));
413 
414  cout<<endl<<" sc32 "<<fhf->GetBinContent(1)<<" "<<" sc42 "<<fhf->GetBinContent(2)<<endl;
415 
416  fHistList = (TList*)GetOutputData(1);
417  if(!fHistList){exit(1);}
418 
419  // Do some calculation in offline mode here:
420  // ...
421 
422  TFile *f = new TFile("AnalysisResultsSC.root","RECREATE");
423  fHistList->Write(fHistList->GetName(),TObject::kSingleKey);
424 
425  delete f;
426 
427 } // end of void AliAnalysisTaskForStudents::Terminate(Option_t *)
428 
429 //================================================================================================================
430 
432 {
433  // Initialize all data members which are arrays in this method.
434 
435  for(Int_t i=0;i<9;i++)
436  {
437  fsc4[i] = 0.;
438  fcentral[i] = 0.;
439  fyerr[i] = 0.;
440  }
441 
442 
443  // end
444 
445 } // void AliAnalysisTaskForStudents::InitializeArrays()
446 
447 //=======================================================================================================================
448 
450 {
451  // Book and nest all lists nested in the base list fHistList.
452 
453  // a) Book and nest lists for control histograms;
454  // b) Book and nest lists for final results.
455 
456  TString sMethodName = "void AliAnalysisTaskForStudents::BookAndNestAllLists()";
457  if(!fHistList){Fatal(sMethodName.Data(),"fHistList is NULL");}
458 
459  // a) Book and nest lists for control histograms:
461  fControlHistogramsList->SetName("ControlHistograms");
462  fControlHistogramsList->SetOwner(kTRUE);
463  fHistList->Add(fControlHistogramsList);
464 
465  // b) Book and nest lists for final results:
466  fFinalResultsList = new TList();
467  fFinalResultsList->SetName("FinalResults");
468  fFinalResultsList->SetOwner(kTRUE);
470 
471 } // void AliAnalysisTaskForStudents::BookAndNestAllLists()
472 
473 //=======================================================================================================================
474 
476 {
477  // Book all control histograms.
478 
479  // a) Book histogram to hold pt spectra;
480  // b) ...
481 
482  // a) Book histogram to hold pt spectra:
483  fPtHist = new TH1F("fPtHist","atrack->Pt()",fNbins,fMinBin,fMaxBin);
484  fPtHist->SetStats(kFALSE);
485  fPtHist->SetFillColor(kBlue-10);
486  fPtHist->GetXaxis()->SetTitle("p_{t}");
488 
489  fCentralityHist = new TH1F("fCentralityHist","ams->GetMultiplicityPercentile(\"V0M\")",fNCentralityBins,fMinCentrality,fMaxCentrality);
490  fCentralityHist->SetFillColor(kBlue-10);
491  fCentralityHist->GetXaxis()->SetTitle("centrality percentile");
493 
494  fMultHist = new TH1F("fMultHist","Multiplicity Distribution",1000,0,3000);
495  fMultHist->GetXaxis()->SetTitle("m");
496  fMultHist->SetLineColor(4);
498 
499  fPhiHist = new TH1F("fPhiHist","Phi Distribution",1000,0.,6.3);
500  fPhiHist->GetXaxis()->SetTitle("Phi");
501  fPhiHist->SetLineColor(4);
503 
504  fEtaHist = new TH1F("fEtaHist","Eta Distribution",1000,-1.,1.);
505  fEtaHist->GetXaxis()->SetTitle("Eta");
506  fEtaHist->SetLineColor(4);
508  //fControlHistogramsList->Add(fhf);
509 
510 
512  fgr->SetName("gr");
513  fgr->SetMarkerColor(2);
514  fgr->SetMarkerStyle(21);
515  fgr->SetMinimum(fymin);
516  fgr->SetMaximum(fymax);
517  fgr->SetMarkerSize(1.5);
518  fgr->GetYaxis()->SetTitleOffset(1.2);
519  fgr->GetXaxis()->SetTitle("centrality");
520  fgr->GetYaxis()->SetTitle("SC(4,2)");
521 
522  fhr2 = new TProfile("fhr2","fhr2 ",3,0.,3.);
523  fhr2->Sumw2();
525 
526  fhr3 = new TProfile("fhr3","fhr3 ",2,0.,1.);
527  fhr3->Sumw2();
529 
530  fhrc22 = new TProfile("fhrc22","fhrc22 ",10,0.,10);
531  fhrc22->Sumw2();
533  fhrc23 = new TProfile("fhrc23","fhrc23 ",10,0.,10);
534  fhrc23->Sumw2();
536  fhrc24 = new TProfile("fhrc24","fhrc24 ",10,0.,10);
537  fhrc24->Sumw2();
539  fhrc4 = new TProfile("fhrc4","fhrc4 ",10,0.,10);
540  fhrc4->Sumw2();
542  fhrc3 = new TProfile("fhrc3","fhrc3 ",10,0.,10);
543  fhrc3->Sumw2();
545 
546 
547  // b) ...
548 
549 } // void AliAnalysisTaskForStudents::BookControlHistograms()
550 
551 //=======================================================================================================================
552 
554 {
555  // Book all histograms to hold the final results.
556 
557  fhf = new TH1F("fhf","Profil ",2,0.,100);
558  fhf->GetXaxis()->SetTitle(" Centrality percentile");
559  fhf->GetYaxis()->SetTitle("SC(m,n)");
560  fhf->SetTitle(" ");
561  fhf->SetMarkerColor(4);
562  fhf->SetLineColor(1);
563  fhf->SetLineWidth(2);
564  fhf->SetMarkerSize(1.3);
565  fhf->SetMarkerStyle(8);
566  fhf->SetStats(0);
567  //gStyle->SetErrorX(0.0);
568  fhf->SetOption("pex0");
569 
570  fFinalResultsList->Add(fhf);
571 
572 } // void AliAnalysisTaskForStudents::BookFinalResultsHistograms()
573 
574 //=======================================================================================================================
575 
Int_t charge
double Double_t
Definition: External.C:58
TRandom * gRandom
int Int_t
Definition: External.C:63
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53