DAS  3.0
Das Analysis System
DAS::Unfolding::ExtractHistogram Namespace Reference

Classes

struct  Dist
 
struct  Matrix
 

Functions

template<typename T >
void nodeLoop (TDirectory *dOut, TUnfoldBinning *binning, T t, ostream &cout, TString name, int depth)
 
template<typename T >
void axisLoop (TDirectory *dOut, TUnfoldBinning *node, T t, ostream &cout, vector< int > ibins, int shift, TString name="", TString title="")
 

Detailed Description

Two functors and two functions to extract the distributions and matrices with physical axes from bin IDs.

The two functions allow to loop over

  • the nodes of a global binning
  • and the axes, regardless of the dimensionality.

The two functors are similar:

  • the first one just handles 1D distribution, and is a bit trivial, but necessary to allow the second one;
  • the second one can keep in memory the result of the loops on the first axis and triggers a secound round of loops for the second axis.

Function Documentation

◆ axisLoop()

void DAS::Unfolding::ExtractHistogram::axisLoop ( TDirectory *  dOut,
TUnfoldBinning *  node,
t,
ostream &  cout,
vector< int >  ibins,
int  shift,
TString  name = "",
TString  title = "" 
)

Loop on the axes of the node of a given binning.

< either Dist or Matrix

Parameters
dOutoutput directory
nodechild node
texpecting either a `Dist` or a `Matrix` object
coutstandard output
ibinsglobal bin IDs of present iteration
shiftshift to continue the bin index despite the change of node/binning
150 {
151  int iaxis = count_if(next(begin(ibins)), end(ibins),
152  [](int ibin) { return ibin == 0; });
153  int& ibin = ibins[iaxis];
154  assert(ibin == 0);
155  if (iaxis > 0) {
156  TString axisname = node->GetDistributionAxisLabel(iaxis);
157  cout << "\t\taxis `" << axisname << "`" << endl;
158  name += "_" + axisname + "bin";
159  const TVectorD * edges = node->GetDistributionBinning(iaxis);
160  for (ibin = 1; ibin < edges->GetNrows(); ++ibin) {
161  TString nameExt = name + (ibin + shift),
162  titleExt = title + Form("[%f, %f] ", (*edges)[ibin-1], (*edges)[ibin]);
163  axisLoop(dOut, node, t, cout, ibins, shift, nameExt, titleExt);
164  }
165  }
166  else {
167  cout << "\t\t\tpreparing `" << name << "`" << endl;
168  size_t naxes = ibins.size();
169  vector<double> x(naxes);
170  for (size_t jaxis = 1; jaxis < naxes; ++jaxis) {
171  const TVectorD * edges = node->GetDistributionBinning(jaxis);
172  int ibin = ibins[jaxis];
173  assert(ibin > 0);
174  x[jaxis] = (*edges)[ibin-1]; // vector component (hist bin) index starts from 0 (1)
175  }
176 
177  if constexpr (is_same_v<T,Dist>)
178  t(dOut, name, node, x, title);
179  else if constexpr (is_same_v<T,Matrix>) {
180  if (t.node1 == nullptr) {
181  t.name1 = name;
182  t.node1 = node;
183  t.ibins1 = ibins;
184  t.x1 = x;
185  t.title1 = title;
186  nodeLoop<T>(dOut, t.binning2, t, cout);
187  }
188  else
189  t(dOut, name, node, x, title);
190  }
191  else {
192  cerr << red << "Unexpected type. Skipping.\n" << def;
193  return;
194  }
195  }
196 }

◆ nodeLoop()

void nodeLoop ( TDirectory *  dOut,
TUnfoldBinning *  binning,
t,
ostream &  cout,
TString  name,
int  depth 
)

Loop on the nodes of a given binning.

< either Dist or Matrix

Todo:
d > 2?
Todo:
d > 2?
Parameters
dOutoutput directory
binningglobal binning or parent node
texpecting either a `Dist` or a `Matrix` object
coutstandard output
namename of output directory
depthtrick to know the number of recursive calls
207 {
208  int shift = 0;
209  for (auto node = binning->GetChildNode(); node != nullptr;
210  node = node->GetNextNode()) {
211  TString dirname = name + node->GetName();
212  if (node->GetDistributionNumberOfBins() == 0) {
213  nodeLoop(dOut, node, t, cout, dirname, depth+1);
214  continue;
215  }
216  cout << "\tnode `" << dirname << "`" << endl;
217  auto ddOut = dOut->mkdir(dirname, node->GetTitle(), true /* = `-p` */);
218  ddOut->cd();
219 
220  int dim = node->GetDistributionDimension();
221  TString axisname = node->GetDistributionAxisLabel(0);
222  axisLoop<T>(ddOut, node, t, cout, vector<int>(dim,0), shift, axisname);
223  if (depth > 1) { // NOTE: this logic is tuned for dijet mass, with different resolution in central and forward regions
224  const TVectorD * edges = node->GetDistributionBinning(1 );
225  shift += edges->GetNrows()-1;
226  }
227  } // end of loop on nodes
228 }
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
Step::def
static const char * def
Definition: Step.h:36
DAS::Unfolding::ExtractHistogram::axisLoop
void axisLoop(TDirectory *dOut, TUnfoldBinning *node, T t, ostream &cout, vector< int > ibins, int shift, TString name="", TString title="")
Loop on the axes of the node of a given binning.
Definition: getUnfPhysDist.cc:142
Step::red
static const char * red
Definition: Step.h:34
DAS::Unfolding::ExtractHistogram::nodeLoop
void nodeLoop(TDirectory *, TUnfoldBinning *, T, ostream &, TString="", int=1)
Loop on the nodes of a given binning.
Definition: getUnfPhysDist.cc:201