Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 #include "FWCore/Framework/interface/EDFilter.h"
00028
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/ServiceRegistry/interface/Service.h"
00033
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035
00036 #include "PhysicsTools/UtilAlgos/interface/Selections.h"
00037 #include "PhysicsTools/UtilAlgos/interface/Plotter.h"
00038 #include "PhysicsTools/UtilAlgos/interface/NTupler.h"
00039 #include "PhysicsTools/UtilAlgos/interface/InputTagDistributor.h"
00040
00041
00042
00043
00044
00045 class ConfigurableAnalysis : public edm::EDFilter {
00046 public:
00047 explicit ConfigurableAnalysis(const edm::ParameterSet&);
00048 ~ConfigurableAnalysis();
00049
00050 private:
00051 virtual void beginJob();
00052 virtual bool filter(edm::Event&, const edm::EventSetup&);
00053 virtual void endJob() ;
00054
00055 Selections * selections_;
00056 Plotter * plotter_;
00057 NTupler * ntupler_;
00058
00059 std::vector<std::string> flows_;
00060 bool workAsASelector_;
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 ConfigurableAnalysis::ConfigurableAnalysis(const edm::ParameterSet& iConfig) :
00075 selections_(0), plotter_(0), ntupler_(0)
00076 {
00077
00078 std::string moduleLabel = iConfig.getParameter<std::string>("@module_label");
00079
00080
00081 if (iConfig.exists("InputTags"))
00082 edm::Service<InputTagDistributorService>()->init(moduleLabel,iConfig.getParameter<edm::ParameterSet>("InputTags"));
00083
00084
00085 edm::Service<VariableHelperService>()->init(moduleLabel,iConfig.getParameter<edm::ParameterSet>("Variables"));
00086
00087
00088 selections_ = new Selections(iConfig.getParameter<edm::ParameterSet>("Selections"));
00089
00090
00091 edm::ParameterSet plotPset = iConfig.getParameter<edm::ParameterSet>("Plotter");
00092 if (!plotPset.empty()){
00093 std::string plotterName = plotPset.getParameter<std::string>("ComponentName");
00094 plotter_ = PlotterFactory::get()->create(plotterName, plotPset);
00095 }
00096 else
00097 plotter_ = 0;
00098
00099
00100 edm::ParameterSet ntPset = iConfig.getParameter<edm::ParameterSet>("Ntupler");
00101 if (!ntPset.empty()){
00102 std::string ntuplerName=ntPset.getParameter<std::string>("ComponentName");
00103 ntupler_ = NTuplerFactory::get()->create(ntuplerName, ntPset);
00104 }
00105 else ntupler_=0;
00106
00107 flows_ = iConfig.getParameter<std::vector<std::string> >("flows");
00108 workAsASelector_ = iConfig.getParameter<bool>("workAsASelector");
00109
00110
00111 produces<std::vector<bool> >();
00112
00113
00114 if (ntupler_) ntupler_->registerleaves(this);
00115 }
00116
00117 ConfigurableAnalysis::~ConfigurableAnalysis()
00118 {
00119 delete selections_;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 bool ConfigurableAnalysis::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00129 {
00130 using namespace edm;
00131
00132
00133 bool majorGlobalAccept=false;
00134
00135 std::auto_ptr<std::vector<bool> > passedProduct(new std::vector<bool>(flows_.size(),false));
00136 bool filledOnce=false;
00137
00138
00139 for (Selections::iterator selection=selections_->begin(); selection!=selections_->end();++selection){
00140
00141 bool skip=true;
00142 unsigned int iFlow=0;
00143 for (;iFlow!=flows_.size();++iFlow){if (flows_[iFlow]==selection->name()){skip=false; break;}}
00144 if (skip) continue;
00145
00146
00147 if (plotter_) plotter_->setDir(selection->name());
00148
00149
00150 std::map<std::string, bool> accept=selection->accept(iEvent);
00151
00152 bool globalAccept=true;
00153 std::string separator="";
00154 std::string cumulative="";
00155 std::string allButOne="allBut_";
00156 std::string fullAccept="fullAccept";
00157 std::string fullContent="fullContent";
00158
00159 if (selection->makeContentPlots() && plotter_)
00160 plotter_->fill(fullContent,iEvent);
00161
00162
00163 for (Selection::iterator filterIt=selection->begin(); filterIt!=selection->end();++filterIt){
00164 Filter & filter=(**filterIt);
00165
00166
00167
00168 cumulative+=separator+filter.name(); separator="_";
00169
00170 if (accept[filter.name()]){
00171
00172 if (globalAccept && selection->makeCumulativePlots() && plotter_)
00173 plotter_->fill(cumulative,iEvent);
00174 }
00175 else{
00176 globalAccept=false;
00177
00178 bool goodForAllButThisOne=true;
00179 for (std::map<std::string,bool>::iterator decision=accept.begin(); decision!=accept.end();++decision){
00180 if (decision->first==filter.name()) continue;
00181 if (!decision->second) {
00182 goodForAllButThisOne=false;
00183 break;}
00184 }
00185 if (goodForAllButThisOne && selection->makeAllButOnePlots() && plotter_){
00186 plotter_->fill(allButOne+filter.name(),iEvent);
00187 }
00188 }
00189
00190 }
00191
00192 if (globalAccept){
00193 (*passedProduct)[iFlow]=true;
00194 majorGlobalAccept=true;
00195
00196 if (selection->makeFinalPlots() && !selection->makeCumulativePlots() && plotter_)
00197 plotter_->fill(fullAccept,iEvent);
00198
00199
00200 if (selection->ntuplize() && !filledOnce && ntupler_){
00201 ntupler_->fill(iEvent);
00202 filledOnce=true;}
00203 }
00204
00205 }
00206
00207 iEvent.put(passedProduct);
00208 if (workAsASelector_)
00209 return majorGlobalAccept;
00210 else
00211 return true;
00212 }
00213
00214
00215
00216 void
00217 ConfigurableAnalysis::beginJob()
00218 {
00219 }
00220
00221
00222 void
00223 ConfigurableAnalysis::endJob() {
00224
00225 selections_->print();
00226 if (plotter_) plotter_->complete();
00227 }
00228
00229
00230 DEFINE_FWK_MODULE(ConfigurableAnalysis);