CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
fwlite::Scanner< Collection > Class Template Reference

fwlite::Scanner<C>, a way to inspect or plots elements of a collection C by using the StringParser. More...

#include <Scanner.h>

Public Types

typedef fwlite::Handle< Collection > HandleT
 The type of the Handle to read the Ts from the event. Needed to resolve its Type. More...
 

Public Member Functions

void addEventSelector (fwlite::EventSelector *selector)
 
void clearEventSelector ()
 
size_t count (const char *cut)
 
size_t countEvents ()
 
TH1 * draw (const char *expr, const char *cut, TString drawopt, TH1 *hist)
 
TH1 * draw (const char *expr, const char *cut="", TString drawopt="", const char *hname="htemp", const TH1 *htemplate=nullptr)
 
TH1 * draw (const char *expr, int nbins, double xlow, double xhigh, const char *cut="", const char *drawopt="", const char *hname="htemp")
 
TH1 * draw (const char *expr, int nbins, double *xbins, const char *cut="", const char *drawopt="", const char *hname="htemp")
 
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,x)! More...
 
TH2 * draw2D (TString xexpr, TString yexpr, const char *cut="", TString drawopt="", const char *hname="htemp", TH2 *htemplate=nullptr)
 
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,x)! More...
 
TGraph * drawGraph (TString xexpr, TString yexpr, const char *cut, TString drawopt, TGraph *graph)
 
TGraph * drawGraph (TString xexpr, TString yexpr, const char *cut="", TString drawopt="AP", const char *gname="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 usually (y,x)! More...
 
TProfile * drawProf (TString xexpr, TString yexpr, const char *cut="", TString drawopt="", const char *hname="htemp", TProfile *htemplate=nullptr)
 Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it's usually (y,x)! More...
 
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 usually (y,x)! More...
 
TObjArray & eventSelectors ()
 
RooDataSet * fillDataSet (const char *realvars, const char *boolvars, const char *cut="", const char *name="data")
 
void scan (const char *exprs, const char *cut="", int nmax=-1)
 
 Scanner (fwlite::EventBase *ev, const char *label, const char *instance="", const char *process="")
 
bool selectEvent (const fwlite::EventBase &ev) const
 
void setExpressionSeparator (TString separator)
 
void setIgnoreExceptions (bool ignoreThem)
 
void setMaxEvents (int max)
 
void setMaxLinesToPrint (int lines)
 
void setPrintFullEventId (bool printIt=true)
 

Private Member Functions

TH1 * getSameH1 (const char *hname)
 
TH2 * getSameH2 (const char *hname)
 
TProfile * getSameProf (const char *hname)
 
void htempDelete ()
 
bool wantMore () const
 

Private Attributes

fwlite::EventBaseevent_
 
TObjArray eventSelectors_
 
TString exprSep_
 
HandleT handle_
 
bool ignoreExceptions_
 
std::string instance_
 
std::string label_
 
int maxEvents_
 
int maxLinesToPrint_
 
edm::TypeWithDict objType
 
bool printFullEventId_
 
std::string process_
 

Detailed Description

template<typename Collection>
class fwlite::Scanner< Collection >

fwlite::Scanner<C>, a way to inspect or plots elements of a collection C by using the StringParser.

fwlite::Scanner<C>, a way to inspect or plots elements of a collection C by using the StringParser.

The collection can be something as easy as std::vector<T>, but also some other fancy EDM collections like RefVector, RefToBaseVector and OwnVector (and probably PtrVector, but it was not tested)

If you're using something other than std::vector, you must provide the full typename, including all optional template parameters; e.g. you can't have C = edm::RefVector<reco::MuonCollection>, but you need C = edm::RefVector<vector<reco::Muon>,reco::Muon,edm::refhelper::FindUsingAdvance<vector<reco::Muon>,reco::Muon> > In order to figure out what is the correct full name for a collection in an event, open it in ROOT/FWLite, get the branch name including the trailing ".obj" (hint: Events->GetAlias("label")) usually works), and then do Events->GetBranch("xxx.obj")->GetClassName() to get something like edm::Wrapper<X>. then X is what you want to use to create the fwlite::Scanner. Don't use typedefs, they don't work.

Definition at line 46 of file Scanner.h.

Member Typedef Documentation

◆ HandleT

template<typename Collection >
typedef fwlite::Handle<Collection> fwlite::Scanner< Collection >::HandleT

The type of the Handle to read the Ts from the event. Needed to resolve its Type.

Definition at line 49 of file Scanner.h.

Constructor & Destructor Documentation

◆ Scanner()

template<typename Collection >
fwlite::Scanner< Collection >::Scanner ( fwlite::EventBase ev,
const char *  label,
const char *  instance = "",
const char *  process = "" 
)
inline

Create a Scanner, passing a fwlite Event and the labels (just like you would in 'getByLabel')

Definition at line 52 of file Scanner.h.

References helper::Parser::elementType(), fwlite::Scanner< Collection >::objType, and edm::Wrapper< T >::typeInfo().

53  : event_(ev),
54  label_(label),
56  printFullEventId_(ev->isRealData()),
57  ignoreExceptions_(false),
58  exprSep_(":"),
59  maxEvents_(-1),
60  maxLinesToPrint_(50) {
62  }
bool ignoreExceptions_
Definition: Scanner.h:710
static PFTauRenderPlugin instance
bool printFullEventId_
Definition: Scanner.h:709
TString exprSep_
Definition: Scanner.h:711
std::string label_
Definition: Scanner.h:708
char const * label
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
int maxLinesToPrint_
Definition: Scanner.h:719
static edm::TypeWithDict elementType(const edm::TypeWithDict &wrapperType)
Perform the type deduction form edm::Wrapper<C> to C::value_type and resolves typedefs.
static std::type_info const & typeInfo()
Definition: Wrapper.h:43

Member Function Documentation

◆ addEventSelector()

template<typename Collection >
void fwlite::Scanner< Collection >::addEventSelector ( fwlite::EventSelector selector)
inline

Definition at line 693 of file Scanner.h.

References fwlite::Scanner< Collection >::eventSelectors_.

693 { eventSelectors_.Add(selector); }
TObjArray eventSelectors_
Definition: Scanner.h:715

◆ clearEventSelector()

