CMS 3D CMS Logo

HLTVertexPerformanceAnalyzer.cc
Go to the documentation of this file.
2 
3 using namespace edm;
4 using namespace reco;
5 
7  mainFolder_ = iConfig.getParameter<std::string>("mainFolder");
8  hlTriggerResults_ = consumes<TriggerResults>(iConfig.getParameter<InputTag>("TriggerResults"));
9  VertexCollection_ =
10  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag>>("Vertex"),
11  [this](edm::InputTag const &tag) { return mayConsume<reco::VertexCollection>(tag); });
12  hltPathNames_ = iConfig.getParameter<std::vector<std::string>>("HLTPathNames");
13  simVertexCollection_ = consumes<std::vector<SimVertex>>(iConfig.getParameter<edm::InputTag>("SimVertexCollection"));
14 
15  EDConsumerBase::labelsForToken(hlTriggerResults_, label);
16  hlTriggerResults_Label = label.module;
17 
18  for (unsigned int i = 0; i < VertexCollection_.size(); i++) {
19  EDConsumerBase::labelsForToken(VertexCollection_[i], label);
20  VertexCollection_Label.push_back(label.module);
21  }
22 }
23 
25 
27  triggerConfChanged_ = true;
28  EDConsumerBase::labelsForToken(hlTriggerResults_, label);
29 
30  hltConfigProvider_.init(iRun, iSetup, label.process, triggerConfChanged_);
31  const std::vector<std::string> &allHltPathNames = hltConfigProvider_.triggerNames();
32 
33  // fill hltPathIndexs_ with the trigger number of each hltPathNames_
34  for (size_t trgs = 0; trgs < hltPathNames_.size(); trgs++) {
35  unsigned int found = 1;
36  int it_mem = -1;
37  for (size_t it = 0; it < allHltPathNames.size(); ++it) {
38  found = allHltPathNames.at(it).find(hltPathNames_[trgs]);
39  if (found == 0) {
40  it_mem = (int)it;
41  }
42  } // for allallHltPathNames
43  hltPathIndexs_.push_back(it_mem);
44  } // for hltPathNames_
45 
46  // fill _isfoundHLTs for each hltPathNames_
47  for (size_t trgs = 0; trgs < hltPathNames_.size(); trgs++) {
48  if (hltPathIndexs_[trgs] < 0) {
49  _isfoundHLTs.push_back(false);
50  } else {
51  _isfoundHLTs.push_back(true);
52  }
53  }
54 }
55 
57  bool trigRes = false;
58  using namespace edm;
59 
60  // get triggerResults
61  Handle<TriggerResults> TriggerResulsHandler;
62  if (hlTriggerResults_Label.empty() || hlTriggerResults_Label == "NULL") {
63  edm::LogInfo("NoTriggerResults") << "TriggerResults ==> Empty";
64  return;
65  }
66  iEvent.getByToken(hlTriggerResults_, TriggerResulsHandler);
67  if (TriggerResulsHandler.isValid())
68  trigRes = true;
69  if (!trigRes) {
70  edm::LogInfo("NoTriggerResults") << "TriggerResults ==> not readable";
71  return;
72  }
73  const TriggerResults &triggerResults = *(TriggerResulsHandler.product());
74 
75  // get simVertex
76  float simPV = 0;
77 
79  iEvent.getByToken(simVertexCollection_, simVertexCollection);
80  if (!simVertexCollection.isValid()) {
81  edm::LogInfo("NoSimVertex") << "SimVertex collection is invalid";
82  return;
83  }
84  if (simVertexCollection->empty()) {
85  edm::LogInfo("NoSimVertex") << "SimVertex collection is empty";
86  return;
87  }
88  const SimVertex simPVh = *(simVertexCollection->begin());
89  simPV = simPVh.position().z();
90 
91  // fill the DQM plot
92  Handle<VertexCollection> VertexHandler;
93  for (unsigned int ind = 0; ind < hltPathNames_.size(); ind++) {
94  for (unsigned int coll = 0; coll < VertexCollection_.size(); coll++) {
95  bool VertexOK = false;
96  if (!_isfoundHLTs[ind])
97  continue; // if the hltPath is not in the event, skip the event
98  if (!triggerResults.accept(hltPathIndexs_[ind]))
99  continue; // if the hltPath was not accepted skip the event
100 
101  // get the recoVertex
102  if (!VertexCollection_Label.at(coll).empty() && VertexCollection_Label.at(coll) != "NULL") {
103  iEvent.getByToken(VertexCollection_.at(coll), VertexHandler);
104  if (VertexHandler.isValid() > 0)
105  VertexOK = true;
106  }
107 
108  if (VertexOK) {
109  // calculate the variable (RecoVertex - SimVertex)
110  float value = VertexHandler->begin()->z() - simPV;
111 
112  // if value is over/under flow, assign the extreme value
113  float maxValue = H1_.at(ind)["Vertex_" + VertexCollection_Label.at(coll)]->getTH1F()->GetXaxis()->GetXmax();
114  if (value > maxValue)
115  value = maxValue - 0.0001;
116  if (value < -maxValue)
117  value = -maxValue + 0.0001;
118  // fill the histo
119  H1_.at(ind)["Vertex_" + VertexCollection_Label.at(coll)]->Fill(value);
120  }
121  } // for on VertexCollection_
122  } // for on hltPathNames_
123 }
124 
126  edm::Run const &iRun,
127  edm::EventSetup const &iSetup) {
128  // book the DQM plots
129  using namespace std;
130  std::string dqmFolder;
131  for (unsigned int ind = 0; ind < hltPathNames_.size(); ind++) {
132  dqmFolder = Form("%s/Vertex/%s", mainFolder_.c_str(), hltPathNames_[ind].c_str());
133  H1_.push_back(std::map<std::string, MonitorElement *>());
134  ibooker.setCurrentFolder(dqmFolder);
135  for (unsigned int coll = 0; coll < VertexCollection_.size(); coll++) {
136  float maxValue = 0.02;
137  if (VertexCollection_Label.at(coll) == ("hltFastPrimaryVertex"))
138  maxValue = 2.; // for the hltFastPrimaryVertex use a larger scale (res ~ 1 cm)
139  float vertexU = maxValue;
140  float vertexL = -maxValue;
141  int vertexBins = 100;
142  if (!VertexCollection_Label.at(coll).empty() && VertexCollection_Label.at(coll) != "NULL") {
143  H1_.back()["Vertex_" + VertexCollection_Label.at(coll)] =
144  ibooker.book1D("Vertex_" + VertexCollection_Label.at(coll),
145  VertexCollection_Label.at(coll).c_str(),
146  vertexBins,
147  vertexL,
148  vertexU);
149  H1_.back()["Vertex_" + VertexCollection_Label.at(coll)]->setAxisTitle("vertex error (cm)", 1);
150  }
151  }
152  }
153 }
154 
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool accept() const
Has at least one path accepted the event?
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
char const * label
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:21
Definition: value.py:1
void analyze(const edm::Event &, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:74
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
JetCorrectorParametersCollection coll
Definition: classes.h:10
T const * product() const
Definition: Handle.h:74
static std::string const triggerResults("TriggerResults")
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
fixed size matrix
HLT enums.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
HLTVertexPerformanceAnalyzer(const edm::ParameterSet &)
Definition: Run.h:45