DAS  3.0
Das Analysis System
DAS::TPS Namespace Reference

Classes

struct  Hist
 
struct  MultiJets
 

Functions

void CheckConsistency (DT::MetaInfo &metainfo1, TTree *tIn1, DT::MetaInfo &metainfo2, TTree *tIn2)
 
template<class Jet >
bool overlappingJets (const vector< Jet > &jets1, const vector< Jet > &jets2)
 
void applyEventMixing (const vector< fs::path > &inputs1, const vector< fs::path > &inputs2, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
void applyNjetSkim (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
template<class Jet >
std::vector< Jet > PhaseSpaceSelection (const std::vector< Jet > &jets, float minpt)
 
void getTPSobservables (const vector< fs::path > inputs, const fs::path output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 

Function Documentation

◆ applyEventMixing()

void DAS::TPS::applyEventMixing ( const vector< fs::path > &  inputs1,
const vector< fs::path > &  inputs2,
const fs::path &  output,
const pt::ptree &  config,
const int  steering,
const DT::Slice  slice = {1,0} 
)

Mix the jets from second input to first input to simulate DPS or TPS events. Overlapping jets are properly treated. The input must be taken from applyNjetSkim and must have the same isMC flag and pTcut.

Todo:
fix output logic
Todo:
Merge metainfos
Parameters
inputs1input ROOT files (n-tuples)
inputs2input 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
93  {1,0}
94  )
95 {
96  cout << __func__ << ' ' << slice << " start" << endl;
97 
98  DT::Flow flow1(steering, inputs1);
99  DT::Flow flow2(steering, inputs2);
100  auto tIn1 = flow1.GetInputTree(slice);
101  auto tIn2 = flow2.GetInputTree(slice);
102  auto tOut2 = flow2.GetOutputTree(output);
103  auto tOut1 = flow1.GetOutputTree(output);
104 
105  DT::MetaInfo metainfo1(tOut1);
106  DT::MetaInfo metainfo2(tOut2);
108  metainfo1.Check(config);
109  metainfo2.Check(config);
110  auto isMC = metainfo1.Get<bool>("flags", "isMC");
111 
112  CheckConsistency(metainfo1, tIn1, metainfo2, tIn2);
113 
114  auto recEvent1 = flow1.GetBranchReadWrite<RecEvent>("recEvent");
115  auto recEvent2 = flow2.GetBranchReadOnly <RecEvent>("recEvent");
116  auto genEvent1 = isMC ? flow1.GetBranchReadWrite<GenEvent>("genEvent") : nullptr;
117  auto genEvent2 = isMC ? flow2.GetBranchReadOnly <GenEvent>("genEvent") : nullptr;
118  auto recJets1 = flow1.GetBranchReadWrite<vector<RecJet>>("recJets");
119  auto recJets2 = flow2.GetBranchReadOnly <vector<RecJet>>("recJets");
120  auto genJets1 = isMC ? flow1.GetBranchReadWrite<vector<GenJet>>("genJets") : nullptr;
121  auto genJets2 = isMC ? flow2.GetBranchReadOnly <vector<GenJet>>("genJets") : nullptr;
122 
123  for (DT::Looper looper1(tIn1), looper2(tIn2); looper1() && looper2(); ++looper1, ++looper2) {
124  [[maybe_unused]]
125  static auto& cout = (steering & DT::verbose) ? ::cout : DT::dev_null;
126 
127  if (recJets1 && recJets2) {
128  if (overlappingJets(*recJets1, *recJets2)) continue;
129 
130  // Merge input2's jets into input1's jets
131  recJets1->insert(recJets1->end(), recJets2->begin(), recJets2->end());
132  recEvent1->weights.front() *= recEvent2->weights.front();
133 
134  sort(recJets1->begin(), recJets1->end(), pt_sort); // sort again the jets by pt
135  }
136  if (isMC && genJets1 && genJets2) {
137  if (overlappingJets(*genJets1, *genJets2)) continue;
138 
139  // Merge input2's jets into input1's jets
140  genJets1->insert(genJets1->end(), genJets2->begin(), genJets2->end());
141  genEvent1->weights.front() *= genEvent2->weights.front();
142 
143  sort(genJets1->begin(), genJets1->end(), pt_sort); // sort again the jets by pt
144  }
145 
146  if (steering & DT::fill) tOut1->Fill();
147  }
148 
149  metainfo1.Set<bool>("git", "complete", true);
150  cout << __func__ << ' ' << slice << " stop" << endl;
151 }

◆ applyNjetSkim()

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

Skims the input tree to keep only events with different jet multiplicity, with configurable pT thresholds for leading Njets.

Note
Drop the selection for genJets, as it will tighter the selection on rec level in MC samples than data. In case we only interested in the rec level in this stage, we can drop the gen level selection.
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
41  {1,0}
42  )
43 {
44  cout << __func__ << ' ' << slice << " start" << endl;
45 
46  DT::Flow flow(steering, inputs);
47  auto tIn = flow.GetInputTree(slice);
48  auto [fOut, tOut] = flow.GetOutput(output);
49 
50  DT::MetaInfo metainfo(tOut);
51  metainfo.Check(config);
52  auto isMC = metainfo.Get<bool>("flags", "isMC");
53 
54  const auto minpt = config.get<float>("skims.jets.minpt");
55  metainfo.Set<float>("skims", "jets", "minpt", minpt);
56 
57  const auto Njets = config.get<int>("skims.jets.N");
58  metainfo.Set<int>("skims", "jets", "N", Njets);
59  cout << "Skimming events: Njets = " << Njets << "\t minpt > " << minpt << endl;
60 
61  auto recJets = flow.GetBranchReadOnly<vector<RecJet>>("recJets");
62  auto genJets = isMC ? flow.GetBranchReadOnly<vector<GenJet>>("genJets") : nullptr;
63  auto pileup = flow.GetBranchReadOnly<PileUp>("pileup");
64 
65  for (DT::Looper looper(tIn); looper(); ++looper) {
66  [[ maybe_unused ]]
67  static auto& cout = steering & DT::verbose ? ::cout : DT::dev_null;
68 
69  if (pileup->nVtx > 1) continue; // skip events with more than one vertex
70 
71  bool passRec = recJets && PhaseSpaceSelection(*recJets, minpt).size() == Njets;
72  bool passGen = genJets && PhaseSpaceSelection(*genJets, minpt).size() == Njets;
73 
74  if ((steering & DT::fill) && passRec) tOut->Fill();
77  }
78 
79  metainfo.Set<bool>("git", "complete", true);
80  cout << __func__ << ' ' << slice << " stop" << endl;
81 }

◆ CheckConsistency()

void DAS::TPS::CheckConsistency ( DT::MetaInfo metainfo1,
TTree *  tIn1,
DT::MetaInfo metainfo2,
TTree *  tIn2 
)

Check the consistency between two inputs make sure they have the same isMC flag and pTcut. The number of entries in the two input files doesn’t have to be the same, but the number of entries in the output file will be affected by the smaller one.

37  {
38  struct Dataset {
39  string name;
40  bool isMC;
41  int Njets;
42  float minpt;
43  long long entries;
44  } datasets[] = {
45  {"Input1", metainfo1.Get<bool>("flags", "isMC"), metainfo1.Get<int>("skims", "jets", "N"), metainfo1.Get<float>("skims", "jets", "minpt"), tIn1 ? tIn1->GetEntries() : 0},
46  {"Input2", metainfo2.Get<bool>("flags", "isMC"), metainfo2.Get<int>("skims", "jets", "N"), metainfo2.Get<float>("skims", "jets", "minpt"), tIn2 ? tIn2->GetEntries() : 0}
47  };
48  int minIndex = (datasets[0].entries < datasets[1].entries) ? 0 : 1;
49  cout << "+---------+------+-------+-------+-------------+\n"
50  << "| Dataset | isMC | Njets | pTcut | Entries |\n"
51  << "+---------+------+-------+-------+-------------+\n";
52  for (int i = 0; i < 2; i++) {
53  cout << "| " << setw(7) << left << datasets[i].name
54  << " | " << setw(4) << left << (datasets[i].isMC ? "Yes" : "No")
55  << " | " << setw(5) << left << datasets[i].Njets
56  << " | " << setw(5) << left << datasets[i].minpt
57  << " | " << setw(11 + (i == minIndex ? 9 : 0)) << right
58  << (i == minIndex ? orange + to_string(datasets[i].entries) + def : to_string(datasets[i].entries))
59  << " |\n";
60  }
61  cout << "+---------+------+-------+-------+-------------+\n" << flush;
62 
63  if (datasets[0].isMC != datasets[1].isMC)
64  BOOST_THROW_EXCEPTION( DE::BadInput("The isMC flag is inconsistent between inputs!", tIn1) );
65  if (datasets[0].minpt != datasets[1].minpt)
66  BOOST_THROW_EXCEPTION( DE::BadInput("The pTcut is inconsistent between inputs!", tIn1) );
67 }

◆ getTPSobservables()

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

Calculate the observables that can be used to caracterise 6 jets events.

Parameters
inputsinput ROOT files (n-tuples)
outputname of output root file containing the histograms
configconfig file from `DTOptions`
steeringsteering parameters from `DTOptions`
sliceslices for running
121  {1,0}
122  )
123 {
124  cout << __func__ << ' ' << slice << " start" << endl;
125 
126  DT::Flow flow(steering, inputs);
127  auto tIn = flow.GetInputTree(slice);
128  auto [fOut, tOut] = flow.GetOutput(output);
129 
130  DT::MetaInfo metainfo(tOut);
131  metainfo.Check(config);
132  auto isMC = metainfo.Get<bool>("flags", "isMC");
133 
134  const auto minpt = config.get<float>("skims.jets.minpt");
135  metainfo.Set<float>("skims", "jets", "minpt", minpt);
136 
137  auto rEv = flow.GetBranchReadOnly<RecEvent>("recEvent");
138  auto recJets = flow.GetBranchReadOnly<vector<RecJet>>("recJets");
139  auto gEv = isMC ? flow.GetBranchReadOnly<GenEvent>("genEvent") : nullptr;
140  auto genJets = isMC ? flow.GetBranchReadOnly<vector<GenJet>>("genJets") : nullptr;
141 
142  Hist genHist("gen"),
143  recHist("rec");
144 
145  for (DT::Looper looper(tIn); looper(); ++looper) {
146  [[ maybe_unused ]]
147  static auto& cout = steering & DT::verbose ? ::cout : DT::dev_null;
148 
149  MultiJets recMultijets(*recJets, minpt);
150  if (recMultijets) {
151  double evweight = rEv->weights.front();
152  if (isMC) evweight *= gEv->weights.front();
153  recHist.Fill(recMultijets, evweight);
154  }
155 
156  if (!isMC) continue;
157  MultiJets genMultijets(*genJets, minpt);
158  if (genMultijets) {
159  double evweight = gEv->weights.front();
160  genHist.Fill(genMultijets, evweight);
161  }
162  }
163 
164  recHist.Write(fOut);
165  if (isMC)
166  genHist.Write(fOut);
167  metainfo.Set<bool>("git", "complete", true);
168 
169  cout << __func__ << ' ' << slice << " end" << endl;
170 }