template<typename Collection >
void fwlite::Scanner< Collection >::clearEventSelector ( )
inline

Definition at line 694 of file Scanner.h.

References fwlite::Scanner< Collection >::eventSelectors_.

694 { eventSelectors_.Clear(); }
TObjArray eventSelectors_
Definition: Scanner.h:715

◆ count()

template<typename Collection >
size_t fwlite::Scanner< Collection >::count ( const char *  cut)
inline

Count the number of entries that pass a given cut. See setMaxEvents() to specify how many events to loop on when counting. Events can be further selected by using addEventSelector().

Definition at line 154 of file Scanner.h.

References fwlite::EventBase::atEnd(), DMR_cfg::cut, fwlite::Scanner< Collection >::event_, fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), helper::ScannerBase::test(), and fwlite::EventBase::toBegin().

154  {
155  helper::ScannerBase scanner(objType);
156  scanner.setIgnoreExceptions(ignoreExceptions_);
157 
158  scanner.setCut(cut);
159 
160  size_t npass = 0;
161  int iev = 0;
162  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
163  if (maxEvents_ > -1 && iev > maxEvents_)
164  break;
165  if (!selectEvent(*event_))
166  continue;
167  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
168  const Collection &vals = *handle_;
169  for (size_t j = 0, n = vals.size(); j < n; ++j) {
170  if (scanner.test(&vals[j]))
171  npass++;
172  }
173  }
174  return npass;
175  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ countEvents()

template<typename Collection >
size_t fwlite::Scanner< Collection >::countEvents ( )
inline

Count the number of events, taking into account setMaxEvents() and the event selectors

Definition at line 178 of file Scanner.h.

References fwlite::EventBase::atEnd(), fwlite::Scanner< Collection >::event_, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::maxEvents_, fwlite::Scanner< Collection >::selectEvent(), and fwlite::EventBase::toBegin().

178  {
179  size_t npass = 0;
180  int iev = 0;
181  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
182  if (maxEvents_ > -1 && iev > maxEvents_)
183  break;
184  if (selectEvent(*event_))
185  npass++;
186  }
187  return npass;
188  }
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
fwlite::EventBase * event_
Definition: Scanner.h:707
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ draw() [1/4]

template<typename Collection >
TH1* fwlite::Scanner< Collection >::draw ( const char *  expr,
const char *  cut,
TString  drawopt,
TH1 *  hist 
)
inline

Plot the expression expr for events passing 'cut, into histogram hist. hist is not reset before filling it, so it will add to the existing content.

If "NORM" is specified in the draw options, the output histogram is normalized If "GOFF" is specified in the draw options, the output histogram is not drawn

See setMaxEvents() to specify how many events to loop on when plotting. Events can be further selected by using addEventSelector().

Definition at line 199 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::event_, helper::ScannerBase::fill1D(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, compareTotals::hist, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), and fwlite::EventBase::toBegin().

Referenced by fwlite::Scanner< Collection >::draw().

199  {
200  // prep the machinery
201  helper::ScannerBase scanner(objType);
202  scanner.setIgnoreExceptions(ignoreExceptions_);
203  if (!scanner.addExpression(expr))
204  return nullptr;
205  if (strlen(cut))
206  scanner.setCut(cut);
207 
208  // check histo
209  if (hist == nullptr) {
210  std::cerr << "Method draw(expr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other draw "
211  "methods instead."
212  << std::endl;
213  return nullptr;
214  }
215 
216  // fill histogram
217  int iev = 0;
218  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
219  if (maxEvents_ > -1 && iev > maxEvents_)
220  break;
221  if (!selectEvent(*event_))
222  continue;
223  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
224  const Collection &vals = *handle_;
225  for (size_t j = 0, n = vals.size(); j < n; ++j) {
226  scanner.fill1D(&vals[j], hist);
227  }
228  }
229 
230  if (drawopt.Contains("NORM", TString::kIgnoreCase) && (hist->Integral() != 0)) {
231  hist->Sumw2();
232  hist->Scale(1.0 / hist->Integral());
233  // remove the "NORM" because THistPainter doesn't understand it
234  drawopt(TRegexp("[Nn][Oo][Rr][Mm]")) = "";
235  }
236 
237  if (!drawopt.Contains("GOFF", TString::kIgnoreCase))
238  hist->Draw(drawopt);
239  return hist;
240  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ draw() [2/4]

template<typename Collection >
TH1* fwlite::Scanner< Collection >::draw ( const char *  expr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
const TH1 *  htemplate = nullptr 
)
inline

Plot the expression 'expr' for events passing 'cut', in a histogram named 'hname'

  • If htemplate is provided it will be cloned,
  • otherwise, if "SAME" is among the draw options, it will clone "htemp" (if it's available)
  • otherwise an automatically binned histogram will be used. in the last case, gEnv->GetValue("Hist.Binning.1D.x", 100) is used for the number of bins See draw(const char *expr, const char *cut, TString drawopt, TH1 *histo) for further documentation

Definition at line 248 of file Scanner.h.

References DMR_cfg::cut, fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::getSameH1(), compareTotals::hist, and fwlite::Scanner< Collection >::htempDelete().

252  {
253  TH1 *hist = nullptr;
254  if (htemplate != nullptr) {
255  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname, htemplate->GetName()) != 0))
256  htempDelete();
257  hist = (TH1 *)htemplate->Clone(hname);
258  } else if (drawopt.Contains("SAME", TString::kIgnoreCase)) {
259  hist = getSameH1(hname);
260  }
261 
262  // if in the end we found no way to make "hist"
263  if (hist == nullptr) {
264  if (strcmp(hname, "htemp") == 0)
265  htempDelete();
266  hist = new TH1F(hname, "", gEnv->GetValue("Hist.Binning.1D.x", 100), 0, 0);
267  hist->SetCanExtend(TH1::kAllAxes);
268  }
269  hist->SetTitle((strlen(cut) ? TString(expr) + "{" + cut + "}" : TString(expr)));
270  hist->GetXaxis()->SetTitle(expr);
271  return draw(expr, cut, drawopt, hist);
272  }
TH1 * getSameH1(const char *hname)
Definition: Scanner.h:742
TH1 * draw(const char *expr, const char *cut, TString drawopt, TH1 *hist)
Definition: Scanner.h:199
void htempDelete()
Definition: Scanner.h:732

