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