CMS 3D CMS Logo

ZCountingElectrons.cc
Go to the documentation of this file.
8 
9 #include <TLorentzVector.h>
10 
11 #include <memory>
12 
14 
15 //
16 // -------------------------------------- Constructor --------------------------------------------
17 //
19  : triggerResultsInputTag_(iConfig.getParameter<edm::InputTag>("TriggerResults")),
20  fPVName_token(consumes<reco::VertexCollection>(
21  iConfig.getUntrackedParameter<std::string>("edmPVName", "offlinePrimaryVertices"))),
22 
23  // Electron-specific Parameters
24  fGsfElectronName_token(consumes<edm::View<reco::GsfElectron>>(
25  iConfig.getUntrackedParameter<std::string>("edmGsfEleName", "gedGsfElectrons"))),
26  fSCName_token(consumes<edm::View<reco::SuperCluster>>(
27  iConfig.getUntrackedParameter<std::string>("edmSCName", "particleFlowEGamma"))),
28 
29  // Electron-specific Tags
30  fRhoToken(consumes<double>(iConfig.getParameter<edm::InputTag>("rhoname"))),
31  fBeamspotToken(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamspotName"))),
32  fConversionToken(consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsName"))),
33 
34  // Electron-specific Cuts
35  PtCutL1_(iConfig.getUntrackedParameter<double>("PtCutL1")),
36  PtCutL2_(iConfig.getUntrackedParameter<double>("PtCutL2")),
37  EtaCutL1_(iConfig.getUntrackedParameter<double>("EtaCutL1")),
38  EtaCutL2_(iConfig.getUntrackedParameter<double>("EtaCutL2")),
39 
40  MassBin_(iConfig.getUntrackedParameter<double>("MassBin")),
41  MassMin_(iConfig.getUntrackedParameter<double>("MassMin")),
42  MassMax_(iConfig.getUntrackedParameter<double>("MassMax")),
43 
44  LumiBin_(iConfig.getUntrackedParameter<double>("LumiBin")),
45  LumiMin_(iConfig.getUntrackedParameter<double>("LumiMin")),
46  LumiMax_(iConfig.getUntrackedParameter<double>("LumiMax")),
47 
48  PVBin_(iConfig.getUntrackedParameter<int>("PVBin")),
49  PVMin_(iConfig.getUntrackedParameter<double>("PVMin")),
50  PVMax_(iConfig.getUntrackedParameter<double>("PVMax")),
51 
52  VtxNTracksFitCut_(iConfig.getUntrackedParameter<double>("VtxNTracksFitMin")),
53  VtxNdofCut_(iConfig.getUntrackedParameter<double>("VtxNdofMin")),
54  VtxAbsZCut_(iConfig.getUntrackedParameter<double>("VtxAbsZMax")),
55  VtxRhoCut_(iConfig.getUntrackedParameter<double>("VtxRhoMax")),
56 
57  ELE_ID_WP(iConfig.getUntrackedParameter<std::string>("ElectronIDType", "TIGHT")),
58  EleID_(ElectronIdentifier(iConfig)) {
59  edm::LogInfo("ZCounting") << "Constructor ZCountingElectrons::ZCounting " << std::endl;
60 
61  // Trigger settings
62  triggers = new TriggerTools();
63  triggers->setTriggerResultsToken(consumes<edm::TriggerResults>(triggerResultsInputTag_));
64  triggers->setTriggerEventToken(consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("TriggerEvent")));
66 
67  edm::LogVerbatim("ZCounting") << "ZCounting::ZCounting set trigger names";
68  const std::vector<std::string> patterns_ = iConfig.getParameter<std::vector<std::string>>("ElectronTriggerNames");
69  for (const std::string& pattern_ : patterns_) {
70  triggers->addTriggerRecord(pattern_);
71  }
72 
74 }
75 
76 //
77 // -------------------------------------- Destructor --------------------------------------------
78 //
80  edm::LogInfo("ZCountingElectrons") << "Destructor ZCountingElectrons::~ZCountingElectrons " << std::endl;
81 }
82 
83 //
84 // -------------------------------------- beginRun --------------------------------------------
85 //
86 void ZCountingElectrons::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
87  edm::LogInfo("ZCountingElectrons") << "ZCountingElectrons::beginRun" << std::endl;
88 
89  // initialize triggers
90 
91  edm::LogVerbatim("ZCountingElectrons") << "ZCountingElectrons::dqmBeginRun now at " << iRun.id();
92 
93  bool hltChanged_ = true;
94  if (hltConfigProvider_.init(iRun, iSetup, triggerResultsInputTag_.process(), hltChanged_)) {
95  edm::LogVerbatim("ZCountingElectrons")
96  << "ZCountingElectrons::dqmBeginRun [TriggerObjMatchValueMapsProducer::beginRun] "
97  "HLTConfigProvider initialized [processName() = \""
98  << hltConfigProvider_.processName() << "\", tableName() = \"" << hltConfigProvider_.tableName()
99  << "\", size() = " << hltConfigProvider_.size() << "]";
100  } else {
101  edm::LogError("ZCountingElectrons")
102  << "ZCountingElectrons::dqmBeginRun Initialization of HLTConfigProvider failed for Run=" << iRun.id()
103  << " (process=\"" << triggerResultsInputTag_.process() << "\") -> plugin will not produce outputs for this Run";
104  return;
105  }
106 
108 }
109 //
110 // -------------------------------------- bookHistos --------------------------------------------
111 //
113  edm::LogInfo("ZCountingElectrons") << "ZCountingElectrons::bookHistograms" << std::endl;
114  ibooker_.cd();
115  ibooker_.setCurrentFolder("ZCounting/Histograms");
116 
117  h_npv = ibooker_.book2D(
118  "h_npv", "Events with valid primary vertex", LumiBin_, LumiMin_, LumiMax_, PVBin_, PVMin_, PVMax_);
119 
120  h_npv->setAxisTitle("luminosity section", 1);
121  h_npv->setAxisTitle("number of primary vertices", 2);
122 
123  // Electron histograms
124  h_ee_mass_id_pass_central = ibooker_.book2D("h_ee_mass_id_pass_central",
125  "h_ee_mass_id_pass_central",
126  LumiBin_,
127  LumiMin_,
128  LumiMax_,
129  MassBin_,
130  MassMin_,
131  MassMax_);
132  h_ee_mass_id_fail_central = ibooker_.book2D("h_ee_mass_id_fail_central",
133  "h_ee_mass_id_fail_central",
134  LumiBin_,
135  LumiMin_,
136  LumiMax_,
137  MassBin_,
138  MassMin_,
139  MassMax_);
140  h_ee_mass_id_pass_forward = ibooker_.book2D("h_ee_mass_id_pass_forward",
141  "h_ee_mass_id_pass_forward",
142  LumiBin_,
143  LumiMin_,
144  LumiMax_,
145  MassBin_,
146  MassMin_,
147  MassMax_);
148  h_ee_mass_id_fail_forward = ibooker_.book2D("h_ee_mass_id_fail_forward",
149  "h_ee_mass_id_fail_forward",
150  LumiBin_,
151  LumiMin_,
152  LumiMax_,
153  MassBin_,
154  MassMin_,
155  MassMax_);
156 
157  h_ee_mass_HLT_pass_central = ibooker_.book2D("h_ee_mass_HLT_pass_central",
158  "h_ee_mass_HLT_pass_central",
159  LumiBin_,
160  LumiMin_,
161  LumiMax_,
162  MassBin_,
163  MassMin_,
164  MassMax_);
165  h_ee_mass_HLT_fail_central = ibooker_.book2D("h_ee_mass_HLT_fail_central",
166  "h_ee_mass_HLT_fail_central",
167  LumiBin_,
168  LumiMin_,
169  LumiMax_,
170  MassBin_,
171  MassMin_,
172  MassMax_);
173  h_ee_mass_HLT_pass_forward = ibooker_.book2D("h_ee_mass_HLT_pass_forward",
174  "h_ee_mass_HLT_pass_forward",
175  LumiBin_,
176  LumiMin_,
177  LumiMax_,
178  MassBin_,
179  MassMin_,
180  MassMax_);
181  h_ee_mass_HLT_fail_forward = ibooker_.book2D("h_ee_mass_HLT_fail_forward",
182  "h_ee_mass_HLT_fail_forward",
183  LumiBin_,
184  LumiMin_,
185  LumiMax_,
186  MassBin_,
187  MassMin_,
188  MassMax_);
189 
190  h_ee_yield_Z_ebeb = ibooker_.book1D("h_ee_yield_Z_ebeb", "h_ee_yield_Z_ebeb", LumiBin_, LumiMin_, LumiMax_);
191  h_ee_yield_Z_ebee = ibooker_.book1D("h_ee_yield_Z_ebee", "h_ee_yield_Z_ebee", LumiBin_, LumiMin_, LumiMax_);
192  h_ee_yield_Z_eeee = ibooker_.book1D("h_ee_yield_Z_eeee", "h_ee_yield_Z_eeee", LumiBin_, LumiMin_, LumiMax_);
193 }
194 
195 //
196 // -------------------------------------- Analyze --------------------------------------------
197 //
198 //--------------------------------------------------------------------------------------------------
200  const edm::EventSetup& iSetup) { // Fill event tree on the fly
201  edm::LogInfo("ZCountingElectrons") << "ZCountingElectrons::analyze" << std::endl;
202 
203  //-------------------------------
204  //--- Vertex
205  //-------------------------------
207  iEvent.getByToken(fPVName_token, hVertexProduct);
208  if (!hVertexProduct.isValid()) {
209  edm::LogWarning("ZCounting") << "ZCountingElectrons::analyze - no valid primary vertex product found" << std::endl;
210  return;
211  }
212  // const reco::VertexCollection* pvCol = hVertexProduct.product();
213  // const reco::Vertex* pv = &(*pvCol->begin());
214  int nvtx = 0;
215 
216  for (auto const& itVtx : *hVertexProduct) {
217  if (itVtx.isFake())
218  continue;
219  if (itVtx.tracksSize() < VtxNTracksFitCut_)
220  continue;
221  if (itVtx.ndof() < VtxNdofCut_)
222  continue;
223  if (fabs(itVtx.z()) > VtxAbsZCut_)
224  continue;
225  if (itVtx.position().Rho() > VtxRhoCut_)
226  continue;
227 
228  // if (nvtx == 0) {
229  // pv = &itVtx;
230  // }
231  nvtx++;
232  }
233 
234  h_npv->Fill(iEvent.luminosityBlock(), nvtx);
235 
236  //-------------------------------
237  //--- Trigger
238  //-------------------------------
240 
241  // Trigger requirement
242  if (!triggers->pass())
243  return;
244 
245  // Get Electrons
248 
249  // Get SuperClusters
251  iEvent.getByToken(fSCName_token, superclusters);
252 
253  // Get Rho
254  edm::Handle<double> rhoHandle;
255  iEvent.getByToken(fRhoToken, rhoHandle);
256  EleID_.setRho(*rhoHandle);
257 
258  // Get beamspot
259  edm::Handle<reco::BeamSpot> beamspotHandle;
260  iEvent.getByToken(fBeamspotToken, beamspotHandle);
261 
262  // Conversions
263  edm::Handle<reco::ConversionCollection> conversionsHandle;
264  iEvent.getByToken(fConversionToken, conversionsHandle);
265 
267  enum { eEleEle2HLT = 1, eEleEle1HLT1L1, eEleEle1HLT, eEleEleNoSel, eEleSC }; // event category enum
268 
269  // Loop over Tags
270  for (size_t itag = 0; itag < electrons->size(); ++itag) {
271  const auto el1 = electrons->ptrAt(itag);
272  if (not EleID_.passID(el1, beamspotHandle, conversionsHandle))
273  continue;
274 
275  float pt1 = el1->pt();
276  float eta1 = el1->eta();
277  float phi1 = el1->phi();
278 
279  if (!triggers->passObj(eta1, phi1))
280  continue;
281  TLorentzVector vTag(0., 0., 0., 0.);
282  vTag.SetPtEtaPhiM(pt1, eta1, phi1, ELECTRON_MASS);
283 
284  // Tag selection: kinematic cuts, lepton selection and trigger matching
285  double tag_pt = vTag.Pt();
286  double tag_abseta = fabs(vTag.Eta());
287 
288  bool tag_is_valid_tag = ele_tag_selection(tag_pt, tag_abseta);
289  bool tag_is_valid_probe = ele_probe_selection(tag_pt, tag_abseta);
290 
291  if (not(tag_is_valid_tag or tag_is_valid_probe))
292  continue;
293 
294  // Loop over probes
295  for (size_t iprobe = 0; iprobe < superclusters->size(); ++iprobe) {
296  // Initialize probe
297  const auto sc = superclusters->ptrAt(iprobe);
298  if (*sc == *(el1->superCluster())) {
299  continue;
300  }
301 
302  // Find matching electron
303  for (size_t iele = 0; iele < electrons->size(); ++iele) {
304  if (iele == itag)
305  continue;
306  const auto ele = electrons->ptrAt(iele);
307  if (*sc == *(ele->superCluster())) {
308  eleProbe = ele;
309  break;
310  }
311  }
312 
313  // Assign final probe 4-vector
314  TLorentzVector vProbe(0., 0., 0., 0.);
315  if (eleProbe.isNonnull()) {
316  vProbe.SetPtEtaPhiM(eleProbe->pt(), eleProbe->eta(), eleProbe->phi(), ELECTRON_MASS);
317  } else {
318  double pt = sc->energy() * sqrt(1 - pow(tanh(sc->eta()), 2));
319  vProbe.SetPtEtaPhiM(pt, sc->eta(), sc->phi(), ELECTRON_MASS);
320  }
321 
322  // Probe Selection
323  double probe_pt = vProbe.Pt();
324  double probe_abseta = fabs(sc->eta());
325  bool probe_is_valid_probe = ele_probe_selection(probe_pt, probe_abseta);
326  if (!probe_is_valid_probe)
327  continue;
328 
329  // Good Probe found!
330 
331  // Require good Z
332  TLorentzVector vDilep = vTag + vProbe;
333 
334  if ((vDilep.M() < MassMin_) || (vDilep.M() > MassMax_))
335  continue;
336  if (eleProbe.isNonnull() and (eleProbe->charge() != -el1->charge()))
337  continue;
338 
339  // Good Z found!
340  long ls = iEvent.luminosityBlock();
341  bool probe_pass_trigger = triggers->passObj(vProbe.Eta(), vProbe.Phi());
342  bool probe_pass_id = eleProbe.isNonnull() and EleID_.passID(eleProbe, beamspotHandle, conversionsHandle);
343 
345  bool probe_is_forward = probe_abseta > ELE_ETA_CRACK_LOW;
346  bool tag_is_forward = tag_abseta > ELE_ETA_CRACK_LOW;
347 
348  if (probe_pass_id) {
349  if (probe_is_forward and tag_is_forward) {
351  } else if (!probe_is_forward and !tag_is_forward) {
353  } else {
355  }
356  }
357 
358  if (!tag_is_valid_tag)
359  continue;
360 
362  if (probe_pass_id) {
363  if (probe_is_forward) {
364  h_ee_mass_id_pass_forward->Fill(ls, vDilep.M());
365  } else {
366  h_ee_mass_id_pass_central->Fill(ls, vDilep.M());
367  }
368  } else {
369  if (probe_is_forward) {
370  h_ee_mass_id_fail_forward->Fill(ls, vDilep.M());
371  } else {
372  h_ee_mass_id_fail_central->Fill(ls, vDilep.M());
373  }
374  }
375 
377  if (probe_pass_id and probe_pass_trigger) {
378  if (probe_is_forward) {
379  h_ee_mass_HLT_pass_forward->Fill(ls, vDilep.M());
380  } else {
381  h_ee_mass_HLT_pass_central->Fill(ls, vDilep.M());
382  }
383  } else if (probe_pass_id) {
384  if (probe_is_forward) {
385  h_ee_mass_HLT_fail_forward->Fill(ls, vDilep.M());
386  } else {
387  h_ee_mass_HLT_fail_central->Fill(ls, vDilep.M());
388  }
389  }
390  } // End of probe loop
391  } //End of tag loop
392 }
393 
394 //
395 // -------------------------------------- functions --------------------------------------------
396 //
397 
398 bool ZCountingElectrons::ele_probe_selection(double pt, double abseta) {
399  if (pt < PtCutL2_)
400  return false;
401  if (abseta > EtaCutL2_)
402  return false;
403  if ((abseta > ELE_ETA_CRACK_LOW) and (abseta < ELE_ETA_CRACK_HIGH))
404  return false;
405  return true;
406 }
407 
408 bool ZCountingElectrons::ele_tag_selection(double pt, double abseta) {
409  if (pt < PtCutL1_)
410  return false;
411  if (abseta > EtaCutL1_)
412  return false;
413  if ((abseta > ELE_ETA_CRACK_LOW) and (abseta < ELE_ETA_CRACK_HIGH))
414  return false;
415  return true;
416 }
417 
Log< level::Info, true > LogVerbatim
MonitorElement * h_ee_yield_Z_ebeb
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * h_ee_mass_id_pass_forward
void setDRMAX(const double _drMax)
Definition: TriggerTools.h:28
void tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
MonitorElement * h_ee_mass_HLT_pass_forward
double pt() const final
transverse momentum
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * h_ee_yield_Z_ebee
const edm::InputTag triggerResultsInputTag_
void initHLTObjects(const HLTConfigProvider &hltConfigProvider_)
Definition: TriggerTools.cc:35
const std::string ELE_ID_WP
const float ELE_ETA_CRACK_LOW
MonitorElement * h_ee_yield_Z_eeee
edm::EDGetTokenT< edm::View< reco::GsfElectron > > fGsfElectronName_token
void setTriggerEventToken(edm::EDGetTokenT< trigger::TriggerEvent > token)
Definition: TriggerTools.h:27
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
bool ele_probe_selection(double pt, double abseta)
edm::EDGetTokenT< reco::BeamSpot > fBeamspotToken
void Fill(long long x)
edm::EDGetTokenT< double > fRhoToken
MonitorElement * h_ee_mass_HLT_fail_central
int iEvent
Definition: GenABIO.cc:224
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::VertexCollection > fPVName_token
bool ele_tag_selection(double pt, double abseta)
unsigned int size() const
number of trigger paths in trigger table
T sqrt(T t)
Definition: SSEVec.h:19
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::EDGetTokenT< reco::ConversionCollection > fConversionToken
bool passID(const reco::GsfElectronPtr &ele, edm::Handle< reco::BeamSpot > beamspot, edm::Handle< reco::ConversionCollection > conversions)
void setTriggerResultsToken(edm::EDGetTokenT< edm::TriggerResults > token)
Definition: TriggerTools.h:26
HLTConfigProvider hltConfigProvider_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool pass() const
MonitorElement * h_ee_mass_HLT_fail_forward
MonitorElement * h_ee_mass_HLT_pass_central
const float ELE_ETA_CRACK_HIGH
bool passObj(const double eta, const double phi) const
MonitorElement * h_ee_mass_id_pass_central
MonitorElement * h_ee_mass_id_fail_central
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
TriggerTools * triggers
def ls(path, rec=False)
Definition: eostools.py:349
ZCountingElectrons(const edm::ParameterSet &ps)
void setRho(double rho)
void addTriggerRecord(const std::string &name)
Definition: TriggerTools.h:30
~ZCountingElectrons() override
const std::string & processName() const
process name
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
MonitorElement * h_npv
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
const std::string & tableName() const
HLT ConfDB table name.
HLT enums.
void setID(std::string ID)
void readEvent(const edm::Event &iEvent)
Definition: TriggerTools.cc:90
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
ElectronIdentifier EleID_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::string const & process() const
Definition: InputTag.h:40
double phi() const final
momentum azimuthal angle
MonitorElement * h_ee_mass_id_fail_forward
edm::EDGetTokenT< edm::View< reco::SuperCluster > > fSCName_token
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Definition: Run.h:45
int charge() const final
electric charge
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
double eta() const final
momentum pseudorapidity