◆ draw() [3/4]

template<typename Collection >
TH1* fwlite::Scanner< Collection >::draw ( const char *  expr,
int  nbins,
double  xlow,
double  xhigh,
const char *  cut = "",
const char *  drawopt = "",
const char *  hname = "htemp" 
)
inline

Make a histogram named hname with nbins from xlow to xhigh, and then call draw(). If "SAME" is passed in the draw options, complain and ignore the binning.

Definition at line 276 of file Scanner.h.

References DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::getSameH1(), fwlite::Scanner< Collection >::htempDelete(), and LaserClient_cfi::nbins.

282  {
283  if (TString(drawopt).Contains("SAME", TString::kIgnoreCase)) {
284  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
285  TH1 *hsame = getSameH1(hname);
286  return draw(expr, cut, drawopt, hsame);
287  }
288  if (strcmp(hname, "htemp") == 0)
289  htempDelete();
290  TH1 *htemp = new TH1F(hname, expr, nbins, xlow, xhigh);
291  if (strlen(cut))
292  htemp->SetTitle(TString(expr) + "{" + cut + "}");
293  htemp->GetXaxis()->SetTitle(expr);
294  return draw(expr, cut, drawopt, htemp);
295  }
TH1 * getSameH1(const char *hname)
Definition: Scanner.h:742
TH1 * draw(const char *expr, const char *cut, TString drawopt, TH1 *hist)
Definition: Scanner.h:199
void htempDelete()
Definition: Scanner.h:732

◆ draw() [4/4]

template<typename Collection >
TH1* fwlite::Scanner< Collection >::draw ( const char *  expr,
int  nbins,
double *  xbins,
const char *  cut = "",
const char *  drawopt = "",
const char *  hname = "htemp" 
)
inline

Make a histogram named hname with nbins with boundaries xbins, and then call draw(). If "SAME" is passed in the draw options, complain and ignore the binning.

Definition at line 298 of file Scanner.h.

References DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::getSameH1(), fwlite::Scanner< Collection >::htempDelete(), LaserClient_cfi::nbins, and fw3dlego::xbins.

303  {
304  if (TString(drawopt).Contains("SAME", TString::kIgnoreCase)) {
305  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
306  TH1 *hsame = getSameH1(hname);
307  return draw(expr, cut, drawopt, hsame);
308  }
309  if (strcmp(hname, "htemp") == 0)
310  htempDelete();
311  TH1 *htemp = new TH1F(hname, expr, nbins, xbins);
312  if (strlen(cut))
313  htemp->SetTitle(TString(expr) + "{" + cut + "}");
314  htemp->GetXaxis()->SetTitle(expr);
315  return draw(expr, cut, drawopt, htemp);
316  }
const double xbins[]
TH1 * getSameH1(const char *hname)
Definition: Scanner.h:742
TH1 * draw(const char *expr, const char *cut, TString drawopt, TH1 *hist)
Definition: Scanner.h:199
void htempDelete()
Definition: Scanner.h:732

◆ draw2D() [1/3]

template<typename Collection >
TH2* fwlite::Scanner< Collection >::draw2D ( TString  xexpr,
TString  yexpr,
const char *  cut,
TString  drawopt,
TH2 *  hist 
)
inline

Just like draw() except that it uses TH2. Note that the order is (x,y) while in ROOT it's usually (y,x)!

Definition at line 411 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::event_, helper::ScannerBase::fill2D(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, compareTotals::hist, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), and fwlite::EventBase::toBegin().

Referenced by fwlite::Scanner< Collection >::draw2D().

411  {
412  // prep the machinery
413  helper::ScannerBase scanner(objType);
414  scanner.setIgnoreExceptions(ignoreExceptions_);
415  if (!scanner.addExpression((const char *)xexpr))
416  return nullptr;
417  if (!scanner.addExpression((const char *)yexpr))
418  return nullptr;
419  if (strlen(cut))
420  scanner.setCut(cut);
421 
422  // check histo
423  if (hist == nullptr) {
424  std::cerr << "Method draw2D(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the other "
425  "draw methods instead."
426  << std::endl;
427  return nullptr;
428  }
429 
430  // fill histogram
431  int iev = 0;
432  for (event_->toBegin(), iev = 0; !event_->atEnd(); ++(*event_), ++iev) {
433  if (maxEvents_ > -1 && iev > maxEvents_)
434  break;
435  if (!selectEvent(*event_))
436  continue;
437  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
438  const Collection &vals = *handle_;
439  for (size_t j = 0, n = vals.size(); j < n; ++j) {
440  scanner.fill2D(&vals[j], hist);
441  }
442  }
443 
444  if (!strlen(hist->GetTitle()))
445  hist->SetTitle((strlen(cut) ? yexpr + ":" + xexpr + "{" + cut + "}" : yexpr + ":" + xexpr));
446  if (!strlen(hist->GetXaxis()->GetTitle()))
447  hist->GetXaxis()->SetTitle(xexpr);
448  if (!strlen(hist->GetYaxis()->GetTitle()))
449  hist->GetYaxis()->SetTitle(yexpr);
450  if (!TString(drawopt).Contains("GOFF", TString::kIgnoreCase))
451  hist->Draw(drawopt);
452  return hist;
453  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ draw2D() [2/3]

template<typename Collection >
TH2* fwlite::Scanner< Collection >::draw2D ( TString  xexpr,
TString  yexpr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
TH2 *  htemplate = nullptr 
)
inline

Just like draw() except that it uses TH2. Note that the order is (x,y) while in ROOT it's usually (y,x)! Note that automatical binning for TH2s is more expensive, as it requires to loop on the events twice!

Definition at line 456 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), DMR_cfg::cut, fwlite::Scanner< Collection >::draw2D(), helper::ScannerBase::eval(), fwlite::Scanner< Collection >::event_, fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::getSameH2(), fwlite::Scanner< Collection >::handle_, compareTotals::hist, fwlite::Scanner< Collection >::htempDelete(), caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), helper::ScannerBase::test(), fwlite::EventBase::toBegin(), x, TrackerOfflineValidation_Dqm_cff::xmax, TrackerOfflineValidation_Dqm_cff::xmin, L1TOccupancyClient_cfi::ymax, and L1TOccupancyClient_cfi::ymin.

