DAS  3.0
Das Analysis System
DAS::Photon Namespace Reference

Classes

class  ConversionVetoApplier
 
class  IDApplier
 
struct  PerformanceHist
 

Functions

void applyPhotonConversionVeto (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
void applyPhotonID (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
void Fill (const GenPhoton &genPhoton, const vector< RecPhoton > &recPhotons, const float minPt, const float minAbsEta, const float maxAbsEta, const double w_gen_ev, const double w_rec_ev, map< TString, PerformanceHist > &histograms, TString region, TEfficiency &eff_pt)
 
void getPhotonSpectrum (const vector< fs::path > &inputs, const fs::path &output, const int steering, const DT::Slice slice={1, 0})
 

Function Documentation

◆ applyPhotonConversionVeto()

void DAS::Photon::applyPhotonConversionVeto ( const vector< fs::path > &  inputs,
const fs::path &  output,
const pt::ptree &  config,
const int  steering,
const DT::Slice  slice = {1,0} 
)

Applies one of the photon conversion veto and (optionally) scale factors.

This function fetches the scale factor for the ID cut previously applied using applyPhotonID (automatically retrieved from the metainfo).

Todo:
ControlPlots
Parameters
inputsinput ROOT files (n-tuples)
outputoutput ROOT file (n-tuple)
configconfig handled with `Darwin::Tools::options`
steeringparameters obtained from explicit options
slicenumber and index of slice
120  {1,0}
121  )
122 {
123  cout << __func__ << ' ' << slice << " start" << endl;
124 
125  DT::Flow flow(steering);
126  auto tIn = flow.GetInputTree(inputs, slice);
127  auto tOut = flow.GetOutputTree(output);
128 
129  DT::MetaInfo metainfo(tOut);
130  metainfo.Check(config);
131 
132  auto recPhotons = flow.GetBranchReadWrite<vector<RecPhoton>>("recPhotons");
133 
134  auto ID = metainfo.Get<string>("corrections", "photons", "ID", "WP");
135  auto table = config.get<fs::path>("corrections.photons.conversion_veto.table");
136  auto type = config.get<string>("corrections.photons.conversion_veto.type");
137  metainfo.Set<string>("corrections", "photons", "conversion_veto", "type", type);
138  metainfo.Set<fs::path>("corrections", "photons", "conversion_veto", "table", table);
139 
140  ConversionVetoApplier applier(table, ID, table != "/dev/null",
141  steering & DT::syst, type);
142  for (const auto& name: applier.weightNames())
143  metainfo.Set<string>("variations", RecPhoton::WeightVar, name);
144 
146 
147  for (DT::Looper looper(tIn); looper(); ++looper) {
148  [[ maybe_unused]]
149  static auto& cout = steering & DT::verbose ? ::cout : DT::dev_null;
150 
151  applier(*recPhotons);
152 
153  if (steering & DT::fill) tOut->Fill();
154  }
155 
156  metainfo.Set<bool>("git", "complete", true);
157 
158  cout << __func__ << ' ' << slice << " stop" << endl;
159 }

◆ applyPhotonID()

void DAS::Photon::applyPhotonID ( const vector< fs::path > &  inputs,
const fs::path &  output,
const pt::ptree &  config,
const int  steering,
const DT::Slice  slice = {1,0} 
)
Todo:
ControlPlots
Parameters
inputsinput ROOT files (n-tuples)
outputoutput ROOT file (n-tuple)
configconfig handled with `Darwin::Tools::options`
steeringparameters obtained from explicit options
slicenumber and index of slice
100  {1,0}
101  )
102 {
103  cout << __func__ << ' ' << slice << " start" << endl;
104 
105  DT::Flow flow(steering);
106  auto tIn = flow.GetInputTree(inputs, slice);
107  auto tOut = flow.GetOutputTree(output);
108 
109  DT::MetaInfo metainfo(tOut);
110  metainfo.Check(config);
111 
112  auto recPhotons = flow.GetBranchReadWrite<vector<RecPhoton>>("recPhotons");
113 
114  auto ID = config.get<string>("corrections.photons.ID.WP");
115  auto path = config.get<fs::path>("corrections.photons.ID.table");
116  metainfo.Set<string>("corrections", "photons", "ID", "WP", ID);
117  metainfo.Set<fs::path>("corrections", "photons", "ID", "table", path);
118  IDApplier applier(path, ID, path != "/dev/null", steering & DT::syst);
119  for (const auto& name: applier.weightNames())
120  metainfo.Set<string>("variations", RecPhoton::WeightVar, name);
121 
123 
124  for (DT::Looper looper(tIn); looper(); ++looper) {
125  [[ maybe_unused]]
126  static auto& cout = steering & DT::verbose ? ::cout : DT::dev_null;
127 
128  applier(*recPhotons);
129 
130  if (steering & DT::fill) tOut->Fill();
131  }
132 
133  metainfo.Set<bool>("git", "complete", true);
134 
135  cout << __func__ << ' ' << slice << " stop" << endl;
136 }

