7 #include <TObjString.h>
9 #include <TDirectory.h>
13 #if !defined(__CINT__) && !defined(__MAKECINT__)
15 #include <RooArgList.h>
16 #include <RooDataSet.h>
17 #include <RooRealVar.h>
18 #include <RooCategory.h>
43 template<
typename Collection>
77 void scan(
const char *exprs,
const char *
cut=
"",
int nmax=-1) {
81 TObjArray *exprArray = TString(exprs).Tokenize(
exprSep_);
84 printf(
" : %9s : %4s : %9s : %3s",
"RUN",
"LUMI",
"EVENT",
"#IT");
85 rowline += 3*4+9+4+9+3-1;
87 printf(
" : %5s : %3s",
"EVENT",
"#IT");
90 for (
int i = 0;
i < exprArray->GetEntries(); ++
i) {
91 TString str = ((TObjString *)(*exprArray)[
i])->GetString();
94 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
95 lb = lb.substr(1,ex.find(
'=')-1);
96 ex = ex.substr(ex.find(
'=')+1);
99 printf(
" : %8s", (lb.size()>8 ? lb.substr(lb.size()-8) : lb).c_str());
106 TString rule(
'-', rowline);
107 std::cout <<
" " << rule <<
" " << std::endl;
111 int iev = 0,
line = 0;
119 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
120 if (!scanner.
test(&vals[
j]))
continue;
123 printf(
" : %9d : %4d : %9d : %3lu",
id.
run(),
id.luminosityBlock(),
id.
event(), (
unsigned long)j);
125 printf(
" : %5d : %3lu", iev, (
unsigned long)j);
127 scanner.
print(&vals[j]);
158 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
159 if (scanner.
test(&vals[
j])) npass++;
185 TH1 *
draw(
const char *expr,
const char *
cut, TString drawopt, TH1 *
hist) {
190 if (strlen(cut)) scanner.
setCut(cut);
194 std::cerr <<
"Method draw(expr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
205 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
206 scanner.
fill1D(&vals[
j], hist);
210 if (drawopt.Contains(
"NORM",TString::kIgnoreCase) && (hist->Integral() != 0)) {
212 hist->Scale(1.0/hist->Integral());
214 drawopt(TRegexp(
"[Nn][Oo][Rr][Mm]")) =
"";
217 if (!drawopt.Contains(
"GOFF",TString::kIgnoreCase)) hist->Draw(drawopt);
227 TH1 *
draw(
const char *expr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp",
const TH1 *htemplate = 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)) {
239 hist =
new TH1F(hname,
"", gEnv->GetValue(
"Hist.Binning.1D.x",100), 0, 0);
240 hist->SetBit(TH1::kCanRebin);
242 hist->SetTitle((strlen(
cut) ? TString(expr)+
"{"+
cut+
"}" : TString(expr)));
243 hist->GetXaxis()->SetTitle(expr);
244 return draw(expr,
cut, drawopt, hist);
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;
254 return draw(expr,
cut, drawopt, hsame);
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);
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;
268 return draw(expr,
cut, drawopt, hsame);
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);
279 TProfile *
drawProf(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TProfile *
hist) {
285 if (strlen(cut)) scanner.
setCut(cut);
289 std::cerr <<
"Method drawProf(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
300 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
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);
312 TProfile *
drawProf(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp", TProfile *htemplate = 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)) {
324 hist =
new TProfile(hname,
"", gEnv->GetValue(
"Hist.Binning.1D.x",100), 0., 0.);
325 hist->SetBit(TProfile::kCanRebin);
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;
335 return drawProf(xexpr, yexpr,
cut, drawopt, hsame);
338 TProfile * htemp =
new TProfile(hname,
"", bins, xlow, xhigh);
344 TH2 *
draw2D(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TH2 *
hist) {
350 if (strlen(cut)) scanner.
setCut(cut);
354 std::cerr <<
"Method draw2D(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw methods instead." << std::endl;
365 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
366 scanner.
fill2D(&vals[
j], hist);
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);
378 TH2 *
draw2D(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"",
const char *hname =
"htemp", TH2 *htemplate = 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)) {
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);
409 if ((xmin == 0) || (x <= xmin)) xmin =
x;
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);
418 return draw2D(xexpr, yexpr,
cut, drawopt, hist);
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;
428 return draw2D(xexpr, yexpr,
cut, drawopt, hsame);
431 TH2 * htemp =
new TH2F(
"htemp",
"", xbins, xlow, xhigh, ybins,ylow,yhigh);
432 return draw2D(xexpr,yexpr,
cut,drawopt,htemp);
436 TGraph *
drawGraph(TString xexpr, TString yexpr,
const char *
cut, TString drawopt, TGraph *
graph) {
442 if (strlen(cut)) scanner.
setCut(cut);
446 graph =
new TGraph();
447 graph->SetNameTitle(
"htemp", (strlen(cut) ? yexpr+
":"+xexpr+
"{"+cut+
"}" : yexpr+
":"+xexpr));
457 for (
size_t j = 0,
n = vals.size();
j <
n; ++
j) {
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);
470 TGraph *
drawGraph(TString xexpr, TString yexpr,
const char *
cut =
"", TString drawopt =
"AP",
const char *gname =
"htemp") {
472 TGraph *
graph =
new TGraph();
473 graph->SetNameTitle(gname, (strlen(
cut) ? yexpr+
":"+xexpr+
"{"+
cut+
"}" : yexpr+
":"+xexpr));
485 RooDataSet *
fillDataSet(
const char *realvars,
const char *boolvars,
const char *
cut=
"",
const char *
name=
"data") {
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();
498 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
499 lb = lb.substr(1,ex.find(
'=')-1);
500 ex = ex.substr(ex.find(
'=')+1);
503 std::cerr <<
"Filed to define real variable '" << lb <<
"', expr = '" << ex <<
"'" << std::endl;
507 RooRealVar *var =
new RooRealVar(lb.c_str(),lb.c_str(), 0.0);
510 for (
int i = 0;
i < nbools; ++
i) {
511 TString str = ((TObjString *)(*catArray)[
i])->GetString();
514 if ((ex[0] ==
'@') && (ex.find(
'=') != std::string::npos)) {
515 lb = lb.substr(1,ex.find(
'=')-1);
516 ex = ex.substr(ex.find(
'=')+1);
519 std::cerr <<
"Filed to define bool variable '" << lb <<
"', cut = '" << ex <<
"'" << std::endl;
522 RooCategory *cat =
new RooCategory(lb.c_str(), lb.c_str());
523 cat->defineType(
"fail",0);
524 cat->defineType(
"pass",1);
528 RooDataSet *ds =
new RooDataSet(
name,
name, vars);
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));
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)));
594 fprintf(stderr,
"Type <CR> to continue or q to quit ==> ");
596 int readch = getchar(),
answer = readch;
598 while (readch !=
'\n' && readch != EOF) readch = getchar();
605 TObject *
obj = gDirectory->Get(
"htemp");
606 if (obj) obj->Delete();
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);
617 hist->SetLineColor(kBlack);
618 hist->SetMarkerColor(kBlack);
621 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
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);
633 hist->SetLineColor(kBlack);
634 hist->SetMarkerColor(kBlack);
637 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
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);
649 hist->SetLineColor(kBlack);
650 hist->SetMarkerColor(kBlack);
653 std::cerr <<
"There is no 'htemp' histogram from which to 'SAME'." << std::endl;
void clearEventSelector()
void print(const void *obj) const
virtual edm::EventAuxiliary const & eventAuxiliary() const =0
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...
const T & max(const T &a, const T &b)
edm::TypeWithDict objType
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)
virtual bool atEnd() const =0
volatile std::atomic< bool > shutdown_flag false
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()