CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenFilterEfficiencyProducer.cc
Go to the documentation of this file.
3 
5  filterPath(iConfig.getParameter<std::string>("filterPath")),
6  tns_(),
7  thisProcess(),pathIndex(100000),
8  numEventsPassPos_(0),
9  numEventsPassNeg_(0),
10  numEventsTotalPos_(0),
11  numEventsTotalNeg_(0),
12  sumpass_w_(0.),
13  sumpass_w2_(0.),
14  sumtotal_w_(0.),
15  sumtotal_w2_(0.)
16 {
17  //now do what ever initialization is needed
19  // get tns pointer
21  if (tns_!=0) {
23  std::vector<std::string> theNames = tns_->getTrigPaths();
24  for ( unsigned int i = 0; i < theNames.size(); i++ ) {
25  if ( theNames[i] == filterPath ) { pathIndex = i; continue; }
26  }
27  }
28  else
29  edm::LogError("ServiceNotAvailable") << "TriggerNamesServive not available, no filter information stored";
30  }
31 
32  triggerResultsToken_ = consumes<edm::TriggerResults>(edm::InputTag("TriggerResults","",thisProcess));
33  genEventInfoToken_ = consumes<GenEventInfoProduct>(edm::InputTag("generator",""));
34  produces<GenFilterInfo, edm::InLumi>();
35 
36 
37 }
38 
39 
41 {
42 
43 }
44 
45 
46 //
47 // member functions
48 //
49 
50 // ------------ method called to for each event ------------
51 void
53 {
54 
56  iEvent.getByToken(triggerResultsToken_,trigR);
58  iEvent.getByToken(genEventInfoToken_,genEventScale);
59  if (!genEventScale.isValid()) return;
60  double weight = genEventScale->weight();
61 
62  unsigned int nSize = (*trigR).size();
63  // std::cout << "Number of paths in TriggerResults = " << nSize << std::endl;
64  if ( nSize >= pathIndex ) {
65 
66  if (!trigR->wasrun(pathIndex))return;
67  if ( trigR->accept(pathIndex) ) {
68  sumpass_w_ += weight;
69  sumpass_w2_+= weight*weight;
70 
72  sumtotal_w2_+= weight*weight;
73 
74  if(weight > 0)
75  {
78  }
79  else
80  {
83  }
84 
85  }
86  else // if fail the filter
87  {
89  sumtotal_w2_+= weight*weight;
90 
91  if(weight > 0)
93  else
95  }
96  // std::cout << "Total events = " << numEventsTotal << " passed = " << numEventsPassed << std::endl;
97 
98  }
99 
100 }
101 
102 void
104 
109  sumpass_w_=0;
110  sumpass_w2_=0;
111  sumtotal_w_=0;
112  sumtotal_w2_=0;
113 
114 }
115 void
117 }
118 
119 void
121 
122  std::auto_ptr<GenFilterInfo> thisProduct(new GenFilterInfo(
127  sumpass_w_,
128  sumpass_w2_,
129  sumtotal_w_,
131  ));
132  iLumi.put(thisProduct);
133 }
int i
Definition: DBlmapReader.cc:9
std::string const & getProcessName() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
int iEvent
Definition: GenABIO.cc:230
bool isValid() const
Definition: HandleBase.h:75
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, const edm::EventSetup &) override
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
GenFilterEfficiencyProducer(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual void endLuminosityBlock(edm::LuminosityBlock const &, const edm::EventSetup &) override
Strings const & getTrigPaths() const
virtual void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
edm::service::TriggerNamesService * tns_
void put(std::auto_ptr< PROD > product)
Put a new product.