◆ Fill()

void DAS::Photon::Fill ( const GenPhoton genPhoton,
const vector< RecPhoton > &  recPhotons,
const float  minPt,
const float  minAbsEta,
const float  maxAbsEta,
const double  w_gen_ev,
const double  w_rec_ev,
map< TString, PerformanceHist > &  histograms,
TString  region,
TEfficiency &  eff_pt 
)
82 {
83  double w_gen_ph = genPhoton.weights.front();
84  // Fill histograms for generated photon
85  histograms.at(region + "_gen").Fill(genPhoton, w_gen_ev * w_gen_ph);
86 
87  const float maxDr = 0.1;
88  bool matched = false;
89  // Loop over the reco photons
90  for (const auto& recPhoton: recPhotons) {
91  if (recPhoton.CorrP4().Pt() < minPt) continue;
92  if (abs(recPhoton.CorrP4().Eta()) > maxAbsEta) continue;
93  if (abs(recPhoton.CorrP4().Eta()) < minAbsEta) continue;
94 
95  // Calculate weight for the reconstructed photon
96  double w_rec_ph = recPhoton.weights.front();
97 
98  // Fill histograms for reconstructed photon
99  histograms.at(region + "_rec").Fill(recPhoton, w_gen_ev*w_rec_ev*w_rec_ph);
100 
101  // Matching criterion (dR < maxDr)
102  if (DeltaR(recPhoton.CorrP4(), genPhoton.CorrP4()) > maxDr) continue;
103 
104  // Fill histograms for matched photon
105  histograms.at("matched_" + region + "_rec").Fill(recPhoton, w_gen_ev * w_rec_ev* w_rec_ph);
106  histograms.at("matched_" + region + "_gen").Fill(genPhoton, w_gen_ev * w_gen_ph); // \todo Use rec-level weight? (depends what we want to do with this histogram)
107 
108  matched = true;
109  break;
110  }
111 
112  eff_pt.FillWeighted(matched, w_gen_ph, genPhoton.CorrPt());
113 }

◆ getPhotonSpectrum()

void DAS::Photon::getPhotonSpectrum ( const vector< fs::path > &  inputs,
const fs::path &  output,
const int  steering,
const DT::Slice  slice = {1, 0} 
)

Obtain photon plots.

