CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleSystematicsAnalyzer.cc
Go to the documentation of this file.
4 
6 public:
9  virtual bool filter(edm::Event &, const edm::EventSetup&) override;
10  virtual void beginJob() ;
11  virtual void endJob() ;
12 private:
14  std::vector<edm::InputTag> weightTags_;
15  unsigned int originalEvents_;
16  std::vector<double> weightedEvents_;
17  unsigned int selectedEvents_;
18  std::vector<double> weightedSelectedEvents_;
19  std::vector<double> weighted2SelectedEvents_;
20 };
21 
29 
32 
35  selectorPath_(pset.getUntrackedParameter<std::string> ("SelectorPath","")),
36  weightTags_(pset.getUntrackedParameter<std::vector<edm::InputTag> > ("WeightTags")) {
37 }
38 
41 
44  originalEvents_ = 0;
45  selectedEvents_ = 0;
46  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Uncertainties will be determined for the following tags: ";
47  for (unsigned int i=0; i<weightTags_.size(); ++i) {
48  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\t" << weightTags_[i].encode();
49  weightedEvents_.push_back(0.);
50  weightedSelectedEvents_.push_back(0.);
51  weighted2SelectedEvents_.push_back(0.);
52  }
53 }
54 
57  if (originalEvents_==0) {
58  edm::LogVerbatim("SimpleSystematicsAnalysis") << "NO EVENTS => NO RESULTS";
59  return;
60  }
61  if (selectedEvents_==0) {
62  edm::LogVerbatim("SimpleSystematicsAnalysis") << "NO SELECTED EVENTS => NO RESULTS";
63  return;
64  }
65 
66  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\n>>>> Begin of Weight systematics summary >>>>";
67  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Total number of analyzed data: " << originalEvents_ << " [events]";
68  double originalAcceptance = double(selectedEvents_)/originalEvents_;
69  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Total number of selected data: " << selectedEvents_ << " [events], corresponding to acceptance: [" << originalAcceptance*100 << " +- " << 100*sqrt( originalAcceptance*(1.-originalAcceptance)/originalEvents_) << "] %";
70 
71  for (unsigned int i=0; i<weightTags_.size(); ++i) {
72  edm::LogVerbatim("SimpleSystematicsAnalysis") << "Results for Weight Tag: " << weightTags_[i].encode() << " ---->";
73 
74  double acc_central = 0.;
75  double acc2_central = 0.;
76  if (weightedEvents_[i]>0) {
77  acc_central = weightedSelectedEvents_[i]/weightedEvents_[i];
78  acc2_central = weighted2SelectedEvents_[i]/weightedEvents_[i];
79  }
80  double waverage = weightedEvents_[i]/originalEvents_;
81  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tTotal Events after reweighting: " << weightedEvents_[i] << " [events]";
82  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tEvents selected after reweighting: " << weightedSelectedEvents_[i] << " [events]";
83  edm::LogVerbatim("SimpleSystematicsAnalysis") << "\tAcceptance after reweighting: [" << acc_central*100 << " +- " <<
84  100*sqrt((acc2_central/waverage-acc_central*acc_central)/originalEvents_)
85  << "] %";
86  double xi = acc_central-originalAcceptance;
87  double deltaxi = (acc2_central-(originalAcceptance+2*xi+xi*xi))/originalEvents_;
88  if (deltaxi>0) deltaxi = sqrt(deltaxi); else deltaxi = 0.;
89  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";
90 
91  }
92  edm::LogVerbatim("SimpleSystematicsAnalysis") << ">>>> End of Weight systematics summary >>>>";
93 
94 }
95 
99 
100  bool selectedEvent = false;
102  if (!ev.getByLabel(edm::InputTag("TriggerResults"), triggerResults)) {
103  edm::LogError("SimpleSystematicsAnalysis") << ">>> TRIGGER collection does not exist !!!";
104  return false;
105  }
106 
107  const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
108  unsigned int pathIndex = trigNames.triggerIndex(selectorPath_);
109  bool pathFound = (pathIndex<trigNames.size()); // pathIndex >= 0, since pathIndex is unsigned
110  if (pathFound) {
111  if (triggerResults->accept(pathIndex)) selectedEvent = true;
112  }
113  //edm::LogVerbatim("SimpleSystematicsAnalysis") << ">>>> Path Name: " << selectorPath_ << ", selected? " << selectedEvent;
114 
115  if (selectedEvent) selectedEvents_++;
116 
117  for (unsigned int i=0; i<weightTags_.size(); ++i) {
118  edm::Handle<double> weightHandle;
119  ev.getByLabel(weightTags_[i], weightHandle);
120  weightedEvents_[i] += (*weightHandle);
121  if (selectedEvent) {
122  weightedSelectedEvents_[i] += (*weightHandle);
123  weighted2SelectedEvents_[i] += pow((*weightHandle),2);
124  }
125  }
126 
127  return true;
128 }
129 
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:207
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Strings::size_type size() const
Definition: TriggerNames.cc:39
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
T sqrt(T t)
Definition: SSEVec.h:48
virtual bool filter(edm::Event &, const edm::EventSetup &) override
std::vector< double > weightedEvents_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:75
std::vector< double > weighted2SelectedEvents_
SimpleSystematicsAnalyzer(const edm::ParameterSet &pset)
std::vector< double > weightedSelectedEvents_
std::vector< edm::InputTag > weightTags_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40