CMS 3D CMS Logo

ZEEDetails.cc
Go to the documentation of this file.
1 // system includes
2 #include <fstream>
3 #include <iostream>
4 #include <map>
5 #include <memory>
6 #include <ostream>
7 #include <set>
8 #include <string>
9 #include <vector>
10 
11 // user includes
34 
35 // ROOT includes
36 #include "TFile.h"
37 #include "TLorentzVector.h"
38 #include "TMath.h"
39 
40 class ZEEDetails : public DQMEDAnalyzer {
41 public:
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 
45 protected:
46  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
47  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
48 
49 private:
52 
61 
62  const double maxEta_;
63  const double minPt_;
64  const double maxDeltaPhiInEB_;
65  const double maxDeltaEtaInEB_;
66  const double maxHOEEB_;
67  const double maxSigmaiEiEEB_;
68  const double maxDeltaPhiInEE_;
69  const double maxDeltaEtaInEE_;
70  const double maxHOEEE_;
71  const double maxSigmaiEiEEE_;
72  const double maxNormChi2_;
73  const double maxD0_;
74  const double maxDz_;
75  const int minPixelHits_;
76  const int minStripHits_;
77  const double maxIso_;
78  const double minPtHighest_;
79  const double minInvMass_;
80  const double maxInvMass_;
82  std::vector<float> vpu_;
83  std::vector<float> vtrack_;
84  const bool isMC_;
85  const bool doPUCorrection_;
87 
91 };
92 
95  desc.addUntracked<std::string>("moduleName", "ZEEDetails");
96  desc.addUntracked<std::string>("folderName", "ElectronTracks");
97  desc.addUntracked<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"));
98  desc.addUntracked<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"));
99  desc.addUntracked<edm::InputTag>("puTag", edm::InputTag("addPileupInfo"));
100  desc.addUntracked<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"));
101  desc.addUntracked<double>("maxEta", 2.4);
102  desc.addUntracked<double>("minPt", 5);
103  desc.addUntracked<double>("maxDeltaPhiInEB", 0.15);
104  desc.addUntracked<double>("maxDeltaEtaInEB", 0.007);
105  desc.addUntracked<double>("maxHOEEB", 0.12);
106  desc.addUntracked<double>("maxSigmaiEiEEB", 0.01);
107  desc.addUntracked<double>("maxDeltaPhiInEE", 0.1);
108  desc.addUntracked<double>("maxDeltaEtaInEE", 0.009);
109  desc.addUntracked<double>("maxHOEEB_", .10);
110  desc.addUntracked<double>("maxSigmaiEiEEE", 0.03);
111  desc.addUntracked<double>("maxNormChi2", 10);
112  desc.addUntracked<double>("maxD0", 0.02);
113  desc.addUntracked<double>("maxDz", 20.);
114  desc.addUntracked<uint32_t>("minPixelHits", 1);
115  desc.addUntracked<uint32_t>("minStripHits", 8);
116  desc.addUntracked<double>("maxIso", 0.3);
117  desc.addUntracked<double>("minPtHighest", 24);
118  desc.addUntracked<double>("minInvMass", 75);
119  desc.addUntracked<double>("maxInvMass", 105);
120  desc.addUntracked<std::string>("trackQuality", "highPurity");
121  desc.addUntracked<bool>("isMC", false);
122  desc.addUntracked<bool>("doPUCorrection", false);
123  desc.addUntracked<std::string>("puScaleFactorFile", "PileupScaleFactor.root");
124  descriptions.addWithDefaultLabel(desc);
125 }
126 
128  : moduleName_(ps.getUntrackedParameter<std::string>("moduleName", "ZEEDetails")),
129  folderName_(ps.getUntrackedParameter<std::string>("folderName", "ElectronTracks")),
130  electronTag_(ps.getUntrackedParameter<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"))),
131  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
132  puSummaryTag_(ps.getUntrackedParameter<edm::InputTag>("puTag", edm::InputTag("addPileupInfo"))),
133  vertexTag_(ps.getUntrackedParameter<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"))),
134  electronToken_(consumes<reco::GsfElectronCollection>(electronTag_)),
135  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
136  puSummaryToken_(consumes<std::vector<PileupSummaryInfo> >(puSummaryTag_)),
137  vertexToken_(consumes<reco::VertexCollection>(vertexTag_)),
138  maxEta_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
139  minPt_(ps.getUntrackedParameter<double>("minPt", 5)),
140  maxDeltaPhiInEB_(ps.getUntrackedParameter<double>("maxDeltaPhiInEB", 0.15)),
141  maxDeltaEtaInEB_(ps.getUntrackedParameter<double>("maxDeltaEtaInEB", 0.007)),
142  maxHOEEB_(ps.getUntrackedParameter<double>("maxHOEEB", 0.12)),
143  maxSigmaiEiEEB_(ps.getUntrackedParameter<double>("maxSigmaiEiEEB", 0.01)),
144  maxDeltaPhiInEE_(ps.getUntrackedParameter<double>("maxDeltaPhiInEE", 0.1)),
145  maxDeltaEtaInEE_(ps.getUntrackedParameter<double>("maxDeltaEtaInEE", 0.009)),
146  maxHOEEE_(ps.getUntrackedParameter<double>("maxHOEEB_", .10)),
147  maxSigmaiEiEEE_(ps.getUntrackedParameter<double>("maxSigmaiEiEEE", 0.03)),
148  maxNormChi2_(ps.getUntrackedParameter<double>("maxNormChi2", 10)),
149  maxD0_(ps.getUntrackedParameter<double>("maxD0", 0.02)),
150  maxDz_(ps.getUntrackedParameter<double>("maxDz", 20.)),
151  minPixelHits_(ps.getUntrackedParameter<uint32_t>("minPixelHits", 1)),
152  minStripHits_(ps.getUntrackedParameter<uint32_t>("minStripHits", 8)),
153  maxIso_(ps.getUntrackedParameter<double>("maxIso", 0.3)),
154  minPtHighest_(ps.getUntrackedParameter<double>("minPtHighest", 24)),
155  minInvMass_(ps.getUntrackedParameter<double>("minInvMass", 75)),
156  maxInvMass_(ps.getUntrackedParameter<double>("maxInvMass", 105)),
157  trackQuality_(ps.getUntrackedParameter<std::string>("trackQuality", "highPurity")),
158  isMC_(ps.getUntrackedParameter<bool>("isMC", false)),
159  doPUCorrection_(ps.getUntrackedParameter<bool>("doPUCorrection", false)),
160  puScaleFactorFile_(ps.getUntrackedParameter<std::string>("puScaleFactorFile", "PileupScaleFactor.root")) {
161  if (isMC_ && doPUCorrection_) {
162  vpu_.clear();
163  TFile* f1 = TFile::Open(puScaleFactorFile_.c_str());
164  TH1F* h1 = dynamic_cast<TH1F*>(f1->Get("pileupweight"));
165  for (int i = 1; i <= h1->GetNbinsX(); ++i)
166  vpu_.push_back(h1->GetBinContent(i));
167  f1->Close();
168  }
169 }
170 
171 void ZEEDetails::bookHistograms(DQMStore::IBooker& ibook, edm::Run const& iRun, edm::EventSetup const& iSetup) {
172  std::string currentFolder = moduleName_ + "/" + folderName_;
173  ibook.setCurrentFolder(currentFolder);
174  Zpt_ = ibook.book1D("Zpt", "Z-Boson p_{T}", 100, 0.0, 100.0);
175  ZInvMass_ = ibook.book1D("ZInvMass", "m_{ee}", 200, minInvMass_, maxInvMass_);
176  EoverP_ = ibook.book3D("EoverP", "EoverP", 48, -2.4, 2.4, 36, -3.2, 3.2, 100, 0, 10);
177 }
178 
180  std::vector<TLorentzVector> list;
181  std::vector<int> chrgeList;
182  std::vector<reco::GsfElectron> finalelectrons;
183 
184  // Read Electron Collection
186  iEvent.getByToken(electronToken_, electronColl);
187 
189  iEvent.getByToken(bsToken_, beamSpot);
190 
191  if (electronColl.isValid()) {
192  for (auto const& ele : *electronColl) {
193  if (!ele.ecalDriven())
194  continue;
195  if (ele.pt() < minPt_)
196  continue;
197  // set a max Eta cut
198  if (!(ele.isEB() || ele.isEE()))
199  continue;
200 
201  double hOverE = ele.hadronicOverEm();
202  double sigmaee = ele.sigmaIetaIeta();
203  double deltaPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
204  double deltaEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
205 
206  // separate cut for barrel and endcap
207  if (ele.isEB()) {
208  if (fabs(deltaPhiIn) >= maxDeltaPhiInEB_ && fabs(deltaEtaIn) >= maxDeltaEtaInEB_ && hOverE >= maxHOEEB_ &&
209  sigmaee >= maxSigmaiEiEEB_)
210  continue;
211  } else if (ele.isEE()) {
212  if (fabs(deltaPhiIn) >= maxDeltaPhiInEE_ && fabs(deltaEtaIn) >= maxDeltaEtaInEE_ && hOverE >= maxHOEEE_ &&
213  sigmaee >= maxSigmaiEiEEE_)
214  continue;
215  }
216 
217  reco::GsfTrackRef trk = ele.gsfTrack();
218  reco::TrackRef tk = ele.closestCtfTrackRef();
219  if (!trk.isNonnull())
220  continue; // only electrons with tracks
221  if (!tk.isNonnull())
222  continue;
223  double chi2 = trk->chi2();
224  double ndof = trk->ndof();
225  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
226  if (chbyndof >= maxNormChi2_)
227  continue;
228 
229  double trkd0 = trk->d0();
230  if (beamSpot.isValid()) {
231  trkd0 = -(trk->dxy(beamSpot->position()));
232  } else {
233  edm::LogError("ElectronTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
234  }
235  if (std::fabs(trkd0) >= maxD0_)
236  continue;
237 
238  const reco::HitPattern& hitp = trk->hitPattern();
239  int nPixelHits = hitp.numberOfValidPixelHits();
240  if (nPixelHits < minPixelHits_)
241  continue;
242 
243  int nStripHits = hitp.numberOfValidStripHits();
244  if (nStripHits < minStripHits_)
245  continue;
246 
247  // DB corrected PF Isolation
248  reco::GsfElectron::PflowIsolationVariables pfIso = ele.pfIsolationVariables();
249  const float eiso =
250  pfIso.sumChargedHadronPt + std::max(0.0, pfIso.sumNeutralHadronEt + pfIso.sumPhotonEt - 0.5 * pfIso.sumPUPt);
251  if (eiso > maxIso_ * ele.pt())
252  continue;
253 
254  if (!tk->quality(reco::Track::qualityByName(trackQuality_)))
255  continue;
256 
257  TLorentzVector lv;
258  lv.SetPtEtaPhiE(ele.pt(), ele.eta(), ele.phi(), ele.energy());
259  list.push_back(lv);
260  chrgeList.push_back(ele.charge());
261  finalelectrons.push_back(ele);
262  }
263  } else {
264  edm::LogError("ElectronTrackProducer") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
265  }
266 
268  iEvent.getByToken(vertexToken_, vertexColl);
269  if (!vertexColl.isValid()) {
270  edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
271  }
272  if (vertexColl->empty()) {
273  edm::LogError("DqmTrackStudy") << "No good vertex in the event!!";
274  return;
275  }
276 
277  // Access PU information
278  double wfac = 1.0; // for data
279  if (!iEvent.isRealData()) {
281  iEvent.getByToken(puSummaryToken_, PupInfo);
282 
283  if (PupInfo.isValid()) {
284  for (auto const& v : *PupInfo) {
285  int bx = v.getBunchCrossing();
286  if (bx == 0) {
287  int nVertex = (vertexColl.isValid() ? vertexColl->size() : 0);
288  if (doPUCorrection_) {
289  if (nVertex > -1 && nVertex < int(vpu_.size()))
290  wfac = vpu_.at(nVertex);
291  else
292  wfac = 0.0;
293  }
294  }
295  }
296  } else
297  edm::LogError("DqmTrackStudy") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!";
298  }
299 
300  for (unsigned int I = 0; I != finalelectrons.size(); I++) {
301  EoverP_->Fill(finalelectrons[I].superCluster()->eta(),
302  finalelectrons[I].superCluster()->phi(),
303  finalelectrons[I].eEleClusterOverPout(),
304  wfac);
305  }
306 
307  if (list.size() >= 2) {
308  if (chrgeList[0] + chrgeList[1] == 0) {
309  if (list[0].Pt() >= minPtHighest_) {
310  TLorentzVector zv = list[0] + list[1];
311  if ((zv.M() >= minInvMass_) && (zv.M() <= maxInvMass_)) {
312  Zpt_->Fill(zv.Pt(), wfac);
313  ZInvMass_->Fill(zv.Mag(), wfac);
314  }
315  }
316  }
317  }
318 }
319 
320 // Define this as a plug-in
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
const edm::InputTag puSummaryTag_
Definition: ZEEDetails.cc:55
const bool isMC_
Definition: ZEEDetails.cc:84
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const double maxHOEEB_
Definition: ZEEDetails.cc:66
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const std::string folderName_
Definition: ZEEDetails.cc:51
const std::string trackQuality_
Definition: ZEEDetails.cc:81
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:670
const edm::InputTag electronTag_
Definition: ZEEDetails.cc:53
const float maxD0_
Definition: Constants.h:82
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: ZEEDetails.cc:171
const double maxD0_
Definition: ZEEDetails.cc:73
std::vector< float > vpu_
Definition: ZEEDetails.cc:82
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
const double maxDeltaPhiInEE_
Definition: ZEEDetails.cc:68
const int minPixelHits_
Definition: ZEEDetails.cc:75
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: ZEEDetails.cc:179
int numberOfValidStripHits() const
Definition: HitPattern.h:843
void Fill(long long x)
const bool doPUCorrection_
Definition: ZEEDetails.cc:85
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: ZEEDetails.cc:58
const std::string moduleName_
Definition: ZEEDetails.cc:50
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > puSummaryToken_
Definition: ZEEDetails.cc:59
int iEvent
Definition: GenABIO.cc:224
const double maxDeltaEtaInEB_
Definition: ZEEDetails.cc:65
const double minPt_
Definition: ZEEDetails.cc:63
const double minInvMass_
Definition: ZEEDetails.cc:79
const edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Definition: ZEEDetails.cc:57
const double maxDz_
Definition: ZEEDetails.cc:74
const double maxDeltaEtaInEE_
Definition: ZEEDetails.cc:69
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:665
const int minStripHits_
Definition: ZEEDetails.cc:76
const double maxIso_
Definition: ZEEDetails.cc:77
const std::complex< double > I
Definition: I.h:8
const double maxNormChi2_
Definition: ZEEDetails.cc:72
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
Definition: GsfElectron.h:664
const double maxDeltaPhiInEB_
Definition: ZEEDetails.cc:64
const edm::InputTag vertexTag_
Definition: ZEEDetails.cc:56
const double maxInvMass_
Definition: ZEEDetails.cc:80
std::vector< float > vtrack_
Definition: ZEEDetails.cc:83
const double maxEta_
Definition: ZEEDetails.cc:62
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
const double maxHOEEE_
Definition: ZEEDetails.cc:70
const std::string puScaleFactorFile_
Definition: ZEEDetails.cc:86
ZEEDetails(const edm::ParameterSet &)
Definition: ZEEDetails.cc:127
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: ZEEDetails.cc:60
MonitorElement * Zpt_
Definition: ZEEDetails.cc:88
const double maxSigmaiEiEEE_
Definition: ZEEDetails.cc:71
fixed size matrix
HLT enums.
const double minPtHighest_
Definition: ZEEDetails.cc:78
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const double maxSigmaiEiEEB_
Definition: ZEEDetails.cc:67
MonitorElement * ZInvMass_
Definition: ZEEDetails.cc:89
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ZEEDetails.cc:93
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:663
const edm::InputTag bsTag_
Definition: ZEEDetails.cc:54
MonitorElement * book3D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, FUNC onbooking=NOOP())
Definition: DQMStore.h:367
MonitorElement * EoverP_
Definition: ZEEDetails.cc:90
Definition: Run.h:45