Parameters
inputsinput ROOT files (n-tuples)
outputoutput ROOT file (n-tuple)
steeringparameters obtained from explicit options
slicenumber and index of slice
121  {1, 0}
122 ) {
123  cout << __func__ << ' ' << slice << " start" << endl;
124 
125  DT::Flow flow(steering);
126  auto tIn = flow.GetInputTree(inputs, slice);
127  auto [fOut,tOut] = flow.GetOutput(output);
128 
129  DT::MetaInfo metainfo(tOut);
130  auto isMC = metainfo.Get<bool>("flags", "isMC");
131  if (!isMC)
132  BOOST_THROW_EXCEPTION( invalid_argument("Only for MC samples") );
133 
134  auto recEvt = flow.GetBranchReadOnly<RecEvent>("recEvent");
135  auto genEvt = flow.GetBranchReadOnly<GenEvent>("genEvent");
136 
137  auto recPhotons = flow.GetBranchReadOnly<vector<RecPhoton>>("recPhotons");
138  auto genPhotons = flow.GetBranchReadOnly<vector<GenPhoton>>("genPhotons");
139 
140  map<TString, PerformanceHist> histograms;
141  for (TString level: {"rec", "gen"})
142  for (TString region: {"barrel", "endcaps"}) {
143  TString name = region + '_' + level;
144  histograms.insert({name, PerformanceHist(name)});
145  name = "matched_" + name;
146  histograms.insert({name, PerformanceHist(name)});
147  }
148 
149  vector<double> eff_binning {0, 10, 20, 35, 50, 65, 80, 100, 120, 150, 200, 500};
150  TEfficiency barrel_eff_pt("barrel_eff_pt", "", eff_binning.size()-1, eff_binning.data()),
151  endcaps_eff_pt("endcaps_eff_pt", "", eff_binning.size()-1, eff_binning.data());
152 
153  for (DT::Looper looper(tIn); looper(); ++looper) {
154  [[maybe_unused]]
155  static auto& cout = steering & DT::verbose ? ::cout : DT::dev_null;
156 
157  // Loop over the gen photons first!
158  for (const auto& genPhoton : *genPhotons) {
159  const float maxBarrelAbsEta = 1.48,
160  maxEndcapAbsEta = 3.0;
161  const float minPt = 20;
162 
163  if (genPhoton.CorrPt() < minPt) continue;
164 
165  // Calculate weight for the generated photon
166  double w_gen_ev = genEvt->weights.front(),
167  w_rec_ev = recEvt->weights.front();
168 
169  // Calculation for the barrel
170  if (abs(genPhoton.CorrP4().Eta()) < maxBarrelAbsEta)
171  Fill(genPhoton, *recPhotons, minPt, 0., maxBarrelAbsEta,
172  w_gen_ev, w_rec_ev, histograms, "barrel", barrel_eff_pt);
173  // Calculation for the endcaps
174  else if (abs(genPhoton.CorrP4().Eta()) < maxEndcapAbsEta)
175  Fill(genPhoton, *recPhotons, minPt, maxBarrelAbsEta, maxEndcapAbsEta,
176  w_gen_ev, w_rec_ev, histograms, "endcaps", endcaps_eff_pt);
177  }
178  }
179 
180  for (auto& h: histograms)
181  h.second.Write(fOut);
182  fOut->cd();
183  for (auto eff: {&barrel_eff_pt, &endcaps_eff_pt}) {
184  eff->SetDirectory(fOut);
185  eff->Write();
186  }
187 
188  metainfo.Set<bool>("git", "complete", true);
189 
190  cout << __func__ << ' ' << slice << " stop" << endl;
191 }
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
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:27
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:69
Step::verbose
static bool verbose
Definition: Step.h:40
Darwin::Tools::Looper
Facility to loop over a n-tuple, including parallelisation and printing.
Definition: Looper.h:32
Darwin::Tools::syst
@ syst
activate -s to systematic uncertainties
Definition: Options.h:29
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
DAS::Photon::Fill
void Fill(const GenPhoton &genPhoton, const vector< RecPhoton > &recPhotons, const float minPt, const float minAbsEta, const float maxAbsEta, const double w_gen_ev, const double w_rec_ev, map< TString, PerformanceHist > &histograms, TString region, TEfficiency &eff_pt)
Definition: getPhotonPerformance.cc:71
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:264
DAS::Unfolding::DrellYan::minPt
static const double minPt
Definition: ZPtY.h:35
Ntupliser_cfg.isMC
string isMC
Definition: Ntupliser_cfg.py:59
jercExample.inputs
def inputs
Definition: jercExample.py:118
Darwin::Tools::dev_null
static std::ostream dev_null(nullptr)
to redirect output stream to nowhere