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_(consumes<reco::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_ = consumes<edm::TriggerResults>(conf.getParameter<edm::InputTag>("triggerResultsLabel"));
48  triggerSummaryLabel_ = consumes<trigger::TriggerEvent>(conf.getParameter<edm::InputTag>("triggerSummaryLabel"));
49  electronLabel_ = consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("electronCollection"));
50  primaryVertexLabel_ = consumes<reco::VertexCollection>(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  for (size_t i = 0; i < electronIdNames_.size(); i++)
85  //std::cout <<"done"<<std::endl;
86 }
87 void TopElectronHLTOfflineSource::setupHistos(std::vector<EleMEs> topEleHists)
88 {
89  for (size_t i = 0; i < eleMEs_.size(); ++i)
90  {
91  topEleHists.push_back(eleMEs_[i]);
92  }
93 }
95 {
96 }
98 {
100 }
102 {
103 }
104 
106 {
107  if(!dbe_) return;
108  // ---- Get Trigger Decisions for all triggers under investigation ----
110  if(!iEvent.getByToken(triggerResultsLabel_, hltResults) || !hltResults.product()) return; //bail if we didnt get trigger results
111 
112 
113 
114  if (!hltConfigValid_) return;
115 
116  std::vector<bool> superTriggerAccepts;
117  std::vector<bool> electronTriggerAccepts;
118 
119  for (size_t i = 0; i < superTriggerNames_.size(); ++i)
120  {
121  unsigned int triggerIndex( hltConfig_.triggerIndex(superTriggerNames_[i]) );
122  bool accept = false;
123 
124  if (triggerIndex < hltResults->size())
125  {
126  accept = hltResults->accept(triggerIndex);
127  }
128 
129  superTriggerAccepts.push_back(accept);
130  }
131 
132  for (size_t i = 0; i < electronTriggerNames_.size(); ++i)
133  {
134  unsigned int triggerIndex( hltConfig_.triggerIndex(electronTriggerNames_[i]) );
135  bool accept = false;
136 
137  if (triggerIndex < hltResults->size())
138  {
139  accept = hltResults->accept(triggerIndex);
140  }
141 
142  electronTriggerAccepts.push_back(accept);
143  }
144 
145  // get reconstructed electron collection
146  if(!iEvent.getByToken(electronLabel_, eleHandle_) || !eleHandle_.product()) return;
147 
148  // Get Trigger Event, providing the information about trigger objects
150 
152  if(!iEvent.getByToken(primaryVertexLabel_, vertexHandle) || !vertexHandle.product()) return;
153 
154  reco::Vertex::Point vertexPoint(0., 0., 0.);
155  if (vertexHandle.product()->size() != 0)
156  {
157  const reco::Vertex& theVertex = vertexHandle.product()->front();
158  vertexPoint = theVertex.position();
159  }
160  else
161  {
162  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
163  if(!iEvent.getByToken(beamSpot_, recoBeamSpotHandle) || !recoBeamSpotHandle.product()) return;
164 
165  vertexPoint = recoBeamSpotHandle->position();
166  }
167 
168  trigger::size_type jetFilterPos = triggerEvent_->filterIndex(triggerJetFilterLabel_);
169  std::vector<const trigger::TriggerObject*> triggerJets;
170 
171  if (jetFilterPos != triggerEvent_->sizeFilters())
172  {
173  for (size_t i = 0; i < triggerEvent_->filterKeys(jetFilterPos).size(); ++i)
174  {
175  size_t objNr = triggerEvent_->filterKeys(jetFilterPos)[i];
176  if(objNr<triggerEvent_->sizeObjects()){
177  triggerJets.push_back(& triggerEvent_->getObjects()[objNr]);
178  }
179  }
180  }
181 
182  trigger::size_type eleFilterPos = triggerEvent_->filterIndex(triggerElectronFilterLabel_);
183  std::vector<const trigger::TriggerObject*> triggerElectrons;
184 
185  if (eleFilterPos != triggerEvent_->sizeFilters())
186  {
187  for (size_t i = 0; i < triggerEvent_->filterKeys(eleFilterPos).size(); ++i)
188  {
189  size_t objNr = triggerEvent_->filterKeys(eleFilterPos)[i];
190  if(objNr<triggerEvent_->sizeObjects()){
191  triggerElectrons.push_back(& triggerEvent_->getObjects()[objNr]);
192  }
193  }
194  }
195 
197 
198  for(size_t eleNr=0; eleNr < eles.size(); ++eleNr)
199  {
200 
201  const reco::GsfElectron& ele = eles[eleNr];
202 
203  // electron selection
204 
205  if(ele.et() > electronMinEt_ && std::abs(ele.eta()) < electronMaxEta_)
206  {
207  size_t index = 0;
208  for (size_t i = 0; i < superTriggerNames_.size(); ++i)
209  {
210  if (superTriggerAccepts[i])
211  fill(eleMEs_[index], iEvent, eleNr, triggerJets, triggerElectrons, vertexPoint);
212  index++;
213 
214  for (size_t j = 0; j < electronTriggerNames_.size(); ++j)
215  {
216  if (superTriggerAccepts[i] && electronTriggerAccepts[j])
217  fill(eleMEs_[index], iEvent, eleNr, triggerJets, triggerElectrons, vertexPoint);
218  index++;
219  }
220  }
221  }
222  }
223 }
224 
225 void TopElectronHLTOfflineSource::EleMEs::setup(DQMStore* dbe, const std::vector<std::string>& eleIdNames, bool addExtraId, const std::string& name)
226 {
227  for (size_t i = 0; i < eleIdNames.size(); ++i)
228  {
229  eleIdNames_.push_back(eleIdNames[i]);
230  if (addExtraId)
231  eleIdNames_.push_back(eleIdNames[i]+"extraId");
232  }
233 
234  addMESets(name);
235 
236  for (size_t i = 0; i < eleMESets_.size(); ++i)
237  {
238  setupMESet(eleMESets_[i], dbe, name+"_"+fullName(i));
239  LogDebug("TopElectronHLTOfflineSource") << "Booked MonitorElement with name " << name;
240  }
241 }
243 {
244  eleSet.ele_et = dbe->book1D("ele_"+name+"_et", "ele_"+name+"_et", 50, 0., 500.);
245  eleSet.ele_eta = dbe->book1D("ele_"+name+"_eta", "ele_"+name+"_eta", 50, -2.5, 2.5);
246  eleSet.ele_phi = dbe->book1D("ele_"+name+"_phi","ele_"+name+"_phi", 50, -3.1416, 3.1416);
247  eleSet.ele_isolEm = dbe->book1D("ele_"+name+"_isolEm", "ele_"+name+"_isolEm", 50, -0.05, 3.);
248  eleSet.ele_isolHad = dbe->book1D("ele_"+name+"_isolHad", "ele_"+name+"_isolHad", 50, -0.05, 5.);
249  eleSet.ele_minDeltaR = dbe->book1D("ele_"+name+"_minDeltaR", "ele_"+name+"_minDeltaR", 50, 0., 1.);
250  eleSet.global_n30jets = dbe->book1D("ele_"+name+"_global_n30jets", "ele_"+name+"_global_n30jets", 10, -0.5, 9.5);
251  eleSet.global_sumEt = dbe->book1D("ele_"+name+"_global_sumEt", "ele_"+name+"_global_sumEt", 50, 0., 1000.);
252  eleSet.ele_gsftrack_etaError = dbe->book1D("ele_"+name+"_gsftrack_etaError", "ele_"+name+"_gsftrack_etaError", 50, 0., 0.005);
253  eleSet.ele_gsftrack_phiError = dbe->book1D("ele_"+name+"_gsftrack_phiError", "ele_"+name+"_gsftrack_phiError", 50, 0., 0.005);
254  eleSet.ele_gsftrack_numberOfValidHits = dbe->book1D("ele_"+name+"_gsftrack_numberOfValidHits", "ele_"+name+"_gsftrack_numberOfValidHits", 25, -0.5, 24.5);
255  eleSet.ele_gsftrack_dzPV = dbe->book1D("ele_"+name+"_gsftrack_dzPV", "ele_"+name+"_gsftrack_dzPV", 50, 0., 0.2);
256 }
257 
259 {
260  eleMENames_.push_back("EB");
261  eleMENames_.push_back("EE");
262  name_ = name;
263  for (size_t i=0; i < eleIdNames_.size() * eleMENames_.size(); ++i)
264  {
265  eleMESets_.push_back(EleMESet());
266  }
267 }
268 
269 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)
270 {
271  const reco::GsfElectron& ele = (*eleHandle_)[eleIndex];
272 
273  float dzPV = std::abs(ele.gsfTrack()->dz(vertexPoint));
274 
275  bool isTriggerMatched = false;
276  for (size_t i = 0; i < triggerElectrons.size(); ++i)
277  {
278  if (deltaR(*(triggerElectrons[i]), ele.p4()) < 0.3)
279  isTriggerMatched = true;
280  }
281 
282  if (requireTriggerMatch_ && !isTriggerMatched)
283  return;
284 
285  // Calculate minimum deltaR to closest jet and sumEt (all jets)
286  float minDeltaR = 999.;
287  float sumEt = 0.;
288 
289  for (size_t jetNr = 0; jetNr < triggerJets.size(); ++jetNr)
290  {
291  const trigger::TriggerObject& jet = *triggerJets[jetNr];
292 
293  sumEt += jet.et();
294 
295  float dr = deltaR(jet, ele.p4());
296 
297  if (!excludeCloseJets_ && dr < minDeltaR)
298  minDeltaR = dr;
299  if (excludeCloseJets_ && dr > 0.1 && dr < minDeltaR)
300  minDeltaR = dr;
301  }
302 
303  for (size_t j = 0; j < eleMEs.eleIdNames().size(); ++j)
304  {
305  bool eId = true;
306 
307  edm::Handle<edm::ValueMap<float> > eIdMapHandle;
308  iEvent.getByToken(eleIdTokenCollection_[j], eIdMapHandle);
309  const edm::ValueMap<float>& eIdMap = *eIdMapHandle;
310  eId = eIdMap[edm::Ref<reco::GsfElectronCollection>(eleHandle_, eleIndex)];
311 
312  bool extraId = true;
313  if (addExtraId_)
314  {
315  if (ele.gsfTrack()->etaError() > extraIdCutsSigmaEta_)
316  extraId = false;
317  if (ele.gsfTrack()->phiError() > extraIdCutsSigmaPhi_)
318  extraId = false;
319  if (dzPV > extraIdCutsDzPV_)
320  extraId = false;
321  }
322 
323  for (size_t i = 0; i < eleMEs.eleMENames().size(); ++i)
324  {
325  if (eId && eleMEs.eleMENames()[i] == "EB" && ele.isEB()&& !ele.isGap())
326  eleMEs.fill(eleMEs.getMESet(i, j), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
327  if (eId && eleMEs.eleMENames()[i] == "EE" && ele.isEE()&& !ele.isGap())
328  eleMEs.fill(eleMEs.getMESet(i, j), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
329  if (addExtraId_)
330  {
331  if (eId && extraId && eleMEs.eleMENames()[i] == "EB" && ele.isEB()&& !ele.isGap())
332  eleMEs.fill(eleMEs.getMESet(i, j+1), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
333  if (eId && extraId && eleMEs.eleMENames()[i] == "EE" && ele.isEE()&& !ele.isGap())
334  eleMEs.fill(eleMEs.getMESet(i, j+1), ele, minDeltaR, sumEt, triggerJets.size(), dzPV);
335  }
336  }
337  if (addExtraId_)
338  ++j;
339 
340  }
341 }
342 void TopElectronHLTOfflineSource::EleMEs::fill(EleMESet& eleMESet, const reco::GsfElectron& ele, float minDeltaR, float sumEt, int n30jets, float dzPV)
343 {
344  LogDebug("TopElectronHLTOfflineSource") << "filling the histos with " << ele.et();
345 
346  eleMESet.ele_et->Fill(ele.et());
347  eleMESet.ele_eta->Fill(ele.eta());
348  eleMESet.ele_phi->Fill(ele.phi());
349  eleMESet.ele_isolEm->Fill(ele.dr03EcalRecHitSumEt());
350  eleMESet.ele_isolHad->Fill(ele.dr03HcalTowerSumEt());
351  eleMESet.ele_minDeltaR->Fill(minDeltaR);
352  eleMESet.global_n30jets->Fill(n30jets);
353  eleMESet.global_sumEt->Fill(sumEt);
354  eleMESet.ele_gsftrack_etaError->Fill(ele.gsfTrack()->etaError());
355  eleMESet.ele_gsftrack_phiError->Fill(ele.gsfTrack()->phiError());
356  eleMESet.ele_gsftrack_numberOfValidHits->Fill(ele.gsfTrack()->numberOfValidHits());
357  eleMESet.ele_gsftrack_dzPV->Fill(dzPV);
358 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:229
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
virtual double et() const
transverse energy
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual float phi() const
momentum azimuthal angle
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
std::vector< std::string > electronIdNames_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:26
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > eleIdTokenCollection_
uint16_t size_type
const Point & position() const
position
Definition: Vertex.h:106
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool isEE() const
Definition: GsfElectron.h:348
bool isEB() const
Definition: GsfElectron.h:347
const std::vector< std::string > & eleIdNames()
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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:22
bool isGap() const
Definition: GsfElectron.h:349
edm::EDGetTokenT< edm::TriggerResults > triggerResultsLabel_
edm::EDGetTokenT< reco::BeamSpot > beamSpot_
int iEvent
Definition: GenABIO.cc:230
edm::Handle< reco::GsfElectronCollection > eleHandle_
virtual float eta() const
momentum pseudorapidity
std::vector< std::string > electronTriggerNames_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
void setVerbose(unsigned level)
Definition: DQMStore.cc:631
virtual void setupHistos(const std::vector< EleMEs >)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexLabel_
void fill(EleMESet &eleMESet, const reco::GsfElectron &ele, float minDeltaR, float sumEt, int n30jets, float dzPV)
tuple conf
Definition: dbtoconf.py:185
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
edm::EDGetTokenT< reco::GsfElectronCollection > electronLabel_
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:81
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:475
double dzPV(const LorentzVector &vtx, const LorentzVector &p4, const LorentzVector &pv)
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)
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryLabel_
float dr03HcalTowerSumEt() const
Definition: GsfElectron.h:478
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:667
TopElectronHLTOfflineSource(const edm::ParameterSet &conf)
Definition: Run.h:41
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:183