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