461  {
462  TH2 *hist = nullptr;
463  if (htemplate != nullptr) {
464  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname, htemplate->GetName()) != 0))
465  htempDelete();
466  hist = (TH2 *)htemplate->Clone(hname);
467  } else if (drawopt.Contains("SAME", TString::kIgnoreCase)) {
468  hist = getSameH2(hname);
469  }
470 
471  // if in the end we found no way to make "hist"
472  if (hist == nullptr) {
473  // prep the machinery
474  helper::ScannerBase scanner(objType);
475  scanner.setIgnoreExceptions(ignoreExceptions_);
476  if (!scanner.addExpression((const char *)xexpr))
477  return nullptr;
478  if (!scanner.addExpression((const char *)yexpr))
479  return nullptr;
480  if (strlen(cut))
481  scanner.setCut(cut);
482 
483  if (strcmp(hname, "htemp") == 0)
484  htempDelete();
485  // ok this is much more a hack than for the 1D case
486  double xmin = 0, xmax = -1, ymin = 0, ymax = -1;
487  int iev;
488  for (event_->toBegin(), iev = 0; !event_->atEnd(); ++(*event_), ++iev) {
489  if (maxEvents_ > -1 && iev > maxEvents_)
490  break;
491  if (!selectEvent(*event_))
492  continue;
493  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
494  const Collection &vals = *handle_;
495  for (size_t j = 0, n = vals.size(); j < n; ++j) {
496  if (!scanner.test(&vals[j]))
497  continue;
498  double x = scanner.eval(&vals[j], 0);
499  double y = scanner.eval(&vals[j], 1);
500  if ((xmax == -1) || (x >= xmax))
501  xmax = x;
502  if ((xmin == 0) || (x <= xmin))
503  xmin = x;
504  if ((ymax == -1) || (y >= ymax))
505  ymax = y;
506  if ((ymin == 0) || (y <= ymin))
507  ymin = y;
508  }
509  }
510  hist = new TH2F(hname,
511  "",
512  gEnv->GetValue("Hist.Binning.2D.x", 20),
513  xmin,
514  xmax,
515  gEnv->GetValue("Hist.Binning.2D.y", 20),
516  ymin,
517  ymax);
518  }
519  return draw2D(xexpr, yexpr, cut, drawopt, hist);
520  }
bool ignoreExceptions_
Definition: Scanner.h:710
TH2 * getSameH2(const char *hname)
Definition: Scanner.h:758
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
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:411
virtual bool atEnd() const =0
void htempDelete()
Definition: Scanner.h:732
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ draw2D() [3/3]

template<typename Collection >
TH2* fwlite::Scanner< Collection >::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" 
)
inline

Just like draw() except that it uses TH2. Note that the order is (x,y) while in ROOT it's usually (y,x)!

Definition at line 523 of file Scanner.h.

References DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::getSameH2(), fwlite::Scanner< Collection >::htempDelete(), and fw3dlego::xbins.

533  {
534  if (TString(drawopt).Contains("SAME", TString::kIgnoreCase)) {
535  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
536  TH2 *hsame = getSameH2(hname);
537  return draw2D(xexpr, yexpr, cut, drawopt, hsame);
538  }
539  if (strcmp(hname, "htemp") == 0)
540  htempDelete();
541  TH2 *htemp = new TH2F("htemp", "", xbins, xlow, xhigh, ybins, ylow, yhigh);
542  return draw2D(xexpr, yexpr, cut, drawopt, htemp);
543  }
const double xbins[]
TH2 * getSameH2(const char *hname)
Definition: Scanner.h:758
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:411
void htempDelete()
Definition: Scanner.h:732

◆ drawGraph() [1/2]

template<typename Collection >
TGraph* fwlite::Scanner< Collection >::drawGraph ( TString  xexpr,
TString  yexpr,
const char *  cut,
TString  drawopt,
TGraph *  graph 
)
inline

Draw a scatter plot of x vs y for events passing the cut.

Definition at line 546 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), DMR_cfg::cut, fwlite::Scanner< Collection >::event_, helper::ScannerBase::fillGraph(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), and fwlite::EventBase::toBegin().

Referenced by fwlite::Scanner< Collection >::drawGraph().

546  {
547  // prep the machinery
548  helper::ScannerBase scanner(objType);
549  scanner.setIgnoreExceptions(ignoreExceptions_);
550  if (!scanner.addExpression((const char *)xexpr))
551  return nullptr;
552  if (!scanner.addExpression((const char *)yexpr))
553  return nullptr;
554  if (strlen(cut))
555  scanner.setCut(cut);
556 
557  // make graph, if needed
558  if (graph == nullptr) {
559  graph = new TGraph();
560  graph->SetNameTitle("htemp", (strlen(cut) ? yexpr + ":" + xexpr + "{" + cut + "}" : yexpr + ":" + xexpr));
561  }
562 
563  // fill graph
564  int iev = 0;
565  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
566  if (maxEvents_ > -1 && iev > maxEvents_)
567  break;
568  if (!selectEvent(*event_))
569  continue;
570  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
571  const Collection &vals = *handle_;
572  for (size_t j = 0, n = vals.size(); j < n; ++j) {
573  scanner.fillGraph(&vals[j], graph);
574  }
575  }
576 
577  if (!strlen(graph->GetTitle()))
578  graph->SetTitle((strlen(cut) ? yexpr + ":" + xexpr + "{" + cut + "}" : yexpr + ":" + xexpr));
579  if (!strlen(graph->GetXaxis()->GetTitle()))
580  graph->GetXaxis()->SetTitle(xexpr);
581  if (!strlen(graph->GetYaxis()->GetTitle()))
582  graph->GetYaxis()->SetTitle(yexpr);
583  if (!TString(drawopt).Contains("GOFF", TString::kIgnoreCase))
584  graph->Draw(drawopt);
585  return graph;
586  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ drawGraph() [2/2]

template<typename Collection >
TGraph* fwlite::Scanner< Collection >::drawGraph ( TString  xexpr,
TString  yexpr,
const char *  cut = "",
TString  drawopt = "AP",
const char *  gname = "htemp" 
)
inline

Draw a scatter plot of x vs y for events passing the cut.

Definition at line 589 of file Scanner.h.

