DAS  3.0
Das Analysis System
applyDataLumiZeroBias.cc File Reference
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <filesystem>
#include "Core/Objects/interface/Jet.h"
#include "Core/Objects/interface/Event.h"
#include "Core/CommonTools/interface/terminal.h"
#include "Core/CommonTools/interface/Looper.h"
#include "Core/CommonTools/interface/MetaInfo.h"
#include "Core/CommonTools/interface/toolbox.h"
#include "Core/CommonTools/interface/ControlPlots.h"
#include <TROOT.h>
#include <TFile.h>
#include <TChain.h>
#include <TH2.h>
#include "TriggerEff.h"
+ Include dependency graph for applyDataLumiZeroBias.cc:

Functions

void applyDataPrescalesZeroBias (const fs::path &input, const fs::path &output, auto total_lumi, auto maxpt, int nSplit=1, int nNow=0)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ applyDataPrescalesZeroBias()

void applyDataPrescalesZeroBias ( const fs::path &  input,
const fs::path &  output,
auto  total_lumi,
auto  maxpt,
int  nSplit = 1,
int  nNow = 0 
)

Normalise with prescales.

Parameters
inputname of input root file
outputname of output root file
nSplitnumber of jobs/tasks/cores
nNowindex of job/task/core
38 {
39  assert(fs::exists(input));
40  TChain * oldchain = new TChain("events");
41  oldchain->Add(input.c_str());
42 
43  vector<RecJet> * recJets = nullptr;
44  Event * event = nullptr;
45  Trigger * trigger = nullptr;
46  oldchain->SetBranchAddress("recJets", &recJets);
47  oldchain->SetBranchAddress("event", &event);
48  oldchain->SetBranchAddress("trigger", &trigger);
49 
50  if (fs::exists(output))
51  cerr << red << output << " will be overwritten\n" << normal;
52  auto newfile = TFile::Open(output.c_str(), "RECREATE");
53  auto newtree = oldchain->CloneTree(0);
54 
55  MetaInfo metainfo(newtree);
56  if (nNow == 0) metainfo.Print();
57  metainfo.AddCorrection("normalised");
58 
59  int year = metainfo.year();
60  assert(year > 2015 && year < 2019);
61 
62  assert(total_lumi > 0);
63  auto inv_total_lumi = 1./total_lumi;
64 
65  newfile->cd();
66 
67  // a few control plots
68  ControlPlots::isMC = false;
69  vector<ControlPlots> corr ;
70  for (int i=0; i<metainfo.GetNRecEvWgts(); i++)
71  corr.push_back(ControlPlots(metainfo.GetRecEvWgt(i)));
72 
73  cout << "looping over events:" << endl;
74 
75  Looper looper(__func__, oldchain, nSplit, nNow);
76  while (looper.Next()) {
77 
78  // we find the leading jet in tracker acceptance
79  auto leadingInTk = recJets->begin();
80  while (leadingInTk != recJets->end()
81  && abs(leadingInTk->Rapidity()) >= 2.5)
82  ++leadingInTk;
83 
84  // removed events alreadu covered by jet triggers
85  if (leadingInTk != recJets->end() && leadingInTk->CorrPt() >= maxpt) continue;
86 
87  // get prescale
88  auto preHLT = trigger->PreHLT.front();
89  auto preL1min = trigger->PreL1min.front();
90  auto preL1max = trigger->PreL1max.front();
91  assert(preL1min == preL1max);
92  if (preL1min != preL1max)
93  cerr << "\x1B[31m\e[1m" << preL1min << ' ' << preL1max << "\x1B[30m\e[0m\n";
94 
95  auto prescale = preHLT * preL1min;
96 
97  // sanity checks:
98 
99  // 1) we assume that the same prescale is indeed constant for a given LS
100  {
101  static vector<map<pair<int,int>,int>> prescales(1); // this could be written in a simpler way...
102  pair<int,int> runlum = {event->runNo, event->lumi};
103  if (prescales.front().count(runlum))
104  assert(prescales.front().at(runlum) == prescale);
105  else
106  prescales.front()[runlum] = prescale;
107  }
108 
109  // 2) check that the data have not yet been rescaled
110  assert(event->genWgts.size() == 0 && event->recWgts.size() == 1 && event->recWgts.front() == 1);
111 
112  // setting the inverse of the eff lumi to the event including correction of for the trigger efficiency
113  for (size_t i = 0; i < corr.size(); ++i)
114  event->recWgts.at(i) *= prescale * inv_total_lumi;
115 
116  newtree->Fill();
117  for(size_t i=0; i<corr.size(); i++){
118  if(recJets->size()==0) continue;
119  corr.at(i)(*recJets, event->recWgts.at(i));
120  }
121  }
122 
123  cout << "saving" << endl;
124  newtree->AutoSave();
125  for (size_t i = 0; i < corr.size(); ++i)
126  corr.at(i).Write(newfile);
127  auto controlplots = newfile->mkdir("controlplots");
128  controlplots->cd();
129  newfile->Close();
130  delete oldchain;
131 }

◆ main()

int main ( int  argc,
char *  argv[] 
)
135 {
136  gROOT->SetBatch();
137 
138  if (argc < 4) {
139  cout << argv[0] << " input output lumi_file turnon_file trigger_curves [nSplit [nNow]]\n"
140  << "where\tinput = data n-tuple\n"
141  << " \toutput = new n-tuple\n"
142  << " \ttotal_lumi = lumi in /pb (can be found in `$DAS_WORKAREA/tables/lumi`)\n"
143  << " \tmaxpt = max pt to be covered by ZeroBias trigger (suggestion: lowest pt threshold in `$DAS_WORKAREA/tables/trigger`)\n"
144  << flush;
145  return EXIT_SUCCESS;
146  }
147 
148  fs::path input = argv[1],
149  output = argv[2];
150  auto total_lumi = atof(argv[3]),
151  maxpt = atof(argv[4]);
152 
153  int nNow = 0, nSplit = 1;
154  if (argc > 5) nSplit = atoi(argv[5]);
155  if (argc > 6) nNow = atoi(argv[6]);
156 
157  applyDataPrescalesZeroBias(input, output, total_lumi, maxpt, nSplit, nNow);
158  return EXIT_SUCCESS;
159 }
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
applyDataPrescalesZeroBias
void applyDataPrescalesZeroBias(const fs::path &input, const fs::path &output, auto total_lumi, auto maxpt, int nSplit=1, int nNow=0)
Normalise with prescales.
Definition: applyDataLumiZeroBias.cc:32
DAS::ControlPlots
Definition: ControlPlots.h:17
Ntupliser_cfg.year
int year
Definition: Ntupliser_cfg.py:63
DAS::Trigger
Definition: Event.h:71
DAS::Trigger::PreL1max
std::vector< int > PreL1max
L1 max pre-scale.
Definition: Event.h:75
Step::red
static const char * red
Definition: Step.h:34
DAS::MN::maxpt
static const double maxpt
Definition: getMNobservables.cc:42
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.input
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
DAS::Trigger::PreL1min
std::vector< int > PreL1min
L1 min pre-scale.
Definition: Event.h:74
normal
static const char * normal
Definition: colours.h:8
Ntupliser_cfg.isMC
string isMC
Definition: Ntupliser_cfg.py:59
DAS::Trigger::PreHLT
std::vector< int > PreHLT
HLT prescale.
Definition: Event.h:73