CMS 3D CMS Logo

ZEEDetails.cc
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TH1.h"
3 #include "TMath.h"
4 #include <iostream>
5 #include <fstream>
6 #include "TSystem.h"
7 
22 #include "TLorentzVector.h"
23 #include <string>
24 #include <ostream>
25 
27  : moduleName_(ps.getUntrackedParameter<std::string>("moduleName", "ZEEDetails")),
28  folderName_(ps.getUntrackedParameter<std::string>("folderName", "ElectronTracks")),
29  electronTag_(ps.getUntrackedParameter<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"))),
30  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
31  puSummaryTag_(ps.getUntrackedParameter<edm::InputTag>("puTag", edm::InputTag("addPileupInfo"))),
32  vertexTag_(ps.getUntrackedParameter<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"))),
33  electronToken_(consumes<reco::GsfElectronCollection>(electronTag_)),
34  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
35  puSummaryToken_(consumes<std::vector<PileupSummaryInfo> >(puSummaryTag_)),
36  vertexToken_(consumes<reco::VertexCollection>(vertexTag_)),
37  maxEta_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
38  minPt_(ps.getUntrackedParameter<double>("minPt", 5)),
39  maxDeltaPhiInEB_(ps.getUntrackedParameter<double>("maxDeltaPhiInEB", 0.15)),
40  maxDeltaEtaInEB_(ps.getUntrackedParameter<double>("maxDeltaEtaInEB", 0.007)),
41  maxHOEEB_(ps.getUntrackedParameter<double>("maxHOEEB", 0.12)),
42  maxSigmaiEiEEB_(ps.getUntrackedParameter<double>("maxSigmaiEiEEB", 0.01)),
43  maxDeltaPhiInEE_(ps.getUntrackedParameter<double>("maxDeltaPhiInEE", 0.1)),
44  maxDeltaEtaInEE_(ps.getUntrackedParameter<double>("maxDeltaEtaInEE", 0.009)),
45  maxHOEEE_(ps.getUntrackedParameter<double>("maxHOEEB_", .10)),
46  maxSigmaiEiEEE_(ps.getUntrackedParameter<double>("maxSigmaiEiEEE", 0.03)),
47  maxNormChi2_(ps.getUntrackedParameter<double>("maxNormChi2", 10)),
48  maxD0_(ps.getUntrackedParameter<double>("maxD0", 0.02)),
49  maxDz_(ps.getUntrackedParameter<double>("maxDz", 20.)),
50  minPixelHits_(ps.getUntrackedParameter<uint32_t>("minPixelHits", 1)),
51  minStripHits_(ps.getUntrackedParameter<uint32_t>("minStripHits", 8)),
52  maxIso_(ps.getUntrackedParameter<double>("maxIso", 0.3)),
53  minPtHighest_(ps.getUntrackedParameter<double>("minPtHighest", 24)),
54  minInvMass_(ps.getUntrackedParameter<double>("minInvMass", 60)),
55  maxInvMass_(ps.getUntrackedParameter<double>("maxInvMass", 120)),
56  trackQuality_(ps.getUntrackedParameter<std::string>("trackQuality", "highPurity")),
57  isMC_(ps.getUntrackedParameter<bool>("isMC", false)),
58  doPUCorrection_(ps.getUntrackedParameter<bool>("doPUCorrection", false)),
59  puScaleFactorFile_(ps.getUntrackedParameter<std::string>("puScaleFactorFile", "PileupScaleFactor.root")) {
60  if (isMC_ && doPUCorrection_) {
61  vpu_.clear();
62  TFile* f1 = TFile::Open(puScaleFactorFile_.c_str());
63  TH1F* h1 = dynamic_cast<TH1F*>(f1->Get("pileupweight"));
64  for (int i = 1; i <= h1->GetNbinsX(); ++i)
65  vpu_.push_back(h1->GetBinContent(i));
66  f1->Close();
67  }
68 }
69 
70 void ZEEDetails::bookHistograms(DQMStore::IBooker& ibook, edm::Run const& iRun, edm::EventSetup const& iSetup) {
71  std::string currentFolder = moduleName_ + "/" + folderName_;
72  ibook.setCurrentFolder(currentFolder);
73  Zpt_ = ibook.book1D("Zpt", "Z-Boson p_{T}", 100, 0.0, 100.0);
74  ZInvMass_ = ibook.book1D("ZInvMass", "m_{ee}", 200, minInvMass_, maxInvMass_);
75  EoverP_ = ibook.book3D("EoverP", "EoverP", 48, -2.4, 2.4, 36, -3.2, 3.2, 100, 0, 10);
76 }
77 
79  std::vector<TLorentzVector> list;
80  std::vector<int> chrgeList;
81  std::vector<reco::GsfElectron> finalelectrons;
82 
83  // Read Electron Collection
85  iEvent.getByToken(electronToken_, electronColl);
86 
88  iEvent.getByToken(bsToken_, beamSpot);
89 
90  if (electronColl.isValid()) {
91  for (auto const& ele : *electronColl) {
92  if (!ele.ecalDriven())
93  continue;
94  if (ele.pt() < minPt_)
95  continue;
96  // set a max Eta cut
97  if (!(ele.isEB() || ele.isEE()))
98  continue;
99 
100  double hOverE = ele.hadronicOverEm();
101  double sigmaee = ele.sigmaIetaIeta();
102  double deltaPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
103  double deltaEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
104 
105  // separate cut for barrel and endcap
106  if (ele.isEB()) {
107  if (fabs(deltaPhiIn) >= maxDeltaPhiInEB_ && fabs(deltaEtaIn) >= maxDeltaEtaInEB_ && hOverE >= maxHOEEB_ &&
108  sigmaee >= maxSigmaiEiEEB_)
109  continue;
110  } else if (ele.isEE()) {
111  if (fabs(deltaPhiIn) >= maxDeltaPhiInEE_ && fabs(deltaEtaIn) >= maxDeltaEtaInEE_ && hOverE >= maxHOEEE_ &&
112  sigmaee >= maxSigmaiEiEEE_)
113  continue;
114  }
115 
116  reco::GsfTrackRef trk = ele.gsfTrack();
117  reco::TrackRef tk = ele.closestCtfTrackRef();
118  if (!trk.isNonnull())
119  continue; // only electrons with tracks
120  if (!tk.isNonnull())
121  continue;
122  double chi2 = trk->chi2();
123  double ndof = trk->ndof();
124  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
125  if (chbyndof >= maxNormChi2_)
126  continue;
127 
128  double trkd0 = trk->d0();
129  if (beamSpot.isValid()) {
130  trkd0 = -(trk->dxy(beamSpot->position()));
131  } else {
132  edm::LogError("ElectronTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
133  }
134  if (std::fabs(trkd0) >= maxD0_)
135  continue;
136 
137  const reco::HitPattern& hitp = trk->hitPattern();
138  int nPixelHits = hitp.numberOfValidPixelHits();
139  if (nPixelHits < minPixelHits_)
140  continue;
141 
142  int nStripHits = hitp.numberOfValidStripHits();
143  if (nStripHits < minStripHits_)
144  continue;
145 
146  // DB corrected PF Isolation
147  reco::GsfElectron::PflowIsolationVariables pfIso = ele.pfIsolationVariables();
148  const float eiso =
149  pfIso.sumChargedHadronPt + std::max(0.0, pfIso.sumNeutralHadronEt + pfIso.sumPhotonEt - 0.5 * pfIso.sumPUPt);
150  if (eiso > maxIso_ * ele.pt())
151  continue;
152 
153  if (!tk->quality(reco::Track::qualityByName(trackQuality_)))
154  continue;
155 
156  TLorentzVector lv;
157  lv.SetPtEtaPhiE(ele.pt(), ele.eta(), ele.phi(), ele.energy());
158  list.push_back(lv);
159  chrgeList.push_back(ele.charge());
160  finalelectrons.push_back(ele);
161  }
162  } else {
163  edm::LogError("ElectronTrackProducer") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
164  }
165 
167  iEvent.getByToken(vertexToken_, vertexColl);
168  if (!vertexColl.isValid()) {
169  edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
170  }
171  if (vertexColl->empty()) {
172  edm::LogError("DqmTrackStudy") << "No good vertex in the event!!";
173  return;
174  }
175 
176  // Access PU information
177  double wfac = 1.0; // for data
178  if (!iEvent.isRealData()) {
180  iEvent.getByToken(puSummaryToken_, PupInfo);
181 
182  if (PupInfo.isValid()) {
183  for (auto const& v : *PupInfo) {
184  int bx = v.getBunchCrossing();
185  if (bx == 0) {
186  int nVertex = (vertexColl.isValid() ? vertexColl->size() : 0);
187  if (doPUCorrection_) {
188  if (nVertex > -1 && nVertex < int(vpu_.size()))
189  wfac = vpu_.at(nVertex);
190  else
191  wfac = 0.0;
192  }
193  }
194  }
195  } else
196  edm::LogError("DqmTrackStudy") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!";
197  }
198 
199  for (unsigned int I = 0; I != finalelectrons.size(); I++) {
200  EoverP_->Fill(finalelectrons[I].superCluster()->eta(),
201  finalelectrons[I].superCluster()->phi(),
202  finalelectrons[I].eEleClusterOverPout(),
203  wfac);
204  }
205 
206  if (list.size() >= 2) {
207  if (chrgeList[0] + chrgeList[1] == 0) {
208  if (list[0].Pt() >= minPtHighest_) {
209  TLorentzVector zv = list[0] + list[1];
210  if ((zv.M() >= minInvMass_) && (zv.M() <= maxInvMass_)) {
211  Zpt_->Fill(zv.Pt(), wfac);
212  ZInvMass_->Fill(zv.Mag(), wfac);
213  }
214  }
215  }
216  }
217 }
218 
219 // Define this as a plug-in
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
std::string puScaleFactorFile_
Definition: ZEEDetails.h:73
const edm::InputTag puSummaryTag_
Definition: ZEEDetails.h:42
const double maxHOEEB_
Definition: ZEEDetails.h:53
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
float *__restrict__ zv
const std::string trackQuality_
Definition: ZEEDetails.h:68
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:670
const edm::InputTag electronTag_
Definition: ZEEDetails.h:40
const float maxD0_
Definition: Constants.h:82
std::string folderName_
Definition: ZEEDetails.h:38
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:70
const double maxD0_
Definition: ZEEDetails.h:60
std::vector< float > vpu_
Definition: ZEEDetails.h:69
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
const double maxDeltaPhiInEE_
Definition: ZEEDetails.h:55
const int minPixelHits_
Definition: ZEEDetails.h:62
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: ZEEDetails.cc:78
int numberOfValidStripHits() const
Definition: HitPattern.h:843
void Fill(long long x)
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: ZEEDetails.h:45
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > puSummaryToken_
Definition: ZEEDetails.h:46
int iEvent
Definition: GenABIO.cc:224
const double maxDeltaEtaInEB_
Definition: ZEEDetails.h:52
const double minPt_
Definition: ZEEDetails.h:50
const double minInvMass_
Definition: ZEEDetails.h:66
const edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Definition: ZEEDetails.h:44
const double maxDeltaEtaInEE_
Definition: ZEEDetails.h:56
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:665
const int minStripHits_
Definition: ZEEDetails.h:63
const double maxIso_
Definition: ZEEDetails.h:64
const std::complex< double > I
Definition: I.h:8
const double maxNormChi2_
Definition: ZEEDetails.h:59
#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.h:51
const edm::InputTag vertexTag_
Definition: ZEEDetails.h:43
const double maxInvMass_
Definition: ZEEDetails.h:67
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
const double maxHOEEE_
Definition: ZEEDetails.h:57
ZEEDetails(const edm::ParameterSet &)
Definition: ZEEDetails.cc:26
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: ZEEDetails.h:47
MonitorElement * Zpt_
Definition: ZEEDetails.h:75
const double maxSigmaiEiEEE_
Definition: ZEEDetails.h:58
fixed size matrix
HLT enums.
const double minPtHighest_
Definition: ZEEDetails.h:65
std::string moduleName_
Definition: ZEEDetails.h:37
bool doPUCorrection_
Definition: ZEEDetails.h:72
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.h:54
MonitorElement * ZInvMass_
Definition: ZEEDetails.h:76
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:663
const edm::InputTag bsTag_
Definition: ZEEDetails.h:41
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.h:77
bool isMC_
Definition: ZEEDetails.h:71
Definition: Run.h:45