CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATElectronProducer.cc
Go to the documentation of this file.
1 //
2 // $Id: PATElectronProducer.cc,v 1.49 2011/06/27 15:57:48 bellan Exp $
3 //
4 
6 
9 
14 
17 
20 
23 
24 
27 
32 
35 
36 #include <vector>
37 #include <memory>
38 
39 
40 using namespace pat;
41 using namespace std;
42 
43 
45  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), false) ,
46  useUserData_(iConfig.exists("userData"))
47 {
48 
49  // general configurables
50  electronSrc_ = iConfig.getParameter<edm::InputTag>( "electronSource" );
51  embedGsfElectronCore_ = iConfig.getParameter<bool> ( "embedGsfElectronCore" );
52  embedGsfTrack_ = iConfig.getParameter<bool> ( "embedGsfTrack" );
53  embedSuperCluster_= iConfig.getParameter<bool> ( "embedSuperCluster" );
54  embedTrack_ = iConfig.getParameter<bool> ( "embedTrack" );
55 
56  // pflow specific
57  pfElecSrc_ = iConfig.getParameter<edm::InputTag>( "pfElectronSource" );
58  useParticleFlow_ = iConfig.getParameter<bool>( "useParticleFlow" );
59  linkToPFSource_ = iConfig.getParameter<edm::InputTag>( "linkToPFSource" ); //SAK
60  embedPFCandidate_ = iConfig.getParameter<bool>( "embedPFCandidate" );
61 
62 
63  // MC matching configurables
64  addGenMatch_ = iConfig.getParameter<bool> ( "addGenMatch" );
65  if (addGenMatch_) {
66  embedGenMatch_ = iConfig.getParameter<bool> ( "embedGenMatch" );
67  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
68  genMatchSrc_.push_back(iConfig.getParameter<edm::InputTag>( "genParticleMatch" ));
69  } else {
70  genMatchSrc_ = iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" );
71  }
72  }
73 
74  // resolution configurables
75  addResolutions_ = iConfig.getParameter<bool> ( "addResolutions" );
76  if (addResolutions_) {
78  }
79 
80 
81  // electron ID configurables
82  addElecID_ = iConfig.getParameter<bool> ( "addElectronID" );
83  if (addElecID_) {
84  // it might be a single electron ID
85  if (iConfig.existsAs<edm::InputTag>("electronIDSource")) {
86  elecIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("electronIDSource")));
87  }
88  // or there might be many of them
89  if (iConfig.existsAs<edm::ParameterSet>("electronIDSources")) {
90  // please don't configure me twice
91  if (!elecIDSrcs_.empty()) throw cms::Exception("Configuration") <<
92  "PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
93  // read the different electron ID names
94  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("electronIDSources");
95  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
96  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
97  elecIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
98  }
99  }
100  // but in any case at least once
101  if (elecIDSrcs_.empty()) throw cms::Exception("Configuration") <<
102  "PATElectronProducer: id addElectronID is true, you must specify either:\n" <<
103  "\tInputTag electronIDSource = <someTag>\n" << "or\n" <<
104  "\tPSet electronIDSources = { \n" <<
105  "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
106  "\t}\n";
107  }
108 
109  // construct resolution calculator
110 
111  // // IsoDeposit configurables
112  // if (iConfig.exists("isoDeposits")) {
113  // edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
114  // if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
115  // if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
116  // if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));
117 
118 
119  // if (depconf.exists("user")) {
120  // std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
121  // std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
122  // int key = UserBaseIso;
123  // for ( ; it != ed; ++it, ++key) {
124  // isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
125  // }
126  // }
127  // }
128 
129  // read isoDeposit labels, for direct embedding
130  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_);
131 
132  // read isolation value labels, for direct embedding
133  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_);
134 
135  // Efficiency configurables
136  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
137  if (addEfficiencies_) {
139  }
140 
141  // Check to see if the user wants to add user data
142  if ( useUserData_ ) {
144  }
145 
146  // embed high level selection variables?
147  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
148  if ( embedHighLevelSelection_ ) {
149  beamLineSrc_ = iConfig.getParameter<edm::InputTag>("beamLineSrc");
150  usePV_ = iConfig.getParameter<bool>("usePV");
151  pvSrc_ = iConfig.getParameter<edm::InputTag>("pvSrc");
152  }
153 
154 
155  // produces vector of muons
156  produces<std::vector<Electron> >();
157 
158 }
159 
160 
162 }
163 
164 
166 
167  // Get the collection of electrons from the event
169  iEvent.getByLabel(electronSrc_, electrons);
170 
171  if (iEvent.isRealData()){
172  addGenMatch_ = false;
173  embedGenMatch_ = false;
174  }
175 
176  // Get the ESHandle for the transient track builder, if needed for
177  // high level selection embedding
179 
180  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
181 
183  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
184 
185  IsoDepositMaps deposits(isoDepositLabels_.size());
186  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
187  iEvent.getByLabel(isoDepositLabels_[j].second, deposits[j]);
188  }
189 
190  IsolationValueMaps isolationValues(isolationValueLabels_.size());
191  for (size_t j = 0; j<isolationValueLabels_.size(); ++j) {
192  iEvent.getByLabel(isolationValueLabels_[j].second, isolationValues[j]);
193  }
194 
195  // prepare the MC matching
196  GenAssociations genMatches(genMatchSrc_.size());
197  if (addGenMatch_) {
198  for (size_t j = 0, nd = genMatchSrc_.size(); j < nd; ++j) {
199  iEvent.getByLabel(genMatchSrc_[j], genMatches[j]);
200  }
201  }
202 
203  // prepare ID extraction
204  std::vector<edm::Handle<edm::ValueMap<float> > > idhandles;
205  std::vector<pat::Electron::IdPair> ids;
206  if (addElecID_) {
207  idhandles.resize(elecIDSrcs_.size());
208  ids.resize(elecIDSrcs_.size());
209  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
210  iEvent.getByLabel(elecIDSrcs_[i].second, idhandles[i]);
211  ids[i].first = elecIDSrcs_[i].first;
212  }
213  }
214 
215 
216  // prepare the high level selection:
217  // needs beamline
218  reco::TrackBase::Point beamPoint(0,0,0);
219  reco::Vertex primaryVertex;
220  reco::BeamSpot beamSpot;
221  bool beamSpotIsValid = false;
222  bool primaryVertexIsValid = false;
223  if ( embedHighLevelSelection_ ) {
224  // Get the beamspot
225  edm::Handle<reco::BeamSpot> beamSpotHandle;
226  iEvent.getByLabel(beamLineSrc_, beamSpotHandle);
227 
228  // Get the primary vertex
230  iEvent.getByLabel( pvSrc_, pvHandle );
231 
232  // This is needed by the IPTools methods from the tracking group
233  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
234 
235  if ( ! usePV_ ) {
236  if ( beamSpotHandle.isValid() ){
237  beamSpot = *beamSpotHandle;
238  beamSpotIsValid = true;
239  } else{
240  edm::LogError("DataNotAvailable")
241  << "No beam spot available from EventSetup, not adding high level selection \n";
242  }
243 
244  double x0 = beamSpot.x0();
245  double y0 = beamSpot.y0();
246  double z0 = beamSpot.z0();
247 
248  beamPoint = reco::TrackBase::Point ( x0, y0, z0 );
249  } else {
250  if ( pvHandle.isValid() && !pvHandle->empty() ) {
251  primaryVertex = pvHandle->at(0);
252  primaryVertexIsValid = true;
253  } else {
254  edm::LogError("DataNotAvailable")
255  << "No primary vertex available from EventSetup, not adding high level selection \n";
256  }
257  }
258  }
259 
260  std::vector<Electron> * patElectrons = new std::vector<Electron>();
261 
262  if( useParticleFlow_ ) {
264  iEvent.getByLabel(pfElecSrc_, pfElectrons);
265  //-- SAK ------------------------------------------------------------------
267  if (linkToPFSource_.label().length())
268  iEvent.getByLabel(linkToPFSource_, pfForLinking);
269  //-- SAK ------------------------------------------------------------------
270  unsigned index=0;
271 
272  for( reco::PFCandidateConstIterator i = pfElectrons->begin();
273  i != pfElectrons->end(); ++i, ++index) {
274 
275  reco::PFCandidateRef pfRef(pfElectrons, index);
276  reco::PFCandidatePtr ptrToPFElectron(pfElectrons,index);
277 // reco::CandidateBaseRef pfBaseRef( pfRef );
278 
279  reco::GsfTrackRef PfTk= i->gsfTrackRef();
280 
281  bool Matched=false;
282  bool MatchedToAmbiguousGsfTrack=false;
283  for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
284  unsigned int idx = itElectron - electrons->begin();
285  if (Matched || MatchedToAmbiguousGsfTrack) continue;
286 
287  reco::GsfTrackRef EgTk= itElectron->gsfTrack();
288 
289  if (itElectron->gsfTrack()==i->gsfTrackRef()){
290  Matched=true;
291  }
292  else {
293  for( reco::GsfTrackRefVector::const_iterator it = itElectron->ambiguousGsfTracksBegin() ;
294  it!=itElectron->ambiguousGsfTracksEnd(); it++ ){
295  MatchedToAmbiguousGsfTrack |= (bool)(i->gsfTrackRef()==(*it));
296  }
297  }
298 
299  if (Matched || MatchedToAmbiguousGsfTrack){
300 
301  // ptr needed for finding the matched gen particle
302  reco::CandidatePtr ptrToGsfElectron(electrons,idx);
303 
304  // ref to base needed for the construction of the pat object
305  const edm::RefToBase<reco::GsfElectron>& elecsRef = electrons->refAt(idx);
306  Electron anElectron(elecsRef);
307  anElectron.setPFCandidateRef( pfRef );
308 
309  if( embedPFCandidate_ ) anElectron.embedPFCandidate();
310 
311  if ( useUserData_ ) {
312  userDataHelper_.add( anElectron, iEvent, iSetup );
313  }
314 
315 
316  // embed high level selection
317  if ( embedHighLevelSelection_ ) {
318  // get the global track
319  reco::GsfTrackRef track = PfTk;
320 
321  // Make sure the collection it points to is there
322  if ( track.isNonnull() && track.isAvailable() ) {
323 
324  reco::TransientTrack tt = trackBuilder->build(track);
325  embedHighLevel( anElectron,
326  track,
327  tt,
328  primaryVertex,
329  primaryVertexIsValid,
330  beamSpot,
331  beamSpotIsValid );
332 
333  if ( !usePV_ ) {
334  double corr_d0 = track->dxy( beamPoint );
335  anElectron.setDB( corr_d0, -1.0 );
336  } else {
337  std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
338  double d0_corr = result.second.value();
339  double d0_err = result.second.error();
340  anElectron.setDB( d0_corr, d0_err );
341  }
342  }
343  }
344 
345  //Electron Id
346 
347  if (addElecID_) {
348  //STANDARD EL ID
349  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
350  ids[i].second = (*idhandles[i])[elecsRef];
351  }
352  //SPECIFIC PF ID
353  ids.push_back(std::make_pair("pf_evspi",pfRef->mva_e_pi()));
354  ids.push_back(std::make_pair("pf_evsmu",pfRef->mva_e_mu()));
355  anElectron.setElectronIDs(ids);
356  }
357 
358 // fillElectron(anElectron,elecsRef,pfBaseRef,
359 // genMatches, deposits, isolationValues);
360 
361  //COLIN small warning !
362  // we are currently choosing to take the 4-momentum of the PFCandidate;
363  // the momentum of the GsfElectron is saved though
364  // we must therefore match the GsfElectron.
365  // because of this, we should not change the source of the electron matcher
366  // to the collection of PFElectrons in the python configuration
367  // I don't know what to do with the efficiencyLoader, since I don't know
368  // what this class is for.
369  fillElectron2( anElectron,
370  ptrToPFElectron,
371  ptrToGsfElectron,
372  ptrToGsfElectron,
373  genMatches, deposits, isolationValues );
374 
375  //COLIN need to use fillElectron2 in the non-pflow case as well, and to test it.
376 
377  //-- SAK ------------------------------------------------------------------
378  if (linkToPFSource_.label().length() && anElectron.pfCandidateRef().id() != pfForLinking.id()) {
379  reco::CandidatePtr source = anElectron.pfCandidateRef()->sourceCandidatePtr(0);
380  while (source.id() != pfForLinking.id()) {
381  source = source->sourceCandidatePtr(0);
382  if (source.isNull())
383  throw cms::Exception("InputSource", "Object in "+pfElecSrc_.encode()+" does not link back to "+linkToPFSource_.encode());
384  } // end loop over inheritance chain
385  anElectron.setPFCandidateRef(reco::PFCandidateRef(pfForLinking, source.key()));
386  }
387  //-- SAK ------------------------------------------------------------------
388  patElectrons->push_back(anElectron);
389  }
390  }
391  //if( !Matched && !MatchedToAmbiguousGsfTrack) std::cout << "!!!!A pf electron could not be matched to a gsf!!!!" << std::endl;
392  }
393  }
394 
395  else{
396  for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
397  // construct the Electron from the ref -> save ref to original object
398  unsigned int idx = itElectron - electrons->begin();
399  edm::RefToBase<reco::GsfElectron> elecsRef = electrons->refAt(idx);
400  reco::CandidateBaseRef elecBaseRef(elecsRef);
401  Electron anElectron(elecsRef);
402 
403  // add resolution info
404 
405  // Isolation
406  if (isolator_.enabled()) {
407  isolator_.fill(*electrons, idx, isolatorTmpStorage_);
408  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
409  // better to loop backwards, so the vector is resized less times
410  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
411  anElectron.setIsolation(it->first, it->second);
412  }
413  }
414 
415  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
416  anElectron.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[elecsRef]);
417  }
418 
419  // add electron ID info
420  if (addElecID_) {
421  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
422  ids[i].second = (*idhandles[i])[elecsRef];
423  }
424  anElectron.setElectronIDs(ids);
425  }
426 
427 
428  if ( useUserData_ ) {
429  userDataHelper_.add( anElectron, iEvent, iSetup );
430  }
431 
432 
433  // embed high level selection
434  if ( embedHighLevelSelection_ ) {
435  // get the global track
436  reco::GsfTrackRef track = itElectron->gsfTrack();
437 
438  // Make sure the collection it points to is there
439  if ( track.isNonnull() && track.isAvailable() ) {
440 
441  reco::TransientTrack tt = trackBuilder->build(track);
442  embedHighLevel( anElectron,
443  track,
444  tt,
445  primaryVertex,
446  primaryVertexIsValid,
447  beamSpot,
448  beamSpotIsValid );
449 
450 
451  if ( !usePV_ ) {
452  double corr_d0 = track->dxy( beamPoint );
453  anElectron.setDB( corr_d0, -1.0 );
454  } else {
455 
456  std::pair<bool,Measurement1D> result = IPTools::absoluteTransverseImpactParameter(tt, primaryVertex);
457  double d0_corr = result.second.value();
458  double d0_err = result.second.error();
459  anElectron.setDB( d0_corr, d0_err );
460  }
461  }
462  }
463 
464  // add sel to selected
465  fillElectron( anElectron, elecsRef,elecBaseRef,
466  genMatches, deposits, isolationValues);
467  patElectrons->push_back(anElectron);
468  }
469  }
470 
471  // sort electrons in pt
472  std::sort(patElectrons->begin(), patElectrons->end(), pTComparator_);
473 
474  // add the electrons to the event output
475  std::auto_ptr<std::vector<Electron> > ptr(patElectrons);
476  iEvent.put(ptr);
477 
478  // clean up
480 
481 }
482 
484  const edm::RefToBase<reco::GsfElectron>& elecRef,
485  const reco::CandidateBaseRef& baseRef,
486  const GenAssociations& genMatches,
487  const IsoDepositMaps& deposits,
488  const IsolationValueMaps& isolationValues
489  ) const {
490 
491  //COLIN: might want to use the PFCandidate 4-mom. Which one is in use now?
492  // if (useParticleFlow_)
493  // aMuon.setP4( aMuon.pfCandidateRef()->p4() );
494 
495  //COLIN:
496  //In the embedding case, the reference cannot be used to look into a value map.
497  //therefore, one has to had the PFCandidateRef to this function, which becomes a bit
498  //too much specific.
499 
500  // in fact, this function needs a baseref or ptr for genmatch
501  // and a baseref or ptr for isodeposits and isolationvalues.
502  // baseref is not needed
503  // the ptrForIsolation and ptrForMatching should be defined upstream.
504 
505  // is the concrete elecRef needed for the efficiency loader? what is this loader?
506  // how can we make it compatible with the particle flow electrons?
507 
509  if (embedGsfTrack_) anElectron.embedGsfTrack();
510  if (embedSuperCluster_) anElectron.embedSuperCluster();
511  if (embedTrack_) anElectron.embedTrack();
512 
513  // store the match to the generated final state muons
514  if (addGenMatch_) {
515  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
516  if(useParticleFlow_) {
517  reco::GenParticleRef genElectron = (*genMatches[i])[anElectron.pfCandidateRef()];
518  anElectron.addGenParticleRef(genElectron);
519  }
520  else {
521  reco::GenParticleRef genElectron = (*genMatches[i])[elecRef];
522  anElectron.addGenParticleRef(genElectron);
523  }
524  }
525  if (embedGenMatch_) anElectron.embedGenParticle();
526  }
527 
528  if (efficiencyLoader_.enabled()) {
529  efficiencyLoader_.setEfficiencies( anElectron, elecRef );
530  }
531 
532  if (resolutionLoader_.enabled()) {
533  resolutionLoader_.setResolutions(anElectron);
534  }
535 
536  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
537  if(useParticleFlow_) {
538 
539  reco::PFCandidateRef pfcandref = anElectron.pfCandidateRef();
540  assert(!pfcandref.isNull());
541  reco::CandidatePtr source = pfcandref->sourceCandidatePtr(0);
543  (*deposits[j])[source]);
544  }
545  else
547  (*deposits[j])[elecRef]);
548  }
549 
550  for (size_t j = 0; j<isolationValues.size(); ++j) {
551  if(useParticleFlow_) {
552  reco::CandidatePtr source = anElectron.pfCandidateRef()->sourceCandidatePtr(0);
554  (*isolationValues[j])[source]);
555  }
556  else
558  (*isolationValues[j])[elecRef]);
559  }
560 
561 
562 
563 }
564 
566  const reco::CandidatePtr& candPtrForIsolation,
567  const reco::CandidatePtr& candPtrForGenMatch,
568  const reco::CandidatePtr& candPtrForLoader,
569  const GenAssociations& genMatches,
570  const IsoDepositMaps& deposits,
571  const IsolationValueMaps& isolationValues) const {
572 
573  //COLIN/Florian: use the PFCandidate 4-mom.
574  anElectron.setEcalDrivenMomentum(anElectron.p4()) ;
575  anElectron.setP4( anElectron.pfCandidateRef()->p4() );
576 
577 
578  // is the concrete elecRef needed for the efficiency loader? what is this loader?
579  // how can we make it compatible with the particle flow electrons?
580 
582  if (embedGsfTrack_) anElectron.embedGsfTrack();
583  if (embedSuperCluster_) anElectron.embedSuperCluster();
584  if (embedTrack_) anElectron.embedTrack();
585 
586  // store the match to the generated final state muons
587 
588  if (addGenMatch_) {
589  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
590  reco::GenParticleRef genElectron = (*genMatches[i])[candPtrForGenMatch];
591  anElectron.addGenParticleRef(genElectron);
592  }
593  if (embedGenMatch_) anElectron.embedGenParticle();
594  }
595 
596  //COLIN what's this? does it have to be GsfElectron specific?
597  if (efficiencyLoader_.enabled()) {
598  efficiencyLoader_.setEfficiencies( anElectron, candPtrForLoader );
599  }
600 
601  if (resolutionLoader_.enabled()) {
602  resolutionLoader_.setResolutions(anElectron);
603  }
604 
605  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
609 
611  (*deposits[j])[candPtrForGenMatch]);
612  }
613  else if (deposits[j]->contains(candPtrForIsolation.id())) {
615  (*deposits[j])[candPtrForIsolation]);
616  }
617  else {
619  (*deposits[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
620  }
621  }
622 
623  for (size_t j = 0; j<isolationValues.size(); ++j) {
628  (*isolationValues[j])[candPtrForGenMatch]);
629  }
630  else if (isolationValues[j]->contains(candPtrForIsolation.id())) {
632  (*isolationValues[j])[candPtrForIsolation]);
633  }
634  else {
636  (*isolationValues[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
637  }
638 
639  }
640 }
641 
642 
643 // ParameterSet description for module
645 {
647  iDesc.setComment("PAT electron producer module");
648 
649  // input source
650  iDesc.add<edm::InputTag>("electronSource", edm::InputTag("no default"))->setComment("input collection");
651 
652  // embedding
653  iDesc.add<bool>("embedGsfElectronCore", true)->setComment("embed external gsf electron core");
654  iDesc.add<bool>("embedGsfTrack", true)->setComment("embed external gsf track");
655  iDesc.add<bool>("embedSuperCluster", true)->setComment("embed external super cluster");
656  iDesc.add<bool>("embedTrack", false)->setComment("embed external track");
657 
658  // pf specific parameters
659  iDesc.add<edm::InputTag>("pfElectronSource", edm::InputTag("pfElectrons"))->setComment("particle flow input collection");
660  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
661  iDesc.add<edm::InputTag>("linkToPFSource", edm::InputTag())->setComment("alternative PF collection to link to (pfCandidateRef) -- traverses inheritance chain up to this");
662  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
663 
664  // MC matching configurables
665  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
666  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
667  std::vector<edm::InputTag> emptySourceVector;
668  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
669  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
670  )->setComment("input with MC match information");
671 
672  // electron ID configurables
673  iDesc.add<bool>("addElectronID",true)->setComment("add electron ID variables");
674  edm::ParameterSetDescription electronIDSourcesPSet;
675  electronIDSourcesPSet.setAllowAnything();
676  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("electronIDSource", edm::InputTag(), true) xor
677  edm::ParameterDescription<edm::ParameterSetDescription>("electronIDSources", electronIDSourcesPSet, true)
678  )->setComment("input with electron ID variables");
679 
680 
681  // IsoDeposit configurables
682  edm::ParameterSetDescription isoDepositsPSet;
683  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
684  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
685  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
686  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
687  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
688  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
689  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
690  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
691  iDesc.addOptional("isoDeposits", isoDepositsPSet);
692 
693  // isolation values configurables
694  edm::ParameterSetDescription isolationValuesPSet;
695  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
696  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
697  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
698  isolationValuesPSet.addOptional<edm::InputTag>("pfAllParticles");
699  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
700  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
701  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
702  isolationValuesPSet.addOptional<std::vector<edm::InputTag> >("user");
703  iDesc.addOptional("isolationValues", isolationValuesPSet);
704 
705  // Efficiency configurables
706  edm::ParameterSetDescription efficienciesPSet;
707  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
708  iDesc.add("efficiencies", efficienciesPSet);
709  iDesc.add<bool>("addEfficiencies", false);
710 
711  // Check to see if the user wants to add user data
712  edm::ParameterSetDescription userDataPSet;
714  iDesc.addOptional("userData", userDataPSet);
715 
716  // electron shapes
717  iDesc.add<bool>("addElectronShapes", true);
718  iDesc.add<edm::InputTag>("reducedBarrelRecHitCollection", edm::InputTag("reducedEcalRecHitsEB"));
719  iDesc.add<edm::InputTag>("reducedEndcapRecHitCollection", edm::InputTag("reducedEcalRecHitsEE"));
720 
721  edm::ParameterSetDescription isolationPSet;
722  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
723  iDesc.add("userIsolation", isolationPSet);
724 
725  // Resolution configurables
727 
728  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
729  edm::ParameterSetDescription highLevelPSet;
730  highLevelPSet.setAllowAnything();
731  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
732  )->setComment("input with high level selection");
734  )->setComment("input with high level selection");
735  iDesc.addNode( edm::ParameterDescription<bool>("usePV", bool(), true)
736  )->setComment("input with high level selection, use primary vertex (true) or beam line (false)");
737 
738  descriptions.add("PATElectronProducer", iDesc);
739 
740 }
741 
742 
743 
745  const char* psetName,
747 
748  labels.clear();
749 
750  if (iConfig.exists( psetName )) {
751  edm::ParameterSet depconf
752  = iConfig.getParameter<edm::ParameterSet>(psetName);
753 
754  if (depconf.exists("tracker")) labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
755  if (depconf.exists("ecal")) labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
756  if (depconf.exists("hcal")) labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
757  if (depconf.exists("pfAllParticles")) {
758  labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
759  }
760  if (depconf.exists("pfChargedHadrons")) {
761  labels.push_back(std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
762  }
763  if (depconf.exists("pfNeutralHadrons")) {
764  labels.push_back(std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
765  }
766  if (depconf.exists("pfPhotons")) {
767  labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
768  }
769  if (depconf.exists("user")) {
770  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
771  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
772  int key = UserBaseIso;
773  for ( ; it != ed; ++it, ++key) {
774  labels.push_back(std::make_pair(IsolationKeys(key), *it));
775  }
776  }
777  }
778 
779 
780 }
781 
782 
783 // embed various impact parameters with errors
784 // embed high level selection
786  reco::GsfTrackRef track,
788  reco::Vertex & primaryVertex,
789  bool primaryVertexIsValid,
790  reco::BeamSpot & beamspot,
791  bool beamspotIsValid
792  )
793 {
794  // Correct to PV
795 
796  // PV2D
797  std::pair<bool,Measurement1D> result =
799  GlobalVector(track->px(),
800  track->py(),
801  track->pz()),
802  primaryVertex);
803  double d0_corr = result.second.value();
804  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
805  anElectron.setDB( d0_corr, d0_err, pat::Electron::PV2D);
806 
807 
808  // PV3D
809  result =
811  GlobalVector(track->px(),
812  track->py(),
813  track->pz()),
814  primaryVertex);
815  d0_corr = result.second.value();
816  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
817  anElectron.setDB( d0_corr, d0_err, pat::Electron::PV3D);
818 
819 
820  // Correct to beam spot
821  // make a fake vertex out of beam spot
822  reco::Vertex vBeamspot(beamspot.position(), beamspot.covariance3D());
823 
824  // BS2D
825  result =
827  GlobalVector(track->px(),
828  track->py(),
829  track->pz()),
830  vBeamspot);
831  d0_corr = result.second.value();
832  d0_err = beamspotIsValid ? result.second.error() : -1.0;
833  anElectron.setDB( d0_corr, d0_err, pat::Electron::BS2D);
834 
835  // BS3D
836  result =
838  GlobalVector(track->px(),
839  track->py(),
840  track->pz()),
841  vBeamspot);
842  d0_corr = result.second.value();
843  d0_err = beamspotIsValid ? result.second.error() : -1.0;
844  anElectron.setDB( d0_corr, d0_err, pat::Electron::BS3D);
845 }
846 
848 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
T getParameter(std::string const &) const
void setComment(std::string const &value)
double z0() const
z coordinate
Definition: BeamSpot.h:69
Assists in assimilating all pat::UserData into pat objects.
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:170
void embedTrack()
method to store the electron&#39;s Track internally
Definition: Electron.cc:175
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:99
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:181
void embedGsfElectronCore()
method to store the electron&#39;s core internally
Definition: Electron.cc:146
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
void setElectronIDs(const std::vector< IdPair > &ids)
Definition: Electron.h:112
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:119
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:196
ProductID id() const
Definition: HandleBase.cc:15
void embedSuperCluster()
method to store the electron&#39;s SuperCluster internally
Definition: Electron.cc:165
void setAllowAnything()
allow any parameter label/value pairs
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_
Definition: Electron.cc:215
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setDB(double dB, double edB, IpType type=None)
Definition: Electron.cc:275
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
void embedHighLevel(pat::Electron &anElectron, reco::GsfTrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
void fillElectron(Electron &aElectron, const ElectronBaseRef &electronRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
common electron filling, for both the standard and PF2PAT case
bool exists(std::string const &parameterName) const
checks if a parameter exists
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
Definition: Electron.h:135
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
bool isAvailable() const
Definition: Ref.h:275
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setEcalDrivenMomentum(const Candidate::LorentzVector &mom)
Definition: Electron.h:173
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool isRealData() const
Definition: EventBase.h:60
std::string encode() const
Definition: InputTag.cc:72
std::vector< edm::InputTag > genMatchSrc_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:173
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:189
U second(std::pair< T, U > const &p)
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:249
void setComment(std::string const &value)
GreaterByPt< Electron > pTComparator_
pat::helper::MultiIsolator isolator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
int iEvent
Definition: GenABIO.cc:243
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
Produces pat::Electron&#39;s.
bool isNull() const
Checks for null.
Definition: Ref.h:246
PATElectronProducer(const edm::ParameterSet &iConfig)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void embedGenParticle()
Definition: PATObject.h:669
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:169
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates
Definition: Electron.cc:207
math::XYZPoint Point
point in the space
Definition: TrackBase.h:76
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool embedHighLevelSelection_
embed high level selection variables?
bool first
Definition: L1TdeRCT.cc:79
bool isValid() const
Definition: HandleBase.h:76
std::pair< std::string, edm::InputTag > NameTag
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void embedGsfTrack()
method to store the electron&#39;s GsfTrack internally
Definition: Electron.cc:155
tuple labels
Definition: L1TDQM_cfg.py:62
key_type key() const
Definition: Ptr.h:174
void fillElectron2(Electron &anElectron, const reco::CandidatePtr &candPtrForIsolation, const reco::CandidatePtr &candPtrForGenMatch, const reco::CandidatePtr &candPtrForLoader, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:653
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
pat::helper::EfficiencyLoader efficiencyLoader_
const T & get() const
Definition: EventSetup.h:55
pat::PATUserDataHelper< pat::Electron > userDataHelper_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
bool useParticleFlow_
pflow specific
Analysis-level electron class.
Definition: Electron.h:50
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::pair< bool, Measurement1D > absoluteTransverseImpactParameter(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:43
std::string const & label() const
Definition: InputTag.h:25
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
bool isNull() const
Checks for null.
Definition: Ptr.h:153
std::vector< IsolationLabel > IsolationLabels
list key
Definition: combine.py:13
IsolationLabels isolationValueLabels_
double y0() const
y coordinate
Definition: BeamSpot.h:67
pat::helper::KinResolutionsLoader resolutionLoader_
const Point & position() const
position
Definition: BeamSpot.h:63
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels)
ProductID id() const
Accessor for product ID.
Definition: Ref.h:255
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
static const HistoName names[]
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.
Global3DVector GlobalVector
Definition: GlobalVector.h:10
std::vector< NameTag > elecIDSrcs_
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:82
double x0() const
x coordinate
Definition: BeamSpot.h:65
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps