CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ConfigurableAnalysis Class Reference

#include <CommonTools/UtilAlgos/src/ConfigurableAnalysis.cc>

Inheritance diagram for ConfigurableAnalysis:
edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 ConfigurableAnalysis (const edm::ParameterSet &)
 ~ConfigurableAnalysis ()

Private Member Functions

virtual void beginJob ()
virtual void endJob ()
virtual bool filter (edm::Event &, const edm::EventSetup &)

Private Attributes

std::vector< std::string > flows_
NTuplerntupler_
Plotterplotter_
Selectionsselections_
bool workAsASelector_

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 45 of file ConfigurableAnalysis.cc.


Constructor & Destructor Documentation

ConfigurableAnalysis::ConfigurableAnalysis ( const edm::ParameterSet iConfig) [explicit]

Definition at line 74 of file ConfigurableAnalysis.cc.

References edm::ParameterSet::empty(), edm::ParameterSet::exists(), flows_, reco::get(), edm::ParameterSet::getParameter(), init, moduleLabel(), ntupler_, RecoTauValidation_cfi::plotPset, plotter_, NTupler::registerleaves(), selections_, and workAsASelector_.

                                                                         :
  selections_(0), plotter_(0), ntupler_(0)
{

  std::string moduleLabel = iConfig.getParameter<std::string>("@module_label");

  //configure inputag distributor
  if (iConfig.exists("InputTags"))
    edm::Service<InputTagDistributorService>()->init(moduleLabel,iConfig.getParameter<edm::ParameterSet>("InputTags"));

  //configure the variable helper
  edm::Service<VariableHelperService>()->init(moduleLabel,iConfig.getParameter<edm::ParameterSet>("Variables"));

  //list of selections
  selections_ = new Selections(iConfig.getParameter<edm::ParameterSet>("Selections"));

  //plotting device
  edm::ParameterSet plotPset = iConfig.getParameter<edm::ParameterSet>("Plotter");
  if (!plotPset.empty()){
    std::string plotterName = plotPset.getParameter<std::string>("ComponentName");
    plotter_ = PlotterFactory::get()->create(plotterName, plotPset);
  }
  else
    plotter_ = 0;

  //ntupling device
  edm::ParameterSet ntPset = iConfig.getParameter<edm::ParameterSet>("Ntupler");
  if (!ntPset.empty()){
    std::string ntuplerName=ntPset.getParameter<std::string>("ComponentName");
    ntupler_ = NTuplerFactory::get()->create(ntuplerName, ntPset);
  }
  else ntupler_=0;
  
  flows_ = iConfig.getParameter<std::vector<std::string> >("flows");
  workAsASelector_ = iConfig.getParameter<bool>("workAsASelector");

  //vector of passed selections
  produces<std::vector<bool> >();

  //ntupler needs to register its products
  if (ntupler_) ntupler_->registerleaves(this);
}
ConfigurableAnalysis::~ConfigurableAnalysis ( )

Definition at line 117 of file ConfigurableAnalysis.cc.

References selections_.

{
  delete selections_;
}

Member Function Documentation

void ConfigurableAnalysis::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDFilter.

Definition at line 217 of file ConfigurableAnalysis.cc.

{
}
void ConfigurableAnalysis::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDFilter.

Definition at line 223 of file ConfigurableAnalysis.cc.

References Plotter::complete(), plotter_, Selections::print(), and selections_.

                             {
  //print summary tables
  selections_->print();
  if (plotter_) plotter_->complete();
}
bool ConfigurableAnalysis::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDFilter.

Definition at line 128 of file ConfigurableAnalysis.cc.

References accept(), Selections::begin(), Selections::end(), NTupler::fill(), Plotter::fill(), flows_, iEvent, Filter::name(), ntupler_, plotter_, edm::Event::put(), elec_selection::selection(), selections_, Plotter::setDir(), createPayload::skip, and workAsASelector_.

{
  using namespace edm;

  //will the filter pass or not.
  bool majorGlobalAccept=false;

  std::auto_ptr<std::vector<bool> > passedProduct(new std::vector<bool>(flows_.size(),false));
  bool filledOnce=false;  

  // loop the requested selections
  for (Selections::iterator selection=selections_->begin(); selection!=selections_->end();++selection){
    //was this flow of filter actually asked for
    bool skip=true;
    unsigned int iFlow=0;
    for (;iFlow!=flows_.size();++iFlow){if (flows_[iFlow]==selection->name()){skip=false; break;}}
    if (skip) continue;

    //make a specific direction in the plotter
    if (plotter_) plotter_->setDir(selection->name());
    
    // apply individual filters on the event
    std::map<std::string, bool> accept=selection->accept(iEvent);
    
    bool globalAccept=true;
    std::string separator="";
    std::string cumulative="";
    std::string allButOne="allBut_";
    std::string fullAccept="fullAccept";
    std::string fullContent="fullContent";

    if (selection->makeContentPlots() && plotter_)
      plotter_->fill(fullContent,iEvent);

    //loop the filters to make cumulative and allButOne job
    for (Selection::iterator filterIt=selection->begin(); filterIt!=selection->end();++filterIt){
      Filter & filter=(**filterIt);
      //      bool lastCut=((filterIt+1)==selection->end());

      //increment the directory name
      cumulative+=separator+filter.name(); separator="_";

      if (accept[filter.name()]){
        //      if (globalAccept && selection->makeCumulativePlots() && !lastCut)
        if (globalAccept && selection->makeCumulativePlots() && plotter_)
          plotter_->fill(cumulative,iEvent);
      }
      else{
        globalAccept=false;
        // did all the others filter fire
        bool goodForAllButThisOne=true;
        for (std::map<std::string,bool>::iterator decision=accept.begin(); decision!=accept.end();++decision){
          if (decision->first==filter.name()) continue;
          if (!decision->second) {
            goodForAllButThisOne=false;
            break;}
        }
        if (goodForAllButThisOne && selection->makeAllButOnePlots() && plotter_){
          plotter_->fill(allButOne+filter.name(),iEvent);
        }
      }
      
    }// loop over the filters in this selection

    if (globalAccept){
      (*passedProduct)[iFlow]=true;
      majorGlobalAccept=true;
      //make final plots only if no cumulative plots
      if (selection->makeFinalPlots() && !selection->makeCumulativePlots() && plotter_)
        plotter_->fill(fullAccept,iEvent);

      //make the ntuple and put it in the event
      if (selection->ntuplize() && !filledOnce && ntupler_){
        ntupler_->fill(iEvent);
        filledOnce=true;}
    }
    
  }//loop the different filter order/number: loop the Selections

  iEvent.put(passedProduct);
  if (workAsASelector_)
    return majorGlobalAccept;
  else
    return true;
}

Member Data Documentation

std::vector<std::string> ConfigurableAnalysis::flows_ [private]

Definition at line 59 of file ConfigurableAnalysis.cc.

Referenced by ConfigurableAnalysis(), and filter().

Definition at line 57 of file ConfigurableAnalysis.cc.

Referenced by ConfigurableAnalysis(), and filter().

Definition at line 56 of file ConfigurableAnalysis.cc.

Referenced by ConfigurableAnalysis(), endJob(), and filter().

Definition at line 60 of file ConfigurableAnalysis.cc.

Referenced by ConfigurableAnalysis(), and filter().