AliPhysics  15d9304 (15d9304)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalList.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: R. Haake *
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 #include "TList.h"
17 #include "TH1.h"
18 #include "THnBase.h"
19 #include "AliLog.h"
20 #include "AliEmcalList.h"
21 
25 
26 //________________________________________________________________________
27 AliEmcalList::AliEmcalList() : TList(), fUseScaling(kFALSE)
28 {
29  // constructor
30 }
31 
33 //________________________________________________________________________
35 {
36  if(!hlist)
37  return 0;
38 
39  AliInfo(Form("Scaled merging for list %s is %sactivated.", hlist->GetName(),(fUseScaling) ? "" : "not "));
40  if(!fUseScaling)
41  return TList::Merge(hlist);
42 
43  // #### Retrieve xsection and ntrials from histograms in this list
44  // NOTE: they must be directly added to the AliEmcalList, not nested in sublists!
45  TH1* xsection = static_cast<TH1*>(FindObject("fHistXsection"));
46  TH1* ntrials = static_cast<TH1*>(FindObject("fHistTrials"));
47 
48  // #### If xsection or ntrials are not given, go to fatal
49  if(!(xsection && ntrials))
50  AliFatal("Scaled merging is active but AliEmcalList does not contain fHistXsection or fHistTrials. Do not activate scaling for those lists or include these histograms.");
51 
52  // #### Do the scaling only on the last level when we mix several pt hard bins
53  // This is easy to find out checking the std histos in hlist
54  Bool_t isLastLevel = IsLastMergeLevel(hlist);
55 
56  // #### On last level, do the scaling
57  if(isLastLevel)
58  {
59  AliInfo(Form("===== LAST LEVEL OF MERGING ====="));
60 
61  // Scale all histograms in this list
62  Double_t scalingFactor = GetScalingFactor(xsection, ntrials);
63  ScaleAllHistograms(this, scalingFactor);
64 
65  // Scale all histograms in the lists to be merged
66  TIter listIterator(hlist);
67  while (AliEmcalList* tmpList = static_cast<AliEmcalList*>(listIterator()))
68  {
69  xsection = static_cast<TH1*>(tmpList->FindObject("fHistXsection"));
70  ntrials = static_cast<TH1*>(tmpList->FindObject("fHistTrials"));
71  scalingFactor = GetScalingFactor(xsection, ntrials);
72  ScaleAllHistograms(tmpList, scalingFactor);
73  }
74  }
75 
76  AliInfo("Merge() done.");
77 
78  TList::Merge(hlist);
79  return hlist->GetEntries() + 1;
80 }
81 
83 //________________________________________________________________________
85 {
86  TIter listIterator(hlist);
87  while (TObject* listObject = listIterator())
88  {
89  // Recurse into nested all lists
90  TCollection* sublist = dynamic_cast<TCollection*>(listObject);
91  if(sublist)
92  {
93  ScaleAllHistograms(sublist, scalingFactor);
94  continue;
95  }
96 
97  // Otherwise, scale TH1-derived / THnBase-derived histograms
98  if (!(listObject->InheritsFrom(TH1::Class()) || listObject->InheritsFrom(THnBase::Class())))
99  continue;
100 
101  // Don't scale profiles and histograms used for scaling
102  TString histogram_class (listObject->ClassName());
103  if (!strcmp(listObject->GetName(), "fHistXsection") || !strcmp(listObject->GetName(), "fHistTrials"))
104  {
105  AliInfo(Form("Histogram %s will not be scaled, because a scaling histogram", listObject->GetName()));
106  continue;
107  }
108  if (histogram_class.Contains("TProfile"))
109  {
110  AliInfo(Form("Histogram %s will not be scaled, because it is a TProfile", listObject->GetName()));
111  continue;
112  }
113 
114  TH1 *histogram = dynamic_cast<TH1 *>(listObject);
115  if(histogram) {
116  // Handle TH1/TH2/TH3
117  histogram->Sumw2();
118  histogram->Scale(scalingFactor);
119  } else {
120  // Handle THn
121  THnBase *histogramND = dynamic_cast<THnBase *>(listObject);
122  histogramND->Sumw2();
123  histogramND->Scale(scalingFactor);
124  }
125  AliInfo(Form("Histogram %s (%s) was scaled...", listObject->GetName(), histogram_class.Data()));
126 
127  }
128 }
129 
131 //________________________________________________________________________
133 {
134  Int_t binNumber = GetFilledBinNumber(xsection);
135  if(!binNumber)
136  {
137  AliInfo("List already scaled or scaling invalid. Scaling factor = 1.");
138  return 1.0;
139  }
140 
141  Double_t valNTRIALS = ntrials->GetBinContent(binNumber);
142  Double_t valXSEC = xsection->GetBinContent(binNumber);
143  Double_t scalingFactor = 0;
144  if(valNTRIALS)
145  scalingFactor = valXSEC/valNTRIALS;
146 
147  AliInfo(Form("## Bin %i: trials=%f, xsec=%f -> scaling=%f", binNumber, valNTRIALS, valXSEC, scalingFactor));
148  return scalingFactor;
149 }
150 
153 //________________________________________________________________________
155 {
156  // Get the pt hard bin number that is filled in this object
157  TH1* xsection = static_cast<TH1*>(FindObject("fHistXsection"));
158  Int_t binNumberThis = GetFilledBinNumber(xsection);
159 
160  TIter listIterator(collection);
161  while (AliEmcalList* tmpList = static_cast<AliEmcalList*>(listIterator()))
162  {
163  // For every list in the collection, test if they are from different pt hard bins
164  xsection = static_cast<TH1*>(tmpList->FindObject("fHistXsection"));
165  if(binNumberThis != GetFilledBinNumber(xsection))
166  return kTRUE;
167  }
168  return kFALSE;
169 }
170 
174 //________________________________________________________________________
176 {
177  AliInfo(Form("%s: nbinsX=%i", hist->GetName(), hist->GetNbinsX()));
178 
179  Int_t binFound = 0;
180  for(Int_t i=1; i<=hist->GetNbinsX(); i++)
181  {
182  AliInfo(Form("%s: bin=%i, val=%f", hist->GetName(), i, hist->GetBinContent(i)));
183  if(hist->GetBinContent(i))
184  {
185  if(!binFound)
186  binFound = i;
187  else
188  {
189  return 0; // more than one bin filled (e.g. when merging is partly done)
190  }
191  }
192  }
193 
194  if(!binFound)
195  AliError("No bin filled in scaling histogram.");
196 
197  // 0 if no bin found or more than one filled, otherwise returns bin number
198  return binFound;
199 }
double Double_t
Definition: External.C:58
Bool_t fUseScaling
if true, scaling will be done. if false AliEmcalList simplifies to TList
Definition: AliEmcalList.h:40
long long Long64_t
Definition: External.C:43
Int_t GetFilledBinNumber(TH1 *hist)
void ScaleAllHistograms(TCollection *hlist, Double_t scalingFactor)
Function that does the scaling of all histograms in hlist recursively.
int Int_t
Definition: External.C:63
Bool_t IsLastMergeLevel(TCollection *collection)
Double_t GetScalingFactor(TH1 *xsection, TH1 *ntrials)
Helper function scaling factor.
Long64_t Merge(TCollection *hlist)
Overridden Merge function.
TH1 * Merge(const TH1 *cen, const TH1 *fwd, Double_t &xlow, Double_t &xhigh)
TObject * FindObject(int bin, const char *nameH, const TList *lst, Bool_t normPerEvent=kTRUE)
Enhanced TList-derived class that implements correct merging for pt_hard binned production.
Definition: AliEmcalList.h:25
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
bool Bool_t
Definition: External.C:53
Definition: External.C:196