1 #ifndef PhysicsTools_FWLite_Scanner_h 2 #define PhysicsTools_FWLite_Scanner_h 9 #include <TObjString.h> 10 #include <TObjArray.h> 11 #include <TDirectory.h> 15 #if !defined(__CINT__) && !defined(__MAKECINT__) 17 #include <RooArgList.h> 18 #include <RooDataSet.h> 19 #include <RooRealVar.h> 20 #include <RooCategory.h> 45 template<
typename Collection>
79 void scan(
const char *exprs,
const char *
cut=
"",
int nmax=-1) {
83 TObjArray *exprArray = TString(exprs).Tokenize(
exprSep_);
86 printf(
" : %9s : %4s : %9s : %3s",
"RUN",
"LUMI",
"EVENT",
"#IT");
87 rowline += 3*4+9+4+9+3-1;
89 printf(
" : %5s : %3s",
"EVENT",
"#IT");
92 for (
int i = 0;
i < exprArray->GetEntries(); ++
i) {
93 TString
str = ((TObjString *)(*exprArray)[
i])->GetString();
96 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
97 lb = lb.substr(1,ex.find(
'=')-1);
98 ex = ex.substr(ex.find(
'=')+1);
101 printf(
" : %8s", (lb.size()>8 ? lb.substr(lb.size()-8) : lb).c_str());
108 TString rule(
'-', rowline);
109 std::cout <<
" " << rule <<
" " << std::endl;
113 int iev = 0,
line = 0;
121 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
122 if (!scanner.
test(&vals[j]))
continue;
125 printf(
" : %9u : %4u : %9llu : %3lu",
id.
run(),
id.luminosityBlock(),
id.
event(), (
unsigned long)j);
127 printf(
" : %5d : %3lu", iev, (
unsigned long)j);
129 scanner.
print(&vals[j]);
160 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
161 if (scanner.
test(&vals[j])) npass++;
192 if (strlen(cut)) scanner.
setCut(cut);
196 std::cerr <<
"Method draw(expr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
207 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
208 scanner.
fill1D(&vals[j], hist);
212 if (drawopt.Contains(
"NORM",TString::kIgnoreCase) && (hist->Integral() != 0)) {
214 hist->Scale(1.0/hist->Integral());
216 drawopt(TRegexp(
"[Nn][Oo][Rr][Mm]")) =
"";
219 if (!drawopt.Contains(
"GOFF",TString::kIgnoreCase)) hist->Draw(drawopt);
229 TH1 *
draw(
const char *
expr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp",
const TH1 *htemplate = 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)) {
241 hist =
new TH1F(hname,
"", gEnv->GetValue(
"Hist.Binning.1D.x",100), 0, 0);
242 hist->SetCanExtend(TH1::kAllAxes);
244 hist->SetTitle((strlen(
cut) ? TString(expr)+
"{"+
cut+
"}" : TString(expr)));
245 hist->GetXaxis()->SetTitle(expr);
246 return draw(expr,
cut, drawopt, hist);
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;
256 return draw(expr,
cut, drawopt, hsame);
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);
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;
270 return draw(expr,
cut, drawopt, hsame);
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);
281 TProfile *
drawProf(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TProfile *
hist) {
287 if (strlen(cut)) scanner.
setCut(cut);
291 std::cerr <<
"Method drawProf(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
302 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
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);
314 TProfile *
drawProf(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp", TProfile *htemplate = 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)) {
326 hist =
new TProfile(hname,
"", gEnv->GetValue(
"Hist.Binning.1D.x",100), 0., 0.);
327 hist->SetCanExtend(TH1::kAllAxes);
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;
337 return drawProf(xexpr, yexpr,
cut, drawopt, hsame);
340 TProfile * htemp =
new TProfile(hname,
"", bins, xlow, xhigh);
346 TH2 *
draw2D(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TH2 *
hist) {
352 if (strlen(cut)) scanner.
setCut(cut);
356 std::cerr <<
"Method draw2D(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
367 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
368 scanner.
fill2D(&vals[j], hist);
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);
380 TH2 *
draw2D(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp", TH2 *htemplate = 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)) {
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);
411 if ((xmin == 0) || (x <= xmin)) xmin = x;
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);
420 return draw2D(xexpr, yexpr,
cut, drawopt, hist);
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;
430 return draw2D(xexpr, yexpr,
cut, drawopt, hsame);
433 TH2 * htemp =
new TH2F(
"htemp",
"", xbins, xlow, xhigh, ybins,ylow,yhigh);
434 return draw2D(xexpr,yexpr,
cut,drawopt,htemp);
438 TGraph *
drawGraph(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TGraph *graph) {
444 if (strlen(cut)) scanner.
setCut(cut);
448 graph =
new TGraph();
449 graph->SetNameTitle(
"htemp", (strlen(cut) ? yexpr+
":"+xexpr+
"{"+cut+
"}" : yexpr+
":"+xexpr));
459 for (
size_t j = 0,
n = vals.size(); j <
n; ++j) {
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);
472 TGraph *
drawGraph(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"AP",
const char *gname =
"htemp") {
474 TGraph *graph =
new TGraph();
475 graph->SetNameTitle(gname, (strlen(
cut) ? yexpr+
":"+xexpr+
"{"+
cut+
"}" : yexpr+
":"+xexpr));
487 RooDataSet *
fillDataSet(
const char *realvars,
const char *boolvars,
const char *
cut=
"",
const char *
name=
"data") {
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();
500 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
501 lb = lb.substr(1,ex.find(
'=')-1);
502 ex = ex.substr(ex.find(
'=')+1);
505 std::cerr <<
"Filed to define real variable '" << lb <<
"', expr = '" << ex <<
"'" << std::endl;
509 RooRealVar *
var =
new RooRealVar(lb.c_str(),lb.c_str(), 0.0);
512 for (
int i = 0;
i < nbools; ++
i) {
513 TString
str = ((TObjString *)(*catArray)[
i])->GetString();
516 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
517 lb = lb.substr(1,ex.find(
'=')-1);
518 ex = ex.substr(ex.find(
'=')+1);
521 std::cerr <<
"Filed to define bool variable '" << lb <<
"', cut = '" << ex <<
"'" << std::endl;
524 RooCategory *
cat =
new RooCategory(lb.c_str(), lb.c_str());
525 cat->defineType(
"fail",0);
526 cat->defineType(
"pass",1);
530 RooDataSet *ds =
new RooDataSet(
name,
name, vars);
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));
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)));
596 fprintf(stderr,
"Type <CR> to continue or q to quit ==> ");
598 int readch = getchar(),
answer = readch;
600 while (readch !=
'\n' && readch != EOF) readch = getchar();
607 TObject *
obj = gDirectory->Get(
"htemp");
608 if (obj) obj->Delete();
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);
619 hist->SetLineColor(kBlack);
620 hist->SetMarkerColor(kBlack);
623 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
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);
635 hist->SetLineColor(kBlack);
636 hist->SetMarkerColor(kBlack);
639 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
647 if (gDirectory && gDirectory->Get(
"htemp") != 0 &&
649 TProfile *
hist = (TProfile*) ((TProfile*) gDirectory->Get(
"htemp"))->Clone(hname);
651 hist->SetLineColor(kBlack);
652 hist->SetMarkerColor(kBlack);
655 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
663 #endif // PhysicsTools_FWLite_Scanner_h void clearEventSelector()
void print(const void *obj) const
void addEventSelector(fwlite::EventSelector *selector)
void setPrintFullEventId(bool printIt=true)
void fill2D(const void *obj, TH2 *hist2d) const
static PFTauRenderPlugin instance
TObjArray eventSelectors_
size_t count(const char *cut)
void setIgnoreExceptions(bool ignoreThem)
void setMaxLinesToPrint(int lines)
TH2 * getSameH2(const char *hname)
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's usually (y...
void setExpressionSeparator(TString separator)
TH2 * draw2D(TString xexpr, TString yexpr, const char *cut="", TString drawopt="", const char *hname="htemp", TH2 *htemplate=0)
TH1 * draw(const char *expr, int nbins, double *xbins, const char *cut="", const char *drawopt="", const char *hname="htemp")
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's usuall...
TH1 * getSameH1(const char *hname)
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")
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=0, const char *iProcessLabel=0)
fwlite::Handle< Collection > HandleT
The type of the Handle to read the Ts from the event. Needed to resolve its Type. ...
TH1 * draw(const char *expr, int nbins, double xlow, double xhigh, const char *cut="", const char *drawopt="", const char *hname="htemp")
fwlite::Scanner<C>, a way to inspect or plots elements of a collection C by using the StringParser...
edm::TypeWithDict objType
virtual bool atEnd() const =0
fwlite::EventBase * event_
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 'get' call and the data could not be found.
void fill1D(const void *obj, TH1 *hist) const
TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut, TString drawopt, TGraph *graph)
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's usuall...
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="")
bool addExpression(const char *expr)
void scan(const char *exprs, const char *cut="", int nmax=-1)
void setIgnoreExceptions(bool ignoreThem)
RooDataSet * fillDataSet(const char *realvars, const char *boolvars, const char *cut="", const char *name="data")
TProfile * getSameProf(const char *hname)
TH1 * draw(const char *expr, const char *cut="", TString drawopt="", const char *hname="htemp", const TH1 *htemplate=0)
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)
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's usuall...
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's usually (y...
void fillProf(const void *obj, TProfile *prof) const
void setMaxEvents(int max)
bool selectEvent(const fwlite::EventBase &ev) const
virtual EventBase const & toBegin()=0
void fillGraph(const void *obj, TGraph *graph) const
TObjArray & eventSelectors()
static std::type_info const & typeInfo()
virtual edm::EventAuxiliary const & eventAuxiliary() const =0