]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ESDCheck/AliAnalysisTaskPt.cxx
Adding OpenFile in CreateOutput (Yves)
[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>
30
31#include "AliAnalysisTaskPt.h"
32#include "AliESD.h"
33#include "AliLog.h"
34
35//________________________________________________________________________
36AliAnalysisTaskPt::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//________________________________________________________________________
c52c2132 49void AliAnalysisTaskPt::ConnectInputData(Option_t *)
1dfe075f 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
c52c2132 62 // One should first check if the branch address was taken by some other task
63 char ** address = (char **)GetBranchAddress(0, "ESD");
64 if (address) {
65 fESD = (AliESD*)(*address);
66 } else {
67 fESD = new AliESD();
68 SetBranchAddress(0, "ESD", &fESD);
1dfe075f 69 }
c52c2132 70}
1dfe075f 71
c52c2132 72//________________________________________________________________________
73void AliAnalysisTaskPt::CreateOutputObjects()
74{
75 // create histograms
1e20f195 76
77 OpenFile(0) ;
78
1dfe075f 79 fhPt = new TH1F("fhPt","This is the Pt distribution",15,0.1,3.1);
80 fhPt->SetStats(kTRUE);
81 fhPt->GetXaxis()->SetTitle("P_{T} [GeV]");
82 fhPt->GetYaxis()->SetTitle("#frac{dN}{dP_{T}}");
83 fhPt->GetXaxis()->SetTitleColor(1);
84 fhPt->SetMarkerStyle(kFullCircle);
85
86 // create output container
87
88 fOutputContainer = new TObjArray(1) ;
89 fOutputContainer->SetName(GetName()) ;
90
91 fOutputContainer->AddAt(fhPt, 0) ;
92}
93
94//________________________________________________________________________
95void AliAnalysisTaskPt::Exec(Option_t *)
96{
97 // Processing of one event
98
99 Long64_t entry = fChain->GetReadEntry() ;
100
101 if (!fESD) {
102 AliError("fESD is not connected to the input!") ;
103 return ;
104 }
105
106 if ( !((entry-1)%100) )
107 AliInfo(Form("%s ----> Processing event # %lld", (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ;
108
109 //************************ Pt tracks *************************************
110
111 for(Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
112 AliESDtrack * ESDTrack = fESD->GetTrack(iTracks);
113 Double_t momentum[3];
114 ESDTrack->GetPxPyPz(momentum);
115 Double_t Pt = sqrt(pow(momentum[0],2) + pow(momentum[1],2));
116 fhPt->Fill(Pt);
117 }//track loop
118
119 PostData(0, fOutputContainer);
120}
121
122//________________________________________________________________________
123void AliAnalysisTaskPt::Terminate(Option_t *)
124{
125 // Processing when the event loop is ended
84eb42a1 126
2704006a 127 Bool_t problem=kFALSE;
128
84eb42a1 129 AliInfo(Form(" *** %s Report:", GetName())) ;
130
1dfe075f 131 TCanvas *c1 = new TCanvas("c1","Pt",10,10,310,310);
132 c1->SetFillColor(10);
133 c1->SetHighLightColor(10);
134
135 c1->cd(1)->SetLeftMargin(0.15);
136 c1->cd(1)->SetBottomMargin(0.15);
84eb42a1 137 if (fhPt->GetMaximum() > 0 )
138 c1->cd(1)->SetLogy();
c52c2132 139 fOutputContainer = (TObjArray*)GetOutputData(0);
140 fhPt = (TH1F*)fOutputContainer->At(0);
141 if (fhPt) fhPt->DrawCopy("E");
1dfe075f 142
143 c1->Print("TracksPt.eps");
144
145 char line[1024] ;
84eb42a1 146 sprintf(line, ".!tar -zcf %s.tar.gz *.eps", GetName()) ;
1dfe075f 147 gROOT->ProcessLine(line);
148 sprintf(line, ".!rm -fR *.eps");
149 gROOT->ProcessLine(line);
150
2704006a 151 AliInfo(Form("!!! All the eps files are in %s.tar.gz !!!", GetName())) ;
152
153 char * report ;
154 if(problem)
155 report="Problems found, please check!!!";
156 else
157 report="OK";
158
159 AliInfo(Form("*** %s Summary Report: %s \n",GetName(), report)) ;
1dfe075f 160}