]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/AlidNdEtaCorrectionSelector.cxx
coding conventions (Alberto)
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaCorrectionSelector.cxx
CommitLineData
dc740de4 1/* $Id$ */
2
79ab56b9 3#include "AlidNdEtaCorrectionSelector.h"
539b6cb4 4
5#include <TStyle.h>
6#include <TSystem.h>
7#include <TCanvas.h>
8#include <TParticle.h>
9#include <TParticlePDG.h>
10
745e836a 11#include <TChain.h>
12#include <TSelector.h>
13
539b6cb4 14#include <AliLog.h>
79ab56b9 15#include <AliGenEventHeader.h>
539b6cb4 16#include <AliTracker.h>
745e836a 17#include <AliHeader.h>
fcf2fb36 18#include <AliESDVertex.h>
19#include <AliESD.h>
20#include <AliESDtrack.h>
539b6cb4 21
37dbb69e 22#include "esdTrackCuts/AliESDtrackCuts.h"
79ab56b9 23#include "dNdEtaCorrection.h"
539b6cb4 24
79ab56b9 25ClassImp(AlidNdEtaCorrectionSelector)
539b6cb4 26
fcf2fb36 27AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector() :
539b6cb4 28 AliSelector(),
29 fEsdTrackCuts(0),
75e130df 30 fdNdEtaCorrection(0),
31 fdNdEtaCorrectionFinal(0)
539b6cb4 32{
79ab56b9 33 //
539b6cb4 34 // Constructor. Initialization of pointers
79ab56b9 35 //
539b6cb4 36}
37
79ab56b9 38AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector()
539b6cb4 39{
79ab56b9 40 //
41 // Destructor
42 //
539b6cb4 43
44 // histograms are in the output list and deleted when the output
45 // list is deleted by the TSelector dtor
46}
47
79ab56b9 48void AlidNdEtaCorrectionSelector::Begin(TTree * tree)
539b6cb4 49{
50 // The Begin() function is called at the start of the query.
51 // When running with PROOF Begin() is only called on the client.
52 // The tree argument is deprecated (on PROOF 0 is passed).
53
54 AliSelector::Begin(tree);
539b6cb4 55}
56
79ab56b9 57void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree)
539b6cb4 58{
59 // The SlaveBegin() function is called after the Begin() function.
60 // When running with PROOF SlaveBegin() is called on each slave server.
61 // The tree argument is deprecated (on PROOF 0 is passed).
62
63 AliSelector::SlaveBegin(tree);
64
79ab56b9 65 fdNdEtaCorrection = new dNdEtaCorrection();
539b6cb4 66
79ab56b9 67 if (fChain)
68 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fChain->GetUserInfo()->FindObject("AliESDtrackCuts"));
539b6cb4 69
79ab56b9 70 if (!fEsdTrackCuts)
b8e8168f 71 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info");
539b6cb4 72}
73
79ab56b9 74Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry)
539b6cb4 75{
76 // The Process() function is called for each entry in the tree (or possibly
77 // keyed object in the case of PROOF) to be processed. The entry argument
78 // specifies which entry in the currently loaded tree is to be processed.
79 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
80 // to read either all or the required parts of the data. When processing
81 // keyed objects with PROOF, the object is already loaded and is available
82 // via the fObject pointer.
83 //
84 // This function should contain the "body" of the analysis. It can contain
85 // simple or elaborate selection criteria, run algorithms on the data
86 // of the event and typically fill histograms.
87
88 // WARNING when a selector is used with a TChain, you must use
89 // the pointer to the current TTree to call GetEntry(entry).
90 // The entry is always the local entry number in the current tree.
91 // Assuming that fChain is the pointer to the TChain being processed,
92 // use fChain->GetTree()->GetEntry(entry).
93
94 if (AliSelector::Process(entry) == kFALSE)
95 return kFALSE;
96
b8e8168f 97 // check prerequesites
98 if (!fESD)
99 {
100 AliDebug(AliLog::kError, "ESD branch not available");
101 return kFALSE;
102 }
103
dc740de4 104 AliHeader* header = GetHeader();
105 if (!header)
b8e8168f 106 {
dc740de4 107 AliDebug(AliLog::kError, "Header not available");
b8e8168f 108 return kFALSE;
109 }
110
111 if (!fEsdTrackCuts)
112 {
113 AliDebug(AliLog::kError, "fESDTrackCuts not available");
539b6cb4 114 return kFALSE;
b8e8168f 115 }
539b6cb4 116
117 // ########################################################
118 // get the EDS vertex
119 const AliESDVertex* vtxESD = fESD->GetVertex();
120
745e836a 121 Bool_t goodEvent = kTRUE;
122
79ab56b9 123 // the vertex should be reconstructed
745e836a 124 if (strcmp(vtxESD->GetName(),"default")==0)
125 goodEvent = kFALSE;
539b6cb4 126
79ab56b9 127 Double_t vtx_res[3];
539b6cb4 128 vtx_res[0] = vtxESD->GetXRes();
129 vtx_res[1] = vtxESD->GetYRes();
130 vtx_res[2] = vtxESD->GetZRes();
745e836a 131
539b6cb4 132 // the resolution should be reasonable???
133 if (vtx_res[2]==0 || vtx_res[2]>0.1)
745e836a 134 goodEvent = kFALSE;
135
539b6cb4 136
137 // ########################################################
138 // get the MC vertex
dc740de4 139 AliGenEventHeader* genHeader = header->GenEventHeader();
539b6cb4 140
141 TArrayF vtxMC(3);
142 genHeader->PrimaryVertex(vtxMC);
539b6cb4 143
e8cb44f1 144 fdNdEtaCorrection->FillEvent(vtxMC[2]);
145
146 if (goodEvent)
147 fdNdEtaCorrection->FillUsedEvent(vtxMC[2]);
148
149
150
539b6cb4 151 // ########################################################
152 // loop over mc particles
153 TTree* particleTree = GetKinematics();
154 TParticle* particle = 0;
155 particleTree->SetBranchAddress("Particles", &particle);
156
dc740de4 157 Int_t nPrim = header->GetNprimary();
158 Int_t nTotal = header->GetNtrack();
539b6cb4 159
160 for (Int_t i_mc = nTotal - nPrim; i_mc < nTotal; ++i_mc)
161 {
162 particleTree->GetEntry(i_mc);
163
164 if (!particle)
165 continue;
166
4dd2ad81 167 if (IsPrimaryCharged(particle, nPrim) == kFALSE)
539b6cb4 168 continue;
169
745e836a 170 Float_t eta = particle->Eta();
171
172 fdNdEtaCorrection->FillParticleAllEvents(vtxMC[2], eta);
173
174 if (goodEvent)
e8cb44f1 175 fdNdEtaCorrection->FillParticleWhenUsedEvent(vtxMC[2], eta);
745e836a 176
539b6cb4 177 }// end of mc particle
178
e8cb44f1 179 if (!goodEvent)
180 return kTRUE;
181
539b6cb4 182 // ########################################################
183 // loop over esd tracks
184 Int_t nTracks = fESD->GetNumberOfTracks();
185 for (Int_t t=0; t<nTracks; t++)
186 {
187 AliESDtrack* esdTrack = fESD->GetTrack(t);
188
189 // cut the esd track?
190 if (!fEsdTrackCuts->AcceptTrack(esdTrack))
191 continue;
192
539b6cb4 193 // using the eta of the mc particle
194 Int_t label = TMath::Abs(esdTrack->GetLabel());
79ab56b9 195 if (label == 0)
539b6cb4 196 {
b8e8168f 197 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
539b6cb4 198 continue;
199 }
200 particleTree->GetEntry(nTotal - nPrim + label);
201
745e836a 202 fdNdEtaCorrection->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta());
539b6cb4 203
204 } // end of track loop
205
206 return kTRUE;
207}
208
79ab56b9 209void AlidNdEtaCorrectionSelector::SlaveTerminate()
539b6cb4 210{
211 // The SlaveTerminate() function is called after all entries or objects
212 // have been processed. When running with PROOF SlaveTerminate() is called
213 // on each slave server.
214
215 AliSelector::SlaveTerminate();
216
217 // Add the histograms to the output on each slave server
218 if (!fOutput)
219 {
b8e8168f 220 AliDebug(AliLog::kError, "ERROR: Output list not initialized");
539b6cb4 221 return;
222 }
79ab56b9 223
745e836a 224 fOutput->Add(fdNdEtaCorrection);
539b6cb4 225}
226
79ab56b9 227void AlidNdEtaCorrectionSelector::Terminate()
539b6cb4 228{
229 // The Terminate() function is the last function to be called during
230 // a query. It always runs on the client, it can be used to present
231 // the results graphically or save the results to file.
232
233 AliSelector::Terminate();
234
745e836a 235 fdNdEtaCorrectionFinal = dynamic_cast<dNdEtaCorrection*> (fOutput->FindObject("dndeta_correction"));
79ab56b9 236
237 fdNdEtaCorrectionFinal->Finish();
539b6cb4 238
239 TFile* fout = new TFile("correction_map.root","RECREATE");
240
241 fEsdTrackCuts->SaveHistograms("esd_track_cuts");
79ab56b9 242 fdNdEtaCorrectionFinal->SaveHistograms();
539b6cb4 243
244 fout->Write();
245 fout->Close();
246
79ab56b9 247 fdNdEtaCorrectionFinal->DrawHistograms();
539b6cb4 248}