AliPhysics  32b88a8 (32b88a8)
 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 "AliLog.h"
19 #include "AliEmcalList.h"
20 
24 
25 //________________________________________________________________________
26 AliEmcalList::AliEmcalList() : TList(), fUseScaling(kFALSE)
27 {
28  // constructor
29 }
30 
32 //________________________________________________________________________
34 {
35  if(!hlist)
36  return 0;
37 
38  AliInfo(Form("Scaled merging for list %s is %sactivated.", hlist->GetName(),(fUseScaling) ? "" : "not "));
39  if(!fUseScaling)
40  return TList::Merge(hlist);
41 
42  // #### Retrieve xsection and ntrials from histograms in this list
43  // NOTE: they must be directly added to the AliEmcalList, not nested in sublists!
44  TH1* xsection = static_cast<TH1*>(FindObject("fHistXsection"));
45  TH1* ntrials = static_cast<TH1*>(FindObject("fHistTrials"));
46 
47  // #### If xsection or ntrials are not given, go to fatal
48  if(!(xsection && ntrials))
49  AliFatal("Scaled merging is active but AliEmcalList does not contain fHistXsection or fHistTrials. Do not activate scaling for those lists or include these histograms.");
50 
51  // #### Do the scaling only on the last level when we mix several pt hard bins
52  // This is easy to find out checking the std histos in hlist
53  Bool_t isLastLevel = IsLastMergeLevel(hlist);
54 
55  // #### On last level, do the scaling
56  if(isLastLevel)
57  {
58  AliInfo(Form("===== LAST LEVEL OF MERGING ====="));
59 
60  // Scale all histograms in this list
61  Double_t scalingFactor = GetScalingFactor(xsection, ntrials);
62  ScaleAllHistograms(this, scalingFactor);
63 
64  // Scale all histograms in the lists to be merged
65  TIter listIterator(hlist);
66  while (AliEmcalList* tmpList = static_cast<AliEmcalList*>(listIterator()))
67  {
68  xsection = static_cast<TH1*>(tmpList->FindObject("fHistXsection"));
69  ntrials = static_cast<TH1*>(tmpList->FindObject("fHistTrials"));
70  scalingFactor = GetScalingFactor(xsection, ntrials);
71  ScaleAllHistograms(tmpList, scalingFactor);
72  }
73  }
74 
75  AliInfo("Merge() done.");
76 
77  TList::Merge(hlist);
78  return hlist->GetEntries() + 1;
79 }
80 
82 //________________________________________________________________________
84 {
85  TIter listIterator(hlist);
86  while (TObject* listObject = listIterator())
87  {
88  // Recurse into nested all lists
89  TCollection* sublist = dynamic_cast<TCollection*>(listObject);
90  if(sublist)
91  {
92  ScaleAllHistograms(sublist, scalingFactor);
93  continue;
94  }
95 
96  // Otherwise, scale TH1-derived histograms
97  TH1* histogram = dynamic_cast<TH1*>(listObject);
98  if (!histogram)
99  continue;
100 
101  // Don't scale profiles and histograms used for scaling
102  TString histogram_class (histogram->ClassName());
103  if (!strcmp(histogram->GetName(), "fHistXsection") || !strcmp(histogram->GetName(), "fHistTrials"))
104  {
105  AliInfo(Form("Histogram %s will not be scaled, because a scaling histogram", histogram->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", histogram->GetName()));
111  continue;
112  }
113 
114  histogram->Sumw2();
115  histogram->Scale(scalingFactor);
116  AliInfo(Form("Histogram %s (%s) was scaled...", histogram->GetName(), histogram_class.Data()));
117 
118  }
119 }
120 
122 //________________________________________________________________________
124 {
125  Int_t binNumber = GetFilledBinNumber(xsection);
126  if(!binNumber)
127  {
128  AliInfo("List already scaled or scaling invalid. Scaling factor = 1.");
129  return 1.0;
130  }
131 
132  Double_t valNTRIALS = ntrials->GetBinContent(binNumber);
133  Double_t valXSEC = xsection->GetBinContent(binNumber);
134  Double_t scalingFactor = 0;
135  if(valNTRIALS)
136  scalingFactor = valXSEC/valNTRIALS;
137 
138  AliInfo(Form("## Bin %i: trials=%f, xsec=%f -> scaling=%f", binNumber, valNTRIALS, valXSEC, scalingFactor));
139  return scalingFactor;
140 }
141 
144 //________________________________________________________________________
146 {
147  // Get the pt hard bin number that is filled in this object
148  TH1* xsection = static_cast<TH1*>(FindObject("fHistXsection"));
149  Int_t binNumberThis = GetFilledBinNumber(xsection);
150 
151  TIter listIterator(collection);
152  while (AliEmcalList* tmpList = static_cast<AliEmcalList*>(listIterator()))
153  {
154  // For every list in the collection, test if they are from different pt hard bins
155  xsection = static_cast<TH1*>(tmpList->FindObject("fHistXsection"));
156  if(binNumberThis != GetFilledBinNumber(xsection))
157  return kTRUE;
158  }
159  return kFALSE;
160 }
161 
165 //________________________________________________________________________
167 {
168  AliInfo(Form("%s: nbinsX=%i", hist->GetName(), hist->GetNbinsX()));
169 
170  Int_t binFound = 0;
171  for(Int_t i=1; i<=hist->GetNbinsX(); i++)
172  {
173  AliInfo(Form("%s: bin=%i, val=%f", hist->GetName(), i, hist->GetBinContent(i)));
174  if(hist->GetBinContent(i))
175  {
176  if(!binFound)
177  binFound = i;
178  else
179  {
180  return 0; // more than one bin filled (e.g. when merging is partly done)
181  }
182  }
183  }
184 
185  if(!binFound)
186  AliError("No bin filled in scaling histogram.");
187 
188  // 0 if no bin found or more than one filled, otherwise returns bin number
189  return binFound;
190 }
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:38
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:23
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
bool Bool_t
Definition: External.C:53
Definition: External.C:196