CMS 3D CMS Logo

ElectronConversionRejectionValidator.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
5 //
7 
8 //
12 //
13 
14 //
27 
28 //
29 //
30 #include "TFile.h"
31 #include "TH1.h"
32 #include "TH2.h"
33 #include "TTree.h"
34 #include "TVector3.h"
35 #include "TProfile.h"
36 #include "TMath.h"
37 //
46 using namespace std;
47 
48 
50 {
51 
52  fName_ = pset.getUntrackedParameter<std::string>("Name");
53  verbosity_ = pset.getUntrackedParameter<int>("Verbosity");
54  parameters_ = pset;
55 
56  gsfElectronCollectionProducer_ = pset.getParameter<std::string>("gsfElectronProducer");
57  gsfElectronCollection_ = pset.getParameter<std::string>("gsfElectronCollection");
58 
59  conversionCollectionProducer_ = pset.getParameter<std::string>("convProducer");
60  conversionCollection_ = pset.getParameter<std::string>("conversionCollection");
61  // conversionTrackProducer_ = pset.getParameter<std::string>("trackProducer");
62  gsfElecToken_ = consumes<reco::GsfElectronCollection>(
63  edm::InputTag(gsfElectronCollectionProducer_,
64  gsfElectronCollection_));
65  convToken_ = consumes<reco::ConversionCollection>(
66  edm::InputTag(conversionCollectionProducer_,
67  conversionCollection_));
68 
69  isRunCentrally_= pset.getParameter<bool>("isRunCentrally");
70 
71  elePtMin_ = pset.getParameter<double>("elePtMin");
72  eleExpectedHitsInnerMax_ = pset.getParameter<int>("eleExpectedHitsInnerMax");
73  eleD0Max_ = pset.getParameter<double>("eleD0Max");
74  offline_pvToken_ = consumes<reco::VertexCollection>(
75  pset.getUntrackedParameter<edm::InputTag> ("offlinePV",
76  edm::InputTag("offlinePrimaryVertices")));
77  beamspotToken_ = consumes<reco::BeamSpot>(
78  pset.getUntrackedParameter<edm::InputTag> ("beamspot",
79  edm::InputTag("offlineBeamSpot")));
80 
81  nEvt_=0;
82  nEntry_=0;
83 }
84 
86 
87 
89  edm::Run const &, edm::EventSetup const & ){
90 
91  double ptMin = parameters_.getParameter<double>("ptMin");
92  double ptMax = parameters_.getParameter<double>("ptMax");
93  int ptBin = parameters_.getParameter<int>("ptBin");
94 
95  double trackptMin = parameters_.getParameter<double>("trackptMin");
96  double trackptMax = parameters_.getParameter<double>("trackptMax");
97  int trackptBin = parameters_.getParameter<int>("trackptBin");
98 
99  double etaMin = parameters_.getParameter<double>("etaMin");
100  double etaMax = parameters_.getParameter<double>("etaMax");
101  int etaBin = parameters_.getParameter<int>("etaBin");
102 
103  double phiMin = -TMath::Pi();
104  double phiMax = TMath::Pi();
105  int phiBin = parameters_.getParameter<int>("phiBin");
106 
107 
108  double rhoMin = parameters_.getParameter<double>("rhoMin");
109  double rhoMax = parameters_.getParameter<double>("rhoMax");
110  int rhoBin = parameters_.getParameter<int>("rhoBin");
111 
112  double zMin = parameters_.getParameter<double>("zMin");
113  double zMax = parameters_.getParameter<double>("zMax");
114  int zBin = parameters_.getParameter<int>("zBin");
115 
117  // SC from reco photons
118 
119  //TString simfolder = TString(
120  //std::string simpath = dqmpath_ + "SimulationInfo";
121  ibooker.setCurrentFolder(dqmpath_);
122  //
123  // simulation information about conversions
124  // Histograms for efficiencies
125  h_elePtAll_ = ibooker.book1D("elePtAll", "# of Electrons", ptBin, ptMin, ptMax);
126  h_eleEtaAll_ = ibooker.book1D("eleEtaAll", "# of Electrons", etaBin, etaMin, etaMax);
127  h_elePhiAll_ = ibooker.book1D("elePhiAll", "# of Electrons", phiBin, phiMin, phiMax);
128 
129  h_elePtPass_ = ibooker.book1D("elePtPass", "# of Electrons", ptBin, ptMin, ptMax);
130  h_eleEtaPass_ = ibooker.book1D("eleEtaPass", "# of Electrons", etaBin, etaMin, etaMax);
131  h_elePhiPass_ = ibooker.book1D("elePhiPass", "# of Electrons", phiBin, phiMin, phiMax);
132 
133  h_elePtFail_ = ibooker.book1D("elePtFail", "# of Electrons", ptBin, ptMin, ptMax);
134  h_eleEtaFail_ = ibooker.book1D("eleEtaFail", "# of Electrons",etaBin, etaMin, etaMax);
135  h_elePhiFail_ = ibooker.book1D("elePhiFail", "# of Electrons", phiBin, phiMin, phiMax);
136 
137  h_convPt_ = ibooker.book1D("convPt", "# of Electrons", ptBin, ptMin, ptMax);
138  h_convEta_ = ibooker.book1D("convEta", "# of Electrons", etaBin, etaMin, etaMax);
139  h_convPhi_ = ibooker.book1D("convPhi", "# of Electrons", phiBin, phiMin, phiMax);
140  h_convRho_ = ibooker.book1D("convRho", "# of Electrons", rhoBin, rhoMin, rhoMax);
141  h_convZ_ = ibooker.book1D("convZ", "# of Electrons", zBin, zMin, zMax);
142  h_convProb_ = ibooker.book1D("convProb", "# of Electrons", 100, 0.0, 1.0);
143 
144  h_convLeadTrackpt_ = ibooker.book1D("convLeadTrackpt", "# of Electrons", trackptBin,
145  trackptMin, trackptMax);
146 
147  h_convTrailTrackpt_ = ibooker.book1D("convTrailTrackpt", "# of Electrons", trackptBin,
148  trackptMin, trackptMax);
149 
150  h_convLog10TrailTrackpt_ = ibooker.book1D("convLog10TrailTrackpt", "# of Electrons",
151  ptBin, -2.0, 3.0);
152 
153  h_convLeadTrackAlgo_ = ibooker.book1D("convLeadTrackAlgo", "# of Electrons", reco::TrackBase::algoSize, -0.5, reco::TrackBase::algoSize-0.5);
154  h_convTrailTrackAlgo_ = ibooker.book1D("convLeadTrackAlgo", "# of Electrons", reco::TrackBase::algoSize, -0.5, reco::TrackBase::algoSize-0.5);
155 }
156 
158 
159  using namespace edm;
160 
161 
162  nEvt_++;
163  LogInfo("ElectronConversionRejectionValidator")
164  << "ElectronConversionRejectionValidator Analyzing event number: "
165  << e.id() << " Global Counter " << nEvt_ <<"\n";
166 
169  e.getByToken(convToken_, convHandle);
170  if (!convHandle.isValid()) {
171  edm::LogError("ElectronConversionRejectionValidator")
172  << "Error! Can't get the Conversion collection "<< std::endl;
173  return;
174  }
175 
177  Handle<reco::GsfElectronCollection> gsfElectronHandle;
178  e.getByToken(gsfElecToken_, gsfElectronHandle);
179  const reco::GsfElectronCollection &gsfElectronCollection = *(gsfElectronHandle.product());
180  if (!gsfElectronHandle.isValid()) {
181  edm::LogError("ElectronConversionRejectionValidator")
182  << "Error! Can't get the Electron collection "<< std::endl;
183  return;
184  }
185 
186  // offline Primary vertex
188  e.getByToken(offline_pvToken_, vertexHandle);
189  if (!vertexHandle.isValid()) {
190  edm::LogError("ElectronConversionRejectionValidator")
191  << "Error! Can't get the product primary Vertex Collection "<< "\n";
192  return;
193  }
194  const reco::Vertex &thevtx = vertexHandle->at(0);
195 
197  e.getByToken(beamspotToken_, bsHandle);
198  if (!bsHandle.isValid()) {
199  edm::LogError("ElectronConversionRejectionValidator")
200  << "Error! Can't get the product beamspot Collection "<< "\n";
201  return;
202  }
203  const reco::BeamSpot &thebs = *bsHandle.product();
204 
205 
206  //loop over electrons
207  for (reco::GsfElectronCollection::const_iterator iele = gsfElectronCollection.begin(); iele!=gsfElectronCollection.end(); ++iele) {
208  //apply basic pre-selection cuts to remove the conversions with obviously displaced tracks which will anyways be
209  //removed from the analysis by the hit pattern or impact parameter requirements
210  if (iele->pt() < elePtMin_) continue;
211  if (iele->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > eleExpectedHitsInnerMax_) continue;
212  if ( std::abs(iele->gsfTrack()->dxy(thevtx.position())) > eleD0Max_ ) continue;
213 
214  //fill information for all electrons
215  h_elePtAll_->Fill(iele->pt());
216  h_eleEtaAll_->Fill(iele->eta());
217  h_elePhiAll_->Fill(iele->phi());
218 
219 
220  //find matching conversion if any
221  reco::Conversion const* conv = ConversionTools::matchedConversion(*iele,*convHandle,thebs.position());
222  //fill information on passing electrons only if there is no matching conversion (electron passed the conversion rejection cut!)
223  if (conv == nullptr) {
224  h_elePtPass_->Fill(iele->pt());
225  h_eleEtaPass_->Fill(iele->eta());
226  h_elePhiPass_->Fill(iele->phi());
227  }
228  else {
229  //matching conversion, electron failed conversion rejection cut
230  //fill information on electron and matching conversion
231  //(Note that in case of multiple matching conversions passing the requirements, the conversion tools returns the one closest to the IP,
232  //which is most likely to be the conversion of the primary photon in case there was one.)
233 
234  //fill electron info
235  h_elePtFail_->Fill(iele->pt());
236  h_eleEtaFail_->Fill(iele->eta());
237  h_elePhiFail_->Fill(iele->phi());
238 
239  //fill conversion info
240  math::XYZVectorF convmom = conv->refittedPairMomentum();
241  h_convPt_->Fill(convmom.rho());
242  h_convEta_->Fill(convmom.eta());
243  h_convPhi_->Fill(convmom.phi());
244  h_convRho_->Fill(conv->conversionVertex().position().rho());
245  h_convZ_->Fill(conv->conversionVertex().position().z());
246  h_convProb_->Fill(ChiSquaredProbability(conv->conversionVertex().chi2(),conv->conversionVertex().ndof()));
247 
248  //fill information about conversion tracks
249  if (conv->tracks().size()<2) continue;
250 
251  RefToBase<reco::Track> tk1 = conv->tracks().front();
252  RefToBase<reco::Track> tk2 = conv->tracks().back();
253 
254  RefToBase<reco::Track> tklead;
255  RefToBase<reco::Track> tktrail;
256  if (tk1->pt() >= tk2->pt()) {
257  tklead = tk1;
258  tktrail = tk2;
259  }
260  else {
261  tklead = tk2;
262  tktrail = tk1;
263  }
264  h_convLeadTrackpt_->Fill(tklead->pt());
265  h_convTrailTrackpt_->Fill(tktrail->pt());
266  h_convLog10TrailTrackpt_->Fill(log10(tktrail->pt()));
267  h_convLeadTrackAlgo_->Fill(tklead->algo());
268  h_convTrailTrackAlgo_->Fill(tktrail->algo());
269 
270  }
271  }
272 
273 }
const reco::Vertex & conversionVertex() const
returns the reco conversion vertex
Definition: Conversion.h:98
const double Pi
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static reco::Conversion const * matchedConversion(const reco::GsfElectron &ele, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
static HepMC::IO_HEPEVT conv
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const Point & position() const
position
Definition: Vertex.h:109
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
math::XYZVectorF refittedPairMomentum() const
Conversion tracks momentum from the tracks refitted with vertex constraint.
Definition: Conversion.cc:248
TrackAlgorithm algo() const
Definition: TrackBase.h:536
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
double pt() const
track transverse momentum
Definition: TrackBase.h:660
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double chi2() const
chi-squares
Definition: Vertex.h:98
float ChiSquaredProbability(double chiSquared, double nrDOF)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:17
bool isValid() const
Definition: HandleBase.h:74
double ndof() const
Definition: Vertex.h:105
void analyze(const edm::Event &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &bei, edm::Run const &, edm::EventSetup const &) override
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
std::vector< edm::RefToBase< reco::Track > > const & tracks() const
vector of track to base references
Definition: Conversion.cc:176
Definition: Run.h:45