References DMR_cfg::cut, fwlite::Scanner< Collection >::drawGraph(), and fwlite::Scanner< Collection >::htempDelete().

590  {
591  if (strcmp(gname, "htemp") == 0)
592  htempDelete();
593  TGraph *graph = new TGraph();
594  graph->SetNameTitle(gname, (strlen(cut) ? yexpr + ":" + xexpr + "{" + cut + "}" : yexpr + ":" + xexpr));
595  return drawGraph(xexpr, yexpr, cut, drawopt, graph);
596  }
TGraph * drawGraph(TString xexpr, TString yexpr, const char *cut, TString drawopt, TGraph *graph)
Definition: Scanner.h:546
void htempDelete()
Definition: Scanner.h:732

◆ drawProf() [1/3]

template<typename Collection >
TProfile* fwlite::Scanner< Collection >::drawProf ( TString  xexpr,
TString  yexpr,
const char *  cut,
TString  drawopt,
TProfile *  hist 
)
inline

Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it's usually (y,x)!

Definition at line 320 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::event_, helper::ScannerBase::fillProf(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, compareTotals::hist, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), and fwlite::EventBase::toBegin().

Referenced by fwlite::Scanner< Collection >::drawProf().

320  {
321  // prep the machinery
322  helper::ScannerBase scanner(objType);
323  scanner.setIgnoreExceptions(ignoreExceptions_);
324  if (!scanner.addExpression(xexpr.Data()))
325  return nullptr;
326  if (!scanner.addExpression(yexpr.Data()))
327  return nullptr;
328  if (strlen(cut))
329  scanner.setCut(cut);
330 
331  // check histo
332  if (hist == nullptr) {
333  std::cerr << "Method drawProf(xexpr, yexpr, cut, drawopt, hist) cannot be called with null 'hist'. Use the "
334  "other draw methods instead."
335  << std::endl;
336  return nullptr;
337  }
338 
339  // fill histogram
340  int iev = 0;
341  for (event_->toBegin(); !event_->atEnd(); ++(*event_), ++iev) {
342  if (maxEvents_ > -1 && iev > maxEvents_)
343  break;
344  if (!selectEvent(*event_))
345  continue;
346  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
347  const Collection &vals = *handle_;
348  for (size_t j = 0, n = vals.size(); j < n; ++j) {
349  scanner.fillProf(&vals[j], hist);
350  }
351  }
352 
353  if (!strlen(hist->GetTitle()))
354  hist->SetTitle((strlen(cut) ? yexpr + ":" + xexpr + "{" + cut + "}" : yexpr + ":" + xexpr));
355  if (!strlen(hist->GetXaxis()->GetTitle()))
356  hist->GetXaxis()->SetTitle(xexpr);
357  if (!strlen(hist->GetYaxis()->GetTitle()))
358  hist->GetYaxis()->SetTitle(yexpr);
359  if (!TString(drawopt).Contains("GOFF", TString::kIgnoreCase))
360  hist->Draw(drawopt);
361  return hist;
362  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
virtual bool atEnd() const =0
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ drawProf() [2/3]

template<typename Collection >
TProfile* fwlite::Scanner< Collection >::drawProf ( TString  xexpr,
TString  yexpr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
TProfile *  htemplate = nullptr 
)
inline

Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it's usually (y,x)!

Definition at line 364 of file Scanner.h.

References DMR_cfg::cut, fwlite::Scanner< Collection >::drawProf(), fwlite::Scanner< Collection >::getSameProf(), compareTotals::hist, and fwlite::Scanner< Collection >::htempDelete().

369  {
370  TProfile *hist = nullptr;
371  if (htemplate != nullptr) {
372  if ((strcmp(hname, "htemp") == 0) && (strcmp(hname, htemplate->GetName()) != 0))
373  htempDelete();
374  hist = (TProfile *)htemplate->Clone(hname);
375  } else if (drawopt.Contains("SAME", TString::kIgnoreCase)) {
376  hist = getSameProf(hname);
377  }
378 
379  // if in the end we found no way to make "hist"
380  if (hist == nullptr) {
381  if (strcmp(hname, "htemp") == 0)
382  htempDelete();
383  hist = new TProfile(hname, "", gEnv->GetValue("Hist.Binning.1D.x", 100), 0., 0.);
384  hist->SetCanExtend(TH1::kAllAxes);
385  }
386  return drawProf(xexpr, yexpr, cut, drawopt, hist);
387  }
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:320
TProfile * getSameProf(const char *hname)
Definition: Scanner.h:774
void htempDelete()
Definition: Scanner.h:732

◆ drawProf() [3/3]

template<typename Collection >
TProfile* fwlite::Scanner< Collection >::drawProf ( TString  xexpr,
int  bins,
double  xlow,
double  xhigh,
TString  yexpr,
const char *  cut = "",
const char *  drawopt = "",
const char *  hname = "htemp" 
)
inline

Just like draw() except that it uses TProfile. Note that the order is (x,y) while in ROOT it's usually (y,x)!

Definition at line 390 of file Scanner.h.

References trigObjTnPSource_cfi::bins, DMR_cfg::cerr, DMR_cfg::cut, fwlite::Scanner< Collection >::drawProf(), fwlite::Scanner< Collection >::getSameProf(), and fwlite::Scanner< Collection >::htempDelete().

397  {
398  if (TString(drawopt).Contains("SAME", TString::kIgnoreCase)) {
399  std::cerr << "Binning is ignored when 'SAME' is specified." << std::endl;
400  TProfile *hsame = getSameProf(hname);
401  return drawProf(xexpr, yexpr, cut, drawopt, hsame);
402  }
403  if (strcmp(hname, "htemp") == 0)
404  htempDelete();
405  TProfile *htemp = new TProfile(hname, "", bins, xlow, xhigh);
406  return drawProf(xexpr, yexpr, cut, drawopt, htemp);
407  }
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:320
TProfile * getSameProf(const char *hname)
Definition: Scanner.h:774
void htempDelete()
Definition: Scanner.h:732

◆ eventSelectors()

template<typename Collection >
TObjArray& fwlite::Scanner< Collection >::eventSelectors ( )
inline

Definition at line 695 of file Scanner.h.

References fwlite::Scanner< Collection >::eventSelectors_.

695 { return eventSelectors_; }
TObjArray eventSelectors_
Definition: Scanner.h:715

◆ fillDataSet()

template<typename Collection >
RooDataSet* fwlite::Scanner< Collection >::fillDataSet ( const char *  realvars,
const char *  boolvars,
const char *  cut = "",
const char *  name = "data" 
)
inline

Fill a RooDataSet.

  • Real variables are defined just like in the scan() command; a list separated by ":" (see also setExpressionSeparator());
  • Boolean variables are defined just like cuts, and are created as RooCategory with two states: pass(1) and fail(0). For each variable, the name is taken from the expression itself, or can be specified manuall by using the notation "@name=expr" Note: the dataset contains one entry per item, irrespectively of how entries are distributed among events.

Definition at line 605 of file Scanner.h.

References helper::ScannerBase::addExpression(), helper::ScannerBase::addExtraCut(), fwlite::EventBase::atEnd(), eostools::cat(), DMR_cfg::cerr, DMR_cfg::cut, helper::ScannerBase::eval(), fwlite::Scanner< Collection >::event_, fwlite::Scanner< Collection >::exprSep_, fwlite::Handle< T >::failedToGet(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, mps_fire::i, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, fwlite::Scanner< Collection >::maxEvents_, dqmiodumpmetadata::n, Skims_PA_cff::name, fwlite::Scanner< Collection >::objType, fwlite::Scanner< Collection >::process_, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), str, AlCaHLTBitMon_QueryRunRegistry::string, helper::ScannerBase::test(), fwlite::EventBase::toBegin(), and trigObjTnPSource_cfi::var.

608  {
609  helper::ScannerBase scanner(objType);
610  scanner.setIgnoreExceptions(ignoreExceptions_);
611 
612  RooArgList vars;
613  TObjArray *exprArray = TString(realvars).Tokenize(exprSep_);
614  TObjArray *catArray = TString(boolvars).Tokenize(exprSep_);
615  int nreals = exprArray->GetEntries();
616  int nbools = catArray->GetEntries();
617  for (int i = 0; i < nreals; ++i) {
618  TString str = ((TObjString *)(*exprArray)[i])->GetString();
619  std::string lb = str.Data();
620  std::string ex = str.Data();
621  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
622  lb = lb.substr(1, ex.find('=') - 1);
623  ex = ex.substr(ex.find('=') + 1);
624  }
625  if (!scanner.addExpression(ex.c_str())) {
626  std::cerr << "Filed to define real variable '" << lb << "', expr = '" << ex << "'" << std::endl;
627  return nullptr;
628  }
629  // FIXME: I have to leave it dangling on the HEAP otherwise ROOT segfaults...
630  RooRealVar *var = new RooRealVar(lb.c_str(), lb.c_str(), 0.0);
631  vars.add(*var);
632  }
633  for (int i = 0; i < nbools; ++i) {
634  TString str = ((TObjString *)(*catArray)[i])->GetString();
635  std::string lb = str.Data();
636  std::string ex = str.Data();
637  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
638  lb = lb.substr(1, ex.find('=') - 1);
639  ex = ex.substr(ex.find('=') + 1);
640  }
641  if (!scanner.addExtraCut(ex.c_str())) {
642  std::cerr << "Filed to define bool variable '" << lb << "', cut = '" << ex << "'" << std::endl;
643  return nullptr;
644  }
645  RooCategory *cat = new RooCategory(lb.c_str(), lb.c_str());
646  cat->defineType("fail", 0);
647  cat->defineType("pass", 1);
648  vars.add(*cat);
649  }
650 
651  RooDataSet *ds = new RooDataSet(name, name, vars);
652 
653  if (strlen(cut))
654  scanner.setCut(cut);
655  int iev = 0;
656  for (event_->toBegin(); !event_->atEnd(); ++iev, ++(*event_)) {
657  if (maxEvents_ > -1 && iev > maxEvents_)
658  break;
659  if (!selectEvent(*event_))
660  continue;
661  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
662  if (handle_.failedToGet()) {
663  if (ignoreExceptions_)
664  continue;
665  }
666  const Collection &vals = *handle_;
667  for (size_t j = 0, n = vals.size(); j < n; ++j) {
668  if (!scanner.test(&vals[j]))
669  continue;
670  for (int i = 0; i < nreals; ++i) {
671  RooRealVar *var = (RooRealVar *)vars.at(i);
672  var->setVal(scanner.eval(&vals[j], i));
673  }
674  for (int i = 0; i < nbools; ++i) {
675  RooCategory *cat = (RooCategory *)vars.at(i + nreals);
676  cat->setIndex(int(scanner.test(&vals[j], i + 1))); // 0 is the event selection cut
677  }
678  ds->add(vars);
679  }
680  }
681 
682  delete exprArray;
683  delete catArray;
684 
685  return ds;
686  }
bool ignoreExceptions_
Definition: Scanner.h:710
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
TString exprSep_
Definition: Scanner.h:711
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
def cat(path)
Definition: eostools.py:401
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
std::string instance_
Definition: Scanner.h:708
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
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:63
virtual bool atEnd() const =0
vars
Definition: DeepTauId.cc:166
#define str(s)
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ getSameH1()

