]>
Commit | Line | Data |
---|---|---|
5376e016 CP |
1 | #include "AliAnalysisMuMuBase.h" |
2 | ||
3 | /** | |
4 | * | |
5 | * \ingroup pwg-muon-mumu | |
6 | * | |
7 | * \class AliAnalysisMuMuBase | |
8 | * | |
9 | * Defines the interface of a sub-analysis to be steered by AliAnalysisTaskMuMu | |
10 | * | |
11 | * Daugther class has to implement one method : | |
12 | * | |
13 | * - \ref DefineHistogramCollection | |
14 | * | |
15 | * It may implement one or several of the FillHistosForXXX methods : | |
16 | * | |
17 | * - \ref FillHistosForEvent to fill histograms for one event | |
18 | * - \ref FillHistosForMCEvent to fill histograms for one MC event | |
19 | * - \ref FillHistosForTrack to fill histograms for one track | |
20 | * - \ref FillHistosForPair to fill histograms for one muon track pair | |
21 | * | |
22 | * More rarely it may also implement : | |
23 | * | |
24 | * - \ref SetRun to do some changes when run number changes | |
25 | * - \ref Terminate to finalize before ending | |
26 | * - \ref SetEvent to e.g. append information to VEvent | |
27 | * | |
28 | * Daugther class can use the following methods : | |
29 | * | |
30 | * - \ref HasMC to know if MC information is available in the analyzed data | |
31 | * - \ref Event to access the current event | |
32 | * - \ref MCEvent to access to current MC event (if available) | |
33 | * | |
34 | * A few trivial cut methods (\ref AlwaysTrue and \ref AlwaysFalse) are defined as well and | |
35 | * can be used to register some control cut combinations (see \ref AliAnalysisMuMuCutCombination) | |
36 | * | |
37 | */ | |
38 | ||
39 | #include "AliMergeableCollection.h" | |
40 | #include "AliCounterCollection.h" | |
41 | #include "TList.h" | |
42 | #include "TObjString.h" | |
43 | #include "TMath.h" | |
44 | #include "TObjArray.h" | |
45 | #include "AliLog.h" | |
46 | #include "AliAnalysisMuMuBinning.h" | |
47 | #include "TH1F.h" | |
48 | #include "TH2F.h" | |
49 | #include "TProfile.h" | |
50 | #include "TRegexp.h" | |
51 | #include "AliVEvent.h" | |
52 | #include "AliAODEvent.h" | |
53 | #include "AliESDEvent.h" | |
54 | #include "AliLog.h" | |
55 | #include "AliAnalysisMuMuCutCombination.h" | |
56 | #include "AliAnalysisMuMuCutRegistry.h" | |
57 | ||
58 | ClassImp(AliAnalysisMuMuBase) | |
59 | ||
5376e016 CP |
60 | //_____________________________________________________________________________ |
61 | AliAnalysisMuMuBase::AliAnalysisMuMuBase() | |
62 | : | |
63 | TObject(), | |
64 | fEventCounters(0x0), | |
65 | fHistogramCollection(0x0), | |
66 | fBinning(0x0), | |
67 | fCutRegistry(0x0), | |
68 | fEvent(0x0), | |
69 | fMCEvent(0x0), | |
70 | fHistogramToDisable(0x0), | |
71 | fHasMC(kFALSE) | |
72 | { | |
73 | /// default ctor | |
74 | } | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | void | |
78 | AliAnalysisMuMuBase::CreateEventHistos(UInt_t dataType, | |
79 | const char* what, | |
80 | const char* hname, const char* htitle, | |
81 | Int_t nbinsx, Double_t xmin, Double_t xmax, | |
82 | Int_t nbinsy, Double_t ymin, Double_t ymax) const | |
83 | { | |
84 | /** Append histograms at the event level. Depending on dataType the created histograms | |
85 | * are for real data only, MC data only, or both | |
86 | */ | |
87 | ||
88 | if ( IsHistogramDisabled(hname) ) return; | |
89 | ||
90 | TObjArray pathNames; | |
91 | pathNames.SetOwner(kTRUE); | |
92 | ||
93 | if ( dataType & kHistoForData ) | |
94 | { | |
95 | pathNames.Add(new TObjString(Form("/%s",what))); | |
96 | } | |
97 | if ( ( dataType & kHistoForMCInput ) && HasMC() ) | |
98 | { | |
16560e8e | 99 | pathNames.Add(new TObjString(Form("/%s/%s",MCInputPrefix(),what))); |
5376e016 CP |
100 | } |
101 | ||
102 | CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax); | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | void | |
107 | AliAnalysisMuMuBase::CreateEventHistos(UInt_t dataType, | |
108 | const char* eventSelection, | |
109 | const char* triggerClassName, | |
110 | const char* centrality, | |
111 | const char* hname, const char* htitle, | |
112 | Int_t nbinsx, Double_t xmin, Double_t xmax, | |
113 | Int_t nbinsy, Double_t ymin, Double_t ymax) const | |
114 | { | |
115 | /** Append histograms at the event level. Depending on dataType the created histograms | |
116 | * are for real data only, MC data only, or both | |
117 | */ | |
118 | ||
119 | if ( IsHistogramDisabled(hname) ) return; | |
120 | ||
121 | TObjArray pathNames; | |
122 | pathNames.SetOwner(kTRUE); | |
123 | ||
124 | if ( dataType & kHistoForData ) | |
125 | { | |
126 | pathNames.Add(new TObjString(Form("/%s/%s/%s",eventSelection,triggerClassName,centrality))); | |
127 | } | |
128 | if ( ( dataType & kHistoForMCInput ) && HasMC() ) | |
129 | { | |
16560e8e | 130 | pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality))); |
5376e016 CP |
131 | } |
132 | ||
133 | CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax); | |
134 | } | |
135 | ||
136 | //_____________________________________________________________________________ | |
137 | void | |
138 | AliAnalysisMuMuBase::CreateHistos(const TObjArray& paths, | |
139 | const char* hname, const char* htitle, | |
140 | Int_t nbinsx, Double_t xmin, Double_t xmax, | |
141 | Int_t nbinsy, Double_t ymin, Double_t ymax) const | |
142 | { | |
143 | /// Create multiple copies of histogram hname, one per path | |
144 | ||
145 | if ( IsHistogramDisabled(hname) ) return; | |
146 | ||
147 | StdoutToAliDebug(1,paths.Print();); | |
148 | ||
149 | TIter next(&paths); | |
150 | TObjString* pathName; | |
151 | ||
152 | while ( ( pathName = static_cast<TObjString*>(next()) ) ) | |
153 | { | |
154 | TH1* h(0x0); | |
155 | ||
156 | if ( nbinsy > 0 ) | |
157 | { | |
158 | AliDebug(1,Form("Created TH2F %s/%s",pathName->String().Data(),hname)); | |
159 | h = new TH2F(hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax); | |
160 | } | |
161 | else if ( nbinsy == 0 ) | |
162 | { | |
163 | AliDebug(1,Form("Created TProfile %s/%s",pathName->String().Data(),hname)); | |
164 | h = new TProfile(hname,htitle,nbinsx,xmin,xmax,ymin,ymax); | |
165 | h->Sumw2(); | |
16560e8e | 166 | static_cast<TProfile*>(h)->Approximate(); |
5376e016 CP |
167 | } |
168 | else | |
169 | { | |
170 | AliDebug(1,Form("Created TH1F %s/%s",pathName->String().Data(),hname)); | |
171 | h = new TH1F(hname,htitle,nbinsx,xmin,xmax); | |
172 | ||
173 | if ( nbinsy < -1 ) | |
174 | { | |
175 | h->Sumw2(); | |
176 | } | |
177 | } | |
178 | ||
179 | HistogramCollection()->Adopt(pathName->String().Data(),h); | |
180 | } | |
181 | ||
182 | StdoutToAliDebug(1,HistogramCollection()->Print("*");); | |
183 | } | |
184 | ||
185 | //_____________________________________________________________________________ | |
186 | void | |
16560e8e | 187 | AliAnalysisMuMuBase::CreateTrackHistos(UInt_t dataType, |
188 | const char* eventSelection, | |
5376e016 CP |
189 | const char* triggerClassName, |
190 | const char* centrality, | |
191 | const char* hname, const char* htitle, | |
192 | Int_t nbinsx, Double_t xmin, Double_t xmax, | |
193 | Int_t nbinsy, Double_t ymin, Double_t ymax) const | |
194 | { | |
195 | /// Create n copies of an histogram (with name=hname, title=htitle, etc..) | |
196 | /// where n = # of track cut combinations defined | |
197 | /// see also CreateHistos | |
198 | ||
199 | ||
200 | if ( IsHistogramDisabled(hname) ) return; | |
201 | ||
202 | TObjArray pathNames; | |
203 | pathNames.SetOwner(kTRUE); | |
204 | ||
205 | TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrack)); | |
206 | AliAnalysisMuMuCutCombination* cutCombination; | |
207 | ||
208 | while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) ) | |
209 | { | |
16560e8e | 210 | if ( dataType & kHistoForData ) |
211 | { | |
212 | pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName()))); | |
213 | } | |
214 | if ( ( dataType & kHistoForMCInput ) && HasMC() ) | |
215 | { | |
216 | pathNames.Add(new TObjString(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality,cutCombination->GetName()))); | |
217 | } | |
218 | ||
5376e016 CP |
219 | } |
220 | ||
221 | CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax); | |
222 | } | |
223 | ||
224 | //_____________________________________________________________________________ | |
225 | void | |
16560e8e | 226 | AliAnalysisMuMuBase::CreatePairHistos(UInt_t dataType, |
227 | const char* eventSelection, | |
228 | const char* triggerClassName, | |
229 | const char* centrality, | |
230 | const char* hname, const char* htitle, | |
231 | Int_t nbinsx, Double_t xmin, Double_t xmax, | |
232 | Int_t nbinsy, Double_t ymin, Double_t ymax) const | |
5376e016 CP |
233 | { |
234 | /// Create n copies of an histogram (with name=hname, title=htitle, etc..) | |
235 | /// where n = # of track *pair* cut combinations defined | |
236 | /// see also CreateHistos | |
16560e8e | 237 | |
5376e016 CP |
238 | if ( IsHistogramDisabled(hname) ) return; |
239 | ||
240 | TObjArray pathNames; | |
241 | pathNames.SetOwner(kTRUE); | |
242 | ||
243 | TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrackPair)); | |
244 | AliAnalysisMuMuCutCombination* cutCombination; | |
245 | ||
246 | while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) ) | |
247 | { | |
16560e8e | 248 | if ( dataType & kHistoForData ) |
249 | { | |
250 | pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName()))); | |
251 | } | |
252 | if ( ( dataType & kHistoForMCInput ) && HasMC() ) | |
253 | { | |
254 | pathNames.Add(new TObjString(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality,cutCombination->GetName()))); | |
255 | } | |
5376e016 CP |
256 | } |
257 | ||
258 | CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax); | |
259 | } | |
260 | ||
261 | //_____________________________________________________________________________ | |
262 | void AliAnalysisMuMuBase::DisableHistograms(const char* pattern) | |
263 | { | |
264 | /// Disable the histogramming of all the histograms matching the pattern | |
265 | ||
266 | TString spattern(pattern); | |
267 | if (spattern=="*") | |
268 | { | |
269 | delete fHistogramToDisable; | |
270 | fHistogramToDisable = 0x0; | |
271 | } | |
272 | ||
273 | if (!fHistogramToDisable) | |
274 | { | |
275 | fHistogramToDisable = new TList; | |
276 | fHistogramToDisable->SetOwner(kTRUE); | |
277 | } | |
278 | ||
279 | fHistogramToDisable->Add(new TObjString(spattern)); | |
280 | } | |
281 | ||
282 | //_____________________________________________________________________________ | |
283 | Int_t AliAnalysisMuMuBase::GetNbins(Double_t xmin, Double_t xmax, Double_t xstep) | |
284 | { | |
285 | /// Compute number of bins to get a given step between each values in the xmin,xmax range | |
286 | if ( TMath::AreEqualRel(xstep,0.0,1E-9) ) return 1; | |
287 | ||
288 | return TMath::Nint(TMath::Abs((xmax-xmin)/xstep)); | |
289 | } | |
290 | ||
291 | //_____________________________________________________________________________ | |
292 | TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* triggerClassName, const char* histoname) | |
293 | { | |
294 | /// Get one histo back | |
295 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,histoname)) : 0x0; | |
296 | } | |
297 | ||
298 | //_____________________________________________________________________________ | |
299 | TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* histoname) | |
300 | { | |
301 | /// Get one histo back | |
302 | return fHistogramCollection ? fHistogramCollection->Histo(eventSelection,histoname) : 0x0; | |
303 | } | |
304 | ||
305 | //_____________________________________________________________________________ | |
306 | TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, | |
307 | const char* triggerClassName, | |
308 | const char* cent, | |
309 | const char* histoname) | |
310 | { | |
311 | /// Get one histo back | |
312 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,cent),histoname) : 0x0; | |
313 | } | |
314 | ||
315 | //_____________________________________________________________________________ | |
316 | TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, | |
317 | const char* triggerClassName, | |
318 | const char* cent, | |
319 | const char* what, | |
320 | const char* histoname) | |
321 | { | |
322 | /// Get one histo back | |
323 | ||
324 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,cent,what),histoname) : 0x0; | |
325 | } | |
326 | ||
16560e8e | 327 | //_____________________________________________________________________________ |
328 | TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection, | |
329 | const char* histoname) | |
330 | { | |
331 | /// Get one histo profile back | |
332 | ||
333 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s",eventSelection),histoname)) : 0x0; | |
334 | } | |
335 | ||
336 | //_____________________________________________________________________________ | |
337 | TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection, | |
338 | const char* triggerClassName, | |
339 | const char* histoname) | |
340 | { | |
341 | /// Get one histo profile back | |
342 | ||
343 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s",eventSelection,triggerClassName),histoname)) : 0x0; | |
344 | } | |
345 | ||
346 | //_____________________________________________________________________________ | |
347 | TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection, | |
348 | const char* triggerClassName, | |
349 | const char* cent, | |
350 | const char* histoname) | |
351 | { | |
352 | /// Get one histo profile back | |
353 | ||
354 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s",eventSelection,triggerClassName,cent),histoname)) : 0x0; | |
355 | } | |
356 | ||
357 | //_____________________________________________________________________________ | |
358 | TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection, | |
359 | const char* triggerClassName, | |
360 | const char* cent, | |
361 | const char* what, | |
362 | const char* histoname) | |
363 | { | |
364 | /// Get one histo profile back | |
365 | ||
366 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,cent,what),histoname)) : 0x0; | |
367 | } | |
368 | ||
5376e016 CP |
369 | //_____________________________________________________________________________ |
370 | void AliAnalysisMuMuBase::Init(AliCounterCollection& cc, | |
371 | AliMergeableCollection& hc, | |
372 | const AliAnalysisMuMuBinning& binning, | |
373 | const AliAnalysisMuMuCutRegistry& registry) | |
374 | { | |
375 | /// Set the internal references | |
376 | fEventCounters = &cc; | |
377 | fHistogramCollection = &hc; | |
378 | fBinning = &binning; | |
379 | fCutRegistry = ®istry; | |
380 | } | |
381 | ||
382 | //_____________________________________________________________________________ | |
383 | Bool_t AliAnalysisMuMuBase::IsHistogramDisabled(const char* hname) const | |
384 | { | |
385 | /// Whether or not a given histogram (identified by its name) | |
386 | /// is disabled or not | |
387 | ||
388 | if ( !fHistogramToDisable ) | |
389 | { | |
390 | return kFALSE; | |
391 | } | |
392 | TString shname(hname); | |
393 | TIter next(fHistogramToDisable); | |
394 | TObjString* str(0x0); | |
395 | ||
396 | while ( ( str = static_cast<TObjString*>(next()) ) ) | |
397 | { | |
398 | if ( shname.Contains(TRegexp(str->String()) ) ) | |
399 | { | |
400 | return kTRUE; | |
401 | } | |
402 | } | |
403 | return kFALSE; | |
404 | } | |
405 | ||
406 | //_____________________________________________________________________________ | |
407 | Bool_t AliAnalysisMuMuBase::IsHistogrammingDisabled() const | |
408 | { | |
409 | /// Whether or not *all* histograms are disabled | |
410 | ||
411 | if ( fHistogramToDisable && fHistogramToDisable->GetEntries()==1 ) | |
412 | { | |
413 | TObjString* r = static_cast<TObjString*>(fHistogramToDisable->First()); | |
414 | if ( r->String() == "*" ) | |
415 | { | |
416 | return kTRUE; | |
417 | } | |
418 | } | |
419 | return kFALSE; | |
420 | } | |
421 | ||
422 | //_____________________________________________________________________________ | |
423 | TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* triggerClassName, const char* histoname) | |
424 | { | |
425 | /// Get one histo back | |
16560e8e | 426 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,histoname)) : 0x0; |
5376e016 CP |
427 | } |
428 | ||
429 | //_____________________________________________________________________________ | |
430 | TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* histoname) | |
431 | { | |
432 | /// Get one histo back | |
16560e8e | 433 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",MCInputPrefix(),eventSelection,histoname)) : 0x0; |
5376e016 CP |
434 | } |
435 | ||
436 | //_____________________________________________________________________________ | |
437 | TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, | |
438 | const char* triggerClassName, | |
439 | const char* cent, | |
440 | const char* histoname) | |
441 | { | |
442 | /// Get one histo back | |
16560e8e | 443 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent),histoname) : 0x0; |
5376e016 CP |
444 | } |
445 | ||
446 | //_____________________________________________________________________________ | |
447 | TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, | |
448 | const char* triggerClassName, | |
449 | const char* cent, | |
450 | const char* what, | |
451 | const char* histoname) | |
452 | { | |
453 | /// Get one histo back | |
454 | ||
16560e8e | 455 | return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent,what),histoname) : 0x0; |
456 | } | |
457 | ||
458 | //_____________________________________________________________________________ | |
459 | TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection, | |
460 | const char* histoname) | |
461 | { | |
462 | /// Get one histo profile back | |
463 | ||
464 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s",MCInputPrefix(),eventSelection),histoname)) : 0x0; | |
465 | } | |
466 | ||
467 | //_____________________________________________________________________________ | |
468 | TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection, | |
469 | const char* triggerClassName, | |
470 | const char* histoname) | |
471 | { | |
472 | /// Get one histo profile back | |
473 | ||
474 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName),histoname)) : 0x0; | |
475 | } | |
476 | ||
477 | //_____________________________________________________________________________ | |
478 | TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection, | |
479 | const char* triggerClassName, | |
480 | const char* cent, | |
481 | const char* histoname) | |
482 | { | |
483 | /// Get one histo profile back | |
484 | ||
485 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent),histoname)) : 0x0; | |
486 | } | |
487 | ||
488 | //_____________________________________________________________________________ | |
489 | TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection, | |
490 | const char* triggerClassName, | |
491 | const char* cent, | |
492 | const char* what, | |
493 | const char* histoname) | |
494 | { | |
495 | /// Get one histo profile back | |
496 | ||
497 | return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent,what),histoname)) : 0x0; | |
5376e016 CP |
498 | } |
499 | ||
500 | //_____________________________________________________________________________ | |
501 | void AliAnalysisMuMuBase::SetEvent(AliVEvent* event, AliMCEvent* mcEvent) | |
502 | { | |
503 | /// Set pointers to event (and mcEvent) | |
504 | /// This is the place where a sub analysis might (if really needed) | |
505 | /// append things to the event. Please DO NOT alter the original content, | |
506 | /// only add to it. Unless of course you want to shoot yourself in the | |
507 | /// foot... | |
508 | ||
509 | fEvent = event; | |
510 | fMCEvent = mcEvent; | |
511 | } |