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)
62 const char* MCINPUTPREFIX = "MCINPUT";
65 //_____________________________________________________________________________
66 AliAnalysisMuMuBase::AliAnalysisMuMuBase()
70 fHistogramCollection(0x0),
75 fHistogramToDisable(0x0),
81 //_____________________________________________________________________________
83 AliAnalysisMuMuBase::CreateEventHistos(UInt_t dataType,
85 const char* hname, const char* htitle,
86 Int_t nbinsx, Double_t xmin, Double_t xmax,
87 Int_t nbinsy, Double_t ymin, Double_t ymax) const
89 /** Append histograms at the event level. Depending on dataType the created histograms
90 * are for real data only, MC data only, or both
93 if ( IsHistogramDisabled(hname) ) return;
96 pathNames.SetOwner(kTRUE);
98 if ( dataType & kHistoForData )
100 pathNames.Add(new TObjString(Form("/%s",what)));
102 if ( ( dataType & kHistoForMCInput ) && HasMC() )
104 pathNames.Add(new TObjString(Form("/%s/%s",MCINPUTPREFIX,what)));
107 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
110 //_____________________________________________________________________________
112 AliAnalysisMuMuBase::CreateEventHistos(UInt_t dataType,
113 const char* eventSelection,
114 const char* triggerClassName,
115 const char* centrality,
116 const char* hname, const char* htitle,
117 Int_t nbinsx, Double_t xmin, Double_t xmax,
118 Int_t nbinsy, Double_t ymin, Double_t ymax) const
120 /** Append histograms at the event level. Depending on dataType the created histograms
121 * are for real data only, MC data only, or both
124 if ( IsHistogramDisabled(hname) ) return;
127 pathNames.SetOwner(kTRUE);
129 if ( dataType & kHistoForData )
131 pathNames.Add(new TObjString(Form("/%s/%s/%s",eventSelection,triggerClassName,centrality)));
133 if ( ( dataType & kHistoForMCInput ) && HasMC() )
135 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",MCINPUTPREFIX,eventSelection,triggerClassName,centrality)));
138 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
141 //_____________________________________________________________________________
143 AliAnalysisMuMuBase::CreateHistos(const TObjArray& paths,
144 const char* hname, const char* htitle,
145 Int_t nbinsx, Double_t xmin, Double_t xmax,
146 Int_t nbinsy, Double_t ymin, Double_t ymax) const
148 /// Create multiple copies of histogram hname, one per path
150 if ( IsHistogramDisabled(hname) ) return;
152 StdoutToAliDebug(1,paths.Print(););
155 TObjString* pathName;
157 while ( ( pathName = static_cast<TObjString*>(next()) ) )
163 AliDebug(1,Form("Created TH2F %s/%s",pathName->String().Data(),hname));
164 h = new TH2F(hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
166 else if ( nbinsy == 0 )
168 AliDebug(1,Form("Created TProfile %s/%s",pathName->String().Data(),hname));
169 h = new TProfile(hname,htitle,nbinsx,xmin,xmax,ymin,ymax);
174 AliDebug(1,Form("Created TH1F %s/%s",pathName->String().Data(),hname));
175 h = new TH1F(hname,htitle,nbinsx,xmin,xmax);
183 HistogramCollection()->Adopt(pathName->String().Data(),h);
186 StdoutToAliDebug(1,HistogramCollection()->Print("*"););
189 //_____________________________________________________________________________
191 AliAnalysisMuMuBase::CreateTrackHistos(const char* eventSelection,
192 const char* triggerClassName,
193 const char* centrality,
194 const char* hname, const char* htitle,
195 Int_t nbinsx, Double_t xmin, Double_t xmax,
196 Int_t nbinsy, Double_t ymin, Double_t ymax) const
198 /// Create n copies of an histogram (with name=hname, title=htitle, etc..)
199 /// where n = # of track cut combinations defined
200 /// see also CreateHistos
203 if ( IsHistogramDisabled(hname) ) return;
206 pathNames.SetOwner(kTRUE);
208 TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrack));
209 AliAnalysisMuMuCutCombination* cutCombination;
211 while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) )
213 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName())));
216 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
219 //_____________________________________________________________________________
221 AliAnalysisMuMuBase::CreatePairHistos(const char* eventSelection,
222 const char* triggerClassName,
223 const char* centrality,
224 const char* hname, const char* htitle,
225 Int_t nbinsx, Double_t xmin, Double_t xmax,
226 Int_t nbinsy, Double_t ymin, Double_t ymax) const
228 /// Create n copies of an histogram (with name=hname, title=htitle, etc..)
229 /// where n = # of track *pair* cut combinations defined
230 /// see also CreateHistos
233 if ( IsHistogramDisabled(hname) ) return;
236 pathNames.SetOwner(kTRUE);
238 TIter nextCutCombination(CutRegistry()->GetCutCombinations(AliAnalysisMuMuCutElement::kTrackPair));
239 AliAnalysisMuMuCutCombination* cutCombination;
241 while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(nextCutCombination())) )
243 pathNames.Add(new TObjString(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,centrality,cutCombination->GetName())));
246 CreateHistos(pathNames,hname,htitle,nbinsx,xmin,xmax,nbinsy,ymin,ymax);
249 //_____________________________________________________________________________
250 void AliAnalysisMuMuBase::DisableHistograms(const char* pattern)
252 /// Disable the histogramming of all the histograms matching the pattern
254 TString spattern(pattern);
257 delete fHistogramToDisable;
258 fHistogramToDisable = 0x0;
261 if (!fHistogramToDisable)
263 fHistogramToDisable = new TList;
264 fHistogramToDisable->SetOwner(kTRUE);
267 fHistogramToDisable->Add(new TObjString(spattern));
270 //_____________________________________________________________________________
271 Int_t AliAnalysisMuMuBase::GetNbins(Double_t xmin, Double_t xmax, Double_t xstep)
273 /// Compute number of bins to get a given step between each values in the xmin,xmax range
274 if ( TMath::AreEqualRel(xstep,0.0,1E-9) ) return 1;
276 return TMath::Nint(TMath::Abs((xmax-xmin)/xstep));
279 //_____________________________________________________________________________
280 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* triggerClassName, const char* histoname)
282 /// Get one histo back
283 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,histoname)) : 0x0;
286 //_____________________________________________________________________________
287 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection, const char* histoname)
289 /// Get one histo back
290 return fHistogramCollection ? fHistogramCollection->Histo(eventSelection,histoname) : 0x0;
293 //_____________________________________________________________________________
294 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection,
295 const char* triggerClassName,
297 const char* histoname)
299 /// Get one histo back
300 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",eventSelection,triggerClassName,cent),histoname) : 0x0;
303 //_____________________________________________________________________________
304 TH1* AliAnalysisMuMuBase::Histo(const char* eventSelection,
305 const char* triggerClassName,
308 const char* histoname)
310 /// Get one histo back
312 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",eventSelection,triggerClassName,cent,what),histoname) : 0x0;
315 //_____________________________________________________________________________
316 void AliAnalysisMuMuBase::Init(AliCounterCollection& cc,
317 AliMergeableCollection& hc,
318 const AliAnalysisMuMuBinning& binning,
319 const AliAnalysisMuMuCutRegistry& registry)
321 /// Set the internal references
322 fEventCounters = &cc;
323 fHistogramCollection = &hc;
325 fCutRegistry = ®istry;
328 //_____________________________________________________________________________
329 Bool_t AliAnalysisMuMuBase::IsHistogramDisabled(const char* hname) const
331 /// Whether or not a given histogram (identified by its name)
332 /// is disabled or not
334 if ( !fHistogramToDisable )
338 TString shname(hname);
339 TIter next(fHistogramToDisable);
340 TObjString* str(0x0);
342 while ( ( str = static_cast<TObjString*>(next()) ) )
344 if ( shname.Contains(TRegexp(str->String()) ) )
352 //_____________________________________________________________________________
353 Bool_t AliAnalysisMuMuBase::IsHistogrammingDisabled() const
355 /// Whether or not *all* histograms are disabled
357 if ( fHistogramToDisable && fHistogramToDisable->GetEntries()==1 )
359 TObjString* r = static_cast<TObjString*>(fHistogramToDisable->First());
360 if ( r->String() == "*" )
368 //_____________________________________________________________________________
369 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* triggerClassName, const char* histoname)
371 /// Get one histo back
372 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCINPUTPREFIX,eventSelection,triggerClassName,histoname)) : 0x0;
375 //_____________________________________________________________________________
376 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection, const char* histoname)
378 /// Get one histo back
379 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s",MCINPUTPREFIX,eventSelection,histoname)) : 0x0;
382 //_____________________________________________________________________________
383 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection,
384 const char* triggerClassName,
386 const char* histoname)
388 /// Get one histo back
389 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s",MCINPUTPREFIX,eventSelection,triggerClassName,cent),histoname) : 0x0;
392 //_____________________________________________________________________________
393 TH1* AliAnalysisMuMuBase::MCHisto(const char* eventSelection,
394 const char* triggerClassName,
397 const char* histoname)
399 /// Get one histo back
401 return fHistogramCollection ? fHistogramCollection->Histo(Form("/%s/%s/%s/%s/%s",MCINPUTPREFIX,eventSelection,triggerClassName,cent,what),histoname) : 0x0;
404 //_____________________________________________________________________________
405 void AliAnalysisMuMuBase::SetEvent(AliVEvent* event, AliMCEvent* mcEvent)
407 /// Set pointers to event (and mcEvent)
408 /// This is the place where a sub analysis might (if really needed)
409 /// append things to the event. Please DO NOT alter the original content,
410 /// only add to it. Unless of course you want to shoot yourself in the