9#ifndef __PRESELECT_AND_CATEGORIZE_H__
10#define __PRESELECT_AND_CATEGORIZE_H__
43#include "TLorentzVector.h"
66 Cutflow(
const std::string& name,
const std::string& nocut_name):
73 void add(
const std::string& name,
int nbins,
float min,
float max) {
75 throw std::runtime_error(
"Cannot add more cuts after init");
78 auto h = std::make_unique<TH1F>(
79 (
"nm1_" + name +
"_h").c_str(),
80 (name +
" N-1").c_str(),
83 cuts_.emplace(name, std::make_pair<std::size_t, std::unique_ptr<TH1F>>(
cuts_.size(), std::move(h)));
88 throw std::runtime_error(
"Cannot init twice.");
92 (
name_ +
"_cutflow_h").c_str(),
93 (
name_ +
" cutflow;;N_{events}").c_str(),
106 void apply(
const std::string& name,
bool descision) {
108 throw std::runtime_error(
"Cut "+name+
" not `add`ed to cutflow.");
113 int i_cut =
cuts_.at(name).first;
119 bool should_fill{
true};
121 for (std::size_t i_cut{0}; i_cut <
cuts_.size(); i_cut++) {
122 if (i_cut !=
cuts_[name].first and
cut_desc_[i_cut].has_value()) {
123 should_fill = (should_fill and
cut_desc_[i_cut].value());
128 cuts_.at(name).second->Fill(value);
138 for (
int i = 0; i <
h_cutflow_->GetNbinsX(); ++i) {
144 for (
const auto& [_name, entry] :
cuts_) {
145 TH1F* h = entry.second.get();
149 int nb = h->GetNbinsX();
150 h->SetBinContent(1, h->GetBinContent(0) + h->GetBinContent(1));
151 h->SetBinContent(0, 0.);
152 h->SetBinContent(nb, h->GetBinContent(nb) + h->GetBinContent(nb + 1));
153 h->SetBinContent(nb + 1, 0.);
161 std::map<std::string,std::pair<std::size_t,std::unique_ptr<TH1F>>>
cuts_;
188 bool has(
const std::string& name) {
189 return bus_.isOnBoard(name);
212 template<
typename BaggageType>
214 if (
bus_.isOnBoard(name)) {
215 throw std::runtime_error(name +
" is already on board the bus.");
218 bus_.board<BaggageType>(name);
219 if (
bus_.attach(tree, name,
false ) == 0) {
220 throw std::runtime_error(
"Unable to find branch " + name +
" in input TTree.");
224 template<
typename BaggageType>
226 if (
bus_.isOnBoard(name)) {
227 throw std::runtime_error(name +
" is already on board the bus.");
229 bus_.board<BaggageType>(name);
230 if (
bus_.attach(tree, name,
true ) == 0) {
231 throw std::runtime_error(
"Unable to create branch " + name +
" in output TTree.");
238 template<
typename BaggageType>
239 const BaggageType&
get(
const std::string& name) {
240 return bus_.get<BaggageType>(name);
243 template<
typename BaggageType>
244 void set(
const std::string& name,
const BaggageType& obj) {
245 if (
bus_.isOnBoard(name)) {
246 bus_.update(name, obj);
249 throw std::runtime_error(
"No branch " + name +
" boarded on the bus.");
260 virtual void setFile(TFile* out_file);
273 std::ifstream file{filepath};
291 std::string
vtxColl_{
"UnconstrainedV0Vertices_KF"};
301 std::shared_ptr<AnaHelpers>
_ah;
Helper class for hipster analysis.
Class used to encapsulate information about a mc particle.
Class used to encapsulate information about a particle.
Base classes for all user event processing components to extend.
Class used to decode TS words.
Class used to encapsulate track information.
Class used to encapsulate tracker hit information.
Class used to encapsulate Vertex information.
void apply(const std::string &name, bool descision)
std::map< std::string, std::pair< std::size_t, std::unique_ptr< TH1F > > > cuts_
std::unique_ptr< TH1F > h_cutflow_
std::vector< std::string > label_names_
Cutflow(const std::string &name, const std::string &nocut_name)
void add(const std::string &name, int nbins, float min, float max)
void fill_nm1(const std::string &name, T value)
std::vector< std::optional< bool > > cut_desc_
void set_label_names(const std::vector< std::string > &label_names)
void board_output(TTree *tree, const std::string &name)
std::vector< std::string > clearable_output_names_
names of the output passengers that are safe to reset each event
void board_input(TTree *tree, const std::string &name)
void set(const std::string &name, const BaggageType &obj)
const BaggageType & get(const std::string &name)
bool has(const std::string &name)
std::shared_ptr< TrackSmearingTool > smearingTool_
virtual bool process(IEvent *ievent)
Process the event and put new data products into it.
virtual void configure(const ParameterSet ¶meters)
Callback for the Processor to configure itself from the given set of parameters.
virtual void setVtxColl(std::string vtx_coll)
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes,...
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts,...
json preselect_json_load(const std::string &filepath)
virtual void setMCColl(std::string mc_coll)
std::string mcColl_
description
std::unique_ptr< TH2F > n_vertices_h_
virtual void setFile(TFile *out_file)
Set output TFile for AnaProcessors.
std::shared_ptr< AnaHelpers > _ah
description
std::map< int, std::vector< double > > beamspot_corrections_
PreselectAndCategorize(const std::string &name, Process &process)
~PreselectAndCategorize()=default
std::map< std::string, double > track_corrections_
std::unique_ptr< TTree > output_tree_
Processor(const std::string &name, Process &process)
Class constructor.
virtual bool process()
Process the histograms and generate analysis output.