CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhysicsPerformanceDBWriterTFormula_fromfile_WPandPL.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <fstream>
4 #include <iostream>
14 
16 {
17 public:
19  virtual void beginJob();
20  virtual void analyze(const edm::Event&, const edm::EventSetup&) {}
21  virtual void endJob() {}
23 
24 private:
25  std::string inputTxtFile;
26  std::string rec1,rec2;
27 
28 };
29 
32 {
33  inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
34  rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
35  rec2 = p.getUntrackedParameter<std::string>("RecordWP");
36 }
37 
39 {
40  //
41  // read object from file
42  //
43 
44  //
45  // File Format is
46  // - tagger name
47  // - cut
48  // - concrete class name
49  // number of results (btageff, btagSF....)
50  // number of binning variables in the parameterization (eta, pt ...)
51  // number of bins
52  // - results (as ints)
53  // - variables (as ints)
54  // - formulas
55  // - the limits
56  //
57 
58  std::ifstream in;
59  in.open(inputTxtFile.c_str());
60  std::string tagger;
61  float cut;
62 
63  std::string concreteType;
64 
65  in >> tagger;
66  std::cout << "WP Tagger is "<<tagger<<std::endl;
67 
68  in >> cut;
69  std::cout << "WP Cut is "<<cut<<std::endl;
70 
71  in >> concreteType;
72  std::cout << "concrete Type is "<<concreteType<<std::endl;
73 
74  int nres=0, nvar=0;
75 
76  in >> nres;
77  in >> nvar;
78 
79  std::cout <<"Using "<<nres<<" results and "<< nvar<<" variables"<<std::endl;
80 
81  unsigned int bins = 0; //temporary for now!!!!!!
82 
83  in >> bins;
84 
85  std::cout <<"Using "<<bins<<" bins"<<std::endl;
86 
87  int number=0;;
88 
89  std::vector<PerformanceResult::ResultType> res;
90  std::vector<BinningVariables::BinningVariablesType> bin;
91  //
92  // read results
93  //
94  number=0;
95  while (number<nres && !in.eof()) {
96  int tmp;
97  in>> tmp;
98  res.push_back((PerformanceResult::ResultType)(tmp));
99  std::cout <<" Result #"<<number <<" is "<<tmp<<std::endl;;
100  number++;
101  }
102  if (number != nres){
103  std::cout <<" Table not well formed"<<std::endl;
104  }
105 
106  //
107  // read the variables
108  //
109 
110 
111 
112  PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
114 
115  std::vector<PhysicsTFormulaPayload> v_ppl;
116 
117  number=0;
118  while (number<nvar && !in.eof()) {
119  int tmp;
120  in>> tmp;
121  bin.push_back((BinningVariables::BinningVariablesType)(tmp));
122  std::cout <<" Variable #"<<number <<" is "<<tmp<<std::endl;;
123  number++;
124  }
125  if (number != nvar){
126  std::cout <<" Table not well formed"<<std::endl;
127  }
128 
129  //
130  // now read the formulas
131  //
132 
133  for (unsigned int recregion =0 ; recregion<bins; ++recregion){
134 
135  std::vector< std::pair<float, float> > limits;
136  std::vector<std::string> formulas;
137 
138  number =0;
139 
140  while (number < nres && (!in.eof())){
141  std::string temp;
142  in >> temp;
143  std::cout <<" Inserting "<<temp<< " as formula in position "<<number<<std::endl;
144  number++;
145  formulas.push_back(temp);
146  }
147  /*
148  if (nres!= number ){
149  std::cout <<" NOT OK, this is not what I would expect"<<std::endl;
150  abort();
151  }
152  */
153 
154  number=0;
155  while (number < nvar && (!in.eof())){
156  float temp1,temp2;
157  in >> temp1;
158  in >> temp2;
159  std::cout <<" Inserting "<<temp1<<","<<temp2<< " as limits in position "<<number<<std::endl;
160  number++;
161  limits.push_back(std::pair<float, float>(temp1,temp2));
162  }
163  /*
164  if (nvar != number ){
165  std::cout <<" NOT OK, this is not what I would expect"<<std::endl;
166  abort();
167  }
168  */
169 
170  //
171  // push it
172  //
173 
174  PhysicsTFormulaPayload ppl(limits, formulas);
175  v_ppl.push_back(ppl);
176 
177  }
178  in.close();
179 
180 
181  if (concreteType == "PerformancePayloadFromBinnedTFormula"){
182  btagpl = new PerformancePayloadFromBinnedTFormula(res, bin, v_ppl);
183  std::cout <<" CHECK: "<<btagpl->formulaPayloads().size()<<std::endl;
184  }else{
185  std::cout <<" Non existing request: " <<concreteType<<std::endl;
186  }
187 
188  std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
189 
190  std::cout << "Start writing the payload" << std::endl;
192  if (s.isAvailable())
193  {
194  if (s->isNewTagRequest(rec1))
195  {
196  s->createNewIOV<PerformancePayload>(btagpl,
197  s->beginOfTime(),
198  s->endOfTime(),
199  rec1);
200  }
201  else
202  {
204  // JUST A STUPID PATCH
205  111,
206  rec1);
207  }
208  }
209  std::cout << "Finised writing the payload" << std::endl;
210 
211  // write also the WP
212  std::cout << "Start writing the WP" << std::endl;
213  if (s.isAvailable())
214  {
215  if (s->isNewTagRequest(rec2))
216  {
218  s->beginOfTime(),
219  s->endOfTime(),
220  rec2);
221  }
222  else
223  {
224 
227  111,
228  rec2);
229  }
230  }
231  std::cout << "Finished writing the WP" << std::endl;
232 
233 
234 }
235 
236 
237 
238 
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< PhysicsTFormulaPayload > & formulaPayloads() const
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:47
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121