]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ESDCheck/AliAnalysisTaskPt.cxx
33d41f2a84b1f1db1810831bf296fb2fab8dfb68
[u/mrichter/AliRoot.git] / ESDCheck / AliAnalysisTaskPt.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 //_________________________________________________________________________
19 // A test analysis task to check the pt of tracks distribution in simulated data
20 //
21 //*-- Panos
22 //////////////////////////////////////////////////////////////////////////////
23
24 #include <TCanvas.h>
25 #include <TChain.h>
26 #include <TFile.h>
27 #include <TH1.h>
28 #include <TROOT.h>
29 #include <TSystem.h>
30
31 #include "AliAnalysisTaskPt.h"
32 #include "AliESD.h"
33 #include "AliLog.h"
34
35 //________________________________________________________________________
36 AliAnalysisTaskPt::AliAnalysisTaskPt(const char *name) :
37   AliAnalysisTask(name,""),  
38   fESD(0), 
39   fhPt(0) 
40 {
41   // Constructor.
42   // Input slot #0 works with an Ntuple
43   DefineInput(0, TChain::Class());
44   // Output slot #0 writes into a TH1 container
45   DefineOutput(0, TObjArray::Class());
46 }
47
48 //________________________________________________________________________
49 void AliAnalysisTaskPt::Init(Option_t *) 
50 {
51   // Initialisation of branch container and histograms 
52   
53   AliInfo(Form("*** Initialization of %s", GetName())) ; 
54   
55   // Get input data
56   fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
57   if (!fChain) {
58     AliError(Form("Input 0 for %s not found\n", GetName()));
59     return ;
60   }
61   
62   if (!fESD) {
63     // One should first check if the branch address was taken by some other task
64     char ** address = (char **)GetBranchAddress(0, "ESD") ;
65     if (address) 
66       fESD = (AliESD *)(*address) ; 
67     if (!fESD) 
68       fChain->SetBranchAddress("ESD", &fESD) ;  
69   }
70   // The output objects will be written to 
71   TDirectory * cdir = gDirectory ; 
72   // Open a file for output #0
73   char outputName[1024] ; 
74   sprintf(outputName, "%s.root", GetName() ) ; 
75   OpenFile(0, outputName , "RECREATE") ; 
76   if (cdir) 
77     cdir->cd() ; 
78   
79   // create histograms 
80
81   fhPt = new TH1F("fhPt","This is the Pt distribution",15,0.1,3.1);
82   fhPt->SetStats(kTRUE);
83   fhPt->GetXaxis()->SetTitle("P_{T} [GeV]");
84   fhPt->GetYaxis()->SetTitle("#frac{dN}{dP_{T}}");
85   fhPt->GetXaxis()->SetTitleColor(1);
86   fhPt->SetMarkerStyle(kFullCircle);
87  
88   // create output container
89   
90   fOutputContainer = new TObjArray(1) ; 
91   fOutputContainer->SetName(GetName()) ;
92   
93   fOutputContainer->AddAt(fhPt, 0) ;
94 }
95
96 //________________________________________________________________________
97 void AliAnalysisTaskPt::Exec(Option_t *) 
98 {
99   // Processing of one event
100     
101   Long64_t entry = fChain->GetReadEntry() ;
102   
103   if (!fESD) {
104     AliError("fESD is not connected to the input!") ; 
105     return ; 
106   }
107   
108   if ( !((entry-1)%100) ) 
109     AliInfo(Form("%s ----> Processing event # %lld",  (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ; 
110   
111   //************************  Pt tracks  *************************************
112  
113   for(Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
114     AliESDtrack * ESDTrack = fESD->GetTrack(iTracks);
115     Double_t momentum[3];
116     ESDTrack->GetPxPyPz(momentum);
117     Double_t Pt = sqrt(pow(momentum[0],2) + pow(momentum[1],2));
118     fhPt->Fill(Pt);
119   }//track loop 
120
121   PostData(0, fOutputContainer);
122 }      
123
124 //________________________________________________________________________
125 void AliAnalysisTaskPt::Terminate(Option_t *) 
126 {
127   // Processing when the event loop is ended
128   
129   TCanvas *c1 = new TCanvas("c1","Pt",10,10,310,310);
130   c1->SetFillColor(10);
131   c1->SetHighLightColor(10);
132   
133   c1->cd(1)->SetLeftMargin(0.15);
134   c1->cd(1)->SetBottomMargin(0.15);  
135   c1->cd(1)->SetLogy();
136   fhPt->DrawCopy("E");
137
138   c1->Print("TracksPt.eps");
139
140   char line[1024] ; 
141   sprintf(line, ".!tar -zcvf %s.tar.gz *.eps", GetName()) ; 
142   gROOT->ProcessLine(line);
143   sprintf(line, ".!rm -fR *.eps"); 
144   gROOT->ProcessLine(line);
145
146   AliInfo(Form("!!! All the eps files are in %s.tar.gz !!! \n", GetName())) ;
147 }