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;
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 
HLTVertexPerformanceAnalyzer::dqmBeginRun
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Definition: HLTVertexPerformanceAnalyzer.cc:26
mps_fire.i
i
Definition: mps_fire.py:428
SimVertex
Definition: SimVertex.h:5
HLTVertexPerformanceAnalyzer.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
caloTruthProducer_cfi.simVertexCollection
simVertexCollection
Definition: caloTruthProducer_cfi.py:29
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
L1TMonitor_cff.dqmFolder
dqmFolder
Definition: L1TMonitor_cff.py:88
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLTVertexPerformanceAnalyzer
Definition: HLTVertexPerformanceAnalyzer.h:33
edm::vector_transform
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
edm::ParameterSet
Definition: ParameterSet.h:47
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
seedmultiplicitymonitor_newtracking_cfi.maxValue
maxValue
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
value
Definition: value.py:1
HLTVertexPerformanceAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HLTVertexPerformanceAnalyzer.cc:56
edm::EventSetup
Definition: EventSetup.h:58
CoreSimVertex::position
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:21
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::EDConsumerBase::labelsForToken
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
Definition: EDConsumerBase.cc:338
std
Definition: JetResolutionObject.h:76
HLTVertexPerformanceAnalyzer::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HLTVertexPerformanceAnalyzer.cc:125
edm::triggerResults
static const std::string triggerResults("TriggerResults")
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
HLTVertexPerformanceAnalyzer::HLTVertexPerformanceAnalyzer
HLTVertexPerformanceAnalyzer(const edm::ParameterSet &)
Definition: HLTVertexPerformanceAnalyzer.cc:6
HLTVertexPerformanceAnalyzer::~HLTVertexPerformanceAnalyzer
~HLTVertexPerformanceAnalyzer() override
Definition: HLTVertexPerformanceAnalyzer.cc:24
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
dqm::impl::MonitorElement::setAxisTitle
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:791
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::TriggerResults
Definition: TriggerResults.h:35
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98