CMS 3D CMS Logo

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