]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ESDCheck/AliAnalysisTaskPt.cxx
Memory leak corrected (Ch. Klein-Boesing)
[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 **************************************************************************/
0b28fd57 15
16/* $Id$ */
17
1dfe075f 18//_________________________________________________________________________
19// A test analysis task to check the pt of tracks distribution in simulated data
20//
21//*-- Panos
22//////////////////////////////////////////////////////////////////////////////
23
0b28fd57 24#include <TCanvas.h>
1dfe075f 25#include <TChain.h>
1dfe075f 26#include <TFile.h>
0b28fd57 27#include <TH1.h>
28#include <TROOT.h>
1dfe075f 29#include <TSystem.h>
1f588058 30#include <TString.h>
1dfe075f 31
32#include "AliAnalysisTaskPt.h"
33#include "AliESD.h"
34#include "AliLog.h"
35
36//________________________________________________________________________
37AliAnalysisTaskPt::AliAnalysisTaskPt(const char *name) :
38 AliAnalysisTask(name,""),
39 fESD(0),
40 fhPt(0)
41{
42 // Constructor.
43 // Input slot #0 works with an Ntuple
44 DefineInput(0, TChain::Class());
45 // Output slot #0 writes into a TH1 container
46 DefineOutput(0, TObjArray::Class());
47}
48
49//________________________________________________________________________
c52c2132 50void AliAnalysisTaskPt::ConnectInputData(Option_t *)
1dfe075f 51{
52 // Initialisation of branch container and histograms
53
54 AliInfo(Form("*** Initialization of %s", GetName())) ;
55
56 // Get input data
57 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
58 if (!fChain) {
59 AliError(Form("Input 0 for %s not found\n", GetName()));
60 return ;
61 }
62
c52c2132 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 } else {
68 fESD = new AliESD();
69 SetBranchAddress(0, "ESD", &fESD);
1dfe075f 70 }
c52c2132 71}
1dfe075f 72
c52c2132 73//________________________________________________________________________
74void AliAnalysisTaskPt::CreateOutputObjects()
75{
76 // create histograms
1e20f195 77
78 OpenFile(0) ;
79
1dfe075f 80 fhPt = new TH1F("fhPt","This is the Pt distribution",15,0.1,3.1);
81 fhPt->SetStats(kTRUE);
82 fhPt->GetXaxis()->SetTitle("P_{T} [GeV]");
83 fhPt->GetYaxis()->SetTitle("#frac{dN}{dP_{T}}");
84 fhPt->GetXaxis()->SetTitleColor(1);
85 fhPt->SetMarkerStyle(kFullCircle);
86
87 // create output container
88
89 fOutputContainer = new TObjArray(1) ;
90 fOutputContainer->SetName(GetName()) ;
91
92 fOutputContainer->AddAt(fhPt, 0) ;
93}
94
95//________________________________________________________________________
96void AliAnalysisTaskPt::Exec(Option_t *)
97{
98 // Processing of one event
99
100 Long64_t entry = fChain->GetReadEntry() ;
101
102 if (!fESD) {
103 AliError("fESD is not connected to the input!") ;
104 return ;
105 }
106
107 if ( !((entry-1)%100) )
108 AliInfo(Form("%s ----> Processing event # %lld", (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ;
109
110 //************************ Pt tracks *************************************
111
112 for(Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
113 AliESDtrack * ESDTrack = fESD->GetTrack(iTracks);
114 Double_t momentum[3];
115 ESDTrack->GetPxPyPz(momentum);
116 Double_t Pt = sqrt(pow(momentum[0],2) + pow(momentum[1],2));
117 fhPt->Fill(Pt);
118 }//track loop
119
120 PostData(0, fOutputContainer);
121}
122
123//________________________________________________________________________
124void AliAnalysisTaskPt::Terminate(Option_t *)
125{
126 // Processing when the event loop is ended
84eb42a1 127
2704006a 128 Bool_t problem=kFALSE;
129
84eb42a1 130 AliInfo(Form(" *** %s Report:", GetName())) ;
131
1dfe075f 132 TCanvas *c1 = new TCanvas("c1","Pt",10,10,310,310);
133 c1->SetFillColor(10);
134 c1->SetHighLightColor(10);
135
136 c1->cd(1)->SetLeftMargin(0.15);
137 c1->cd(1)->SetBottomMargin(0.15);
84eb42a1 138 if (fhPt->GetMaximum() > 0 )
139 c1->cd(1)->SetLogy();
c52c2132 140 fOutputContainer = (TObjArray*)GetOutputData(0);
141 fhPt = (TH1F*)fOutputContainer->At(0);
142 if (fhPt) fhPt->DrawCopy("E");
1dfe075f 143
144 c1->Print("TracksPt.eps");
145
146 char line[1024] ;
84eb42a1 147 sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ;
1dfe075f 148 gROOT->ProcessLine(line);
149 sprintf(line, ".!rm -fR *.eps");
150 gROOT->ProcessLine(line);
151
2704006a 152 AliInfo(Form("!!! All the eps files are in %s.tar.gz !!!", GetName())) ;
153
1f588058 154 TString report ;
2704006a 155 if(problem)
156 report="Problems found, please check!!!";
157 else
158 report="OK";
159
1f588058 160 AliInfo(Form("*** %s Summary Report: %s \n",GetName(), report.Data())) ;
1dfe075f 161}