CMS 3D CMS Logo

BTVHLTOfflineSource.cc
Go to the documentation of this file.
2 
11 
17 
19 
21 
24 
25 #include "TMath.h"
26 #include "TH1F.h"
27 #include "TH2F.h"
28 #include "TProfile.h"
29 #include "TPRegexp.h"
30 
31 #include <cmath>
32 
33 using namespace edm;
34 using namespace reco;
35 using namespace std;
36 using namespace trigger;
37 
39 {
40  LogDebug("BTVHLTOfflineSource") << "constructor....";
41 
42  dirname_ = iConfig.getUntrackedParameter("dirname",std::string("HLT/BTV/"));
43  processname_ = iConfig.getParameter<std::string>("processname");
44  verbose_ = iConfig.getUntrackedParameter< bool >("verbose", false);
45  triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
46  triggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultsLabel");
47  triggerSummaryToken = consumes <trigger::TriggerEvent> (triggerSummaryLabel_);
48  triggerResultsToken = consumes <edm::TriggerResults> (triggerResultsLabel_);
49  triggerSummaryFUToken = consumes <trigger::TriggerEvent> (edm::InputTag(triggerSummaryLabel_.label(),triggerSummaryLabel_.instance(),std::string("FU")));
50  triggerResultsFUToken = consumes <edm::TriggerResults> (edm::InputTag(triggerResultsLabel_.label(),triggerResultsLabel_.instance(),std::string("FU")));
51  csvCaloTagsToken_ = consumes<reco::JetTagCollection> (edm::InputTag("hltCombinedSecondaryVertexBJetTagsCalo"));
52  csvPfTagsToken_ = consumes<reco::JetTagCollection> (edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF"));
53  offlineCSVTokenPF_ = consumes<reco::JetTagCollection> (iConfig.getParameter<edm::InputTag>("offlineCSVLabelPF"));
54  offlineCSVTokenCalo_ = consumes<reco::JetTagCollection> (iConfig.getParameter<edm::InputTag>("offlineCSVLabelCalo"));
55  hltFastPVToken_ = consumes<std::vector<reco::Vertex> > (iConfig.getParameter<edm::InputTag>("hltFastPVLabel"));
56  hltPFPVToken_ = consumes<std::vector<reco::Vertex> > (iConfig.getParameter<edm::InputTag>("hltPFPVLabel"));
57  hltCaloPVToken_ = consumes<std::vector<reco::Vertex> > (iConfig.getParameter<edm::InputTag>("hltCaloPVLabel"));
58  offlinePVToken_ = consumes<std::vector<reco::Vertex> > (iConfig.getParameter<edm::InputTag>("offlinePVLabel"));
59 
60  std::vector<edm::ParameterSet> paths = iConfig.getParameter<std::vector<edm::ParameterSet> >("pathPairs");
61  for(auto & path : paths) {
62  custompathnamepairs_.push_back(make_pair(
63  path.getParameter<std::string>("pathname"),
64  path.getParameter<std::string>("pathtype")
65  ));}
66 }
67 
69 
71 {
72  bool changed(true);
73  if (!hltConfig_.init(run, c, processname_, changed)) {
74  LogDebug("BTVHLTOfflineSource") << "HLTConfigProvider failed to initialize.";
75  }
76 
77  const unsigned int numberOfPaths(hltConfig_.size());
78  for(unsigned int i=0; i!=numberOfPaths; ++i){
79  pathname_ = hltConfig_.triggerName(i);
80  filtername_ = "dummy";
81  unsigned int usedPrescale = 1;
82  unsigned int objectType = 0;
83  std::string triggerType = "";
84  bool trigSelected = false;
85 
86  for (auto & custompathnamepair : custompathnamepairs_){
87  if(pathname_.find(custompathnamepair.first)!=std::string::npos) { trigSelected = true; triggerType = custompathnamepair.second;}
88  }
89 
90  if (!trigSelected) continue;
91 
92  hltPathsAll_.push_back(PathInfo(usedPrescale, pathname_, "dummy", processname_, objectType, triggerType));
93  }
94 
95 
96 }
97 
98 void
100 {
101  iEvent.getByToken(triggerResultsToken, triggerResults_);
102  if(!triggerResults_.isValid()) {
103  iEvent.getByToken(triggerResultsFUToken,triggerResults_);
104  if(!triggerResults_.isValid()) {
105  edm::LogInfo("BTVHLTOfflineSource") << "TriggerResults not found, "
106  "skipping event";
107  return;
108  }
109  }
110 
111  triggerNames_ = iEvent.triggerNames(*triggerResults_);
112 
113  iEvent.getByToken(triggerSummaryToken,triggerObj_);
114  if(!triggerObj_.isValid()) {
115  iEvent.getByToken(triggerSummaryFUToken,triggerObj_);
116  if(!triggerObj_.isValid()) {
117  edm::LogInfo("BTVHLTOfflineSource") << "TriggerEvent not found, "
118  "skipping event";
119  return;
120  }
121  }
122 
123  iEvent.getByToken(csvCaloTagsToken_, csvCaloTags);
124  iEvent.getByToken(csvPfTagsToken_, csvPfTags);
125 
126  Handle<reco::VertexCollection> VertexHandler;
127 
128  Handle<reco::JetTagCollection> offlineJetTagHandlerPF;
129  iEvent.getByToken(offlineCSVTokenPF_, offlineJetTagHandlerPF);
130 
131  Handle<reco::JetTagCollection> offlineJetTagHandlerCalo;
132  iEvent.getByToken(offlineCSVTokenCalo_, offlineJetTagHandlerCalo);
133 
134  Handle<reco::VertexCollection> offlineVertexHandler;
135  iEvent.getByToken(offlinePVToken_, offlineVertexHandler);
136 
137  if(verbose_ && iEvent.id().event()%10000==0)
138  cout<<"Run = "<<iEvent.id().run()<<", LS = "<<iEvent.luminosityBlock()<<", Event = "<<iEvent.id().event()<<endl;
139 
140  if(!triggerResults_.isValid()) return;
141 
142  for(auto & v : hltPathsAll_){
143  unsigned index = triggerNames_.triggerIndex(v.getPath());
144  if (index < triggerNames_.size() ){
145  float DR = 9999.;
146  if (csvPfTags.isValid() && v.getTriggerType() == "PF")
147  {
148  auto iter = csvPfTags->begin();
149 
150  float CSV_online = iter->second;
151  if (CSV_online<0) CSV_online = -0.05;
152 
153  v.getMEhisto_CSV()->Fill(CSV_online);
154  v.getMEhisto_Pt()->Fill(iter->first->pt());
155  v.getMEhisto_Eta()->Fill(iter->first->eta());
156 
157  DR = 9999.;
158  if(offlineJetTagHandlerPF.isValid()){
159  for (auto const & iterO : *offlineJetTagHandlerPF){
160  float CSV_offline = iterO.second;
161  if (CSV_offline<0) CSV_offline = -0.05;
162  DR = reco::deltaR(iterO.first->eta(),iterO.first->phi(),iter->first->eta(),iter->first->phi());
163  if (DR<0.3) {
164  v.getMEhisto_CSV_RECOvsHLT()->Fill(CSV_offline,CSV_online); continue;
165  }
166  }
167  }
168 
169  iEvent.getByToken(hltPFPVToken_, VertexHandler);
170  if (VertexHandler.isValid())
171  {
172  v.getMEhisto_PVz()->Fill(VertexHandler->begin()->z());
173  if (offlineVertexHandler.isValid()) v.getMEhisto_PVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
174  }
175  }
176 
177  if (csvCaloTags.isValid() && v.getTriggerType() == "Calo" && !csvCaloTags->empty())
178  {
179  auto iter = csvCaloTags->begin();
180 
181  float CSV_online = iter->second;
182  if (CSV_online<0) CSV_online = -0.05;
183 
184  v.getMEhisto_CSV()->Fill(CSV_online);
185  v.getMEhisto_Pt()->Fill(iter->first->pt());
186  v.getMEhisto_Eta()->Fill(iter->first->eta());
187 
188  DR = 9999.;
189  if(offlineJetTagHandlerCalo.isValid()){
190  for (auto const & iterO : *offlineJetTagHandlerCalo)
191  {
192  float CSV_offline = iterO.second;
193  if (CSV_offline<0) CSV_offline = -0.05;
194  DR = reco::deltaR(iterO.first->eta(),iterO.first->phi(),iter->first->eta(),iter->first->phi());
195  if (DR<0.3)
196  {
197  v.getMEhisto_CSV_RECOvsHLT()->Fill(CSV_offline,CSV_online); continue;
198  }
199  }
200  }
201 
202  iEvent.getByToken(hltFastPVToken_, VertexHandler);
203  if (VertexHandler.isValid())
204  {
205  v.getMEhisto_PVz()->Fill(VertexHandler->begin()->z());
206  if (offlineVertexHandler.isValid()) v.getMEhisto_fastPVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
207  }
208 
209  iEvent.getByToken(hltCaloPVToken_, VertexHandler);
210  if (VertexHandler.isValid())
211  {
212  v.getMEhisto_fastPVz()->Fill(VertexHandler->begin()->z());
213  if (offlineVertexHandler.isValid()) v.getMEhisto_PVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
214  }
215 
216  }
217 
218 
219  }
220  }
221 
222 }
223 
224 void
226 {
227  iBooker.setCurrentFolder(dirname_);
228  for(auto & v : hltPathsAll_){
229  //
230  std::string trgPathName = HLTConfigProvider::removeVersion(v.getPath());
231  std::string subdirName = dirname_ +"/"+ trgPathName;
232  std::string trigPath = "("+trgPathName+")";
233  iBooker.setCurrentFolder(subdirName);
234 
235  std::string labelname("HLT");
236  std::string histoname(labelname+"");
237  std::string title(labelname+"");
238 
239  histoname = labelname+"_CSV";
240  title = labelname+"_CSV "+trigPath;
241  MonitorElement * CSV = iBooker.book1D(histoname.c_str(),title.c_str(),110,-0.1,1);
242 
243  histoname = labelname+"_Pt";
244  title = labelname+"_Pt "+trigPath;
245  MonitorElement * Pt = iBooker.book1D(histoname.c_str(),title.c_str(),100,0,400);
246 
247  histoname = labelname+"_Eta";
248  title = labelname+"_Eta "+trigPath;
249  MonitorElement * Eta = iBooker.book1D(histoname.c_str(),title.c_str(),60,-3.0,3.0);
250 
251  histoname = "RECOvsHLT_CSV";
252  title = "offline CSV vs online CSV "+trigPath;
253  MonitorElement * CSV_RECOvsHLT = iBooker.book2D(histoname.c_str(),title.c_str(),110,-0.1,1,110,-0.1,1);
254 
255  histoname = labelname+"_PVz";
256  title = "online z(PV) "+trigPath;
257  MonitorElement * PVz = iBooker.book1D(histoname.c_str(),title.c_str(),80,-20,20);
258 
259  histoname = labelname+"_fastPVz";
260  title = "online z(fastPV) "+trigPath;
261  MonitorElement * fastPVz = iBooker.book1D(histoname.c_str(),title.c_str(),80,-20,20);
262 
263  histoname = "HLTMinusRECO_PVz";
264  title = "online z(PV) - offline z(PV) "+trigPath;
265  MonitorElement * PVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(),title.c_str(),200,-0.5,0.5);
266 
267  histoname = "HLTMinusRECO_fastPVz";
268  title = "online z(fastPV) - offline z(PV) "+trigPath;
269  MonitorElement * fastPVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(),title.c_str(),100,-2,2);
270 
271  v.setHistos(CSV,Pt,Eta,CSV_RECOvsHLT,PVz,fastPVz,PVz_HLTMinusRECO,fastPVz_HLTMinusRECO);
272  }
273 }
#define LogDebug(id)
void analyze(const edm::Event &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: EventID.h:39
BTVHLTOfflineSource(const edm::ParameterSet &)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
static const std::string removeVersion(const std::string &trigger)
int iEvent
Definition: GenABIO.cc:230
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
~BTVHLTOfflineSource() override
bool isValid() const
Definition: HandleBase.h:74
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
std::string const & label() const
Definition: InputTag.h:36
edm::EventID id() const
Definition: EventBase.h:60
fixed size matrix
HLT enums.
void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
std::string const & instance() const
Definition: InputTag.h:37
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:272
Definition: Run.h:43