CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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=0)
 
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=0)
 
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=0)
 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 44 of file Scanner.h.

Member Typedef Documentation

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 47 of file Scanner.h.

Constructor & Destructor Documentation

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 50 of file Scanner.h.

Member Function Documentation

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

Definition at line 567 of file Scanner.h.

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

Definition at line 568 of file Scanner.h.

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 145 of file Scanner.h.

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 166 of file Scanner.h.

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 185 of file Scanner.h.

template<typename Collection >
TH1* fwlite::Scanner< Collection >::draw ( const char *  expr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
const TH1 *  htemplate = 0 
)
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 227 of file Scanner.h.

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 250 of file Scanner.h.

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 264 of file Scanner.h.

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 344 of file Scanner.h.

template<typename Collection >
TH2* fwlite::Scanner< Collection >::draw2D ( TString  xexpr,
TString  yexpr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
TH2 *  htemplate = 0 
)
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 378 of file Scanner.h.

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 422 of file Scanner.h.

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 436 of file Scanner.h.

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 470 of file Scanner.h.

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 279 of file Scanner.h.

template<typename Collection >
TProfile* fwlite::Scanner< Collection >::drawProf ( TString  xexpr,
TString  yexpr,
const char *  cut = "",
TString  drawopt = "",
const char *  hname = "htemp",
TProfile *  htemplate = 0 
)
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 312 of file Scanner.h.

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 331 of file Scanner.h.

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

Definition at line 569 of file Scanner.h.

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 485 of file Scanner.h.

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 612 of file Scanner.h.

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 628 of file Scanner.h.

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 644 of file Scanner.h.

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

Definition at line 603 of file Scanner.h.

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 77 of file Scanner.h.

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

Definition at line 570 of file Scanner.h.

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

Definition at line 563 of file Scanner.h.

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

Definition at line 564 of file Scanner.h.

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

Definition at line 577 of file Scanner.h.

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

Definition at line 565 of file Scanner.h.

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

Definition at line 562 of file Scanner.h.

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

Definition at line 592 of file Scanner.h.

Member Data Documentation

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

Definition at line 579 of file Scanner.h.

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

Definition at line 587 of file Scanner.h.

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

Definition at line 583 of file Scanner.h.

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

Definition at line 584 of file Scanner.h.

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

Definition at line 582 of file Scanner.h.

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

Definition at line 580 of file Scanner.h.

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

Definition at line 580 of file Scanner.h.

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

Definition at line 589 of file Scanner.h.

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

Definition at line 591 of file Scanner.h.

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

Definition at line 585 of file Scanner.h.

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

Definition at line 581 of file Scanner.h.

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

Definition at line 580 of file Scanner.h.