template<typename Collection >
TH1* fwlite::Scanner< Collection >::getSameH1 ( const char *  hname)
inlineprivate

Get whatever histogram makes sense for a plot passing "SAME" in drawOpt, and call it hname Currently it won't work if the histogram of which we want to be "SAME" is not called "htemp"

Definition at line 742 of file Scanner.h.

References DMR_cfg::cerr, HLT_2023v12_cff::Class, and compareTotals::hist.

Referenced by fwlite::Scanner< Collection >::draw().

742  {
743  if (gDirectory && gDirectory->Get("htemp") != nullptr &&
744  gDirectory->Get("htemp")->IsA()->InheritsFrom(TH1::Class())) {
745  TH1 *hist = (TH1 *)((TH1 *)gDirectory->Get("htemp"))->Clone(hname);
746  hist->Reset();
747  hist->SetLineColor(kBlack);
748  hist->SetMarkerColor(kBlack);
749  return hist;
750  } else {
751  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
752  return nullptr;
753  }
754  }

◆ getSameH2()

template<typename Collection >
TH2* fwlite::Scanner< Collection >::getSameH2 ( const char *  hname)
inlineprivate

Get whatever histogram makes sense for a plot passing "SAME" in drawOpt, and call it hname Currently it won't work if the histogram of which we want to be "SAME" is not called "htemp"