◆ overlappingJets()

bool DAS::TPS::overlappingJets ( const vector< Jet > &  jets1,
const vector< Jet > &  jets2 
)

Loop all possible jets combinations checking azimuthal difference to avioding overlapping jets.

Todo:
Implement the anti-kt clustering algorithm.
74  {
75  for (const auto& jet1 : jets1) {
76  for (const auto& jet2 : jets2) {
77  if (DeltaR(jet1.p4, jet2.p4) < 0.4) return true;
78  }
79  }
80  return false;
81 }

◆ PhaseSpaceSelection()

std::vector<Jet> DAS::TPS::PhaseSpaceSelection ( const std::vector< Jet > &  jets,
float  minpt 
)

return Jets pass the phase space selection

Todo:
Check pseudorapidty coverage
18  {
19  std::vector<Jet> tempjets;
20  for (const auto& jet : jets)
21  if (jet.CorrPt() > minpt && jet.p4.Eta() < 5.0)
22  tempjets.push_back(jet);
23  return tempjets;
24 }
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:78
Step::verbose
static bool verbose
Definition: Step.h:40
Step::def
static const char * def
Definition: Step.h:36
Darwin::Tools::UserInfo::Get
T Get(TList *mother, const char *key) const
Definition: UserInfo.h:75
Darwin::Tools::Looper
Facility to loop over a n-tuple, including parallelisation and printing.
Definition: Looper.h:22
DAS::PileUp::nVtx
int nVtx
number of vertices in the event
Definition: Event.h:103
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
DAS::pt_sort
bool pt_sort(const PhysicsObject &j1, const PhysicsObject &j2)
Definition: toolbox.h:18
DAS::MN::minpt
static const double minpt
Definition: getMNobservables.cc:39
Ntupliser_cfg.jets
string jets
Definition: Ntupliser_cfg.py:41
DAS::TPS::overlappingJets
bool overlappingJets(const vector< Jet > &jets1, const vector< Jet > &jets2)
Definition: applyEventMixing.cc:74
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:317
orange
static const char * orange
Definition: colours.h:6
pileup
DAS::PileUp pileup
Definition: classes.h:27
DAS::TPS::PhaseSpaceSelection
std::vector< Jet > PhaseSpaceSelection(const std::vector< Jet > &jets, float minpt)
return Jets pass the phase space selection
Definition: common.h:18
Ntupliser_cfg.isMC
dictionary isMC
Definition: Ntupliser_cfg.py:61
DAS::TPS::CheckConsistency
void CheckConsistency(DT::MetaInfo &metainfo1, TTree *tIn1, DT::MetaInfo &metainfo2, TTree *tIn2)
Definition: applyEventMixing.cc:37
jercExample.inputs
def inputs
Definition: jercExample.py:118
Darwin::Tools::dev_null
static std::ostream dev_null(nullptr)
to redirect output stream to nowhere
Darwin::Exceptions::BadInput
Generic exception for ill-defined input (before the event loop).
Definition: exceptions.h:83