]>
Commit | Line | Data |
---|---|---|
6214ec0c | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2008, 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 | **************************************************************************/ | |
15 | ||
16 | // ----------------------------------------------------------------------- | |
17 | // In this analysis task we compare multiple AOD filtermasks. | |
18 | // ----------------------------------------------------------------------- | |
19 | // Author: Misha Veldhoen (misha.veldhoen@cern.ch) | |
20 | ||
21 | #include <iostream> | |
22 | ||
23 | // Basic Includes | |
24 | #include "TH1F.h" | |
25 | #include "TH2F.h" | |
26 | #include "TH3F.h" | |
27 | #include "TFile.h" | |
28 | #include "TFormula.h" | |
29 | #include "TChain.h" | |
30 | #include "TObject.h" | |
31 | #include "TRandom3.h" | |
32 | ||
33 | // Analysis Includes | |
34 | #include "AliAnalysisManager.h" | |
35 | #include "AliAnalysisTaskSE.h" | |
36 | #include "AliInputEventHandler.h" | |
37 | ||
38 | // PID includes. | |
39 | #include "AliPIDResponse.h" | |
40 | ||
41 | // AOD includes. | |
42 | #include "AliAODEvent.h" | |
43 | #include "AliAODTrack.h" | |
44 | #include "AliAODHandler.h" | |
45 | #include "AliAODVertex.h" | |
46 | #include "AliAODInputHandler.h" | |
47 | #include "AliAODMCParticle.h" | |
48 | #include "AliAODMCHeader.h" | |
49 | ||
50 | // Includes from own library | |
51 | #include "AliTrackDiHadronPID.h" | |
52 | #include "AliAODTrackCutsDiHadronPID.h" | |
53 | #include "AliAODEventCutsDiHadronPID.h" | |
54 | ||
55 | // AnalysisTask Header | |
56 | #include "AliAnalysisTaskCompareAODTrackCuts.h" | |
57 | ||
58 | using namespace std; | |
59 | ||
60 | ClassImp(AliAnalysisTaskCompareAODTrackCuts); | |
61 | ||
62 | // ----------------------------------------------------------------------- | |
63 | AliAnalysisTaskCompareAODTrackCuts::AliAnalysisTaskCompareAODTrackCuts(): | |
64 | AliAnalysisTaskSE(), | |
65 | fPIDResponse(0x0), | |
66 | fOutputList(0x0), | |
67 | fIsMC(kFALSE), | |
68 | fVerbose(kFALSE), | |
69 | fCalculateTOFMismatch(kFALSE), | |
28161374 | 70 | fUseMismatchFileFromHomeDir(kTRUE), |
71 | fUseNSigmaOnPIDAxes(kFALSE), | |
6214ec0c | 72 | fEventCuts(0x0), |
73 | fTrackCuts(0x0), | |
74 | fInclusiveTimes(0x0), | |
6214ec0c | 75 | fT0Fill(0x0), |
76 | fLvsEta(0x0), | |
a5422983 | 77 | fGlobalPtvsTPCPt(0x0), |
69868b6b | 78 | fLvsEtaProjections(0x0), |
6214ec0c | 79 | fCurrentAODEvent(0x0), |
80 | fCurrentAODTrack(0x0), | |
81 | fCurrentDiHadronPIDTrack(0x0), | |
82 | fGlobalTracksArray(0x0) | |
83 | ||
84 | { | |
85 | ||
86 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
87 | ||
6214ec0c | 88 | } |
89 | ||
90 | // ----------------------------------------------------------------------- | |
91 | AliAnalysisTaskCompareAODTrackCuts::AliAnalysisTaskCompareAODTrackCuts(const char* name): | |
92 | AliAnalysisTaskSE(name), | |
93 | fPIDResponse(0x0), | |
94 | fOutputList(0x0), | |
95 | fIsMC(kFALSE), | |
96 | fVerbose(kFALSE), | |
97 | fCalculateTOFMismatch(kFALSE), | |
a5422983 | 98 | fUseMismatchFileFromHomeDir(kTRUE), |
28161374 | 99 | fUseNSigmaOnPIDAxes(kFALSE), |
6214ec0c | 100 | fEventCuts(0x0), |
101 | fTrackCuts(0x0), | |
102 | fInclusiveTimes(0x0), | |
6214ec0c | 103 | fT0Fill(0x0), |
104 | fLvsEta(0x0), | |
a5422983 | 105 | fGlobalPtvsTPCPt(0x0), |
69868b6b | 106 | fLvsEtaProjections(0x0), |
6214ec0c | 107 | fCurrentAODEvent(0x0), |
108 | fCurrentAODTrack(0x0), | |
109 | fCurrentDiHadronPIDTrack(0x0), | |
110 | fGlobalTracksArray(0x0) | |
111 | ||
112 | { | |
113 | ||
114 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
115 | ||
116 | // Named Constructor. | |
117 | fTrackCuts = new TObjArray(); | |
118 | fTrackCuts->SetName("fTrackCuts"); | |
119 | ||
6214ec0c | 120 | DefineInput(0,TChain::Class()); |
121 | DefineOutput(1, TList::Class()); | |
122 | ||
123 | } | |
124 | ||
125 | // ----------------------------------------------------------------------- | |
126 | AliAnalysisTaskCompareAODTrackCuts::~AliAnalysisTaskCompareAODTrackCuts() { | |
127 | ||
128 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
129 | ||
130 | } | |
131 | ||
132 | // ----------------------------------------------------------------------- | |
133 | void AliAnalysisTaskCompareAODTrackCuts::UserCreateOutputObjects() { | |
134 | ||
135 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
136 | ||
137 | // Getting a pointer to the analysis manager and input handler. | |
138 | AliAnalysisManager* manager = AliAnalysisManager::GetAnalysisManager(); | |
69868b6b | 139 | if (!manager) {AliFatal("Could not obtain analysis manager.");} |
6214ec0c | 140 | AliInputEventHandler* inputHandler = dynamic_cast<AliInputEventHandler*> (manager->GetInputEventHandler()); |
b4a7e39a | 141 | if (!inputHandler) {AliFatal("Could not obtain input handler."); return;} |
69868b6b | 142 | |
6214ec0c | 143 | // Getting the pointer to the PID response object. |
144 | fPIDResponse = inputHandler->GetPIDResponse(); | |
b4a7e39a | 145 | if (!fPIDResponse) {AliFatal("Could not obtain PID response."); return;} |
6214ec0c | 146 | |
147 | // Create the output list. | |
148 | fOutputList = new TList(); | |
149 | fOutputList->SetOwner(kTRUE); | |
150 | ||
151 | // Adding Event Cuts to the output. | |
152 | fEventCuts->CreateHistos(); // Generating all requested histograms. | |
153 | fOutputList->Add(fEventCuts); | |
154 | ||
155 | // Adding Track Cuts to the output. | |
156 | for (Int_t iCuts = 0; iCuts < fTrackCuts->GetEntries(); iCuts++) { | |
157 | AliAODTrackCutsDiHadronPID* currentcuts = (AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts); | |
158 | currentcuts->CreateHistos(); // Generating all requested histograms. | |
159 | fOutputList->Add(currentcuts); | |
160 | } | |
161 | ||
162 | // Creating inclusive times histogram. | |
163 | fInclusiveTimes = new TH2F("fInclusiveTimes","Inclusive Times;#eta;t (ps)",100,0,1.,1500,10000.,25000.); | |
164 | fOutputList->Add(fInclusiveTimes); | |
165 | ||
a5422983 | 166 | // Create the diagram correlating TPC and Global transverse momenta. |
167 | fGlobalPtvsTPCPt = new TH2F("fGlobalPtvsTPCPt","Global p_{T} vs TPC p_{T}; Global p_{T}; TPC p_{T}",100,0,10,100,0,10); | |
168 | fOutputList->Add(fGlobalPtvsTPCPt); | |
169 | ||
6214ec0c | 170 | // Creating Global Tracks Array |
171 | fGlobalTracksArray = new TObjArray(); | |
172 | ||
173 | // Loading the appropriate external mismatch histograms. | |
a5422983 | 174 | if (fCalculateTOFMismatch) LoadExternalMismatchHistos(); |
6214ec0c | 175 | |
176 | PostData(1,fOutputList); | |
177 | ||
178 | } | |
179 | ||
180 | // ----------------------------------------------------------------------- | |
181 | void AliAnalysisTaskCompareAODTrackCuts::FillGlobalTracksArray() { | |
182 | ||
183 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
184 | ||
185 | // Initialize the mapping for corresponding PID tracks. | |
186 | // See AliAnalysisTaskESDFilter.cxx for explanation about the mapping | |
187 | // between TPC-Only and Global tracks | |
188 | ||
189 | // Create TObjArray for Global Tracks. | |
190 | ||
191 | //cout<<"Global Tracks Array: "<<fGlobalTracksArray<<endl; | |
192 | ||
193 | // Clear previous tracks... | |
194 | fGlobalTracksArray->Clear(); | |
195 | ||
196 | //if (fGlobalTracksArray) delete fGlobalTracksArray; | |
197 | //fGlobalTracksArray = new TObjArray(); | |
198 | ||
199 | AliAODTrack* track = 0x0; | |
200 | ||
201 | for (Int_t iTrack = 0; iTrack < fCurrentAODEvent->GetNumberOfTracks(); iTrack++) { | |
202 | ||
f15c1f69 | 203 | track = dynamic_cast<AliAODTrack*>(fCurrentAODEvent->GetTrack(iTrack)); |
204 | if(!track) AliFatal("Not a standard AOD"); | |
6214ec0c | 205 | if (track->GetID()>-1) fGlobalTracksArray->AddAtAndExpand(track,track->GetID()); |
206 | } | |
207 | ||
208 | } | |
209 | ||
210 | // ----------------------------------------------------------------------- | |
211 | AliAODTrack* AliAnalysisTaskCompareAODTrackCuts::GetGlobalTrack(AliAODTrack* track) { | |
212 | ||
213 | // Returns Global Track corresponding to a TPC-Only Track. | |
214 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
215 | ||
216 | if (track->GetID() >= 0) { | |
217 | cout<<"AliAnalysisTaskCompareAODTrackCuts::GetGlobalTrack -> Input Track is not TPC-Only."<<endl; | |
218 | return 0x0; | |
219 | } | |
220 | ||
221 | if (!fGlobalTracksArray) { | |
222 | cout<<"AliAnalysisTaskCompareAODTrackCuts::GetGlobalTrack -> Global Tracks Array Does not Exist."<<endl; | |
223 | return 0x0; | |
224 | } | |
225 | ||
226 | AliAODTrack* globaltrack = (AliAODTrack*)(fGlobalTracksArray->At(-track->GetID()-1)); | |
227 | if (!globaltrack) { | |
228 | cout<<"AliAnalysisTaskCompareAODTrackCuts::GetGlobalTrack -> No Global Track Found."<<endl; | |
229 | return 0x0; | |
230 | } | |
231 | ||
232 | return globaltrack; | |
233 | ||
234 | } | |
235 | ||
236 | // ----------------------------------------------------------------------- | |
237 | void AliAnalysisTaskCompareAODTrackCuts::UserExec(Option_t*) { | |
238 | ||
239 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
a5422983 | 240 | Int_t nmismatched = 0; |
241 | Int_t nmatched = 0; | |
242 | Int_t nnotof = 0; | |
6214ec0c | 243 | // Input Current Event. |
244 | fCurrentAODEvent = dynamic_cast<AliAODEvent*>(InputEvent()); | |
245 | if (!fCurrentAODEvent) { | |
246 | cout<<"AliAnalysisTaskCompareAODTrackCuts::UserExec -> AOD Event not found."<<endl; | |
247 | return; | |
248 | } | |
249 | ||
250 | // Check Event Cuts Object. | |
251 | if (!fEventCuts) AliFatal("No Event Cuts Object Found!"); | |
252 | ||
253 | // Perform Event Cuts. | |
254 | if (!fEventCuts->IsSelected(fCurrentAODEvent)) {return;} | |
255 | ||
256 | // Check Track Cuts Array. | |
257 | if (!fTrackCuts) AliFatal("No Track Cuts Array Found!"); | |
258 | if (fTrackCuts->GetEntries() == 0) AliFatal("Track Cuts Array is Empty!"); | |
259 | ||
260 | // If MC, then fill MC reconstructed QA histograms. | |
261 | TClonesArray* mcArray = 0x0; | |
262 | TObjArray* mcArrayLabel = 0x0; | |
263 | if (fIsMC) { | |
264 | ||
265 | mcArray = dynamic_cast<TClonesArray*>(fCurrentAODEvent->FindListObject(AliAODMCParticle::StdBranchName())); | |
266 | if (!mcArray) { | |
267 | AliFatal("No MC array found in the AOD."); | |
268 | return; | |
269 | } | |
270 | ||
271 | mcArrayLabel = new TObjArray(10000); | |
272 | ||
273 | // Loop over MC particles. | |
274 | for (Int_t iParticle = 0; iParticle < mcArray->GetEntriesFast(); iParticle++) { | |
275 | ||
276 | // Put the MC Particle in the Label array. | |
277 | AliAODMCParticle* CurrentAODMCParticle = (AliAODMCParticle*) mcArray->At(iParticle); | |
a5422983 | 278 | //cout << "PR: " << CurrentAODMCParticle->IsPhysicalPrimary() << " SW: " << CurrentAODMCParticle->IsSecondaryFromWeakDecay() << " SM: " << CurrentAODMCParticle->IsSecondaryFromMaterial() << endl; |
6214ec0c | 279 | mcArrayLabel->AddAtAndExpand(CurrentAODMCParticle,CurrentAODMCParticle->Label()); |
280 | //cout<<"Index: "<<iParticle<<" Label: "<<CurrentAODMCParticle->Label()<<endl; | |
281 | ||
282 | //if (CurrentAODMCParticle->Label()!=iParticle) cout<<"Index unequal to particle's label!"<<endl; | |
283 | ||
284 | // Loop over all Track Cuts. | |
285 | for (Int_t iCuts = 0; iCuts < fTrackCuts->GetEntries(); iCuts++) { | |
286 | ((AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts))->IsSelectedGeneratedMC(CurrentAODMCParticle); | |
287 | } | |
288 | } | |
289 | } | |
290 | ||
291 | //for (Int_t ii=0; ii<200; ii++) cout<<fLvsEtaProj[ii]<<endl; | |
292 | ||
293 | // Create mapping to Global Tracks. | |
294 | FillGlobalTracksArray(); | |
295 | ||
296 | // Tell the track cuts object that a new event has started. | |
297 | for (Int_t iCuts = 0; iCuts < fTrackCuts->GetEntries(); iCuts++) { | |
298 | AliAODTrackCutsDiHadronPID* currentcuts = (AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts); | |
299 | if (fVerbose) AliInfo(Form("Starting new event for cuts: %s",currentcuts->GetName())); | |
300 | currentcuts->StartNewEvent(); | |
301 | } | |
302 | ||
303 | // Loop over all reconstructed tracks. | |
304 | for (Int_t iTrack = 0; iTrack < fCurrentAODEvent->GetNumberOfTracks(); iTrack++) { | |
305 | ||
306 | // Get the Current Track. | |
f15c1f69 | 307 | fCurrentAODTrack = dynamic_cast<AliAODTrack*>(fCurrentAODEvent->GetTrack(iTrack)); |
308 | if(!fCurrentAODTrack) AliFatal("Not a standard AOD"); | |
6214ec0c | 309 | if (!fCurrentAODTrack) { |
310 | cout<<"AliAnalysisTaskCompareAODTrackCuts::UserExec -> AOD Track not found."<<endl; | |
311 | continue; | |
312 | } | |
313 | ||
314 | // Ignore muon tracks. | |
315 | if (fCurrentAODTrack->IsMuonTrack()) {continue;} | |
316 | ||
317 | // Copy Track info into AliTrackDiHadronPID object. | |
318 | fCurrentDiHadronPIDTrack = 0x0; | |
319 | ||
320 | // Check if we can indeed find a MC particle corresponding to the reconstructed track. | |
321 | /* | |
322 | AliAODMCParticle* MCparticleCheck = (AliAODMCParticle*)mcArrayLabel->At(TMath::Abs(fCurrentAODTrack->GetLabel())); | |
323 | Double_t MCPt1 = -999.; | |
324 | if (MCparticleCheck) MCPt1 = MCparticleCheck->Pt(); | |
325 | AliAODMCParticle* MCparticleCheck2 = (AliAODMCParticle*)mcArray->At(TMath::Abs(fCurrentAODTrack->GetLabel())); | |
326 | Double_t MCPt2 = -999.; | |
327 | if (MCparticleCheck2) MCPt2 = MCparticleCheck2->Pt(); | |
328 | ||
329 | cout<<"AOD track abs label: "<<TMath::Abs(fCurrentAODTrack->GetLabel())<<" MC particle with same label found: "<<(Bool_t)MCparticleCheck<<" and with same index: "<<(Bool_t)MCparticleCheck2<<endl; | |
330 | cout<<"AOD track pt: "<<fCurrentAODTrack->Pt()<<" same label pt: "<<MCPt1<<" same index pt: "<<MCPt2<<endl; | |
331 | //if (!MCparticleCheck) cout<<"MC Particle for a reconstructed track not found."<<endl; | |
332 | */ | |
333 | // Check if it's a TPC-Only or Global Track. | |
334 | if (fCurrentAODTrack->GetID() < 0) { | |
335 | // Q: Do we really need to create the arraylabel object or is the original MC array already nicely ordered. (NOTE THAT WE TAKE THE MC PARTICLES FROM THE mcArray) | |
336 | if (fIsMC) fCurrentDiHadronPIDTrack = new AliTrackDiHadronPID(fCurrentAODTrack,GetGlobalTrack(fCurrentAODTrack),(AliAODMCParticle*)mcArray->At(TMath::Abs(fCurrentAODTrack->GetLabel())),fPIDResponse); | |
337 | else fCurrentDiHadronPIDTrack = new AliTrackDiHadronPID(fCurrentAODTrack,GetGlobalTrack(fCurrentAODTrack),0x0,fPIDResponse); | |
a5422983 | 338 | |
339 | // Fill histogram of Global p_T vs TPC-only p_T | |
340 | fGlobalPtvsTPCPt->Fill(GetGlobalTrack(fCurrentAODTrack)->Pt(), fCurrentAODTrack->Pt()); | |
341 | ||
6214ec0c | 342 | } else { |
343 | if (fIsMC) fCurrentDiHadronPIDTrack = new AliTrackDiHadronPID(fCurrentAODTrack,0x0,(AliAODMCParticle*)mcArray->At(TMath::Abs(fCurrentAODTrack->GetLabel())),fPIDResponse); | |
344 | else fCurrentDiHadronPIDTrack = new AliTrackDiHadronPID(fCurrentAODTrack,0x0,0x0,fPIDResponse); | |
345 | } | |
346 | ||
347 | if (!fCurrentDiHadronPIDTrack) { | |
348 | cout<<"AliAnalysisTaskCompareAODTrackCuts::UserExec -> Copying to DiHadronPIDTrack failed."<<endl; | |
349 | continue; | |
350 | } | |
351 | ||
352 | // Filling random times histogram: | |
353 | ULong_t requestedflags = (UInt_t)(AliAODTrack::kTOFout)|(UInt_t)(AliAODTrack::kTIME); | |
354 | ULong_t trackflags = fCurrentDiHadronPIDTrack->GetFlags(); | |
355 | if (requestedflags&trackflags) {fInclusiveTimes->Fill(TMath::Abs(fCurrentDiHadronPIDTrack->Eta()),fCurrentDiHadronPIDTrack->GetTOFsignal());} | |
356 | ||
357 | Double_t rndhittime = -1.e21; | |
a5422983 | 358 | if (fCalculateTOFMismatch) rndhittime = GenerateRandomHit(fCurrentDiHadronPIDTrack->Eta()); |
6214ec0c | 359 | |
360 | // Loop over all Track Cuts. | |
361 | for (Int_t iCuts = 0; iCuts < fTrackCuts->GetEntries(); iCuts++) { | |
362 | if (fIsMC) ((AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts))->IsSelectedReconstructedMC(fCurrentDiHadronPIDTrack); | |
363 | else ((AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts))->IsSelectedData(fCurrentDiHadronPIDTrack,rndhittime); | |
364 | } | |
365 | ||
a5422983 | 366 | Int_t tofmatchstat = fCurrentDiHadronPIDTrack->GetTOFMatchingStatus(); |
367 | if (tofmatchstat==0) {nmatched++;} | |
368 | if (tofmatchstat==1) {nmismatched++;} | |
369 | if (tofmatchstat==2) {nnotof++;} | |
370 | ||
6214ec0c | 371 | // Delete Current DiHadronPIDTrack. |
372 | delete fCurrentDiHadronPIDTrack; | |
373 | fCurrentDiHadronPIDTrack = 0x0; | |
374 | ||
375 | } | |
376 | ||
377 | // Tell the track cuts object that the event has been processed. | |
378 | for (Int_t iCuts = 0; iCuts < fTrackCuts->GetEntries(); iCuts++) { | |
379 | ((AliAODTrackCutsDiHadronPID*)fTrackCuts->At(iCuts))->EventIsDone(fIsMC); | |
380 | } | |
381 | ||
28161374 | 382 | //cout << "Matched: "<<nmatched<<" Mismatched: "<<nmismatched<<" No TOF hit: "<<nnotof<<endl; |
a5422983 | 383 | |
6214ec0c | 384 | PostData(1,fOutputList); |
385 | ||
386 | } | |
387 | ||
388 | // ----------------------------------------------------------------------- | |
a5422983 | 389 | Bool_t AliAnalysisTaskCompareAODTrackCuts::LoadExternalMismatchHistos() { |
6214ec0c | 390 | |
69868b6b | 391 | // |
392 | // Attempting to load a root file containing information needed | |
393 | // to generate random TOF hits. | |
394 | // | |
6214ec0c | 395 | |
69868b6b | 396 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} |
6214ec0c | 397 | |
69868b6b | 398 | // Opening external TOF file. |
69868b6b | 399 | TFile* fin = 0x0; |
a5422983 | 400 | |
401 | // The default is that the file TOFmismatchHistos.root is taken from the /rootfiles/ directory, | |
402 | // and this works fine when running on the train. When the user submits the jobs himself, he can | |
403 | // choose to not take the file from the home dir, but upload one along with the source code. | |
404 | // If in this case the file is not found, the program tries to get the file from the root directory | |
405 | // anyway. | |
406 | if (fUseMismatchFileFromHomeDir == kFALSE) { | |
407 | fin = TFile::Open("TOFmismatchHistos.root"); | |
408 | if (!fin) {AliWarning("Tried to open uploaded TOFmismatchHistos.root, but failed");} | |
409 | } | |
410 | ||
411 | if (!fin) {fin = TFile::Open("alien:///alice/cern.ch/user/m/mveldhoe/rootfiles/TOFmismatchHistos.root");} | |
412 | ||
69868b6b | 413 | if (!fin) { |
a5422983 | 414 | AliWarning("Couln't open TOFmismatchHistos.root, will not calculate mismatches..."); |
69868b6b | 415 | fCalculateTOFMismatch = kFALSE; |
416 | return kFALSE; | |
a5422983 | 417 | } else { |
418 | AliInfo("Sucessfully loaded TOFmismatchHistos.root"); | |
6214ec0c | 419 | } |
420 | ||
69868b6b | 421 | // Check if the required histograms are present. |
422 | TH1F* tmp1 = (TH1F*)fin->Get("hNewT0Fill"); | |
423 | if (!tmp1) { | |
424 | AliWarning("Couln't find hNewT0Fill, will not calculate mismatches..."); | |
425 | fCalculateTOFMismatch = kFALSE; | |
426 | return kFALSE; | |
427 | } | |
428 | TH2F* tmp2 = (TH2F*)fin->Get("hLvsEta"); | |
429 | if (!tmp2) { | |
430 | AliWarning("Couln't find hLvsEta, will not calculate mismatches..."); | |
431 | fCalculateTOFMismatch = kFALSE; | |
432 | return kFALSE; | |
433 | } | |
434 | ||
435 | // Make a deep copy of the files in the histogram. | |
436 | fT0Fill = (TH1F*)tmp1->Clone("fT0Fill"); | |
437 | fLvsEta = (TH2F*)tmp2->Clone("fLvsEta"); | |
438 | ||
439 | // Close the external file. | |
440 | AliInfo("Closing external file."); | |
441 | fin->Close(); | |
442 | ||
443 | // Creating a TObjArray for LvsEta projections. | |
444 | const Int_t nbinseta = fLvsEta->GetNbinsX(); | |
445 | fLvsEtaProjections = new TObjArray(nbinseta); | |
446 | fLvsEtaProjections->SetOwner(kTRUE); | |
447 | ||
448 | // Making the projections needed (excluding underflow/ overflow). | |
449 | for (Int_t iEtaBin = 1; iEtaBin < (nbinseta + 1); iEtaBin++) { | |
450 | TH1F* tmp = (TH1F*)fLvsEta->ProjectionY(Form("LvsEtaProjection_%i",iEtaBin),iEtaBin,iEtaBin); | |
451 | tmp->SetDirectory(0); | |
452 | fLvsEtaProjections->AddAt(tmp,iEtaBin - 1); | |
6214ec0c | 453 | } |
454 | ||
69868b6b | 455 | return kTRUE; |
6214ec0c | 456 | |
457 | } | |
458 | ||
459 | // ----------------------------------------------------------------------- | |
a5422983 | 460 | Double_t AliAnalysisTaskCompareAODTrackCuts::GenerateRandomHit(Double_t eta) { |
6214ec0c | 461 | |
69868b6b | 462 | // |
463 | // Returns a random TOF time. | |
464 | // | |
6214ec0c | 465 | |
466 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
467 | ||
69868b6b | 468 | // Default (error) value: |
6214ec0c | 469 | Double_t rndhittime = -1.e21; |
470 | ||
69868b6b | 471 | // TOF mismatch flag is not turned on. |
472 | if (!fCalculateTOFMismatch) { | |
473 | AliFatal("Called GenerateRandomHit() method, but flag fCalculateTOFMismatch not set."); | |
474 | return rndhittime; | |
475 | } | |
6214ec0c | 476 | |
69868b6b | 477 | // TOF doesn't extend much further than 0.8. |
478 | if (TMath::Abs(eta) > 0.8) { | |
479 | if (fDebug) {AliInfo("Tried to get a random hit for a track with eta > 0.8.");} | |
480 | return rndhittime; | |
481 | } | |
6214ec0c | 482 | |
69868b6b | 483 | // Finding the bin of the eta. |
484 | TAxis* etaAxis = fLvsEta->GetXaxis(); | |
485 | Int_t etaBin = etaAxis->FindBin(eta); | |
486 | if (etaBin == 0 || (etaBin == etaAxis->GetNbins() + 1)) {return rndhittime;} | |
6214ec0c | 487 | |
69868b6b | 488 | const TH1F* lengthDistribution = (const TH1F*)fLvsEtaProjections->At(etaBin - 1); |
6214ec0c | 489 | |
69868b6b | 490 | if (!lengthDistribution) { |
491 | AliFatal("length Distribution not found."); | |
492 | return rndhittime; | |
6214ec0c | 493 | } |
494 | ||
69868b6b | 495 | Double_t currentRndLength = lengthDistribution->GetRandom(); // in cm. |
496 | ||
497 | // Similar to Roberto's code. | |
498 | Double_t currentRndTime = currentRndLength / (TMath::C() * 1.e2 / 1.e12); | |
499 | Double_t t0fill = -1.26416e+04; | |
500 | rndhittime = fT0Fill->GetRandom() - t0fill + currentRndTime; | |
6214ec0c | 501 | |
502 | return rndhittime; | |
503 | ||
504 | } | |
505 | ||
28161374 | 506 | // ----------------------------------------------------------------------- |
fe463f34 | 507 | void AliAnalysisTaskCompareAODTrackCuts::SetUseNSigmaOnPIDAxes(Bool_t UseNSigma) { |
28161374 | 508 | |
509 | // Will use NSigma on all PID axes. Will also change all track cuts objects | |
510 | // owned by this task. | |
511 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
512 | ||
513 | fUseNSigmaOnPIDAxes = UseNSigma; | |
514 | ||
515 | if (fTrackCuts) { | |
516 | for (Int_t iCut = 0; iCut < fTrackCuts->GetSize(); ++iCut) { | |
517 | AliAODTrackCutsDiHadronPID* cutstmp = (AliAODTrackCutsDiHadronPID*)(fTrackCuts->At(iCut)); | |
518 | if (cutstmp) {cutstmp->SetUseNSigmaOnPIDAxes(UseNSigma);} | |
519 | else {cout << Form("%s -> WARNING: Found an empty spot in the track cuts array...",__func__) << endl;} | |
520 | } | |
521 | } | |
522 | } | |
523 | ||
524 | // ----------------------------------------------------------------------- | |
525 | void AliAnalysisTaskCompareAODTrackCuts::SetEventCuts(AliAODEventCutsDiHadronPID* eventcuts) { | |
526 | ||
527 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
528 | if (!eventcuts) {cout << Form("%s -> ERROR: No Event Cuts Object provided.",__func__) << endl; return;} | |
529 | ||
530 | fEventCuts = eventcuts; | |
531 | ||
532 | } | |
533 | ||
534 | // ----------------------------------------------------------------------- | |
535 | void AliAnalysisTaskCompareAODTrackCuts::AddTrackCuts(AliAODTrackCutsDiHadronPID* trackcuts) { | |
536 | ||
537 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
538 | if (!trackcuts) {cout << Form("%s -> ERROR: No Track Cuts Object provided.",__func__) << endl; return;} | |
539 | if (!fTrackCuts) {cout << Form("%s -> ERROR: No Track Cuts array available.",__func__) << endl; return;} | |
540 | ||
541 | // The setting of the task propagates to the imported track cuts object. | |
542 | trackcuts->SetUseNSigmaOnPIDAxes(fUseNSigmaOnPIDAxes); | |
543 | ||
544 | fTrackCuts->AddLast(trackcuts); | |
545 | ||
546 | } | |
547 | ||
a5422983 | 548 | // ----------------------------------------------------------------------- |
fe463f34 | 549 | void AliAnalysisTaskCompareAODTrackCuts::SetDebugLevel(Int_t debuglvl) { |
a5422983 | 550 | |
551 | // Sets debug level to a certain value, as well as the debug level of the | |
552 | // track cuts objects and event cut object. | |
553 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
554 | ||
555 | fDebug = debuglvl; | |
556 | ||
557 | if (fEventCuts) {fEventCuts->SetDebugLevel(debuglvl);} | |
558 | ||
559 | if (fTrackCuts) { | |
560 | for (Int_t iTrackCutObj = 0; iTrackCutObj < fTrackCuts->GetEntriesFast(); ++iTrackCutObj) { | |
561 | ((AliTrackDiHadronPID*)fTrackCuts->At(iTrackCutObj))->SetDebugLevel(debuglvl); | |
562 | } | |
563 | } | |
564 | ||
565 | } | |
566 | ||
6214ec0c | 567 | // ----------------------------------------------------------------------- |
568 | void AliAnalysisTaskCompareAODTrackCuts::Terminate(Option_t*) { | |
569 | ||
570 | if (fDebug > 0) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;} | |
571 | ||
69868b6b | 572 | if (fCalculateTOFMismatch) { |
573 | delete fT0Fill; | |
574 | fT0Fill = 0x0; | |
575 | delete fLvsEta; | |
576 | fLvsEta = 0x0; | |
577 | delete fLvsEtaProjections; | |
578 | fLvsEtaProjections = 0x0; | |
579 | } | |
6214ec0c | 580 | |
581 | } |