AliPhysics  5a28df1 (5a28df1)
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 
23 ClassImp(AliEmcalList)
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  TString histogram_name (listObject->GetName());
104  if (histogram_name.Contains("fHistXsection") || histogram_name.Contains("fHistTrials") || histogram_name.Contains("fHistEvents"))
105  {
106  AliInfo(Form("Histogram %s will not be scaled, because a scaling histogram", listObject->GetName()));
107  continue;
108  }
109  if (histogram_class.Contains("TProfile"))
110  {
111  AliInfo(Form("Histogram %s will not be scaled, because it is a TProfile", listObject->GetName()));
112  continue;
113  }
114 
115  TH1 *histogram = dynamic_cast<TH1 *>(listObject);
116  if(histogram) {
117  // Handle TH1/TH2/TH3
118  histogram->Sumw2();
119  histogram->Scale(scalingFactor);
120  } else {
121  // Handle THn
122  THnBase *histogramND = dynamic_cast<THnBase *>(listObject);
123  histogramND->Sumw2();
124  histogramND->Scale(scalingFactor);
125  }
126  AliInfo(Form("Histogram %s (%s) was scaled...", listObject->GetName(), histogram_class.Data()));
127 
128  }
129 }
130 
132 //________________________________________________________________________
134 {
135  Int_t binNumber = GetFilledBinNumber(xsection);
136  if(!binNumber)
137  {
138  AliInfo("List already scaled or scaling invalid. Scaling factor = 1.");
139  return 1.0;
140  }
141 
142  Double_t valNTRIALS = ntrials->GetBinContent(binNumber);
143  Double_t valXSEC = xsection->GetBinContent(binNumber);
144  Double_t scalingFactor = 0;
145  if(valNTRIALS)
146  scalingFactor = valXSEC/valNTRIALS;
147 
148  AliInfo(Form("## Bin %i: trials=%f, xsec=%f -> scaling=%f", binNumber, valNTRIALS, valXSEC, scalingFactor));
149  return scalingFactor;
150 }
151 
154 //________________________________________________________________________
156 {
157  // Get the pt hard bin number that is filled in this object
158  TH1* xsection = static_cast<TH1*>(FindObject("fHistXsection"));
159  Int_t binNumberThis = GetFilledBinNumber(xsection);
160 
161  TIter listIterator(collection);
162  while (AliEmcalList* tmpList = static_cast<AliEmcalList*>(listIterator()))
163  {
164  // For every list in the collection, test if they are from different pt hard bins
165  xsection = static_cast<TH1*>(tmpList->FindObject("fHistXsection"));
166  if(binNumberThis != GetFilledBinNumber(xsection))
167  return kTRUE;
168  }
169  return kFALSE;
170 }
171 
175 //________________________________________________________________________
177 {
178  AliInfo(Form("%s: nbinsX=%i", hist->GetName(), hist->GetNbinsX()));
179 
180  Int_t binFound = 0;
181  for(Int_t i=1; i<=hist->GetNbinsX(); i++)
182  {
183  AliInfo(Form("%s: bin=%i, val=%f", hist->GetName(), i, hist->GetBinContent(i)));
184  if(hist->GetBinContent(i))
185  {
186  if(!binFound)
187  binFound = i;
188  else
189  {
190  return 0; // more than one bin filled (e.g. when merging is partly done)
191  }
192  }
193  }
194 
195  if(!binFound)
196  AliError("No bin filled in scaling histogram.");
197 
198  // 0 if no bin found or more than one filled, otherwise returns bin number
199  return binFound;
200 }
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:41
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
bool Bool_t
Definition: External.C:53
Definition: External.C:196