CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
81  Handle<std::vector<SimVertex> > simVertexCollection;
82  iEvent.getByToken(simVertexCollection_, simVertexCollection);
83  const SimVertex simPVh = *(simVertexCollection->begin());
84  simPV=simPVh.position().z();
85 
86  //fill the DQM plot
87  Handle<VertexCollection> VertexHandler;
88  for (unsigned int ind=0; ind<hltPathNames_.size();ind++) {
89  for (unsigned int coll=0; coll<VertexCollection_.size();coll++) {
90  bool VertexOK=false;
91  if ( !_isfoundHLTs[ind]) continue; //if the hltPath is not in the event, skip the event
92  if ( !triggerResults.accept(hltPathIndexs_[ind]) ) continue; //if the hltPath was not accepted skip the event
93 
94  //get the recoVertex
95  if (VertexCollection_Label.at(coll) != "" && VertexCollection_Label.at(coll) != "NULL" )
96  {
97  iEvent.getByToken(VertexCollection_.at(coll), VertexHandler);
98  if (VertexHandler.isValid()>0) VertexOK=true;
99  }
100 
101  if (VertexOK){
102  //calculate the variable (RecoVertex - SimVertex)
103  float value=VertexHandler->begin()->z()-simPV;
104 
105  //if value is over/under flow, assign the extreme value
106  float maxValue=H1_.at(ind)["Vertex_"+VertexCollection_Label.at(coll)]->getTH1F()->GetXaxis()->GetXmax();
107  if(value>maxValue) value=maxValue-0.0001;
108  if(value<-maxValue) value=-maxValue+0.0001;
109  //fill the histo
110  H1_.at(ind)["Vertex_"+VertexCollection_Label.at(coll)] -> Fill(value);
111  }
112  }// for on VertexCollection_
113  }//for on hltPathNames_
114 }
115 
116 
118 {
119  //book the DQM plots
120  using namespace std;
121  std::string dqmFolder;
122  for (unsigned int ind=0; ind<hltPathNames_.size();ind++) {
123  dqmFolder = Form("HLT/BTag/Vertex/%s",hltPathNames_[ind].c_str());
124  H1_.push_back(std::map<std::string, MonitorElement *>());
125  ibooker.setCurrentFolder(dqmFolder);
126  for (unsigned int coll=0; coll<VertexCollection_.size();coll++) {
127  float maxValue = 0.02;
128  if(VertexCollection_Label.at(coll)==("hltFastPrimaryVertex")) maxValue = 2.; //for the hltFastPrimaryVertex use a larger scale (res ~ 1 cm)
129  float vertexU = maxValue;
130  float vertexL = -maxValue;
131  int vertexBins = 100;
132  if ( VertexCollection_Label.at(coll) != "" && VertexCollection_Label.at(coll) != "NULL" ) {
133  H1_.back()["Vertex_"+VertexCollection_Label.at(coll)] = ibooker.book1D("Vertex_"+VertexCollection_Label.at(coll), VertexCollection_Label.at(coll).c_str(), vertexBins, vertexL, vertexU );
134  H1_.back()["Vertex_"+VertexCollection_Label.at(coll)] -> setAxisTitle("vertex error (cm)",1);
135  }
136  }
137  }
138 }
139 
141 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
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
JetCorrectorParametersCollection coll
Definition: classes.h:10
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
static std::string const triggerResults("TriggerResults")
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
HLTVertexPerformanceAnalyzer(const edm::ParameterSet &)
Definition: Run.h:43