CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
82 
83 
84 
85 
87 
88 
89 
90 
92 
93  nEvt_=0;
94  nEntry_=0;
95 
96 
97  dbe_ = 0;
99 
100 
101 
102  // double dPhiTracksMin = parameters_.getParameter<double>("dPhiTracksMin");
103  // double dPhiTracksMax = parameters_.getParameter<double>("dPhiTracksMax");
104  // int dPhiTracksBin = parameters_.getParameter<int>("dPhiTracksBin");
105 
106  // double eoverpMin = parameters_.getParameter<double>("eoverpMin");
107  // double eoverpMax = parameters_.getParameter<double>("eoverpMax");
108  // int eoverpBin = parameters_.getParameter<int>("eoverpBin");
109 
110 
111  // double dEtaTracksMin = parameters_.getParameter<double>("dEtaTracksMin"); // unused
112  // double dEtaTracksMax = parameters_.getParameter<double>("dEtaTracksMax"); // unused
113  // int dEtaTracksBin = parameters_.getParameter<int>("dEtaTracksBin"); // unused
114 
115  // double dCotTracksMin = parameters_.getParameter<double>("dCotTracksMin");
116  // double dCotTracksMax = parameters_.getParameter<double>("dCotTracksMax");
117  // int dCotTracksBin = parameters_.getParameter<int>("dCotTracksBin");
118 
119 
120 
121 }
122 
123 
125  double ptMin = parameters_.getParameter<double>("ptMin");
126  double ptMax = parameters_.getParameter<double>("ptMax");
127  int ptBin = parameters_.getParameter<int>("ptBin");
128 
129  double trackptMin = parameters_.getParameter<double>("trackptMin");
130  double trackptMax = parameters_.getParameter<double>("trackptMax");
131  int trackptBin = parameters_.getParameter<int>("trackptBin");
132 
133  double etaMin = parameters_.getParameter<double>("etaMin");
134  double etaMax = parameters_.getParameter<double>("etaMax");
135  int etaBin = parameters_.getParameter<int>("etaBin");
136 
137  double phiMin = -TMath::Pi();
138  double phiMax = TMath::Pi();
139  int phiBin = parameters_.getParameter<int>("phiBin");
140 
141 
142  double rhoMin = parameters_.getParameter<double>("rhoMin");
143  double rhoMax = parameters_.getParameter<double>("rhoMax");
144  int rhoBin = parameters_.getParameter<int>("rhoBin");
145 
146  double zMin = parameters_.getParameter<double>("zMin");
147  double zMax = parameters_.getParameter<double>("zMax");
148  int zBin = parameters_.getParameter<int>("zBin");
149  if (dbe_) {
150 
152  // SC from reco photons
153 
154  //TString simfolder = TString(
155  //std::string simpath = dqmpath_ + "SimulationInfo";
156  dbe_->setCurrentFolder(dqmpath_);
157  //
158  // simulation information about conversions
159  // Histograms for efficiencies
160  h_elePtAll_ = dbe_->book1D("elePtAll","# of Electrons",ptBin,ptMin,ptMax);
161  h_eleEtaAll_ = dbe_->book1D("eleEtaAll","# of Electrons",etaBin,etaMin,etaMax);
162  h_elePhiAll_ = dbe_->book1D("elePhiAll","# of Electrons",phiBin,phiMin,phiMax);
163 
164  h_elePtPass_ = dbe_->book1D("elePtPass","# of Electrons",ptBin,ptMin,ptMax);
165  h_eleEtaPass_ = dbe_->book1D("eleEtaPass","# of Electrons",etaBin,etaMin,etaMax);
166  h_elePhiPass_ = dbe_->book1D("elePhiPass","# of Electrons",phiBin,phiMin,phiMax);
167 
168  h_elePtFail_ = dbe_->book1D("elePtFail","# of Electrons",ptBin,ptMin,ptMax);
169  h_eleEtaFail_ = dbe_->book1D("eleEtaFail","# of Electrons",etaBin,etaMin,etaMax);
170  h_elePhiFail_ = dbe_->book1D("elePhiFail","# of Electrons",phiBin,phiMin,phiMax);
171 
172  h_convPt_ = dbe_->book1D("convPt","# of Electrons",ptBin,ptMin,ptMax);
173  h_convEta_ = dbe_->book1D("convEta","# of Electrons",etaBin,etaMin,etaMax);
174  h_convPhi_ = dbe_->book1D("convPhi","# of Electrons",phiBin,phiMin,phiMax);
175  h_convRho_ = dbe_->book1D("convRho","# of Electrons",rhoBin,rhoMin,rhoMax);
176  h_convZ_ = dbe_->book1D("convZ","# of Electrons",zBin,zMin,zMax);
177  h_convProb_ = dbe_->book1D("convProb","# of Electrons",100,0.0,1.0);
178 
179  h_convLeadTrackpt_ = dbe_->book1D("convLeadTrackpt","# of Electrons",trackptBin,trackptMin,trackptMax);
180  h_convTrailTrackpt_ = dbe_->book1D("convTrailTrackpt","# of Electrons",trackptBin,trackptMin,trackptMax);
181  h_convLog10TrailTrackpt_ = dbe_->book1D("convLog10TrailTrackpt","# of Electrons",ptBin,-2.0,3.0);
182 
183  h_convLeadTrackAlgo_ = dbe_->book1D("convLeadTrackAlgo","# of Electrons",31,-0.5,30.5);
184  h_convTrailTrackAlgo_ = dbe_->book1D("convLeadTrackAlgo","# of Electrons",31,-0.5,30.5);
185  } // if DQM
186 }
187 
188 
190  edm::EventSetup const & theEventSetup) {
191  bookHistograms();
192 }
193 
195  edm::EventSetup const & theEventSetup) {
196 }
197 
198 
199 
201 
202  using namespace edm;
203 
204 
205  nEvt_++;
206  LogInfo("ElectronConversionRejectionValidator")
207  << "ElectronConversionRejectionValidator Analyzing event number: "
208  << e.id() << " Global Counter " << nEvt_ <<"\n";
209 
212  e.getByToken(convToken_, convHandle);
213  if (!convHandle.isValid()) {
214  edm::LogError("ElectronConversionRejectionValidator")
215  << "Error! Can't get the Conversion collection "<< std::endl;
216  return;
217  }
218 
220  Handle<reco::GsfElectronCollection> gsfElectronHandle;
221  e.getByToken(gsfElecToken_, gsfElectronHandle);
222  const reco::GsfElectronCollection &gsfElectronCollection = *(gsfElectronHandle.product());
223  if (!gsfElectronHandle.isValid()) {
224  edm::LogError("ElectronConversionRejectionValidator")
225  << "Error! Can't get the Electron collection "<< std::endl;
226  return;
227  }
228 
229  // offline Primary vertex
231  e.getByToken(offline_pvToken_, vertexHandle);
232  if (!vertexHandle.isValid()) {
233  edm::LogError("ElectronConversionRejectionValidator")
234  << "Error! Can't get the product primary Vertex Collection "<< "\n";
235  return;
236  }
237  const reco::Vertex &thevtx = vertexHandle->at(0);
238 
240  e.getByToken(beamspotToken_, bsHandle);
241  if (!bsHandle.isValid()) {
242  edm::LogError("ElectronConversionRejectionValidator")
243  << "Error! Can't get the product beamspot Collection "<< "\n";
244  return;
245  }
246  const reco::BeamSpot &thebs = *bsHandle.product();
247 
248 
249  //loop over electrons
250  for (reco::GsfElectronCollection::const_iterator iele = gsfElectronCollection.begin(); iele!=gsfElectronCollection.end(); ++iele) {
251  //apply basic pre-selection cuts to remove the conversions with obviously displaced tracks which will anyways be
252  //removed from the analysis by the hit pattern or impact parameter requirements
253  if (iele->pt() < elePtMin_) continue;
254  if (iele->gsfTrack()->trackerExpectedHitsInner().numberOfHits() > eleExpectedHitsInnerMax_) continue;
255  if ( std::abs(iele->gsfTrack()->dxy(thevtx.position())) > eleD0Max_ ) continue;
256 
257  //fill information for all electrons
258  h_elePtAll_->Fill(iele->pt());
259  h_eleEtaAll_->Fill(iele->eta());
260  h_elePhiAll_->Fill(iele->phi());
261 
262 
263  //find matching conversion if any
264  reco::ConversionRef convref = ConversionTools::matchedConversion(*iele,convHandle,thebs.position());
265  //fill information on passing electrons only if there is no matching conversion (electron passed the conversion rejection cut!)
266  if (convref.isNull()) {
267  h_elePtPass_->Fill(iele->pt());
268  h_eleEtaPass_->Fill(iele->eta());
269  h_elePhiPass_->Fill(iele->phi());
270  }
271  else {
272  //matching conversion, electron failed conversion rejection cut
273  //fill information on electron and matching conversion
274  //(Note that in case of multiple matching conversions passing the requirements, the conversion tools returns the one closest to the IP,
275  //which is most likely to be the conversion of the primary photon in case there was one.)
276 
277  //fill electron info
278  h_elePtFail_->Fill(iele->pt());
279  h_eleEtaFail_->Fill(iele->eta());
280  h_elePhiFail_->Fill(iele->phi());
281 
282  //fill conversion info
283  math::XYZVectorF convmom = convref->refittedPairMomentum();
284  h_convPt_->Fill(convmom.rho());
285  h_convEta_->Fill(convmom.eta());
286  h_convPhi_->Fill(convmom.phi());
287  h_convRho_->Fill(convref->conversionVertex().position().rho());
288  h_convZ_->Fill(convref->conversionVertex().position().z());
289  h_convProb_->Fill(ChiSquaredProbability(convref->conversionVertex().chi2(),convref->conversionVertex().ndof()));
290 
291  //fill information about conversion tracks
292  if (convref->tracks().size()<2) continue;
293 
294  RefToBase<reco::Track> tk1 = convref->tracks().front();
295  RefToBase<reco::Track> tk2 = convref->tracks().back();
296 
297  RefToBase<reco::Track> tklead;
298  RefToBase<reco::Track> tktrail;
299  if (tk1->pt() >= tk2->pt()) {
300  tklead = tk1;
301  tktrail = tk2;
302  }
303  else {
304  tklead = tk2;
305  tktrail = tk1;
306  }
307  h_convLeadTrackpt_->Fill(tklead->pt());
308  h_convTrailTrackpt_->Fill(tktrail->pt());
309  h_convLog10TrailTrackpt_->Fill(log10(tktrail->pt()));
310  h_convLeadTrackAlgo_->Fill(tklead->algo());
311  h_convTrailTrackAlgo_->Fill(tktrail->algo());
312 
313  }
314  }
315 
316 }
317 
318 
319 
320 
321 
323 
324 
325  std::string outputFileName = parameters_.getParameter<std::string>("OutputFileName");
326  if ( ! isRunCentrally_ ) {
327  dbe_->save(outputFileName);
328  }
329 
330  edm::LogInfo("ElectronConversionRejectionValidator") << "Analyzed " << nEvt_ << "\n";
331  // std::cout << "::endJob Analyzed " << nEvt_ << " events " << " with total " << nPho_ << " Photons " << "\n";
332  // std::cout << "ElectronConversionRejectionValidator::endJob Analyzed " << nEvt_ << " events " << "\n";
333 
334  return ;
335 }
336 
337 
const double Pi
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:873
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void bookHistograms(fwlite::EventContainer &eventCont)
TrackAlgorithm algo() const
Definition: TrackBase.h:330
bool isNull() const
Checks for null.
Definition: Ref.h:247
double pt() const
track transverse momentum
Definition: TrackBase.h:129
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float ChiSquaredProbability(double chiSquared, double nrDOF)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2297
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:17
DQMStore * dbe_
return(e1-e2)*(e1-e2)+dp *dp
edm::EventID id() const
Definition: EventBase.h:56
virtual void endRun(edm::Run &r, edm::EventSetup const &es)
static reco::ConversionRef matchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:585
Definition: Run.h:41
virtual void beginRun(edm::Run const &r, edm::EventSetup const &theEventSetup)