]>
Commit | Line | Data |
---|---|---|
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> | |
45e97e28 | 13 | #include <TFile.h> |
745e836a | 14 | |
539b6cb4 | 15 | #include <AliLog.h> |
79ab56b9 | 16 | #include <AliGenEventHeader.h> |
539b6cb4 | 17 | #include <AliTracker.h> |
745e836a | 18 | #include <AliHeader.h> |
fcf2fb36 | 19 | #include <AliESDVertex.h> |
20 | #include <AliESD.h> | |
21 | #include <AliESDtrack.h> | |
45e97e28 | 22 | #include <AliRunLoader.h> |
23 | #include <AliStack.h> | |
539b6cb4 | 24 | |
37dbb69e | 25 | #include "esdTrackCuts/AliESDtrackCuts.h" |
45e97e28 | 26 | #include "dNdEta/AlidNdEtaCorrection.h" |
27 | #include "AliPWG0Helper.h" | |
539b6cb4 | 28 | |
79ab56b9 | 29 | ClassImp(AlidNdEtaCorrectionSelector) |
539b6cb4 | 30 | |
fcf2fb36 | 31 | AlidNdEtaCorrectionSelector::AlidNdEtaCorrectionSelector() : |
16e24ca3 | 32 | AliSelectorRL(), |
539b6cb4 | 33 | fEsdTrackCuts(0), |
45e97e28 | 34 | fdNdEtaCorrection(0) |
539b6cb4 | 35 | { |
79ab56b9 | 36 | // |
539b6cb4 | 37 | // Constructor. Initialization of pointers |
79ab56b9 | 38 | // |
539b6cb4 | 39 | } |
40 | ||
79ab56b9 | 41 | AlidNdEtaCorrectionSelector::~AlidNdEtaCorrectionSelector() |
539b6cb4 | 42 | { |
79ab56b9 | 43 | // |
44 | // Destructor | |
45 | // | |
539b6cb4 | 46 | |
47 | // histograms are in the output list and deleted when the output | |
48 | // list is deleted by the TSelector dtor | |
49 | } | |
50 | ||
79ab56b9 | 51 | void AlidNdEtaCorrectionSelector::Begin(TTree * tree) |
539b6cb4 | 52 | { |
53 | // The Begin() function is called at the start of the query. | |
54 | // When running with PROOF Begin() is only called on the client. | |
55 | // The tree argument is deprecated (on PROOF 0 is passed). | |
56 | ||
16e24ca3 | 57 | AliSelectorRL::Begin(tree); |
539b6cb4 | 58 | } |
59 | ||
79ab56b9 | 60 | void AlidNdEtaCorrectionSelector::SlaveBegin(TTree * tree) |
539b6cb4 | 61 | { |
62 | // The SlaveBegin() function is called after the Begin() function. | |
63 | // When running with PROOF SlaveBegin() is called on each slave server. | |
64 | // The tree argument is deprecated (on PROOF 0 is passed). | |
65 | ||
16e24ca3 | 66 | AliSelectorRL::SlaveBegin(tree); |
539b6cb4 | 67 | |
45e97e28 | 68 | fdNdEtaCorrection = new AlidNdEtaCorrection(); |
539b6cb4 | 69 | |
16e24ca3 | 70 | if (fTree) |
71 | fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fTree->GetUserInfo()->FindObject("AliESDtrackCuts")); | |
539b6cb4 | 72 | |
79ab56b9 | 73 | if (!fEsdTrackCuts) |
b8e8168f | 74 | AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from user info"); |
539b6cb4 | 75 | } |
76 | ||
79ab56b9 | 77 | Bool_t AlidNdEtaCorrectionSelector::Process(Long64_t entry) |
539b6cb4 | 78 | { |
79 | // The Process() function is called for each entry in the tree (or possibly | |
80 | // keyed object in the case of PROOF) to be processed. The entry argument | |
81 | // specifies which entry in the currently loaded tree is to be processed. | |
82 | // It can be passed to either TTree::GetEntry() or TBranch::GetEntry() | |
83 | // to read either all or the required parts of the data. When processing | |
84 | // keyed objects with PROOF, the object is already loaded and is available | |
85 | // via the fObject pointer. | |
86 | // | |
87 | // This function should contain the "body" of the analysis. It can contain | |
88 | // simple or elaborate selection criteria, run algorithms on the data | |
89 | // of the event and typically fill histograms. | |
90 | ||
91 | // WARNING when a selector is used with a TChain, you must use | |
92 | // the pointer to the current TTree to call GetEntry(entry). | |
93 | // The entry is always the local entry number in the current tree. | |
16e24ca3 | 94 | // Assuming that fTree is the pointer to the TChain being processed, |
95 | // use fTree->GetTree()->GetEntry(entry). | |
539b6cb4 | 96 | |
16e24ca3 | 97 | if (AliSelectorRL::Process(entry) == kFALSE) |
539b6cb4 | 98 | return kFALSE; |
99 | ||
b8e8168f | 100 | // check prerequesites |
101 | if (!fESD) | |
102 | { | |
103 | AliDebug(AliLog::kError, "ESD branch not available"); | |
104 | return kFALSE; | |
105 | } | |
106 | ||
dc740de4 | 107 | AliHeader* header = GetHeader(); |
108 | if (!header) | |
b8e8168f | 109 | { |
dc740de4 | 110 | AliDebug(AliLog::kError, "Header not available"); |
b8e8168f | 111 | return kFALSE; |
112 | } | |
113 | ||
45e97e28 | 114 | AliRunLoader* runLoader = GetRunLoader(); |
115 | if (!runLoader) | |
116 | { | |
117 | AliDebug(AliLog::kError, "RunLoader not available"); | |
118 | return kFALSE; | |
119 | } | |
120 | ||
121 | runLoader->LoadKinematics(); | |
122 | AliStack* stack = runLoader->Stack(); | |
123 | if (!stack) | |
124 | { | |
125 | AliDebug(AliLog::kError, "Stack not available"); | |
126 | return kFALSE; | |
127 | } | |
128 | ||
b8e8168f | 129 | if (!fEsdTrackCuts) |
130 | { | |
131 | AliDebug(AliLog::kError, "fESDTrackCuts not available"); | |
539b6cb4 | 132 | return kFALSE; |
b8e8168f | 133 | } |
539b6cb4 | 134 | |
45e97e28 | 135 | Bool_t vertexReconstructed = AliPWG0Helper::IsVertexReconstructed(fESD); |
745e836a | 136 | |
45e97e28 | 137 | Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD); |
539b6cb4 | 138 | |
45e97e28 | 139 | fdNdEtaCorrection->IncreaseEventCount(); |
140 | if (eventTriggered) | |
141 | fdNdEtaCorrection->IncreaseTriggeredEventCount(); | |
539b6cb4 | 142 | |
539b6cb4 | 143 | // get the MC vertex |
dc740de4 | 144 | AliGenEventHeader* genHeader = header->GenEventHeader(); |
539b6cb4 | 145 | |
146 | TArrayF vtxMC(3); | |
147 | genHeader->PrimaryVertex(vtxMC); | |
539b6cb4 | 148 | |
539b6cb4 | 149 | // loop over mc particles |
45e97e28 | 150 | Int_t nPrim = stack->GetNprimary(); |
539b6cb4 | 151 | |
45e97e28 | 152 | for (Int_t iMc = 0; iMc < nPrim; ++iMc) |
539b6cb4 | 153 | { |
45e97e28 | 154 | AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc)); |
155 | ||
156 | TParticle* particle = stack->Particle(iMc); | |
539b6cb4 | 157 | |
158 | if (!particle) | |
45e97e28 | 159 | { |
160 | AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc)); | |
539b6cb4 | 161 | continue; |
45e97e28 | 162 | } |
539b6cb4 | 163 | |
45e97e28 | 164 | if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE) |
539b6cb4 | 165 | continue; |
166 | ||
745e836a | 167 | Float_t eta = particle->Eta(); |
45e97e28 | 168 | Float_t pt = particle->Pt(); |
169 | ||
170 | if (vertexReconstructed) | |
171 | fdNdEtaCorrection->FillParticle(vtxMC[2], eta, pt); | |
539b6cb4 | 172 | |
45e97e28 | 173 | fdNdEtaCorrection->FillParticleAllEvents(eta, pt); |
174 | if (eventTriggered) | |
175 | fdNdEtaCorrection->FillParticleWhenEventTriggered(eta, pt); | |
176 | }// end of mc particle | |
e8cb44f1 | 177 | |
539b6cb4 | 178 | // ######################################################## |
179 | // loop over esd tracks | |
180 | Int_t nTracks = fESD->GetNumberOfTracks(); | |
45e97e28 | 181 | |
182 | // count the number of "good" tracks for vertex reconstruction efficiency | |
183 | // TODO change to number of ITS clusters or similar | |
184 | Int_t nGoodTracks = 0; | |
539b6cb4 | 185 | for (Int_t t=0; t<nTracks; t++) |
186 | { | |
45e97e28 | 187 | AliDebug(AliLog::kDebug+1, Form("ESD Loop: Processing track %d.", t)); |
188 | ||
539b6cb4 | 189 | AliESDtrack* esdTrack = fESD->GetTrack(t); |
190 | ||
191 | // cut the esd track? | |
192 | if (!fEsdTrackCuts->AcceptTrack(esdTrack)) | |
193 | continue; | |
194 | ||
45e97e28 | 195 | nGoodTracks++; |
196 | ||
197 | // using the properties of the mc particle | |
539b6cb4 | 198 | Int_t label = TMath::Abs(esdTrack->GetLabel()); |
79ab56b9 | 199 | if (label == 0) |
539b6cb4 | 200 | { |
b8e8168f | 201 | AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t)); |
539b6cb4 | 202 | continue; |
203 | } | |
539b6cb4 | 204 | |
45e97e28 | 205 | TParticle* particle = stack->Particle(label); |
206 | if (!particle) | |
207 | { | |
208 | AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (track loop).", label)); | |
209 | continue; | |
210 | } | |
539b6cb4 | 211 | |
45e97e28 | 212 | if (vertexReconstructed) |
213 | fdNdEtaCorrection->FillParticleWhenMeasuredTrack(vtxMC[2], particle->Eta(), particle->Pt()); | |
539b6cb4 | 214 | } // end of track loop |
215 | ||
847489f7 | 216 | |
217 | if (eventTriggered) | |
218 | { | |
219 | fdNdEtaCorrection->FillEvent(vtxMC[2], nGoodTracks); | |
220 | if (vertexReconstructed) | |
221 | fdNdEtaCorrection->FillEventWithReconstructedVertex(vtxMC[2], nGoodTracks); | |
222 | } | |
45e97e28 | 223 | |
539b6cb4 | 224 | return kTRUE; |
225 | } | |
226 | ||
79ab56b9 | 227 | void AlidNdEtaCorrectionSelector::SlaveTerminate() |
539b6cb4 | 228 | { |
229 | // The SlaveTerminate() function is called after all entries or objects | |
230 | // have been processed. When running with PROOF SlaveTerminate() is called | |
231 | // on each slave server. | |
232 | ||
16e24ca3 | 233 | AliSelectorRL::SlaveTerminate(); |
539b6cb4 | 234 | |
235 | // Add the histograms to the output on each slave server | |
236 | if (!fOutput) | |
237 | { | |
b8e8168f | 238 | AliDebug(AliLog::kError, "ERROR: Output list not initialized"); |
539b6cb4 | 239 | return; |
240 | } | |
79ab56b9 | 241 | |
745e836a | 242 | fOutput->Add(fdNdEtaCorrection); |
539b6cb4 | 243 | } |
244 | ||
79ab56b9 | 245 | void AlidNdEtaCorrectionSelector::Terminate() |
539b6cb4 | 246 | { |
247 | // The Terminate() function is the last function to be called during | |
248 | // a query. It always runs on the client, it can be used to present | |
249 | // the results graphically or save the results to file. | |
250 | ||
16e24ca3 | 251 | AliSelectorRL::Terminate(); |
539b6cb4 | 252 | |
45e97e28 | 253 | fdNdEtaCorrection = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction")); |
79ab56b9 | 254 | |
45e97e28 | 255 | fdNdEtaCorrection->Finish(); |
539b6cb4 | 256 | |
257 | TFile* fout = new TFile("correction_map.root","RECREATE"); | |
258 | ||
259 | fEsdTrackCuts->SaveHistograms("esd_track_cuts"); | |
45e97e28 | 260 | fdNdEtaCorrection->SaveHistograms(); |
539b6cb4 | 261 | |
262 | fout->Write(); | |
263 | fout->Close(); | |
264 | ||
45e97e28 | 265 | fdNdEtaCorrection->DrawHistograms(); |
539b6cb4 | 266 | } |