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
IterativeCutSelector.cxx
Go to the documentation of this file.
2#include <fstream>
3#include <iostream>
4#include <algorithm>
5
8
9IterativeCutSelector::IterativeCutSelector(const std::string& inputName):BaseSelector(inputName) {
10}
11
12IterativeCutSelector::IterativeCutSelector(const std::string& inputName, const std::string& cfgFile):BaseSelector(inputName,cfgFile) {
13}
14
16
18 if(cutname.find("_gt") != std::string::npos){
19 return true;
20 }
21 else
22 return false;
23}
24
25std::string IterativeCutSelector::getCutVar(std::string cutname){
26
27 std::string substr;
28 bool isCutGT = isCutGreaterThan(cutname);
29 std::string cutvar;
30
31 if(isCutGT) substr = "_gt";
32 else substr = "_lt";
33
34 std::size_t ind = cutname.find(substr); // Find the starting position of substring in the string
35 if(ind !=std::string::npos){
36 cutvar = cutname.erase(ind,substr.length()); // erase function takes two parameter, the starting index in the string from where you want to erase characters and total no of characters you want to erase.
37 }else{
38 std::cout<<"Substring does not exist in the string: "+cutname << std::endl;
39 }
40
41 return cutvar;
42}
43
44void IterativeCutSelector::setCutValue(std::string cutname, double value){
45 std::pair<double,int> pair = cuts[cutname];
46 double ogval = pair.first;
47 int id = pair.second;
48 pair.first = value;
49 pair.second = id;
50 cuts[cutname] = pair;
51 if(debug_)
52 std::cout << "[IterativeCutSelector] Updating cut " << cutname << " value from " << ogval << " to: " << cuts[cutname].first << std::endl;
53}
54
55bool IterativeCutSelector::passCutGTorLT(std::string cutname, double val){
56
57 //Some events are not defined in a given cut variable, and should not be cut in these cases.
58 //These events are assigned a specific double value that is otherwise impossible to see.
59 //If this value is encountered for a given event, do not apply cut to the event.
60 if(val == skipCutVarValue_)
61 return true;
62 if(isCutGreaterThan(cutname)){
63 if (hasCut(cutname)) {
64 if (val < cuts[cutname].first) {
65 return false;
66 }
67 }
68 return true;
69 }
70
71 else{
72 if (hasCut(cutname)) {
73 if (val > cuts[cutname].first) {
74 return false;
75 }
76 }
77 return true;
78 }
79}
80
82 for(cut_it it=cuts.begin(); it != cuts.end(); it++)
83 std::cout << it->first << ": " << it->second.first << std::endl;
84}
85
86void IterativeCutSelector::filterCuts(std::vector<std::string> cut_variable_list){
87
88 //Loop over Test Cuts loaded in from json configuration
89 //for(std::map<std::string, std::pair<double,int>>::iterator it = cuts_ptr->begin(); it != cuts_ptr->end(); it++){
90 for(std::map<std::string, std::pair<double,int>>::iterator it = getPointerToCuts()->begin();
91 it != getPointerToCuts()->end();){
92 std::string cutname = it->first;
93 std::string cutvariable = getCutVar(cutname);
94 bool found = false;
95
96 //Confirm that cut variable is in list of configurable cut variables
97 for(std::vector<std::string>::iterator iit=cut_variable_list.begin(); iit !=cut_variable_list.end(); iit++){
98 if((std::string)*iit == cutvariable){
99 found = true;
100 break;
101 }
102 }
103
104 //If Test Cut Variable does not exist, remove the Test Cut from the list of cuts
105 if(!found){
106 it = getPointerToCuts()->erase(it);
107 }
108 else
109 ++it;
110 }
111}
112
brief description
std::map< std::string, std::pair< double, int > > cuts
description
bool hasCut(const std::string &cutname)
description
std::map< std::string, std::pair< double, int > >::iterator cut_it
description
bool debug_
description
bool isCutGreaterThan(std::string cutname)
is cut of type 'greater than'
std::string getCutVar(std::string cutname)
get cut variable from name
std::map< std::string, std::pair< double, int > > * getPointerToCuts()
get pointer to the base class cuts
void filterCuts(std::vector< std::string > cut_variable_list)
remove cuts that aren't specified in the list of cut variables
void setCutValue(std::string cutname, double value)
set cut value
void printCuts()
prints cuts and values
bool passCutGTorLT(std::string cutname, double val)
does value pass cut