Definition at line 758 of file Scanner.h.

References DMR_cfg::cerr, HLT_2023v12_cff::Class, and compareTotals::hist.

Referenced by fwlite::Scanner< Collection >::draw2D().

758  {
759  if (gDirectory && gDirectory->Get("htemp") != nullptr &&
760  gDirectory->Get("htemp")->IsA()->InheritsFrom(TH2::Class())) {
761  TH2 *hist = (TH2 *)((TH2 *)gDirectory->Get("htemp"))->Clone(hname);
762  hist->Reset();
763  hist->SetLineColor(kBlack);
764  hist->SetMarkerColor(kBlack);
765  return hist;
766  } else {
767  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
768  return nullptr;
769  }
770  }

◆ getSameProf()

template<typename Collection >
TProfile* fwlite::Scanner< Collection >::getSameProf ( const char *  hname)
inlineprivate

Get whatever histogram makes sense for a plot passing "SAME" in drawOpt, and call it hname Currently it won't work if the histogram of which we want to be "SAME" is not called "htemp"

Definition at line 774 of file Scanner.h.

References DMR_cfg::cerr, HLT_2023v12_cff::Class, and compareTotals::hist.

Referenced by fwlite::Scanner< Collection >::drawProf().

774  {
775  if (gDirectory && gDirectory->Get("htemp") != nullptr &&
776  gDirectory->Get("htemp")->IsA()->InheritsFrom(TProfile::Class())) {
777  TProfile *hist = (TProfile *)((TProfile *)gDirectory->Get("htemp"))->Clone(hname);
778  hist->Reset();
779  hist->SetLineColor(kBlack);
780  hist->SetMarkerColor(kBlack);
781  return hist;
782  } else {
783  std::cerr << "There is no 'htemp' histogram from which to 'SAME'." << std::endl;
784  return nullptr;
785  }
786  }

◆ htempDelete()

template<typename Collection >
void fwlite::Scanner< Collection >::htempDelete ( )
inlineprivate

Definition at line 732 of file Scanner.h.

References getGTfromDQMFile::obj.

Referenced by fwlite::Scanner< Collection >::draw(), fwlite::Scanner< Collection >::draw2D(), fwlite::Scanner< Collection >::drawGraph(), and fwlite::Scanner< Collection >::drawProf().

732  {
733  if (gDirectory) {
734  TObject *obj = gDirectory->Get("htemp");
735  if (obj)
736  obj->Delete();
737  }
738  }

◆ scan()

template<typename Collection >
void fwlite::Scanner< Collection >::scan ( const char *  exprs,
const char *  cut = "",
int  nmax = -1 
)
inline

Scan the first nmax entries of the event and print out the values of some expressions.

    The cut is applied to the individual entries. To set Event-wide cuts, use addEventSelector(). 

    The different expressions are separated by ":", unless changed using setExpressionSeparator.
    The title of each column is the text of the expression, unless one specifies it differently
    by using the notation "@label=expression"

    Each row is prefixed by the event id (Run/LS/Event on Data, entry number within the file for MC) 
    and by the index of the object within the collection. The behaviour can be changed through the
    setPrintFullEventId() method.

    The printing will pause by default every 50 lines (see setMaxLinesToPrint() to change this)
    Scanning will stop after nmax events.

Definition at line 80 of file Scanner.h.

References helper::ScannerBase::addExpression(), fwlite::EventBase::atEnd(), gather_cfg::cout, DMR_cfg::cut, edmPickEvents::event, fwlite::Scanner< Collection >::event_, edm::EventBase::eventAuxiliary(), fwlite::Scanner< Collection >::exprSep_, fwlite::Handle< T >::failedToGet(), fwlite::Handle< T >::getByLabel(), fwlite::Scanner< Collection >::handle_, mps_fire::i, caHitNtupletGeneratorKernels::iev, fwlite::Scanner< Collection >::ignoreExceptions_, fwlite::Scanner< Collection >::instance_, dqmiolumiharvest::j, fwlite::Scanner< Collection >::label_, mps_splice::line, fwlite::Scanner< Collection >::maxLinesToPrint_, dqmiodumpmetadata::n, fwlite::Scanner< Collection >::objType, helper::ScannerBase::print(), fwlite::Scanner< Collection >::printFullEventId_, fwlite::Scanner< Collection >::process_, writedatasetfile::run, fwlite::Scanner< Collection >::selectEvent(), helper::ScannerBase::setCut(), helper::ScannerBase::setIgnoreExceptions(), str, AlCaHLTBitMon_QueryRunRegistry::string, helper::ScannerBase::test(), fwlite::EventBase::toBegin(), and fwlite::Scanner< Collection >::wantMore().

