CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(std::vector<edm::ParameterSet>::iterator pathconf = paths.begin() ; pathconf != paths.end(); pathconf++) {
62  custompathnamepairs_.push_back(make_pair(
63  pathconf->getParameter<std::string>("pathname"),
64  pathconf->getParameter<std::string>("pathtype")
65  ));}
66 }
67 
69 {
70 }
71 
73 {
74  bool changed(true);
75  if (!hltConfig_.init(run, c, processname_, changed)) {
76  LogDebug("BTVHLTOfflineSource") << "HLTConfigProvider failed to initialize.";
77  }
78 
79  const unsigned int numberOfPaths(hltConfig_.size());
80  for(unsigned int i=0; i!=numberOfPaths; ++i){
81  pathname_ = hltConfig_.triggerName(i);
82  filtername_ = "dummy";
83  unsigned int usedPrescale = 1;
84  unsigned int objectType = 0;
86  bool trigSelected = false;
87 
88  for (std::vector<std::pair<std::string, std::string> >::iterator custompathnamepair = custompathnamepairs_.begin();
89  custompathnamepair != custompathnamepairs_.end(); ++custompathnamepair){
90  if(pathname_.find(custompathnamepair->first)!=std::string::npos) { trigSelected = true; triggerType = custompathnamepair->second;}
91  }
92 
93  if (!trigSelected) continue;
94 
95  hltPathsAll_.push_back(PathInfo(usedPrescale, pathname_, "dummy", processname_, objectType, triggerType));
96  }
97 
98 
99 }
100 
101 void
103 {
104  iEvent.getByToken(triggerResultsToken, triggerResults_);
105  if(!triggerResults_.isValid()) {
106  iEvent.getByToken(triggerResultsFUToken,triggerResults_);
107  if(!triggerResults_.isValid()) {
108  edm::LogInfo("BTVHLTOfflineSource") << "TriggerResults not found, "
109  "skipping event";
110  return;
111  }
112  }
113 
114  triggerNames_ = iEvent.triggerNames(*triggerResults_);
115 
116  iEvent.getByToken(triggerSummaryToken,triggerObj_);
117  if(!triggerObj_.isValid()) {
118  iEvent.getByToken(triggerSummaryFUToken,triggerObj_);
119  if(!triggerObj_.isValid()) {
120  edm::LogInfo("BTVHLTOfflineSource") << "TriggerEvent not found, "
121  "skipping event";
122  return;
123  }
124  }
125 
126  iEvent.getByToken(csvCaloTagsToken_, csvCaloTags);
127  iEvent.getByToken(csvPfTagsToken_, csvPfTags);
128 
129  Handle<reco::VertexCollection> VertexHandler;
130 
131  Handle<reco::JetTagCollection> offlineJetTagHandlerPF;
132  iEvent.getByToken(offlineCSVTokenPF_, offlineJetTagHandlerPF);
133 
134  Handle<reco::JetTagCollection> offlineJetTagHandlerCalo;
135  iEvent.getByToken(offlineCSVTokenCalo_, offlineJetTagHandlerCalo);
136 
137  Handle<reco::VertexCollection> offlineVertexHandler;
138  iEvent.getByToken(offlinePVToken_, offlineVertexHandler);
139 
140  if(verbose_ && iEvent.id().event()%10000==0)
141  cout<<"Run = "<<iEvent.id().run()<<", LS = "<<iEvent.luminosityBlock()<<", Event = "<<iEvent.id().event()<<endl;
142 
143  if(!triggerResults_.isValid()) return;
144 
145  for(PathInfoCollection::iterator v = hltPathsAll_.begin(); v!= hltPathsAll_.end(); ++v ){
146  unsigned index = triggerNames_.triggerIndex(v->getPath());
147  if (index < triggerNames_.size() ){
148  float DR = 9999.;
149  if (csvPfTags.isValid() && v->getTriggerType() == "PF")
150  {
151  auto iter = csvPfTags->begin();
152 
153  float CSV_online = iter->second;
154  if (CSV_online<0) CSV_online = -0.05;
155 
156  v->getMEhisto_CSV()->Fill(CSV_online);
157  v->getMEhisto_Pt()->Fill(iter->first->pt());
158  v->getMEhisto_Eta()->Fill(iter->first->eta());
159 
160  DR = 9999.;
161  if(offlineJetTagHandlerPF.isValid()){
162  for ( reco::JetTagCollection::const_iterator iterO = offlineJetTagHandlerPF->begin(); iterO != offlineJetTagHandlerPF->end(); iterO++ ){
163  float CSV_offline = iterO->second;
164  if (CSV_offline<0) CSV_offline = -0.05;
165  DR = reco::deltaR(iterO->first->eta(),iterO->first->phi(),iter->first->eta(),iter->first->phi());
166  if (DR<0.3) {
167  v->getMEhisto_CSV_RECOvsHLT()->Fill(CSV_offline,CSV_online); continue;
168  }
169  }
170  }
171 
172  iEvent.getByToken(hltPFPVToken_, VertexHandler);
173  if (VertexHandler.isValid())
174  {
175  v->getMEhisto_PVz()->Fill(VertexHandler->begin()->z());
176  if (offlineVertexHandler.isValid()) v->getMEhisto_PVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
177  }
178  }
179 
180  if (csvCaloTags.isValid() && v->getTriggerType() == "Calo" && !csvCaloTags->empty())
181  {
182  auto iter = csvCaloTags->begin();
183 
184  float CSV_online = iter->second;
185  if (CSV_online<0) CSV_online = -0.05;
186 
187  v->getMEhisto_CSV()->Fill(CSV_online);
188  v->getMEhisto_Pt()->Fill(iter->first->pt());
189  v->getMEhisto_Eta()->Fill(iter->first->eta());
190 
191  DR = 9999.;
192  if(offlineJetTagHandlerCalo.isValid()){
193  for ( reco::JetTagCollection::const_iterator iterO = offlineJetTagHandlerCalo->begin(); iterO != offlineJetTagHandlerCalo->end(); iterO++ )
194  {
195  float CSV_offline = iterO->second;
196  if (CSV_offline<0) CSV_offline = -0.05;
197  DR = reco::deltaR(iterO->first->eta(),iterO->first->phi(),iter->first->eta(),iter->first->phi());
198  if (DR<0.3)
199  {
200  v->getMEhisto_CSV_RECOvsHLT()->Fill(CSV_offline,CSV_online); continue;
201  }
202  }
203  }
204 
205  iEvent.getByToken(hltFastPVToken_, VertexHandler);
206  if (VertexHandler.isValid())
207  {
208  v->getMEhisto_PVz()->Fill(VertexHandler->begin()->z());
209  if (offlineVertexHandler.isValid()) v->getMEhisto_fastPVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
210  }
211 
212  iEvent.getByToken(hltCaloPVToken_, VertexHandler);
213  if (VertexHandler.isValid())
214  {
215  v->getMEhisto_fastPVz()->Fill(VertexHandler->begin()->z());
216  if (offlineVertexHandler.isValid()) v->getMEhisto_PVz_HLTMinusRECO()->Fill(VertexHandler->begin()->z()-offlineVertexHandler->begin()->z());
217  }
218 
219  }
220 
221 
222  }
223  }
224 
225 }
226 
227 void
229 {
230  iBooker.setCurrentFolder(dirname_);
231  for(PathInfoCollection::iterator v = hltPathsAll_.begin(); v!= hltPathsAll_.end(); ++v ){
232  //
233  std::string trgPathName = HLTConfigProvider::removeVersion(v->getPath());
234  std::string subdirName = dirname_ +"/"+ trgPathName;
235  std::string trigPath = "("+trgPathName+")";
236  iBooker.setCurrentFolder(subdirName);
237 
238  std::string labelname("HLT");
239  std::string histoname(labelname+"");
240  std::string title(labelname+"");
241 
242  histoname = labelname+"_CSV";
243  title = labelname+"_CSV "+trigPath;
244  MonitorElement * CSV = iBooker.book1D(histoname.c_str(),title.c_str(),110,-0.1,1);
245 
246  histoname = labelname+"_Pt";
247  title = labelname+"_Pt "+trigPath;
248  MonitorElement * Pt = iBooker.book1D(histoname.c_str(),title.c_str(),100,0,400);
249 
250  histoname = labelname+"_Eta";
251  title = labelname+"_Eta "+trigPath;
252  MonitorElement * Eta = iBooker.book1D(histoname.c_str(),title.c_str(),60,-3.0,3.0);
253 
254  histoname = "RECOvsHLT_CSV";
255  title = "offline CSV vs online CSV "+trigPath;
256  MonitorElement * CSV_RECOvsHLT = iBooker.book2D(histoname.c_str(),title.c_str(),110,-0.1,1,110,-0.1,1);
257 
258  histoname = labelname+"_PVz";
259  title = "online z(PV) "+trigPath;
260  MonitorElement * PVz = iBooker.book1D(histoname.c_str(),title.c_str(),80,-20,20);
261 
262  histoname = labelname+"_fastPVz";
263  title = "online z(fastPV) "+trigPath;
264  MonitorElement * fastPVz = iBooker.book1D(histoname.c_str(),title.c_str(),80,-20,20);
265 
266  histoname = "HLTMinusRECO_PVz";
267  title = "online z(PV) - offline z(PV) "+trigPath;
268  MonitorElement * PVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(),title.c_str(),200,-0.5,0.5);
269 
270  histoname = "HLTMinusRECO_fastPVz";
271  title = "online z(fastPV) - offline z(PV) "+trigPath;
272  MonitorElement * fastPVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(),title.c_str(),100,-2,2);
273 
274  v->setHistos(CSV,Pt,Eta,CSV_RECOvsHLT,PVz,fastPVz,PVz_HLTMinusRECO,fastPVz_HLTMinusRECO);
275  }
276 }
#define LogDebug(id)
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
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:215
transient_vector_type::const_iterator const_iterator
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:62
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
bool isValid() const
Definition: HandleBase.h:75
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
virtual 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:59
tuple cout
Definition: gather_cfg.py:145
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
std::string const & instance() const
Definition: InputTag.h:37
Definition: Run.h:43