test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConfigurableAnalysis.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ConfigurableAnalysis
4 // Class: ConfigurableAnalysis
5 //
13 //
14 // Original Author: Jean-Roch Vlimant
15 // Created: Mon Apr 14 11:39:51 CEST 2008
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
33 
35 
40 
41 //
42 // class decleration
43 //
44 
46  public:
47  explicit ConfigurableAnalysis(const edm::ParameterSet&);
49 
50  private:
51  virtual void beginJob() override;
52  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
53  virtual void endJob() override ;
54 
58 
59  std::vector<std::string> flows_;
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  selections_(0), plotter_(0), ntupler_(0)
76 {
77 
78  std::string moduleLabel = iConfig.getParameter<std::string>("@module_label");
79 
80  //configure inputag distributor
81  if (iConfig.exists("InputTags"))
83 
84  //configure the variable helper
86 
87  //list of selections
89 
90  //plotting device
92  if (!plotPset.empty()){
93  std::string plotterName = plotPset.getParameter<std::string>("ComponentName");
94  plotter_ = PlotterFactory::get()->create(plotterName, plotPset);
95  }
96  else
97  plotter_ = 0;
98 
99  //ntupling device
100  edm::ParameterSet ntPset = iConfig.getParameter<edm::ParameterSet>("Ntupler");
101  if (!ntPset.empty()){
102  std::string ntuplerName=ntPset.getParameter<std::string>("ComponentName");
103  ntupler_ = NTuplerFactory::get()->create(ntuplerName, ntPset);
104  }
105  else ntupler_=0;
106 
107  flows_ = iConfig.getParameter<std::vector<std::string> >("flows");
108  workAsASelector_ = iConfig.getParameter<bool>("workAsASelector");
109 
110  //vector of passed selections
111  produces<std::vector<bool> >();
112 
113  //ntupler needs to register its products
114  if (ntupler_) ntupler_->registerleaves(this);
115 }
116 
118 {
119  delete selections_;
120 }
121 
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called to produce the data ------------
129 {
130  //will the filter pass or not.
131  bool majorGlobalAccept=false;
132 
133  std::auto_ptr<std::vector<bool> > passedProduct(new std::vector<bool>(flows_.size(),false));
134  bool filledOnce=false;
135 
136  // loop the requested selections
138  //was this flow of filter actually asked for
139  bool skip=true;
140  unsigned int iFlow=0;
141  for (;iFlow!=flows_.size();++iFlow){if (flows_[iFlow]==selection->name()){skip=false; break;}}
142  if (skip) continue;
143 
144  //make a specific direction in the plotter
145  if (plotter_) plotter_->setDir(selection->name());
146 
147  // apply individual filters on the event
148  std::map<std::string, bool> accept=selection->accept(iEvent);
149 
150  bool globalAccept=true;
151  std::string separator="";
152  std::string cumulative="";
153  std::string allButOne="allBut_";
154  std::string fullAccept="fullAccept";
155  std::string fullContent="fullContent";
156 
157  if (selection->makeContentPlots() && plotter_)
158  plotter_->fill(fullContent,iEvent);
159 
160  //loop the filters to make cumulative and allButOne job
161  for (Selection::iterator filterIt=selection->begin(); filterIt!=selection->end();++filterIt){
162  Filter & filter=(**filterIt);
163  // bool lastCut=((filterIt+1)==selection->end());
164 
165  //increment the directory name
166  cumulative+=separator+filter.name(); separator="_";
167 
168  if (accept[filter.name()]){
169  // if (globalAccept && selection->makeCumulativePlots() && !lastCut)
170  if (globalAccept && selection->makeCumulativePlots() && plotter_)
171  plotter_->fill(cumulative,iEvent);
172  }
173  else{
174  globalAccept=false;
175  // did all the others filter fire
176  bool goodForAllButThisOne=true;
177  for (std::map<std::string,bool>::iterator decision=accept.begin(); decision!=accept.end();++decision){
178  if (decision->first==filter.name()) continue;
179  if (!decision->second) {
180  goodForAllButThisOne=false;
181  break;}
182  }
183  if (goodForAllButThisOne && selection->makeAllButOnePlots() && plotter_){
184  plotter_->fill(allButOne+filter.name(),iEvent);
185  }
186  }
187 
188  }// loop over the filters in this selection
189 
190  if (globalAccept){
191  (*passedProduct)[iFlow]=true;
192  majorGlobalAccept=true;
193  //make final plots only if no cumulative plots
194  if (selection->makeFinalPlots() && !selection->makeCumulativePlots() && plotter_)
195  plotter_->fill(fullAccept,iEvent);
196 
197  //make the ntuple and put it in the event
198  if (selection->ntuplize() && !filledOnce && ntupler_){
199  ntupler_->fill(iEvent);
200  filledOnce=true;}
201  }
202 
203  }//loop the different filter order/number: loop the Selections
204 
205  iEvent.put(passedProduct);
206  if (workAsASelector_)
207  return majorGlobalAccept;
208  else
209  return true;
210 }
211 
212 
213 // ------------ method called once each job just before starting event loop ------------
214 void
216 {
217 }
218 
219 // ------------ method called once each job just after ending the event loop ------------
220 void
222  //print summary tables
223  selections_->print();
224  if (plotter_) plotter_->complete();
225 }
226 
227 
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:216
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int init
Definition: HydjetWrapper.h:62
selection
main part
Definition: corrVsCorr.py:98
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
int iEvent
Definition: GenABIO.cc:230
iterator end()
Definition: Selections.h:368
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
virtual void endJob() override
virtual unsigned int registerleaves(edm::ProducerBase *producer)=0
const std::string & name()
Definition: Selections.h:31
void print()
Definition: Selections.h:371
iterator begin()
Definition: Selections.h:367
virtual bool filter(edm::Event &, const edm::EventSetup &) override
std::vector< Filter * >::iterator iterator
Definition: Selections.h:113
virtual void beginJob() override
ConfigurableAnalysis(const edm::ParameterSet &)
std::vector< Selection >::iterator iterator
Definition: Selections.h:272
virtual void fill(edm::Event &iEvent)=0
virtual void fill(std::string subDir, const edm::Event &iEvent)=0
virtual void complete()=0
virtual void setDir(std::string dir)=0
T get(const Candidate &c)
Definition: component.h:55
std::vector< std::string > flows_