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 //
29 
30 //
31 //
32 #include "TFile.h"
33 #include "TH1.h"
34 #include "TH2.h"
35 #include "TTree.h"
36 #include "TVector3.h"
37 #include "TProfile.h"
38 #include "TMath.h"
39 //
50 using namespace std;
51 
52 
54  {
55 
56  fName_ = pset.getUntrackedParameter<std::string>("Name");
57  verbosity_ = pset.getUntrackedParameter<int>("Verbosity");
58  parameters_ = pset;
59 
60  gsfElectronCollectionProducer_ = pset.getParameter<std::string>("gsfElectronProducer");
61  gsfElectronCollection_ = pset.getParameter<std::string>("gsfElectronCollection");
62 
63  conversionCollectionProducer_ = pset.getParameter<std::string>("convProducer");
64  conversionCollection_ = pset.getParameter<std::string>("conversionCollection");
65  // conversionTrackProducer_ = pset.getParameter<std::string>("trackProducer");
66 
67  isRunCentrally_= pset.getParameter<bool>("isRunCentrally");
68 
69  elePtMin_ = pset.getParameter<double>("elePtMin");
70  eleExpectedHitsInnerMax_ = pset.getParameter<int>("eleExpectedHitsInnerMax");
71  eleD0Max_ = pset.getParameter<double>("eleD0Max");
72 
73  }
74 
75 
76 
77 
78 
80 
81 
82 
83 
85 
86  nEvt_=0;
87  nEntry_=0;
88 
89 
90  dbe_ = 0;
92 
93 
94  double ptMin = parameters_.getParameter<double>("ptMin");
95  double ptMax = parameters_.getParameter<double>("ptMax");
96  int ptBin = parameters_.getParameter<int>("ptBin");
97 
98  double trackptMin = parameters_.getParameter<double>("trackptMin");
99  double trackptMax = parameters_.getParameter<double>("trackptMax");
100  int trackptBin = parameters_.getParameter<int>("trackptBin");
101 
102 // double resMin = parameters_.getParameter<double>("resMin");
103 // double resMax = parameters_.getParameter<double>("resMax");
104 // int resBin = parameters_.getParameter<int>("resBin");
105 
106  double etaMin = parameters_.getParameter<double>("etaMin");
107  double etaMax = parameters_.getParameter<double>("etaMax");
108  int etaBin = parameters_.getParameter<int>("etaBin");
109 
110  double phiMin = -TMath::Pi();
111  double phiMax = TMath::Pi();
112  int phiBin = parameters_.getParameter<int>("phiBin");
113 
114 
115  double rhoMin = parameters_.getParameter<double>("rhoMin");
116  double rhoMax = parameters_.getParameter<double>("rhoMax");
117  int rhoBin = parameters_.getParameter<int>("rhoBin");
118 
119  double zMin = parameters_.getParameter<double>("zMin");
120  double zMax = parameters_.getParameter<double>("zMax");
121  int zBin = parameters_.getParameter<int>("zBin");
122 
123 // double dPhiTracksMin = parameters_.getParameter<double>("dPhiTracksMin");
124 // double dPhiTracksMax = parameters_.getParameter<double>("dPhiTracksMax");
125 // int dPhiTracksBin = parameters_.getParameter<int>("dPhiTracksBin");
126 
127 // double eoverpMin = parameters_.getParameter<double>("eoverpMin");
128 // double eoverpMax = parameters_.getParameter<double>("eoverpMax");
129 // int eoverpBin = parameters_.getParameter<int>("eoverpBin");
130 
131 
132  // double dEtaTracksMin = parameters_.getParameter<double>("dEtaTracksMin"); // unused
133  // double dEtaTracksMax = parameters_.getParameter<double>("dEtaTracksMax"); // unused
134  // int dEtaTracksBin = parameters_.getParameter<int>("dEtaTracksBin"); // unused
135 
136 // double dCotTracksMin = parameters_.getParameter<double>("dCotTracksMin");
137 // double dCotTracksMax = parameters_.getParameter<double>("dCotTracksMax");
138 // int dCotTracksBin = parameters_.getParameter<int>("dCotTracksBin");
139 
140 
141  if (dbe_) {
142 
144  // SC from reco photons
145 
146  //TString simfolder = TString(
147  //std::string simpath = dqmpath_ + "SimulationInfo";
148  dbe_->setCurrentFolder(dqmpath_);
149  //
150  // simulation information about conversions
151  // Histograms for efficiencies
152  h_elePtAll_ = dbe_->book1D("elePtAll","# of Electrons",ptBin,ptMin,ptMax);
153  h_eleEtaAll_ = dbe_->book1D("eleEtaAll","# of Electrons",etaBin,etaMin,etaMax);
154  h_elePhiAll_ = dbe_->book1D("elePhiAll","# of Electrons",phiBin,phiMin,phiMax);
155 
156  h_elePtPass_ = dbe_->book1D("elePtPass","# of Electrons",ptBin,ptMin,ptMax);
157  h_eleEtaPass_ = dbe_->book1D("eleEtaPass","# of Electrons",etaBin,etaMin,etaMax);
158  h_elePhiPass_ = dbe_->book1D("elePhiPass","# of Electrons",phiBin,phiMin,phiMax);
159 
160  h_elePtFail_ = dbe_->book1D("elePtFail","# of Electrons",ptBin,ptMin,ptMax);
161  h_eleEtaFail_ = dbe_->book1D("eleEtaFail","# of Electrons",etaBin,etaMin,etaMax);
162  h_elePhiFail_ = dbe_->book1D("elePhiFail","# of Electrons",phiBin,phiMin,phiMax);
163 
164  h_convPt_ = dbe_->book1D("convPt","# of Electrons",ptBin,ptMin,ptMax);
165  h_convEta_ = dbe_->book1D("convEta","# of Electrons",etaBin,etaMin,etaMax);
166  h_convPhi_ = dbe_->book1D("convPhi","# of Electrons",phiBin,phiMin,phiMax);
167  h_convRho_ = dbe_->book1D("convRho","# of Electrons",rhoBin,rhoMin,rhoMax);
168  h_convZ_ = dbe_->book1D("convZ","# of Electrons",zBin,zMin,zMax);
169  h_convProb_ = dbe_->book1D("convProb","# of Electrons",100,0.0,1.0);
170 
171  h_convLeadTrackpt_ = dbe_->book1D("convLeadTrackpt","# of Electrons",trackptBin,trackptMin,trackptMax);
172  h_convTrailTrackpt_ = dbe_->book1D("convTrailTrackpt","# of Electrons",trackptBin,trackptMin,trackptMax);
173  h_convLog10TrailTrackpt_ = dbe_->book1D("convLog10TrailTrackpt","# of Electrons",ptBin,-2.0,3.0);
174 
175  h_convLeadTrackAlgo_ = dbe_->book1D("convLeadTrackAlgo","# of Electrons",31,-0.5,30.5);
176  h_convTrailTrackAlgo_ = dbe_->book1D("convLeadTrackAlgo","# of Electrons",31,-0.5,30.5);
177 
178 
179  } // if DQM
180 
181 
182 
183 }
184 
185 
186 
188 
189 
190 }
191 
193 
194 
195 }
196 
197 
198 
200 
201  using namespace edm;
202 
203 
204  nEvt_++;
205  LogInfo("ElectronConversionRejectionValidator") << "ElectronConversionRejectionValidator Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
206  // std::cout << "ElectronConversionRejectionValidator Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
207 
208 
209 
212  e.getByLabel(conversionCollectionProducer_, conversionCollection_ , convHandle);
213  if (!convHandle.isValid()) {
214  edm::LogError("ElectronConversionRejectionValidator") << "Error! Can't get the Conversion collection "<< std::endl;
215  return;
216  }
217 
219  Handle<reco::GsfElectronCollection> gsfElectronHandle;
220  e.getByLabel(gsfElectronCollectionProducer_, gsfElectronCollection_ , gsfElectronHandle);
221  const reco::GsfElectronCollection &gsfElectronCollection = *(gsfElectronHandle.product());
222  if (!gsfElectronHandle.isValid()) {
223  edm::LogError("ElectronConversionRejectionValidator") << "Error! Can't get the Electron collection "<< std::endl;
224  return;
225  }
226 
227  // offline Primary vertex
229  e.getByLabel("offlinePrimaryVertices", vertexHandle);
230  if (!vertexHandle.isValid()) {
231  edm::LogError("ElectronConversionRejectionValidator") << "Error! Can't get the product primary Vertex Collection "<< "\n";
232  return;
233  }
234  const reco::Vertex &thevtx = vertexHandle->at(0);
235 
237  e.getByLabel("offlineBeamSpot", bsHandle);
238  if (!bsHandle.isValid()) {
239  edm::LogError("ElectronConversionRejectionValidator") << "Error! Can't get the product beamspot Collection "<< "\n";
240  return;
241  }
242  const reco::BeamSpot &thebs = *bsHandle.product();
243 
244 
245  //loop over electrons
246  for (reco::GsfElectronCollection::const_iterator iele = gsfElectronCollection.begin(); iele!=gsfElectronCollection.end(); ++iele) {
247  //apply basic pre-selection cuts to remove the conversions with obviously displaced tracks which will anyways be
248  //removed from the analysis by the hit pattern or impact parameter requirements
249  if (iele->pt() < elePtMin_) continue;
250  if (iele->gsfTrack()->trackerExpectedHitsInner().numberOfHits() > eleExpectedHitsInnerMax_) continue;
251  if ( std::abs(iele->gsfTrack()->dxy(thevtx.position())) > eleD0Max_ ) continue;
252 
253  //fill information for all electrons
254  h_elePtAll_->Fill(iele->pt());
255  h_eleEtaAll_->Fill(iele->eta());
256  h_elePhiAll_->Fill(iele->phi());
257 
258 
259  //find matching conversion if any
260  reco::ConversionRef convref = ConversionTools::matchedConversion(*iele,convHandle,thebs.position());
261  //fill information on passing electrons only if there is no matching conversion (electron passed the conversion rejection cut!)
262  if (convref.isNull()) {
263  h_elePtPass_->Fill(iele->pt());
264  h_eleEtaPass_->Fill(iele->eta());
265  h_elePhiPass_->Fill(iele->phi());
266  }
267  else {
268  //matching conversion, electron failed conversion rejection cut
269  //fill information on electron and matching conversion
270  //(Note that in case of multiple matching conversions passing the requirements, the conversion tools returns the one closest to the IP,
271  //which is most likely to be the conversion of the primary photon in case there was one.)
272 
273  //fill electron info
274  h_elePtFail_->Fill(iele->pt());
275  h_eleEtaFail_->Fill(iele->eta());
276  h_elePhiFail_->Fill(iele->phi());
277 
278  //fill conversion info
279  math::XYZVectorF convmom = convref->refittedPairMomentum();
280  h_convPt_->Fill(convmom.rho());
281  h_convEta_->Fill(convmom.eta());
282  h_convPhi_->Fill(convmom.phi());
283  h_convRho_->Fill(convref->conversionVertex().position().rho());
284  h_convZ_->Fill(convref->conversionVertex().position().z());
285  h_convProb_->Fill(ChiSquaredProbability(convref->conversionVertex().chi2(),convref->conversionVertex().ndof()));
286 
287  //fill information about conversion tracks
288  if (convref->tracks().size()<2) continue;
289 
290  RefToBase<reco::Track> tk1 = convref->tracks().front();
291  RefToBase<reco::Track> tk2 = convref->tracks().back();
292 
293  RefToBase<reco::Track> tklead;
294  RefToBase<reco::Track> tktrail;
295  if (tk1->pt() >= tk2->pt()) {
296  tklead = tk1;
297  tktrail = tk2;
298  }
299  else {
300  tklead = tk2;
301  tktrail = tk1;
302  }
303  h_convLeadTrackpt_->Fill(tklead->pt());
304  h_convTrailTrackpt_->Fill(tktrail->pt());
305  h_convLog10TrailTrackpt_->Fill(log10(tktrail->pt()));
306  h_convLeadTrackAlgo_->Fill(tklead->algo());
307  h_convTrailTrackAlgo_->Fill(tktrail->algo());
308 
309  }
310  }
311 
312 }
313 
314 
315 
316 
317 
319 
320 
321  std::string outputFileName = parameters_.getParameter<std::string>("OutputFileName");
322  if ( ! isRunCentrally_ ) {
323  dbe_->save(outputFileName);
324  }
325 
326  edm::LogInfo("ElectronConversionRejectionValidator") << "Analyzed " << nEvt_ << "\n";
327  // std::cout << "::endJob Analyzed " << nEvt_ << " events " << " with total " << nPho_ << " Photons " << "\n";
328  // std::cout << "ElectronConversionRejectionValidator::endJob Analyzed " << nEvt_ << " events " << "\n";
329 
330  return ;
331 }
332 
333 
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:717
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
TrackAlgorithm algo() const
Definition: TrackBase.h:332
bool isNull() const
Checks for null.
Definition: Ref.h:247
double pt() const
track transverse momentum
Definition: TrackBase.h:131
float ChiSquaredProbability(double chiSquared, double nrDOF)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:18
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
DQMStore * dbe_
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:429
Definition: Run.h:33
virtual void beginRun(edm::Run const &r, edm::EventSetup const &theEventSetup)