hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BaseSelector.cxx
Go to the documentation of this file.
1#include "BaseSelector.h"
2#include <fstream>
3#include <iostream>
4
6 BaseSelector("default");
7 m_cfgFile = "";
8 debug_ = false;
9 passSelection = true;
10}
11
12BaseSelector::BaseSelector(const std::string& inputName) {
13 m_name = inputName;
14 m_cfgFile = "";
15 debug_ = false;
16 passSelection = true;
17}
18
19BaseSelector::BaseSelector(const std::string& inputName, const std::string& cfgFile) {
20 m_name = inputName;
21 m_cfgFile = cfgFile;
22 debug_ = false;
23 passSelection=true;
24}
25
26void BaseSelector::setCfgFile(const std::string& cfgFile) {
27 m_cfgFile = cfgFile;
28}
29
30void BaseSelector::setDebug(bool val) {
31 debug_ = val;
32}
33
35
37 if (m_cfgFile.empty()) {
38 std::cout<<"ERROR BaseSelector::Configuration File not specified";
39 return false;
40 }
41
42 std::ifstream i_file(m_cfgFile);
43 i_file >> _h_selections;
44 if (debug_) {
45 for (auto& el : _h_selections.items())
46 std::cout<<el.key() << " : " << el.value() << "\n";
47 }
48
49 for (auto cut : _h_selections.items()) {
50 cuts[cut.key()].first = cut.value().at("cut");
51 cuts[cut.key()].second = cut.value().at("id");
52 labels[cut.key()] = cut.value().at("info");
53 ncuts_++;
54 }
55
56 if (debug_) {
57 for (cut_it it = cuts.begin(); it != cuts.end(); ++it) {
58 std::cout<<it->first<<" [value:]=" <<it->second.first<<" [id:] ="<<it->second.second<<std::endl;
59 }
60 }
61
63 return true;
64}
65
67
68 h_cf_ = std::make_shared<TH1F>((m_name+"_cutflow").c_str(),(m_name+"_cutflow").c_str(),ncuts_+1,0,ncuts_+1);
69 h_cf_->GetXaxis()->SetCanExtend(true);
70 h_cf_->Sumw2();
71 h_cf_->GetXaxis()->SetBinLabel(1,"no-cuts");
72
73 for (cut_it it = cuts.begin(); it != cuts.end(); ++it) {
74 h_cf_->GetXaxis()->SetBinLabel((it->second.second+2),labels[(it->first)].c_str());
75 }
76}
77
78
79//TODO Clean up logic
80bool BaseSelector::passCutEq(const std::string& cutname, double val, double w) {
81
82 if (hasCut(cutname)) {
83 if (val != cuts[cutname].first) {
85 return false;
86 }
87 else {
88 h_cf_->Fill((double)(cuts[cutname].second + 1), w);
90 }
91 }
92 return true;
93}
94
95
96bool BaseSelector::passCutLt(const std::string& cutname, double val, double w) {
97
98 if (hasCut(cutname)) {
99 if (val > cuts[cutname].first) {
100 passSelection = passSelection && false;
101 return false;
102 }
103 else {
104 h_cf_->Fill((double)(cuts[cutname].second + 1), w);
106 }
107 }
108 return true;
109}
110
111bool BaseSelector::passCutGt(const std::string& cutname, double val, double w) {
112
113 if (hasCut(cutname)) {
114 if (val < cuts[cutname].first) {
115 passSelection = passSelection && false;
116 return false;
117 }
118 else {
119 h_cf_->Fill((double)(cuts[cutname].second + 1), w);
121 }
122 }
123 return true;
124}
125
126
std::map< std::string, std::pair< double, int > > cuts
description
json _h_selections
description
bool passCutLt(const std::string &cutname, double val, double weight)
description
int ncuts_
description
bool hasCut(const std::string &cutname)
description
bool passCutGt(const std::string &cutname, double val, double weight)
description
void setDebug(bool val)
Set Debug.
std::map< std::string, std::pair< double, int > >::iterator cut_it
description
std::shared_ptr< TH1F > h_cf_
description
void makeCutFlowHisto()
description
std::map< std::string, std::string > labels
description
bool LoadSelection()
description
std::string m_cfgFile
description
std::string m_name
description
bool passSelection
description
void setCfgFile(const std::string &cfgFile)
Set the Cfg File object.
bool debug_
description
virtual ~BaseSelector()
bool passCutEq(const std::string &cutname, double val, double weight)
description