1 #include "AliAnalysisMuMuBase.h"
5 * \ingroup pwg-muon-mumu
7 * \class AliAnalysisMuMuBase
9 * Defines the interface of a sub-analysis to be steered by AliAnalysisTaskMuMu
11 * Daugther class has to implement one method :
13 * - \ref DefineHistogramCollection
15 * It may implement one or several of the FillHistosForXXX methods :
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
22 * More rarely it may also implement :
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
28 * Daugther class can use the following methods :
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)
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)
39 #include "AliMergeableCollection.h"
40 #include "AliCounterCollection.h"
42 #include "TObjString.h"
44 #include "TObjArray.h"
46 #include "AliAnalysisMuMuBinning.h"
51 #include "AliVEvent.h"
52 #include "AliAODEvent.h"
53 #include "AliESDEvent.h"
55 #include "AliAnalysisMuMuCutCombination.h"
56 #include "AliAnalysisMuMuCutRegistry.h"
58 ClassImp(AliAnalysisMuMuBase)
60 //_____________________________________________________________________________
61 AliAnalysisMuMuBase::AliAnalysisMuMuBase()
65 fHistogramCollection(0x0),
70 fHistogramToDisable(0x0),
76 //_____________________________________________________________________________
78 AliAnalysisMuMuBase::CreateEventHistos(UInt_t dataType,
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
84 /** Append histograms at the event level. Depending on dataType the created histograms
85 * are for real data only, MC data only, or both
88 if ( IsHistogramDisabled(hname) ) return;
91 pathNames.SetOwner(kTRUE);
93 if ( dataType & kHistoForData )
95 pathNames.Add(new TObjString(Form("/%s",what)));
97 if ( ( dataType & kHistoForMCInput ) && HasMC() )
99 pathNames.Add(new TObjString(Form("/%s/%s",MCInputPrefix(),what)));
102 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
105 //_____________________________________________________________________________
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
115 /** Append histograms at the event level. Depending on dataType the created histograms
116 * are for real data only, MC data only, or both
119 if ( IsHistogramDisabled(hname) ) return;
122 pathNames.SetOwner(kTRUE);
124 if ( dataType & kHistoForData )
126 pathNames.Add(new TObjString(Form("/%s/%s/%s",eventSelection,triggerClassName,centrality)));
128 if ( ( dataType & kHistoForMCInput ) && HasMC() )
130 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality)));
133 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
136 //_____________________________________________________________________________
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
143 /// Create multiple copies of histogram hname, one per path
145 if ( IsHistogramDisabled(hname) ) return;
147 StdoutToAliDebug(1,paths.Print(););
150 TObjString* pathName;
152 while ( ( pathName = static_cast<TObjString*>(next()) ) )
158 AliDebug(1,Form("Created TH2F %s/%s",pathName->String().Data(),hname));
159 h = new TH2F(hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
161 else if ( nbinsy == 0 )
163 AliDebug(1,Form("Created TProfile %s/%s",pathName->String().Data(),hname));
164 h = new TProfile(hname,htitle,nbinsx,xmin,xmax,ymin,ymax);
166 static_cast<TProfile*>(h)->Approximate();
170 AliDebug(1,Form("Created TH1F %s/%s",pathName->String().Data(),hname));
171 h = new TH1F(hname,htitle,nbinsx,xmin,xmax);
179 HistogramCollection()->Adopt(pathName->String().Data(),h);
182 StdoutToAliDebug(1,HistogramCollection()->Print("*"););
185 //_____________________________________________________________________________
187 AliAnalysisMuMuBase::CreateTrackHistos(UInt_t dataType,
188 const char* eventSelection,
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
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
200 if ( IsHistogramDisabled(hname) ) return;
203 pathNames.SetOwner(kTRUE);
205 TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrack));
206 AliAnalysisMuMuCutCombination* cutCombination;
208 while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) )
210 if ( dataType & kHistoForData )
212 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName())));
214 if ( ( dataType & kHistoForMCInput ) && HasMC() )
216 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality,cutCombination->GetName())));
221 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
224 //_____________________________________________________________________________
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
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
238 if ( IsHistogramDisabled(hname) ) return;
241 pathNames.SetOwner(kTRUE);
243 TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrackPair));
244 AliAnalysisMuMuCutCombination* cutCombination;
246 while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) )
248 if ( dataType & kHistoForData )
250 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName())));
252 if ( ( dataType & kHistoForMCInput ) && HasMC() )
254 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,centrality,cutCombination->GetName())));
258 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
261 //_____________________________________________________________________________
262 void AliAnalysisMuMuBase::DisableHistograms(const char* pattern)
264 /// Disable the histogramming of all the histograms matching the pattern
266 TString spattern(pattern);
269 delete fHistogramToDisable;
270 fHistogramToDisable = 0x0;
273 if (!fHistogramToDisable)
275 fHistogramToDisable = new TList;
276 fHistogramToDisable->SetOwner(kTRUE);
279 fHistogramToDisable->Add(new TObjString(spattern));
282 //_____________________________________________________________________________
283 Int_t AliAnalysisMuMuBase::GetNbins(Double_t xmin, Double_t xmax, Double_t xstep)
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;
288 return TMath::Nint(TMath::Abs((xmax-xmin)/xstep));
291 //_____________________________________________________________________________
292 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* triggerClassName, const char* histoname)
294 /// Get one histo back
295 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,histoname)) : 0x0;
298 //_____________________________________________________________________________
299 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* histoname)
301 /// Get one histo back
302 return fHistogramCollection ? fHistogramCollection->Histo(eventSelection,histoname) : 0x0;
305 //_____________________________________________________________________________
306 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection,
307 const char* triggerClassName,
309 const char* histoname)
311 /// Get one histo back
312 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,cent),histoname) : 0x0;
315 //_____________________________________________________________________________
316 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection,
317 const char* triggerClassName,
320 const char* histoname)
322 /// Get one histo back
324 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,cent,what),histoname) : 0x0;
327 //_____________________________________________________________________________
328 TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection,
329 const char* histoname)
331 /// Get one histo profile back
333 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s",eventSelection),histoname)) : 0x0;
336 //_____________________________________________________________________________
337 TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection,
338 const char* triggerClassName,
339 const char* histoname)
341 /// Get one histo profile back
343 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s",eventSelection,triggerClassName),histoname)) : 0x0;
346 //_____________________________________________________________________________
347 TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection,
348 const char* triggerClassName,
350 const char* histoname)
352 /// Get one histo profile back
354 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s",eventSelection,triggerClassName,cent),histoname)) : 0x0;
357 //_____________________________________________________________________________
358 TProfile* AliAnalysisMuMuBase::Prof(const char* eventSelection,
359 const char* triggerClassName,
362 const char* histoname)
364 /// Get one histo profile back
366 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,cent,what),histoname)) : 0x0;
369 //_____________________________________________________________________________
370 void AliAnalysisMuMuBase::Init(AliCounterCollection& cc,
371 AliMergeableCollection& hc,
372 const AliAnalysisMuMuBinning& binning,
373 const AliAnalysisMuMuCutRegistry& registry)
375 /// Set the internal references
376 fEventCounters = &cc;
377 fHistogramCollection = &hc;
379 fCutRegistry = ®istry;
382 //_____________________________________________________________________________
383 Bool_t AliAnalysisMuMuBase::IsHistogramDisabled(const char* hname) const
385 /// Whether or not a given histogram (identified by its name)
386 /// is disabled or not
388 if ( !fHistogramToDisable )
392 TString shname(hname);
393 TIter next(fHistogramToDisable);
394 TObjString* str(0x0);
396 while ( ( str = static_cast<TObjString*>(next()) ) )
398 if ( shname.Contains(TRegexp(str->String()) ) )
406 //_____________________________________________________________________________
407 Bool_t AliAnalysisMuMuBase::IsHistogrammingDisabled() const
409 /// Whether or not *all* histograms are disabled
411 if ( fHistogramToDisable && fHistogramToDisable->GetEntries()==1 )
413 TObjString* r = static_cast<TObjString*>(fHistogramToDisable->First());
414 if ( r->String() == "*" )
422 //_____________________________________________________________________________
423 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* triggerClassName, const char* histoname)
425 /// Get one histo back
426 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,histoname)) : 0x0;
429 //_____________________________________________________________________________
430 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* histoname)
432 /// Get one histo back
433 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",MCInputPrefix(),eventSelection,histoname)) : 0x0;
436 //_____________________________________________________________________________
437 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection,
438 const char* triggerClassName,
440 const char* histoname)
442 /// Get one histo back
443 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent),histoname) : 0x0;
446 //_____________________________________________________________________________
447 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection,
448 const char* triggerClassName,
451 const char* histoname)
453 /// Get one histo back
455 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent,what),histoname) : 0x0;
458 //_____________________________________________________________________________
459 TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection,
460 const char* histoname)
462 /// Get one histo profile back
464 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s",MCInputPrefix(),eventSelection),histoname)) : 0x0;
467 //_____________________________________________________________________________
468 TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection,
469 const char* triggerClassName,
470 const char* histoname)
472 /// Get one histo profile back
474 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName),histoname)) : 0x0;
477 //_____________________________________________________________________________
478 TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection,
479 const char* triggerClassName,
481 const char* histoname)
483 /// Get one histo profile back
485 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent),histoname)) : 0x0;
488 //_____________________________________________________________________________
489 TProfile* AliAnalysisMuMuBase::MCProf(const char* eventSelection,
490 const char* triggerClassName,
493 const char* histoname)
495 /// Get one histo profile back
497 return fHistogramCollection ? static_cast<TProfile*>(fHistogramCollection->GetObject(Form("/%s/%s/%s/%s/%s",MCInputPrefix(),eventSelection,triggerClassName,cent,what),histoname)) : 0x0;
500 //_____________________________________________________________________________
501 void AliAnalysisMuMuBase::SetEvent(AliVEvent* event, AliMCEvent* mcEvent)
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