CMS 3D CMS Logo

SimpleSystematicsAnalyzer.cc
Go to the documentation of this file.
5 
7 public:
10  virtual bool filter(edm::Event &, const edm::EventSetup&) override;
11  virtual void beginJob() override ;
12  virtual void endJob() override ;
13 private:
15  std::vector<edm::InputTag> weightTags_;
16  std::vector<edm::EDGetTokenT<double> > weightTokens_;
18  unsigned int originalEvents_;
19  std::vector<double> weightedEvents_;
20  unsigned int selectedEvents_;
21  std::vector<double> weightedSelectedEvents_;
22  std::vector<double> weighted2SelectedEvents_;
23 };
24 
32 
34 
36 
39  selectorPath_(pset.getUntrackedParameter<std::string> ("SelectorPath","")),
40  weightTags_(pset.getUntrackedParameter<std::vector<edm::InputTag> > ("WeightTags")),
41  weightTokens_(edm::vector_transform(weightTags_, [this](edm::InputTag const & tag){return consumes<double>(tag);})),
42  triggerResultsToken_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults"))) {
43 }
44 
47 
50  originalEvents_ = 0;
51  selectedEvents_ = 0;
52  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Uncertainties will be determined for the following tags: ";
53  for (unsigned int i=0; i<weightTags_.size(); ++i) {
54  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\t" << weightTags_[i].encode();
55  weightedEvents_.push_back(0.);
56  weightedSelectedEvents_.push_back(0.);
57  weighted2SelectedEvents_.push_back(0.);
58  }
59 }
60 
63  if (originalEvents_==0) {
64  edm::LogVerbatim("SimpleSystematicsAnalysis") << "NO EVENTS => NO RESULTS";
65  return;
66  }
67  if (selectedEvents_==0) {
68  edm::LogVerbatim("SimpleSystematicsAnalysis") << "NO SELECTED EVENTS => NO RESULTS";
69  return;
70  }
71 
72  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\n>>>> Begin of Weight systematics summary >>>>";
73  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Total number of analyzed data: " << originalEvents_ << " [events]";
74  double originalAcceptance = double(selectedEvents_)/originalEvents_;
75  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Total number of selected data: " << selectedEvents_ << " [events], corresponding to acceptance: [" << originalAcceptance*100 << " +- " << 100*sqrt( originalAcceptance*(1.-originalAcceptance)/originalEvents_) << "] %";
76 
77  for (unsigned int i=0; i<weightTags_.size(); ++i) {
78  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Results for Weight Tag: " << weightTags_[i].encode() << " ---->";
79 
80  double acc_central = 0.;
81  double acc2_central = 0.;
82  if (weightedEvents_[i]>0) {
85  }
86  double waverage = weightedEvents_[i]/originalEvents_;
87  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tTotal Events after reweighting: " << weightedEvents_[i] << " [events]";
88  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tEvents selected after reweighting: " << weightedSelectedEvents_[i] << " [events]";
89  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tAcceptance after reweighting: [" << acc_central*100 << " +- " <<
90  100*sqrt((acc2_central/waverage-acc_central*acc_central)/originalEvents_)
91  << "] %";
92  double xi = acc_central-originalAcceptance;
93  double deltaxi = (acc2_central-(originalAcceptance+2*xi+xi*xi))/originalEvents_;
94  if (deltaxi>0) deltaxi = sqrt(deltaxi); else deltaxi = 0.;
95  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\ti.e. [" << std::setprecision(4) << 100*xi/originalAcceptance << " +- " << std::setprecision(4) << 100*deltaxi/originalAcceptance << "] % relative variation with respect to the original acceptance";
96 
97  }
98  edm::LogVerbatim("SimpleSystematicsAnalysis") << ">>>> End of Weight systematics summary >>>>";
99 
100 }
101 
104  originalEvents_++;
105 
106  bool selectedEvent = false;
108  if (!ev.getByToken(triggerResultsToken_, triggerResults)) {
109  edm::LogError("SimpleSystematicsAnalysis") << ">>> TRIGGER collection does not exist !!!";
110  return false;
111  }
112 
113  const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
114  unsigned int pathIndex = trigNames.triggerIndex(selectorPath_);
115  bool pathFound = (pathIndex<trigNames.size()); // pathIndex >= 0, since pathIndex is unsigned
116  if (pathFound) {
117  if (triggerResults->accept(pathIndex)) selectedEvent = true;
118  }
119  //edm::LogVerbatim("SimpleSystematicsAnalysis") << ">>>> Path Name: " << selectorPath_ << ", selected? " << selectedEvent;
120 
121  if (selectedEvent) selectedEvents_++;
122 
123  for (unsigned int i=0; i<weightTags_.size(); ++i) {
124  edm::Handle<double> weightHandle;
125  ev.getByToken(weightTokens_[i], weightHandle);
126  weightedEvents_[i] += (*weightHandle);
127  if (selectedEvent) {
128  weightedSelectedEvents_[i] += (*weightHandle);
129  weighted2SelectedEvents_[i] += pow((*weightHandle),2);
130  }
131  }
132 
133  return true;
134 }
135 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool accept() const
Has at least one path accepted the event?
bool ev
Strings::size_type size() const
Definition: TriggerNames.cc:39
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
virtual void beginJob() override
std::vector< edm::EDGetTokenT< double > > weightTokens_
T sqrt(T t)
Definition: SSEVec.h:18
virtual bool filter(edm::Event &, const edm::EventSetup &) override
std::vector< double > weightedEvents_
static std::string const triggerResults
Definition: EdmProvDump.cc:41
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
HLT enums.
std::vector< double > weighted2SelectedEvents_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
SimpleSystematicsAnalyzer(const edm::ParameterSet &pset)
std::vector< double > weightedSelectedEvents_
std::vector< edm::InputTag > weightTags_
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:239
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40