DAS  3.0
Das Analysis System
DAS::Muons Namespace Reference

Functions

template<class Muon >
bool keepEvent (const vector< Muon > &muons, float pt1, float pt2)
 
void applyDimuonSkim (const vector< fs::path > &inputs, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 

Function Documentation

◆ applyDimuonSkim()

void DAS::Muons::applyDimuonSkim ( 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 at least two muons, with configurable pT thresholds.

Parameters
inputsinput ROOT files (n-tuple)
outputoutput ROOT file (n-tuple)
configconfig handled with `Darwin::Tools::Options`
steeringparameters obtained from explicit options
slicenumber and index of slice
44  {1,0}
45  )
46 {
47  cout << __func__ << ' ' << slice << " start" << endl;
48 
49  unique_ptr<TChain> tIn = DT::GetChain(inputs);
50  unique_ptr<TFile> fOut(DT_GetOutput(output));
51  auto tOut = unique_ptr<TTree>(tIn->CloneTree(0));
52 
53  DT::MetaInfo metainfo(tOut);
54  metainfo.Check(config);
55  const bool isMC = metainfo.Get<bool>("flags", "isMC");
56 
57  const auto pt1 = config.get<float>("skims.dimuon.pt1");
58  metainfo.Set<float>("skims", "dimuon", "pt1", pt1);
59 
60  const auto pt2 = config.get<float>("skims.dimuon.pt2");
61  metainfo.Set<float>("skims", "dimuon", "pt2", pt2);
62 
63  cout << "Skimming events: pt(mu1) > " << pt1 << "\t pt(mu2) > " << pt2 << endl;
64 
65  // event information
66  GenEvent * genEvt = nullptr;
67  if (isMC)
68  tIn->SetBranchAddress("genEvent", &genEvt);
69 
70  // muon branches
71  vector<RecMuon> * recMuons = nullptr;
72  RecDimuon * recDimuon = nullptr;
73  if (branchExists(tIn, "recMuons")) {
74  tIn->SetBranchAddress("recMuons", &recMuons);
75  recDimuon = new RecDimuon;
76  tOut->Branch("recDimuon", &recDimuon);
77  }
78 
79  vector<GenMuon> * genMuons = nullptr;
80  GenDimuon * genDimuon = nullptr;
81  if (branchExists(tIn, "genMuons")) {
82  tIn->SetBranchAddress("genMuons", &genMuons);
83  genDimuon = new GenDimuon;
84  tOut->Branch("genDimuon", &genDimuon);
85  }
86 
87  if (!recMuons && !genMuons)
88  BOOST_THROW_EXCEPTION( DE::BadInput("No muons in input tree", tIn) );
89 
90  // histogram used in MC for normalisation
91  TH1 * hSumWgt = nullptr;
92  if (isMC) hSumWgt = new TH1F("hSumWgt",";;#sum_{i} w_{i}", 1, -0.5, 0.5);
93 
94  for (DT::Looper looper(tIn, slice); looper(); ++looper) {
95  [[ maybe_unused ]]
96  static auto& cout = (steering & DT::verbose) == DT::verbose ? ::cout : DT::dev_null;
97 
98  bool passesRec = true, passesGen = true;
99 
100  if (recMuons) {
101  passesRec = keepEvent(*recMuons, pt1, pt2);
102  if (passesRec) *recDimuon = recMuons->at(0) + recMuons->at(1);
103  else recDimuon->clear();
104  }
105  if (genMuons) {
106  passesGen = keepEvent(*genMuons, pt1, pt2);
107  if (passesGen) *genDimuon = genMuons->at(0) + genMuons->at(1);
108  else genDimuon->clear();
109  }
110 
111  if ((steering & DT::fill) == DT::fill && (passesRec || passesGen)) tOut->Fill();
112 
113  if (!isMC) continue;
114  auto w = genEvt->weights.front();
115  hSumWgt->Fill(0.0, w);
116  }
117 
118  metainfo.Set<bool>("git", "complete", true);
119  fOut->cd();
120  tOut->Write();
121  if (hSumWgt) hSumWgt->Write();
122 
123  cout << __func__ << ' ' << slice << " stop" << endl;
124 }

◆ keepEvent()

bool DAS::Muons::keepEvent ( const vector< Muon > &  muons,
float  pt1,
float  pt2 
)

Checks whether an event should be kept.

32 {
33  return muons.size() >= 2 && muons[0].p4.Pt() > pt1 && muons[1].p4.Pt() > pt2;
34 }
Step::verbose
static bool verbose
Definition: Step.h:40
Ntupliser_cfg.muons
string muons
Definition: Ntupliser_cfg.py:43
Darwin::Tools::Looper
Facility to loop over a n-tuple, including parallelisation and printing.
Definition: Looper.h:33
Darwin::Tools::GetChain
std::unique_ptr< TChain > GetChain(std::vector< std::filesystem::path > inputs, const char *name="events")
Load chain from a list of files.
Definition: FileUtils.cc:67
DAS::JetEnergy::w
static const float w
Definition: common.h:47
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:65
DAS::Muons::keepEvent
bool keepEvent(const vector< Muon > &muons, float pt1, float pt2)
Checks whether an event should be kept.
Definition: applyDimuonSkim.cc:31
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:28
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:263
DAS::branchExists
bool branchExists(const TTreePtr &tree, TString brName)
Definition: toolbox.h:27
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
DT_GetOutput
#define DT_GetOutput(output)
Definition: FileUtils.h:96
Darwin::Exceptions::BadInput
Generic exception for ill-defined input (before the event loop).
Definition: exceptions.h:68
DAS::RecDimuon
Di< RecMuon, RecMuon > RecDimuon
Definition: Di.h:81
DAS::GenDimuon
Di< GenMuon, GenMuon > GenDimuon
Definition: Di.h:78