CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TopElectronHLTOfflineSource.cc
Go to the documentation of this file.
2 
4 
6 
7 #include <boost/algorithm/string.hpp>
8 
20 
22 
23 //using namespace egHLT;
24 
26  beamSpot_(conf.getParameter<edm::InputTag>("beamSpot")) {
27 
29 
30  if (!dbe_)
31  {
32  edm::LogInfo("TopElectronHLTOfflineSource") << "unable to get DQMStore service?";
33  }
34 
35  if(conf.getUntrackedParameter<bool>("DQMStore", false))
36  {
37  if(!dbe_) dbe_->setVerbose(0);
38  }
39 
40  dirName_ = conf.getParameter<std::string>("DQMDirName");
41 
42  electronIdNames_ = conf.getParameter<std::vector<std::string> >("electronIdNames");
43  hltTag_ = conf.getParameter<std::string>("hltTag");
44  superTriggerNames_ = conf.getParameter<std::vector<std::string> >("superTriggerNames");
45  electronTriggerNames_ = conf.getParameter<std::vector<std::string> >("electronTriggerNames");
46 
47  triggerResultsLabel_ = conf.getParameter<edm::InputTag>("triggerResultsLabel");
48  triggerSummaryLabel_ = conf.getParameter<edm::InputTag>("triggerSummaryLabel");
49  electronLabel_ = conf.getParameter<edm::InputTag>("electronCollection");
50  primaryVertexLabel_ = conf.getParameter<edm::InputTag>("primaryVertexCollection");
51  triggerJetFilterLabel_ = conf.getParameter<edm::InputTag>("triggerJetFilterLabel");
52  triggerElectronFilterLabel_ = conf.getParameter<edm::InputTag>("triggerElectronFilterLabel");
53 
54  excludeCloseJets_ = conf.getParameter<bool>("excludeCloseJets");
55  requireTriggerMatch_ = conf.getParameter<bool>("requireTriggerMatch");
56  electronMinEt_ = conf.getParameter<double>("electronMinEt");
57  electronMaxEta_ = conf.getParameter<double>("electronMaxEta");
58 
59  addExtraId_ = conf.getParameter<bool>("addExtraId");
60  extraIdCutsSigmaEta_ = conf.getParameter<double>("extraIdCutsSigmaEta");
61  extraIdCutsSigmaPhi_ = conf.getParameter<double>("extraIdCutsSigmaPhi");
62  extraIdCutsDzPV_ = conf.getParameter<double>("extraIdCutsDzPV");
63 
64 }
66 {
67 }
68 
70 {
71  if(!dbe_) return;
73  for (size_t i = 0; i < superTriggerNames_.size(); ++i)
74  {
76  for (size_t j = 0; j < electronTriggerNames_.size(); ++j)
77  {
79  //std::cout <<superTriggerNames_[i]+"_"+electronTriggerNames_[j]<<std::endl;
80 
81  }
82  }
83  //std::cout <<"done"<<std::endl;
84 }
85 void TopElectronHLTOfflineSource::setupHistos(std::vector<EleMEs> topEleHists)
86 {
87  for (size_t i = 0; i < eleMEs_.size(); ++i)
88  {
89  topEleHists.push_back(eleMEs_[i]);
90  }
91 }
93 {
94 }
96 {
98 }
100 {
101 }
102 
104 {
105  if(!dbe_) return;
106  // ---- Get Trigger Decisions for all triggers under investigation ----
108  if(!iEvent.getByLabel(triggerResultsLabel_, hltResults) || !hltResults.product()) return; //bail if we didnt get trigger results
109 
110 
111 
112  if (!hltConfigValid_) return;
113 
114  std::vector<bool> superTriggerAccepts;
115  std::vector<bool> electronTriggerAccepts;
116 
117  for (size_t i = 0; i < superTriggerNames_.size(); ++i)
118  {
119  unsigned int triggerIndex( hltConfig_.triggerIndex(superTriggerNames_[i]) );
120  bool accept = false;
121 
122  if (triggerIndex < hltResults->size())
123  {
124  accept = hltResults->accept(triggerIndex);
125  }
126 
127  superTriggerAccepts.push_back(accept);
128  }
129 
130  for (size_t i = 0; i < electronTriggerNames_.size(); ++i)
131  {
132  unsigned int triggerIndex( hltConfig_.triggerIndex(electronTriggerNames_[i]) );
133  bool accept = false;
134 
135  if (triggerIndex < hltResults->size())
136  {
137  accept = hltResults->accept(triggerIndex);
138  }
139 
140  electronTriggerAccepts.push_back(accept);
141  }
142 
143  // get reconstructed electron collection
144  if(!iEvent.getByLabel(electronLabel_, eleHandle_) || !eleHandle_.product()) return;
145 
146  // Get Trigger Event, providing the information about trigger objects
148 
150  if(!iEvent.getByLabel(primaryVertexLabel_, vertexHandle) || !vertexHandle.product()) return;
151 
152  reco::Vertex::Point vertexPoint(0., 0., 0.);
153  if (vertexHandle.product()->size() != 0)
154  {
155  const reco::Vertex& theVertex = vertexHandle.product()->front();
156  vertexPoint = theVertex.position();
157  }
158  else
159  {
160  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
161  if(!iEvent.getByLabel(beamSpot_, recoBeamSpotHandle) || !recoBeamSpotHandle.product()) return;
162 
163  vertexPoint = recoBeamSpotHandle->position();
164  }
165 
166  trigger::size_type jetFilterPos = triggerEvent_->filterIndex(triggerJetFilterLabel_);
167  std::vector<const trigger::TriggerObject*> triggerJets;
168 
169  if (jetFilterPos != triggerEvent_->sizeFilters())
170  {
171  for (size_t i = 0; i < triggerEvent_->filterKeys(jetFilterPos).size(); ++i)
172  {
173  size_t objNr = triggerEvent_->filterKeys(jetFilterPos)[i];
174  if(objNr<triggerEvent_->sizeObjects()){
175  triggerJets.push_back(& triggerEvent_->getObjects()[objNr]);
176  }
177  }
178  }
179 
180  trigger::size_type eleFilterPos = triggerEvent_->filterIndex(triggerElectronFilterLabel_);
181  std::vector<const trigger::TriggerObject*> triggerElectrons;
182 
183  if (eleFilterPos != triggerEvent_->sizeFilters())
184  {
185  for (size_t i = 0; i < triggerEvent_->filterKeys(eleFilterPos).size(); ++i)
186  {
187  size_t objNr = triggerEvent_->filterKeys(eleFilterPos)[i];
188  if(objNr<triggerEvent_->sizeObjects()){
189  triggerElectrons.push_back(& triggerEvent_->getObjects()[objNr]);
190  }
191  }
192  }
193 
195 
196  for(size_t eleNr=0; eleNr < eles.size(); ++eleNr)
197  {
198 
199  const reco::GsfElectron& ele = eles[eleNr];
200 
201  // electron selection
202 
203  if(ele.et() > electronMinEt_ && std::abs(ele.eta()) < electronMaxEta_)
204  {
205  size_t index = 0;
206  for (size_t i = 0; i < superTriggerNames_.size(); ++i)
207  {
208  if (superTriggerAccepts[i])
209  fill(eleMEs_[index], iEvent, eleNr, triggerJets, triggerElectrons, vertexPoint);
210  index++;
211 
212  for (size_t j = 0; j < electronTriggerNames_.size(); ++j)
213  {
214  if (superTriggerAccepts[i] && electronTriggerAccepts[j])
215  fill(eleMEs_[index], iEvent, eleNr, triggerJets, triggerElectrons, vertexPoint);
216  index++;
217  }
218  }
219  }
220  }
221 }
222 
223 void TopElectronHLTOfflineSource::EleMEs::setup(DQMStore* dbe, const std::vector<std::string>& eleIdNames, bool addExtraId, const std::string& name)
224 {
225  for (size_t i = 0; i < eleIdNames.size(); ++i)
226  {
227  eleIdNames_.push_back(eleIdNames[i]);
228  if (addExtraId)
229  eleIdNames_.push_back(eleIdNames[i]+"extraId");
230  }
231 
232  addMESets(name);
233 
234  for (size_t i = 0; i < eleMESets_.size(); ++i)
235  {
236  setupMESet(eleMESets_[i], dbe, name+"_"+fullName(i));
237  LogDebug("TopElectronHLTOfflineSource") << "Booked MonitorElement with name " << name;
238  }
239 }
241 {
242  eleSet.ele_et = dbe->book1D("ele_"+name+"_et", "ele_"+name+"_et", 50, 0., 500.);
243  eleSet.ele_eta = dbe->book1D("ele_"+name+"_eta", "ele_"+name+"_eta", 50, -2.5, 2.5);
244  eleSet.ele_phi = dbe->book1D("ele_"+name+"_phi","ele_"+name+"_phi", 50, -3.1416, 3.1416);
245  eleSet.ele_isolEm = dbe->book1D("ele_"+name+"_isolEm", "ele_"+name+"_isolEm", 50, -0.05, 3.);
246  eleSet.ele_isolHad = dbe->book1D("ele_"+name+"_isolHad", "ele_"+name+"_isolHad", 50, -0.05, 5.);
247  eleSet.ele_minDeltaR = dbe->book1D("ele_"+name+"_minDeltaR", "ele_"+name+"_minDeltaR", 50, 0., 1.);
248  eleSet.global_n30jets = dbe->book1D("ele_"+name+"_global_n30jets", "ele_"+name+"_global_n30jets", 10, -0.5, 9.5);
249  eleSet.global_sumEt = dbe->book1D("ele_"+name+"_global_sumEt", "ele_"+name+"_global_sumEt", 50, 0., 1000.);
250  eleSet.ele_gsftrack_etaError = dbe->book1D("ele_"+name+"_gsftrack_etaError", "ele_"+name+"_gsftrack_etaError", 50, 0., 0.005);
251  eleSet.ele_gsftrack_phiError = dbe->book1D("ele_"+name+"_gsftrack_phiError", "ele_"+name+"_gsftrack_phiError", 50, 0., 0.005);
252  eleSet.ele_gsftrack_numberOfValidHits = dbe->book1D("ele_"+name+"_gsftrack_numberOfValidHits", "ele_"+name+"_gsftrack_numberOfValidHits", 25, -0.5, 24.5);
253  eleSet.ele_gsftrack_dzPV = dbe->book1D("ele_"+name+"_gsftrack_dzPV", "ele_"+name+"_gsftrack_dzPV", 50, 0., 0.2);
254 }
255 
257 {
258  eleMENames_.push_back("EB");
259  eleMENames_.push_back("EE");
260  name_ = name;
261  for (size_t i=0; i < eleIdNames_.size() * eleMENames_.size(); ++i)
262  {
263  eleMESets_.push_back(EleMESet());
264  }
265 }
266 
267 void TopElectronHLTOfflineSource::fill(EleMEs& eleMEs, const edm::Event& iEvent, size_t eleIndex, const std::vector<const trigger::TriggerObject*>& triggerJets, const std::vector<const trigger::TriggerObject*>& triggerElectrons, const reco::Vertex::Point& vertexPoint)
268 {
269  const reco::GsfElectron& ele = (*eleHandle_)[eleIndex];
270 
271  float dzPV = std::abs(ele.gsfTrack()->dz(vertexPoint));
272 
273  bool isTriggerMatched = false;
274  for (size_t i = 0; i < triggerElectrons.size(); ++i)
275  {
276  if (deltaR(*(triggerElectrons[i]), ele.p4()) < 0.3)
277  isTriggerMatched = true;
278  }
279 
280  if (requireTriggerMatch_ && !isTriggerMatched)
281  return;
282 
283  // Calculate minimum deltaR to closest jet and sumEt (all jets)
284  float minDeltaR = 999.;
285  float sumEt = 0.;
286 
287  for (size_t jetNr = 0; jetNr < triggerJets.size(); ++jetNr)
288  {
289  const trigger::TriggerObject& jet = *triggerJets[jetNr];
290 
291  sumEt += jet.et();
292 
293  float dr = deltaR(jet, ele.p4());
294 
295  if (!excludeCloseJets_ && dr < minDeltaR)
296  minDeltaR = dr;
297  if (excludeCloseJets_ && dr > 0.1 && dr < minDeltaR)
298  minDeltaR = dr;
299  }
300 
301  for (size_t j = 0; j < eleMEs.eleIdNames().size(); ++j)
302  {
303  bool eId = true;
304 
305  edm::Handle<edm::ValueMap<float> > eIdMapHandle;
306  iEvent.getByLabel(eleMEs.eleIdNames()[j], eIdMapHandle);
307  const edm::ValueMap<float>& eIdMap = *eIdMapHandle;
308  eId = eIdMap[edm::Ref<reco::GsfElectronCollection>(eleHandle_, eleIndex)];
309 
310  bool extraId = true;
311  if (addExtraId_)
312  {
313  if (ele.gsfTrack()->etaError() > extraIdCutsSigmaEta_)
314  extraId = false;
315  if (ele.gsfTrack()->phiError() > extraIdCutsSigmaPhi_)
316  extraId = false;
317  if (dzPV > extraIdCutsDzPV_)
318  extraId = false;
319  }
320 
321  for (size_t i = 0; i < eleMEs.eleMENames().size(); ++i)
322  {
323  if (eId && eleMEs.eleMENames()[i] == "EB" && ele.isEB()&& !ele.isGap())
324  eleMEs.fill(eleMEs.getMESet(i, j), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
325  if (eId && eleMEs.eleMENames()[i] == "EE" && ele.isEE()&& !ele.isGap())
326  eleMEs.fill(eleMEs.getMESet(i, j), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
327  if (addExtraId_)
328  {
329  if (eId && extraId && eleMEs.eleMENames()[i] == "EB" && ele.isEB()&& !ele.isGap())
330  eleMEs.fill(eleMEs.getMESet(i, j+1), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
331  if (eId && extraId && eleMEs.eleMENames()[i] == "EE" && ele.isEE()&& !ele.isGap())
332  eleMEs.fill(eleMEs.getMESet(i, j+1), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
333  }
334  }
335  if (addExtraId_)
336  ++j;
337 
338  }
339 }
340 void TopElectronHLTOfflineSource::EleMEs::fill(EleMESet& eleMESet, const reco::GsfElectron& ele, float minDeltaR, float sumEt, int n30jets, float dzPV)
341 {
342  LogDebug("TopElectronHLTOfflineSource") << "filling the histos with " << ele.et();
343 
344  eleMESet.ele_et->Fill(ele.et());
345  eleMESet.ele_eta->Fill(ele.eta());
346  eleMESet.ele_phi->Fill(ele.phi());
347  eleMESet.ele_isolEm->Fill(ele.dr03EcalRecHitSumEt());
348  eleMESet.ele_isolHad->Fill(ele.dr03HcalTowerSumEt());
349  eleMESet.ele_minDeltaR->Fill(minDeltaR);
350  eleMESet.global_n30jets->Fill(n30jets);
351  eleMESet.global_sumEt->Fill(sumEt);
352  eleMESet.ele_gsftrack_etaError->Fill(ele.gsfTrack()->etaError());
353  eleMESet.ele_gsftrack_phiError->Fill(ele.gsfTrack()->phiError());
354  eleMESet.ele_gsftrack_numberOfValidHits->Fill(ele.gsfTrack()->numberOfValidHits());
355  eleMESet.ele_gsftrack_dzPV->Fill(dzPV);
356 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual double et() const GCC11_FINAL
transverse energy
int i
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:204
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< std::string > electronIdNames_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:22
uint16_t size_type
const Point & position() const
position
Definition: Vertex.h:93
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool isEE() const
Definition: GsfElectron.h:331
bool isEB() const
Definition: GsfElectron.h:330
const std::vector< std::string > & eleIdNames()
void Fill(long long x)
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:24
bool isGap() const
Definition: GsfElectron.h:332
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
edm::Handle< reco::GsfElectronCollection > eleHandle_
std::vector< std::string > electronTriggerNames_
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
void setVerbose(unsigned level)
Definition: DQMStore.cc:398
virtual void setupHistos(const std::vector< EleMEs >)
void fill(EleMESet &eleMESet, const reco::GsfElectron &ele, float minDeltaR, float sumEt, int n30jets, float dzPV)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple conf
Definition: dbtoconf.py:185
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< std::string > superTriggerNames_
EleMESet & getMESet(size_t namePos, size_t idPos)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void setup(DQMStore *dbe, const std::vector< std::string > &, bool addExtraId, const std::string &name)
T const * product() const
Definition: Handle.h:74
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:437
void fill(EleMEs &eleMEs, const edm::Event &iEvent, size_t eleIndex, const std::vector< const trigger::TriggerObject * > &triggerJets, const std::vector< const trigger::TriggerObject * > &triggerElectrons, const reco::Vertex::Point &vertexPoint)
float dr03HcalTowerSumEt() const
Definition: GsfElectron.h:440
virtual void endRun(const edm::Run &run, const edm::EventSetup &c)
const std::vector< std::string > & eleMENames()
void setupMESet(EleMESet &eleSet, DQMStore *dbe, const std::string &name)
edm::Handle< trigger::TriggerEvent > triggerEvent_
tuple size
Write out results.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
TopElectronHLTOfflineSource(const edm::ParameterSet &conf)
Definition: Run.h:36
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:169