CMS 3D CMS Logo

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