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