80  {
82  scanner.setIgnoreExceptions(ignoreExceptions_);
83 
84  TObjArray *exprArray = TString(exprs).Tokenize(exprSep_);
85  int rowline = 0;
86  if (printFullEventId_) {
87  printf(" : %9s : %4s : %9s : %3s", "RUN", "LUMI", "EVENT", "#IT");
88  rowline += 3 * 4 + 9 + 4 + 9 + 3 - 1; // -1 as first char remain blank
89  } else {
90  printf(" : %5s : %3s", "EVENT", "#IT");
91  rowline += 3 + 6 + 3 + 3 - 1; // -1 as first char remain blank
92  }
93  for (int i = 0; i < exprArray->GetEntries(); ++i) {
94  TString str = ((TObjString *)(*exprArray)[i])->GetString();
95  std::string lb = str.Data();
96  std::string ex = str.Data();
97  if ((ex[0] == '@') && (ex.find('=') != std::string::npos)) {
98  lb = lb.substr(1, ex.find('=') - 1);
99  ex = ex.substr(ex.find('=') + 1);
100  }
101  scanner.addExpression(ex.c_str());
102  printf(" : %8s",
103  (lb.size() > 8 ? lb.substr(lb.size() - 8) : lb)
104  .c_str()); // the rightmost part is usually the more interesting one
105  rowline += 3 + 8;
106  }
107  std::cout << " :" << std::endl;
108  rowline += 2;
109  delete exprArray;
110 
111  TString rule('-', rowline);
112  std::cout << " " << rule << " " << std::endl;
113 
114  if (strlen(cut))
115  scanner.setCut(cut);
116 
117  int iev = 0, line = 0;
118  for (event_->toBegin(); (iev != nmax) && !event_->atEnd(); ++iev, ++(*event_)) {
119  if (!selectEvent(*event_))
120  continue;
121  handle_.getByLabel(*event_, label_.c_str(), instance_.c_str(), process_.c_str());
122  if (handle_.failedToGet()) {
123  if (ignoreExceptions_)
124  continue;
125  }
126  const Collection &vals = *handle_;
127  for (size_t j = 0, n = vals.size(); j < n; ++j) {
128  if (!scanner.test(&vals[j]))
129  continue;
130  if (printFullEventId_) {
132  printf(" : %9u : %4u : %9llu : %3lu", id.run(), id.luminosityBlock(), id.event(), (unsigned long)j);
133  } else {
134  printf(" : %5d : %3lu", iev, (unsigned long)j);
135  }
136  scanner.print(&vals[j]);
137  std::cout << " :" << std::endl;
138  if (++line == maxLinesToPrint_) {
139  line = 0;
140  if (!wantMore()) {
141  iev = nmax - 1; // this is to exit the outer loop
142  break; // and this to exit the inner one
143  }
144  }
145  }
146  }
147  std::cout << std::endl;
148  }
bool ignoreExceptions_
Definition: Scanner.h:710
virtual edm::EventAuxiliary const & eventAuxiliary() const =0
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
bool printFullEventId_
Definition: Scanner.h:709
TString exprSep_
Definition: Scanner.h:711
HandleT handle_
Definition: Scanner.h:712
std::string label_
Definition: Scanner.h:708
edm::TypeWithDict objType
Definition: Scanner.h:713
fwlite::EventBase * event_
Definition: Scanner.h:707
bool wantMore() const
Definition: Scanner.h:720
std::string instance_
Definition: Scanner.h:708
int maxLinesToPrint_
Definition: Scanner.h:719
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
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:63
virtual bool atEnd() const =0
#define str(s)
virtual EventBase const & toBegin()=0
std::string process_
Definition: Scanner.h:708
bool selectEvent(const fwlite::EventBase &ev) const
Definition: Scanner.h:696

◆ selectEvent()

template<typename Collection >
bool fwlite::Scanner< Collection >::selectEvent ( const fwlite::EventBase ev) const
inline

◆ setExpressionSeparator()

template<typename Collection >
void fwlite::Scanner< Collection >::setExpressionSeparator ( TString  separator)
inline

Definition at line 689 of file Scanner.h.

References fwlite::Scanner< Collection >::exprSep_, and mps_merge::separator.

689 { exprSep_ = separator; }
string separator
Definition: mps_merge.py:79
TString exprSep_
Definition: Scanner.h:711

◆ setIgnoreExceptions()

template<typename Collection >
void fwlite::Scanner< Collection >::setIgnoreExceptions ( bool  ignoreThem)
inline

Definition at line 690 of file Scanner.h.

References fwlite::Scanner< Collection >::ignoreExceptions_.

690 { ignoreExceptions_ = ignoreThem; }
bool ignoreExceptions_
Definition: Scanner.h:710

◆ setMaxEvents()

template<typename Collection >
void fwlite::Scanner< Collection >::setMaxEvents ( int  max)
inline

◆ setMaxLinesToPrint()

template<typename Collection >
void fwlite::Scanner< Collection >::setMaxLinesToPrint ( int  lines)
inline

Definition at line 691 of file Scanner.h.

References groupFilesInBlocks::lines, and fwlite::Scanner< Collection >::maxLinesToPrint_.

691 { maxLinesToPrint_ = (lines > 0 ? lines : 2147483647); }
int maxLinesToPrint_
Definition: Scanner.h:719

◆ setPrintFullEventId()

template<typename Collection >
void fwlite::Scanner< Collection >::setPrintFullEventId ( bool  printIt = true)
inline

Definition at line 688 of file Scanner.h.

References fwlite::Scanner< Collection >::printFullEventId_, and riemannFit::printIt().

bool printFullEventId_
Definition: Scanner.h:709
__host__ __device__ void printIt(C *m, const char *prefix="")
Definition: FitUtils.h:53

◆ wantMore()

template<typename Collection >
bool fwlite::Scanner< Collection >::wantMore ( ) const
inlineprivate

Definition at line 720 of file Scanner.h.

References submitPVResolutionJobs::stderr.

Referenced by fwlite::Scanner< Collection >::scan().

720  {
721  // ask if user wants more
722  fprintf(stderr, "Type <CR> to continue or q to quit ==> ");
723  // read first char
724  int readch = getchar(), answer = readch;
725  // poll out remaining chars from buffer
726  while (readch != '\n' && readch != EOF)
727  readch = getchar();
728  // check first char
729  return !(answer == 'q' || answer == 'Q');
730  }

Member Data Documentation

◆ event_

template<typename Collection >
fwlite::EventBase* fwlite::Scanner< Collection >::event_
private

◆ eventSelectors_

template<typename Collection >
TObjArray fwlite::Scanner< Collection >::eventSelectors_
private

◆ exprSep_

template<typename Collection >
TString fwlite::Scanner< Collection >::exprSep_
private

◆ handle_

template<typename Collection >
HandleT fwlite::Scanner< Collection >::handle_
private

◆ ignoreExceptions_

template<typename Collection >
bool fwlite::Scanner< Collection >::ignoreExceptions_
private

◆ instance_

template<typename Collection >
std::string fwlite::Scanner< Collection >::instance_
private

◆ label_

template<typename Collection >
std::string fwlite::Scanner< Collection >::label_
private

◆ maxEvents_

template<typename Collection >
int fwlite::Scanner< Collection >::maxEvents_
private

◆ maxLinesToPrint_

template<typename Collection >
int fwlite::Scanner< Collection >::maxLinesToPrint_
private

◆ objType

template<typename Collection >
edm::TypeWithDict fwlite::Scanner< Collection >::objType
private

◆ printFullEventId_

template<typename Collection >
bool fwlite::Scanner< Collection >::printFullEventId_
private

◆ process_

template<typename Collection >
std::string fwlite::Scanner< Collection >::process_
private