CMS 3D CMS Logo

Scanner.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_FWLite_Scanner_h
2 #define PhysicsTools_FWLite_Scanner_h
3 // these includes are FWLite-safe
6 // these are from ROOT, so they're safe too
7 #include <TString.h>
8 #include <TRegexp.h>
9 #include <TObjString.h>
10 #include <TObjArray.h>
11 #include <TDirectory.h>
12 #include <TEnv.h>
13 #include <TClass.h>
14 
15 #if !defined(__CINT__) && !defined(__MAKECINT__)
16 #include <RooFit.h>
17 #include <RooArgList.h>
18 #include <RooDataSet.h>
19 #include <RooRealVar.h>
20 #include <RooCategory.h>
21 
23 #endif
24 
26 
27 namespace fwlite {
28 
45  template<typename Collection>
46  class Scanner {
47  public:
50 
52  Scanner(fwlite::EventBase *ev, const char *label, const char *instance = "", const char *process="") :
53  event_(ev), label_(label), instance_(instance),
54  printFullEventId_(ev->isRealData()),
56  exprSep_(":"),
57  maxEvents_(-1),
59  {
61  }
62 
63  //------------------------------------------------------------------------------------------------------------------------------------
79  void scan(const char *exprs, const char *cut="", int nmax=-1) {
80  helper::ScannerBase scanner(objType);
82 
83  TObjArray *exprArray = TString(exprs).Tokenize(exprSep_);
84  int rowline = 0;
85  if (printFullEventId_) {
86  printf(" : %9s : %4s : %9s : %3s", "RUN", "LUMI", "EVENT", "#IT");
87  rowline += 3*4+9+4+9+3-1; // -1 as first char remain blank
88  } else {
89  printf(" : %5s : %3s", "EVENT", "#IT");
90  rowline += 3+6+3+3-1; // -1 as first char remain blank
91  }
92  for (int i = 0; i < exprArray->GetEntries(); ++i) {
93  TString str = ((TObjString *)(*exprArray)[i])->GetString();
94  std::string lb = str.Data();
95  std::string ex = str.Data();
96  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
97  lb = lb.substr(1,ex.find('=')-1);
98  ex = ex.substr(ex.find('=')+1);
99  }
100  scanner.addExpression(ex.c_str());
101  printf(" : %8s", (lb.size()>8 ? lb.substr(lb.size()-8) : lb).c_str()); // the rightmost part is usually the more interesting one
102  rowline += 3+8;
103  }
104  std::cout << " :" << std::endl;
105  rowline += 2;
106  delete exprArray;
107 
108  TString rule('-', rowline);
109  std::cout << " " << rule << " " << std::endl;
110 
111  if (strlen(cut)) scanner.setCut(cut);
112 
113  int iev = 0, line = 0;
114  for (event_->toBegin(); (iev != nmax) && !event_->atEnd(); ++iev, ++(*event_)) {
115  if (!selectEvent(*event_)) continue;
116  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
117  if (handle_.failedToGet()) {
118  if (ignoreExceptions_) continue;
119  }
120  const Collection & vals = *handle_;
121  for (size_t j = 0, n = vals.size(); j < n; ++j) {
122  if (!scanner.test(&vals[j])) continue;
123  if (printFullEventId_) {
125  printf(" : %9u : %4u : %9llu : %3lu", id.run(), id.luminosityBlock(), id.event(), (unsigned long)j);
126  } else {
127  printf(" : %5d : %3lu", iev, (unsigned long)j);
128  }
129  scanner.print(&vals[j]);
130  std::cout << " :" << std::endl;
131  if (++line == maxLinesToPrint_) {
132  line = 0;
133  if (!wantMore()) {
134  iev = nmax-1; // this is to exit the outer loop
135  break; // and this to exit the inner one
136  }
137  }
138  }
139  }
140  std::cout << std::endl;
141  }
142 
143  //------------------------------------------------------------------------------------------------------------------------------------
147  size_t count(const char *cut) {
148  helper::ScannerBase scanner(objType);
150 
151  scanner.setCut(cut);
152 
153  size_t npass = 0;
154  int iev = 0;
155  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
156  if (maxEvents_ > -1 && iev > maxEvents_) break;
157  if (!selectEvent(*event_)) continue;
158  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
159  const Collection & vals = *handle_;
160  for (size_t j = 0, n = vals.size(); j < n; ++j) {
161  if (scanner.test(&vals[j])) npass++;
162  }
163  }
164  return npass;
165  }
166 
168  size_t countEvents() {
169  size_t npass = 0;
170  int iev = 0;
171  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
172  if (maxEvents_ > -1 && iev > maxEvents_) break;
173  if (selectEvent(*event_)) npass++;
174  }
175  return npass;
176  }
177 
178  //------------------------------------------------------------------------------------------------------------------------------------
187  TH1 * draw(const char *expr, const char *cut, TString drawopt, TH1 *hist) {
188  // prep the machinery
189  helper::ScannerBase scanner(objType);
191  if (!scanner.addExpression(expr)) return 0;
192  if (strlen(cut)) scanner.setCut(cut);
193 
194  // check histo
195  if (hist == 0) {
196  std::cerr << "Method draw(expr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
197  return 0;
198  }
199 
200  // fill histogram
201  int iev = 0;
202  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
203  if (maxEvents_ > -1 && iev > maxEvents_) break;
204  if (!selectEvent(*event_)) continue;
205  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
206  const Collection & vals = *handle_;
207  for (size_t j = 0, n = vals.size(); j < n; ++j) {
208  scanner.fill1D(&vals[j], hist);
209  }
210  }
211 
212  if (drawopt.Contains("NORM",TString::kIgnoreCase) && (hist->Integral() != 0)) {
213  hist->Sumw2();
214  hist->Scale(1.0/hist->Integral());
215  // remove the "NORM" because THistPainter doesn't understand it
216  drawopt(TRegexp("[Nn][Oo][Rr][Mm]")) = "";
217  }
218 
219  if (!drawopt.Contains("GOFF",TString::kIgnoreCase)) hist->Draw(drawopt);
220  return hist;
221  }
222 
229  TH1 * draw(const char *expr, const char *cut = "", TString drawopt = "", const char *hname = "htemp", const TH1 *htemplate = 0) {
230  TH1 *hist = 0;
231  if (htemplate != 0) {
232  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname,htemplate->GetName()) != 0)) htempDelete();
233  hist = (TH1*) hist->Clone(hname);
234  } else if (drawopt.Contains("SAME",TString::kIgnoreCase)) {
235  hist = getSameH1(hname);
236  }
237 
238  // if in the end we found no way to make "hist"
239  if (hist == 0) {
240  if (strcmp(hname, "htemp") == 0) htempDelete();
241  hist = new TH1F(hname, "", gEnv->GetValue("Hist.Binning.1D.x",100), 0, 0);
242  hist->SetCanExtend(TH1::kAllAxes);
243  }
244  hist->SetTitle((strlen(cut) ? TString(expr)+"{"+cut+"}" : TString(expr)));
245  hist->GetXaxis()->SetTitle(expr);
246  return draw(expr, cut, drawopt, hist);
247  }
248 
249 
252  TH1 * draw(const char *expr, int nbins, double xlow, double xhigh, const char *cut = "", const char *drawopt = "", const char *hname = "htemp") {
253  if (TString(drawopt).Contains("SAME",TString::kIgnoreCase)) {
254  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
255  TH1 *hsame = getSameH1(hname);
256  return draw(expr, cut, drawopt, hsame);
257  }
258  if (strcmp(hname, "htemp") == 0) htempDelete();
259  TH1 * htemp = new TH1F(hname, expr, nbins, xlow, xhigh);
260  if (strlen(cut)) htemp->SetTitle(TString(expr)+"{"+cut+"}");
261  htemp->GetXaxis()->SetTitle(expr);
262  return draw(expr,cut,drawopt,htemp);
263  }
266  TH1 * draw(const char *expr, int nbins, double *xbins, const char *cut = "", const char *drawopt = "", const char *hname = "htemp") {
267  if (TString(drawopt).Contains("SAME",TString::kIgnoreCase)) {
268  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
269  TH1 *hsame = getSameH1(hname);
270  return draw(expr, cut, drawopt, hsame);
271  }
272  if (strcmp(hname, "htemp") == 0) htempDelete();
273  TH1 * htemp = new TH1F(hname, expr, nbins, xbins);
274  if (strlen(cut)) htemp->SetTitle(TString(expr)+"{"+cut+"}");
275  htemp->GetXaxis()->SetTitle(expr);
276  return draw(expr,cut,drawopt,htemp);
277  }
278 
279  //------------------------------------------------------------------------------------------------------------------------------------
281  TProfile * drawProf(TString xexpr, TString yexpr, const char *cut, TString drawopt, TProfile *hist) {
282  // prep the machinery
283  helper::ScannerBase scanner(objType);
285  if (!scanner.addExpression(xexpr.Data())) return 0;
286  if (!scanner.addExpression(yexpr.Data())) return 0;
287  if (strlen(cut)) scanner.setCut(cut);
288 
289  // check histo
290  if (hist == 0) {
291  std::cerr << "Method drawProf(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
292  return 0;
293  }
294 
295  // fill histogram
296  int iev = 0;
297  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
298  if (maxEvents_ > -1 && iev > maxEvents_) break;
299  if (!selectEvent(*event_)) continue;
300  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
301  const Collection & vals = *handle_;
302  for (size_t j = 0, n = vals.size(); j < n; ++j) {
303  scanner.fillProf(&vals[j], hist);
304  }
305  }
306 
307  if (!strlen(hist->GetTitle())) hist->SetTitle((strlen(cut) ? yexpr+":"+xexpr+"{"+cut+"}" : yexpr+":"+xexpr));
308  if (!strlen(hist->GetXaxis()->GetTitle())) hist->GetXaxis()->SetTitle(xexpr);
309  if (!strlen(hist->GetYaxis()->GetTitle())) hist->GetYaxis()->SetTitle(yexpr);
310  if (!TString(drawopt).Contains("GOFF",TString::kIgnoreCase)) hist->Draw(drawopt);
311  return hist;
312  }
314  TProfile * drawProf(TString xexpr, TString yexpr, const char *cut = "", TString drawopt = "", const char *hname = "htemp", TProfile *htemplate = 0) {
315  TProfile *hist = 0;
316  if (htemplate != 0) {
317  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname,htemplate->GetName() )!= 0)) htempDelete();
318  hist = (TProfile*) hist->Clone(hname);
319  } else if (drawopt.Contains("SAME",TString::kIgnoreCase)) {
320  hist = getSameProf(hname);
321  }
322 
323  // if in the end we found no way to make "hist"
324  if (hist == 0) {
325  if (strcmp(hname, "htemp") == 0) htempDelete();
326  hist = new TProfile(hname, "", gEnv->GetValue("Hist.Binning.1D.x",100), 0., 0.);
327  hist->SetCanExtend(TH1::kAllAxes);
328  }
329  return drawProf(xexpr, yexpr, cut, drawopt, hist);
330  }
331 
333  TProfile * drawProf(TString xexpr, int bins, double xlow, double xhigh, TString yexpr, const char *cut = "", const char *drawopt = "", const char *hname = "htemp") {
334  if (TString(drawopt).Contains("SAME",TString::kIgnoreCase)) {
335  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
336  TProfile *hsame = getSameProf(hname);
337  return drawProf(xexpr, yexpr, cut, drawopt, hsame);
338  }
339  if (strcmp(hname, "htemp") == 0) htempDelete();
340  TProfile * htemp = new TProfile(hname, "", bins, xlow, xhigh);
341  return drawProf(xexpr,yexpr,cut,drawopt,htemp);
342  }
343 
344  //------------------------------------------------------------------------------------------------------------------------------------
346  TH2 * draw2D(TString xexpr, TString yexpr, const char *cut, TString drawopt, TH2 *hist) {
347  // prep the machinery
348  helper::ScannerBase scanner(objType);
350  if (!scanner.addExpression((const char *)xexpr)) return 0;
351  if (!scanner.addExpression((const char *)yexpr)) return 0;
352  if (strlen(cut)) scanner.setCut(cut);
353 
354  // check histo
355  if (hist == 0) {
356  std::cerr << "Method draw2D(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
357  return 0;
358  }
359 
360  // fill histogram
361  int iev = 0;
362  for (event_->toBegin(), iev = 0; !event_->atEnd(); ++(*event_), ++iev) {
363  if (maxEvents_ > -1 && iev > maxEvents_) break;
364  if (!selectEvent(*event_)) continue;
365  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
366  const Collection & vals = *handle_;
367  for (size_t j = 0, n = vals.size(); j < n; ++j) {
368  scanner.fill2D(&vals[j], hist);
369  }
370  }
371 
372  if (!strlen(hist->GetTitle())) hist->SetTitle((strlen(cut) ? yexpr+":"+xexpr+"{"+cut+"}" : yexpr+":"+xexpr));
373  if (!strlen(hist->GetXaxis()->GetTitle())) hist->GetXaxis()->SetTitle(xexpr);
374  if (!strlen(hist->GetYaxis()->GetTitle())) hist->GetYaxis()->SetTitle(yexpr);
375  if (!TString(drawopt).Contains("GOFF",TString::kIgnoreCase)) hist->Draw(drawopt);
376  return hist;
377  }
380  TH2 * draw2D(TString xexpr, TString yexpr, const char *cut = "", TString drawopt = "", const char *hname = "htemp", TH2 *htemplate = 0) {
381  TH2 *hist = 0;
382  if (htemplate != 0) {
383  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname,htemplate->GetName()) != 0)) htempDelete();
384  hist = (TH2*) hist->Clone(hname);
385  } else if (drawopt.Contains("SAME",TString::kIgnoreCase)) {
386  hist = getSameH2(hname);
387  }
388 
389  // if in the end we found no way to make "hist"
390  if (hist == 0) {
391  // prep the machinery
392  helper::ScannerBase scanner(objType);
394  if (!scanner.addExpression((const char *)xexpr)) return 0;
395  if (!scanner.addExpression((const char *)yexpr)) return 0;
396  if (strlen(cut)) scanner.setCut(cut);
397 
398  if (strcmp(hname, "htemp") == 0) htempDelete();
399  // ok this is much more a hack than for the 1D case
400  double xmin = 0, xmax = -1, ymin = 0, ymax = -1; int iev;
401  for (event_->toBegin(), iev = 0; !event_->atEnd(); ++(*event_), ++iev) {
402  if (maxEvents_ > -1 && iev > maxEvents_) break;
403  if (!selectEvent(*event_)) continue;
404  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
405  const Collection & vals = *handle_;
406  for (size_t j = 0, n = vals.size(); j < n; ++j) {
407  if (!scanner.test(&vals[j])) continue;
408  double x = scanner.eval(&vals[j],0);
409  double y = scanner.eval(&vals[j],1);
410  if ((xmax == -1) || (x >= xmax)) xmax = x;
411  if ((xmin == 0) || (x <= xmin)) xmin = x;
412  if ((ymax == -1) || (y >= ymax)) ymax = y;
413  if ((ymin == 0) || (y <= ymin)) ymin = y;
414  }
415  }
416  hist = new TH2F(hname, "",
417  gEnv->GetValue("Hist.Binning.2D.x",20), xmin, xmax,
418  gEnv->GetValue("Hist.Binning.2D.y",20), ymin, ymax);
419  }
420  return draw2D(xexpr, yexpr, cut, drawopt, hist);
421  }
422 
424  TH2 * draw2D(TString xexpr, int xbins, double xlow, double xhigh,
425  TString yexpr, int ybins, double ylow, double yhigh,
426  const char *cut = "", const char *drawopt = "", const char *hname="htemp") {
427  if (TString(drawopt).Contains("SAME",TString::kIgnoreCase)) {
428  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
429  TH2 *hsame = getSameH2(hname);
430  return draw2D(xexpr, yexpr, cut, drawopt, hsame);
431  }
432  if (strcmp(hname, "htemp") == 0) htempDelete();
433  TH2 * htemp = new TH2F("htemp", "", xbins, xlow, xhigh, ybins,ylow,yhigh);
434  return draw2D(xexpr,yexpr,cut,drawopt,htemp);
435  }
436 
438  TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut, TString drawopt, TGraph *graph) {
439  // prep the machinery
440  helper::ScannerBase scanner(objType);
442  if (!scanner.addExpression((const char *)xexpr)) return 0;
443  if (!scanner.addExpression((const char *)yexpr)) return 0;
444  if (strlen(cut)) scanner.setCut(cut);
445 
446  // make graph, if needed
447  if (graph == 0) {
448  graph = new TGraph();
449  graph->SetNameTitle("htemp", (strlen(cut) ? yexpr+":"+xexpr+"{"+cut+"}" : yexpr+":"+xexpr));
450  }
451 
452  // fill graph
453  int iev = 0;
454  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
455  if (maxEvents_ > -1 && iev > maxEvents_) break;
456  if (!selectEvent(*event_)) continue;
457  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
458  const Collection & vals = *handle_;
459  for (size_t j = 0, n = vals.size(); j < n; ++j) {
460  scanner.fillGraph(&vals[j], graph);
461  }
462  }
463 
464  if (!strlen(graph->GetTitle())) graph->SetTitle((strlen(cut) ? yexpr+":"+xexpr+"{"+cut+"}" : yexpr+":"+xexpr));
465  if (!strlen(graph->GetXaxis()->GetTitle())) graph->GetXaxis()->SetTitle(xexpr);
466  if (!strlen(graph->GetYaxis()->GetTitle())) graph->GetYaxis()->SetTitle(yexpr);
467  if (!TString(drawopt).Contains("GOFF",TString::kIgnoreCase)) graph->Draw(drawopt);
468  return graph;
469  }
470 
472  TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut = "", TString drawopt = "AP", const char *gname = "htemp") {
473  if (strcmp(gname, "htemp") == 0) htempDelete();
474  TGraph *graph = new TGraph();
475  graph->SetNameTitle(gname, (strlen(cut) ? yexpr+":"+xexpr+"{"+cut+"}" : yexpr+":"+xexpr));
476  return drawGraph(xexpr,yexpr,cut,drawopt,graph);
477  }
478 
479 
480  //------------------------------------------------------------------------------------------------------------------------------------
487  RooDataSet *fillDataSet(const char *realvars, const char *boolvars, const char *cut="", const char *name="data") {
488  helper::ScannerBase scanner(objType);
490 
491  RooArgList vars;
492  TObjArray *exprArray = TString(realvars).Tokenize(exprSep_);
493  TObjArray *catArray = TString(boolvars).Tokenize(exprSep_);
494  int nreals = exprArray->GetEntries();
495  int nbools = catArray->GetEntries();
496  for (int i = 0; i < nreals; ++i) {
497  TString str = ((TObjString *)(*exprArray)[i])->GetString();
498  std::string lb = str.Data();
499  std::string ex = str.Data();
500  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
501  lb = lb.substr(1,ex.find('=')-1);
502  ex = ex.substr(ex.find('=')+1);
503  }
504  if (!scanner.addExpression(ex.c_str())) {
505  std::cerr << "Filed to define real variable '" << lb << "', expr = '" << ex << "'" << std::endl;
506  return 0;
507  }
508  // FIXME: I have to leave it dangling on the HEAP otherwise ROOT segfaults...
509  RooRealVar *var = new RooRealVar(lb.c_str(),lb.c_str(), 0.0);
510  vars.add(*var);
511  }
512  for (int i = 0; i < nbools; ++i) {
513  TString str = ((TObjString *)(*catArray)[i])->GetString();
514  std::string lb = str.Data();
515  std::string ex = str.Data();
516  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
517  lb = lb.substr(1,ex.find('=')-1);
518  ex = ex.substr(ex.find('=')+1);
519  }
520  if (!scanner.addExtraCut(ex.c_str())) {
521  std::cerr << "Filed to define bool variable '" << lb << "', cut = '" << ex << "'" << std::endl;
522  return 0;
523  }
524  RooCategory *cat = new RooCategory(lb.c_str(), lb.c_str());
525  cat->defineType("fail",0);
526  cat->defineType("pass",1);
527  vars.add(*cat);
528  }
529 
530  RooDataSet *ds = new RooDataSet(name, name, vars);
531 
532  if (strlen(cut)) scanner.setCut(cut);
533  int iev = 0;
534  for (event_->toBegin(); !event_->atEnd(); ++iev, ++(*event_)) {
535  if (maxEvents_ > -1 && iev > maxEvents_) break;
536  if (!selectEvent(*event_)) continue;
537  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
538  if (handle_.failedToGet()) {
539  if (ignoreExceptions_) continue;
540  }
541  const Collection & vals = *handle_;
542  for (size_t j = 0, n = vals.size(); j < n; ++j) {
543  if (!scanner.test(&vals[j])) continue;
544  for (int i = 0; i < nreals; ++i) {
545  RooRealVar *var = (RooRealVar *)vars.at(i);
546  var->setVal(scanner.eval(&vals[j], i));
547  }
548  for (int i = 0; i < nbools; ++i) {
549  RooCategory *cat = (RooCategory*) vars.at(i+nreals);
550  cat->setIndex(int(scanner.test(&vals[j], i+1))); // 0 is the event selection cut
551  }
552  ds->add(vars);
553  }
554  }
555 
556  delete exprArray;
557  delete catArray;
558 
559  return ds;
560  }
561 
562 
563 
564  void setPrintFullEventId(bool printIt=true) { printFullEventId_ = printIt; }
566  void setIgnoreExceptions(bool ignoreThem) { ignoreExceptions_ = ignoreThem; }
567  void setMaxLinesToPrint(int lines) { maxLinesToPrint_ = (lines > 0 ? lines : 2147483647); }
568 
569  void addEventSelector(fwlite::EventSelector *selector) { eventSelectors_.Add(selector); }
571  TObjArray & eventSelectors() { return eventSelectors_; }
572  bool selectEvent(const fwlite::EventBase &ev) const {
573  for (int i = 0, n = eventSelectors_.GetEntries(); i < n; ++i) {
574  if (!((fwlite::EventSelector *)(eventSelectors_[i]))->accept(ev)) return false;
575  }
576  return true;
577  }
578 
579  void setMaxEvents(int max) { maxEvents_ = max; }
580  private:
585  TString exprSep_;
586  HandleT handle_;
588 
589  TObjArray eventSelectors_;
590 
592 
594  bool wantMore() const {
595  // ask if user wants more
596  fprintf(stderr,"Type <CR> to continue or q to quit ==> ");
597  // read first char
598  int readch = getchar(), answer = readch;
599  // poll out remaining chars from buffer
600  while (readch != '\n' && readch != EOF) readch = getchar();
601  // check first char
602  return !(answer == 'q' || answer == 'Q');
603  }
604 
605  void htempDelete() {
606  if (gDirectory) {
607  TObject *obj = gDirectory->Get("htemp");
608  if (obj) obj->Delete();
609  }
610  }
611 
614  TH1 *getSameH1(const char *hname) {
615  if (gDirectory && gDirectory->Get("htemp") != 0 &&
616  gDirectory->Get("htemp")->IsA()->InheritsFrom(TH1::Class())) {
617  TH1 *hist = (TH1*) ((TH1*) gDirectory->Get("htemp"))->Clone(hname);
618  hist->Reset();
619  hist->SetLineColor(kBlack);
620  hist->SetMarkerColor(kBlack);
621  return hist;
622  } else {
623  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
624  return 0;
625  }
626  }
627 
630  TH2 *getSameH2(const char *hname) {
631  if (gDirectory && gDirectory->Get("htemp") != 0 &&
632  gDirectory->Get("htemp")->IsA()->InheritsFrom(TH2::Class())) {
633  TH2 *hist = (TH2*) ((TH2*) gDirectory->Get("htemp"))->Clone(hname);
634  hist->Reset();
635  hist->SetLineColor(kBlack);
636  hist->SetMarkerColor(kBlack);
637  return hist;
638  } else {
639  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
640  return 0;
641  }
642  }
643 
646  TProfile *getSameProf(const char *hname) {
647  if (gDirectory && gDirectory->Get("htemp") != 0 &&
648  gDirectory->Get("htemp")->IsA()->InheritsFrom(TProfile::Class())) {
649  TProfile *hist = (TProfile*) ((TProfile*) gDirectory->Get("htemp"))->Clone(hname);
650  hist->Reset();
651  hist->SetLineColor(kBlack);
652  hist->SetMarkerColor(kBlack);
653  return hist;
654  } else {
655  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
656  return 0;
657  }
658  }
659 
660 
661  };
662 }
663 #endif // PhysicsTools_FWLite_Scanner_h
void clearEventSelector()
Definition: Scanner.h:570
void print(const void *obj) const
bool ignoreExceptions_
Definition: Scanner.h:584
string separator
Definition: mps_merge.py:77
void addEventSelector(fwlite::EventSelector *selector)
Definition: Scanner.h:569
const double xbins[]
void setPrintFullEventId(bool printIt=true)
Definition: Scanner.h:564
void fill2D(const void *obj, TH2 *hist2d) const
static PFTauRenderPlugin instance
TObjArray eventSelectors_
Definition: Scanner.h:589
size_t count(const char *cut)
Definition: Scanner.h:147
void setIgnoreExceptions(bool ignoreThem)
void setMaxLinesToPrint(int lines)
Definition: Scanner.h:567
TH2 * getSameH2(const char *hname)
Definition: Scanner.h:630
TH2 * draw2D(TString xexpr, int xbins, double xlow, double xhigh, TString yexpr, int ybins, double ylow, double yhigh, const char *cut="", const char *drawopt="", const char *hname="htemp")
Just like draw() except that it uses TH2. Note that the order is (x,y) while in ROOT it&#39;s usually (y...
Definition: Scanner.h:424
void setExpressionSeparator(TString separator)
Definition: Scanner.h:565
bool printFullEventId_
Definition: Scanner.h:583
TH2 * draw2D(TString xexpr, TString yexpr, const char *cut="", TString drawopt="", const char *hname="htemp", TH2 *htemplate=0)
Definition: Scanner.h:380
TH1 * draw(const char *expr, int nbins, double *xbins, const char *cut="", const char *drawopt="", const char *hname="htemp")
Definition: Scanner.h:266
TProfile * drawProf(TString xexpr, TString yexpr, const char *cut, TString drawopt, TProfile *hist)
Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it&#39;s usuall...
Definition: Scanner.h:281
TString exprSep_
Definition: Scanner.h:585
bool ev
HandleT handle_
Definition: Scanner.h:586
TH1 * getSameH1(const char *hname)
Definition: Scanner.h:614
std::string label_
Definition: Scanner.h:582
bool addExtraCut(const char *cut)
Add one extra cut that can be evaluated separately (as if it was an expression)
TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut="", TString drawopt="AP", const char *gname="htemp")
Definition: Scanner.h:472
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=0, const char *iProcessLabel=0)
Definition: Handle.h:91
fwlite::Handle< Collection > HandleT
The type of the Handle to read the Ts from the event. Needed to resolve its Type. ...
Definition: Scanner.h:49
TH1 * draw(const char *expr, int nbins, double xlow, double xhigh, const char *cut="", const char *drawopt="", const char *hname="htemp")
Definition: Scanner.h:252
def cat(path)
Definition: eostools.py:400
fwlite::Scanner<C>, a way to inspect or plots elements of a collection C by using the StringParser...
Definition: Scanner.h:46
edm::TypeWithDict objType
Definition: Scanner.h:587
size_t countEvents()
Definition: Scanner.h:168
virtual bool atEnd() const =0
fwlite::EventBase * event_
Definition: Scanner.h:581
bool test(const void *obj, size_t icut=0) const
double eval(const void *obj, size_t iexpr=0) const
bool failedToGet() const
Returns true only if Handle was used in a &#39;get&#39; call and the data could not be found.
Definition: Handle.h:64
void fill1D(const void *obj, TH1 *hist) const
TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut, TString drawopt, TGraph *graph)
Definition: Scanner.h:438
TProfile * drawProf(TString xexpr, TString yexpr, const char *cut="", TString drawopt="", const char *hname="htemp", TProfile *htemplate=0)
Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it&#39;s usuall...
Definition: Scanner.h:314
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Scanner(fwlite::EventBase *ev, const char *label, const char *instance="", const char *process="")
Definition: Scanner.h:52
bool addExpression(const char *expr)
void scan(const char *exprs, const char *cut="", int nmax=-1)
Definition: Scanner.h:79
void setIgnoreExceptions(bool ignoreThem)
Definition: Scanner.h:566
std::string instance_
Definition: Scanner.h:582
RooDataSet * fillDataSet(const char *realvars, const char *boolvars, const char *cut="", const char *name="data")
Definition: Scanner.h:487
TProfile * getSameProf(const char *hname)
Definition: Scanner.h:646
TH1 * draw(const char *expr, const char *cut="", TString drawopt="", const char *hname="htemp", const TH1 *htemplate=0)
Definition: Scanner.h:229
int maxLinesToPrint_
Definition: Scanner.h:593
static edm::TypeWithDict elementType(const edm::TypeWithDict &wrapperType)
Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs.
TH1 * draw(const char *expr, const char *cut, TString drawopt, TH1 *hist)
Definition: Scanner.h:187
bool setCut(const char *cut)
Set the default cut that is applied to the events.
TProfile * drawProf(TString xexpr, int bins, double xlow, double xhigh, TString yexpr, const char *cut="", const char *drawopt="", const char *hname="htemp")
Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it&#39;s usuall...
Definition: Scanner.h:333
TH2 * draw2D(TString xexpr, TString yexpr, const char *cut, TString drawopt, TH2 *hist)
Just like draw() except that it uses TH2. Note that the order is (x,y) while in ROOT it&#39;s usually (y...
Definition: Scanner.h:346
void fillProf(const void *obj, TProfile *prof) const
void setMaxEvents(int max)
Definition: Scanner.h:579
bool wantMore() const
Definition: Scanner.h:594
void htempDelete()
Definition: Scanner.h:605
vars
Definition: DeepTauId.cc:77
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:572
#define str(s)
virtual EventBase const & toBegin()=0
void fillGraph(const void *obj, TGraph *graph) const
TObjArray & eventSelectors()
Definition: Scanner.h:571
std::string process_
Definition: Scanner.h:582
answer
Definition: submit.py:44
static std::type_info const & typeInfo()
Definition: Wrapper.h:42
virtual edm::EventAuxiliary const & eventAuxiliary() const =0