CMS 3D CMS Logo

PATElectronProducer.cc
Go to the documentation of this file.
1 //
3 
7 
12 
15 
18 
21 
22 
25 
30 
39 
41 
43 
44 #include <vector>
45 #include <memory>
46 
47 
48 using namespace pat;
49 using namespace std;
50 
51 
53  // general configurables
54  electronToken_(consumes<edm::View<reco::GsfElectron> >(iConfig.getParameter<edm::InputTag>( "electronSource" ))),
55  hConversionsToken_(consumes<reco::ConversionCollection>(edm::InputTag("allConversions"))),
56  embedGsfElectronCore_(iConfig.getParameter<bool>( "embedGsfElectronCore" )),
57  embedGsfTrack_(iConfig.getParameter<bool>( "embedGsfTrack" )),
58  embedSuperCluster_(iConfig.getParameter<bool> ( "embedSuperCluster" )),
59  embedPflowSuperCluster_(iConfig.getParameter<bool> ( "embedPflowSuperCluster" )),
60  embedSeedCluster_(iConfig.getParameter<bool>( "embedSeedCluster" )),
61  embedBasicClusters_(iConfig.getParameter<bool>( "embedBasicClusters" )),
62  embedPreshowerClusters_(iConfig.getParameter<bool>( "embedPreshowerClusters" )),
63  embedPflowBasicClusters_(iConfig.getParameter<bool>( "embedPflowBasicClusters" )),
64  embedPflowPreshowerClusters_(iConfig.getParameter<bool>( "embedPflowPreshowerClusters" )),
65  embedTrack_(iConfig.getParameter<bool>( "embedTrack" )),
66  addGenMatch_(iConfig.getParameter<bool>( "addGenMatch" )),
67  embedGenMatch_(addGenMatch_ ? iConfig.getParameter<bool>( "embedGenMatch" ) : false),
68  embedRecHits_(iConfig.getParameter<bool>( "embedRecHits" )),
69  // pflow configurables
70  useParticleFlow_(iConfig.getParameter<bool>( "useParticleFlow" )),
71  pfElecToken_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>( "pfElectronSource" ))),
72  pfCandidateMapToken_(mayConsume<edm::ValueMap<reco::PFCandidatePtr> >(iConfig.getParameter<edm::InputTag>( "pfCandidateMap" ))),
73  embedPFCandidate_(iConfig.getParameter<bool>( "embedPFCandidate" )),
74  // mva input variables
75  reducedBarrelRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection")),
76  reducedBarrelRecHitCollectionToken_(mayConsume<EcalRecHitCollection>(reducedBarrelRecHitCollection_)),
77  reducedEndcapRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection")),
78  reducedEndcapRecHitCollectionToken_(mayConsume<EcalRecHitCollection>(reducedEndcapRecHitCollection_)),
79  // PFCluster Isolation maps
80  addPFClusterIso_(iConfig.getParameter<bool>("addPFClusterIso")),
81  addPuppiIsolation_(iConfig.getParameter<bool>("addPuppiIsolation")),
82  ecalPFClusterIsoT_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("ecalPFClusterIsoMap"))),
83  hcalPFClusterIsoT_(consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("hcalPFClusterIsoMap"))),
84  // embed high level selection variables?
85  embedHighLevelSelection_(iConfig.getParameter<bool>("embedHighLevelSelection")),
86  beamLineToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"))),
87  pvToken_(mayConsume<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("pvSrc"))),
88  addElecID_(iConfig.getParameter<bool>( "addElectronID" )),
89  pTComparator_(),
90  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false) ,
91  addEfficiencies_(iConfig.getParameter<bool>("addEfficiencies")),
92  addResolutions_(iConfig.getParameter<bool>( "addResolutions" )),
93  useUserData_(iConfig.exists("userData"))
94 
95 {
96  // MC matching configurables (scheduled mode)
97 
98  if (addGenMatch_) {
99  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
101  }
102  else {
103  genMatchTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "genParticleMatch" ), [this](edm::InputTag const & tag){return consumes<edm::Association<reco::GenParticleCollection> >(tag);});
104  }
105  }
106  // resolution configurables
107  if (addResolutions_) {
109  }
110  if(addPuppiIsolation_){
111  //puppi
112  PUPPIIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
113  PUPPIIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
114  PUPPIIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
115  //puppiNoLeptons
116  PUPPINoLeptonsIsolation_charged_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
117  PUPPINoLeptonsIsolation_neutral_hadrons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
118  PUPPINoLeptonsIsolation_photons_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
119  }
120  // electron ID configurables
121  if (addElecID_) {
122  // it might be a single electron ID
123  if (iConfig.existsAs<edm::InputTag>("electronIDSource")) {
124  elecIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("electronIDSource")));
125  }
126  // or there might be many of them
127  if (iConfig.existsAs<edm::ParameterSet>("electronIDSources")) {
128  // please don't configure me twice
129  if (!elecIDSrcs_.empty()){
130  throw cms::Exception("Configuration") << "PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
131  }
132  // read the different electron ID names
133  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("electronIDSources");
134  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
135  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
136  elecIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
137  }
138  }
139  // but in any case at least once
140  if (elecIDSrcs_.empty()){
141  throw cms::Exception("Configuration") <<
142  "PATElectronProducer: id addElectronID is true, you must specify either:\n" <<
143  "\tInputTag electronIDSource = <someTag>\n" << "or\n" <<
144  "\tPSet electronIDSources = { \n" <<
145  "\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
146  "\t}\n";
147  }
148  }
149  elecIDTokens_ = edm::vector_transform(elecIDSrcs_, [this](NameTag const & tag){return mayConsume<edm::ValueMap<float> >(tag.second);});
150  // construct resolution calculator
151 
152  // // IsoDeposit configurables
153  // if (iConfig.exists("isoDeposits")) {
154  // edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
155  // if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
156  // if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
157  // if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));
158 
159 
160  // if (depconf.exists("user")) {
161  // std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
162  // std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
163  // int key = UserBaseIso;
164  // for ( ; it != ed; ++it, ++key) {
165  // isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
166  // }
167  // }
168  // }
169  // isoDepositTokens_ = edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys,edm::InputTag> const & label){return consumes<edm::ValueMap<IsoDeposit> >(label.second);});
170 
171  // read isoDeposit labels, for direct embedding
172  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
173  // read isolation value labels, for direct embedding
175  // read isolation value labels for non PF identified electron, for direct embedding
177  // Efficiency configurables
178  if (addEfficiencies_) {
180  }
181  // Check to see if the user wants to add user data
182  if ( useUserData_ ) {
184  }
185 
186  // produces vector of muons
187  produces<std::vector<Electron> >();
188  }
189 
190 
192 {
193 }
194 
195 
197 {
198  // switch off embedding (in unschedules mode)
199  if (iEvent.isRealData()){
200  addGenMatch_ = false;
201  embedGenMatch_ = false;
202  }
203 
204  edm::ESHandle<CaloTopology> theCaloTopology;
205  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
206  ecalTopology_ = & (*theCaloTopology);
207 
208  // Get the collection of electrons from the event
210  iEvent.getByToken(electronToken_, electrons);
211 
212  // for additional mva variables
213  edm::InputTag reducedEBRecHitCollection(string("reducedEcalRecHitsEB"));
214  edm::InputTag reducedEERecHitCollection(string("reducedEcalRecHitsEE"));
215  //EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection, reducedEERecHitCollection);
217 
218  // for conversion veto selection
220  iEvent.getByToken(hConversionsToken_, hConversions);
221 
222  // Get the ESHandle for the transient track builder, if needed for
223  // high level selection embedding
225 
226  if (isolator_.enabled()) isolator_.beginEvent(iEvent,iSetup);
227 
229  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
230 
232  for (size_t j = 0, nd = isoDepositTokens_.size(); j < nd; ++j) {
233  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
234  }
235 
237  for (size_t j = 0; j<isolationValueTokens_.size(); ++j) {
239  }
240 
242  for (size_t j = 0; j<isolationValueNoPFIdTokens_.size(); ++j) {
244  }
245 
246  // prepare the MC matching
247  GenAssociations genMatches(genMatchTokens_.size());
248  if (addGenMatch_) {
249  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
250  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
251  }
252  }
253 
254  // prepare ID extraction
255  std::vector<edm::Handle<edm::ValueMap<float> > > idhandles;
256  std::vector<pat::Electron::IdPair> ids;
257  if (addElecID_) {
258  idhandles.resize(elecIDSrcs_.size());
259  ids.resize(elecIDSrcs_.size());
260  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
261  iEvent.getByToken(elecIDTokens_[i], idhandles[i]);
262  ids[i].first = elecIDSrcs_[i].first;
263  }
264  }
265 
266 
267  // prepare the high level selection:
268  // needs beamline
269  reco::TrackBase::Point beamPoint(0,0,0);
272  bool beamSpotIsValid = false;
273  bool primaryVertexIsValid = false;
274 
275  // Get the beamspot
276  edm::Handle<reco::BeamSpot> beamSpotHandle;
277  iEvent.getByToken(beamLineToken_, beamSpotHandle);
278 
279  if ( embedHighLevelSelection_ ) {
280  // Get the primary vertex
282  iEvent.getByToken( pvToken_, pvHandle );
283 
284  // This is needed by the IPTools methods from the tracking group
285  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
286 
287  if ( pvHandle.isValid() && !pvHandle->empty() ) {
288  primaryVertex = pvHandle->at(0);
289  primaryVertexIsValid = true;
290  } else {
291  edm::LogError("DataNotAvailable")
292  << "No primary vertex available from EventSetup, not adding high level selection \n";
293  }
294  }
295  //value maps for puppi isolation
296  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
297  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
298  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
299  //value maps for puppiNoLeptons isolation
300  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
301  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
302  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
303  if(addPuppiIsolation_){
304  //puppi
305  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
306  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
307  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
308  //puppiNoLeptons
309  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
310  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
311  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
312  }
313 
314 
315  std::vector<Electron> * patElectrons = new std::vector<Electron>();
316 
317  if( useParticleFlow_ ) {
319  iEvent.getByToken(pfElecToken_, pfElectrons);
320  unsigned index=0;
321 
322  for( reco::PFCandidateConstIterator i = pfElectrons->begin();
323  i != pfElectrons->end(); ++i, ++index) {
324 
325  reco::PFCandidateRef pfRef(pfElectrons, index);
326  reco::PFCandidatePtr ptrToPFElectron(pfElectrons,index);
327 // reco::CandidateBaseRef pfBaseRef( pfRef );
328 
329  reco::GsfTrackRef PfTk= i->gsfTrackRef();
330 
331  bool Matched=false;
332  bool MatchedToAmbiguousGsfTrack=false;
333  for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
334  unsigned int idx = itElectron - electrons->begin();
335  auto elePtr = electrons -> ptrAt(idx);
336  if (Matched || MatchedToAmbiguousGsfTrack) continue;
337 
338  reco::GsfTrackRef EgTk= itElectron->gsfTrack();
339 
340  if (itElectron->gsfTrack()==i->gsfTrackRef()){
341  Matched=true;
342  }
343  else {
344  for( reco::GsfTrackRefVector::const_iterator it = itElectron->ambiguousGsfTracksBegin() ;
345  it!=itElectron->ambiguousGsfTracksEnd(); it++ ){
346  MatchedToAmbiguousGsfTrack |= (bool)(i->gsfTrackRef()==(*it));
347  }
348  }
349 
350  if (Matched || MatchedToAmbiguousGsfTrack){
351 
352  // ptr needed for finding the matched gen particle
353  reco::CandidatePtr ptrToGsfElectron(electrons,idx);
354 
355  // ref to base needed for the construction of the pat object
356  const edm::RefToBase<reco::GsfElectron>& elecsRef = electrons->refAt(idx);
357  Electron anElectron(elecsRef);
358  anElectron.setPFCandidateRef( pfRef );
359  if (addPuppiIsolation_) {
360  anElectron.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[elePtr], (*PUPPIIsolation_neutral_hadrons)[elePtr], (*PUPPIIsolation_photons)[elePtr]);
361  anElectron.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[elePtr], (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr], (*PUPPINoLeptonsIsolation_photons)[elePtr]);
362  }
363  else {
364  anElectron.setIsolationPUPPI(-999., -999.,-999.);
365  anElectron.setIsolationPUPPINoLeptons(-999., -999.,-999.);
366  }
367 
368  //it should be always true when particleFlow electrons are used.
369  anElectron.setIsPF( true );
370 
371  if( embedPFCandidate_ ) anElectron.embedPFCandidate();
372 
373  if ( useUserData_ ) {
374  userDataHelper_.add( anElectron, iEvent, iSetup );
375  }
376 
377  double ip3d = -999; // for mva variable
378 
379  // embed high level selection
380  if ( embedHighLevelSelection_ ) {
381  // get the global track
382  reco::GsfTrackRef track = PfTk;
383 
384  // Make sure the collection it points to is there
385  if ( track.isNonnull() && track.isAvailable() ) {
386 
387  reco::TransientTrack tt = trackBuilder->build(track);
388  embedHighLevel( anElectron,
389  track,
390  tt,
391  primaryVertex,
392  primaryVertexIsValid,
393  beamSpot,
394  beamSpotIsValid );
395 
396  std::pair<bool,Measurement1D> ip3dpv = IPTools::absoluteImpactParameter3D(tt, primaryVertex);
397  ip3d = ip3dpv.second.value(); // for mva variable
398  }
399  }
400 
401  //Electron Id
402 
403  if (addElecID_) {
404  //STANDARD EL ID
405  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
406  ids[i].second = (*idhandles[i])[elecsRef];
407  }
408  //SPECIFIC PF ID
409  ids.push_back(std::make_pair("pf_evspi",pfRef->mva_e_pi()));
410  ids.push_back(std::make_pair("pf_evsmu",pfRef->mva_e_mu()));
411  anElectron.setElectronIDs(ids);
412  }
413 
414  // add missing mva variables
415  std::vector<float> vCov = lazyTools.localCovariances(*( itElectron->superCluster()->seed()));
416  anElectron.setMvaVariables(vCov[1], ip3d);
417  // PFClusterIso
418  if (addPFClusterIso_) {
419  // Get PFCluster Isolation
420  edm::Handle<edm::ValueMap<float> > ecalPFClusterIsoMapH;
421  iEvent.getByToken(ecalPFClusterIsoT_, ecalPFClusterIsoMapH);
422  edm::Handle<edm::ValueMap<float> > hcalPFClusterIsoMapH;
423  iEvent.getByToken(hcalPFClusterIsoT_, hcalPFClusterIsoMapH);
424 
425  anElectron.setEcalPFClusterIso((*ecalPFClusterIsoMapH)[elecsRef]);
426  anElectron.setHcalPFClusterIso((*hcalPFClusterIsoMapH)[elecsRef]);
427  } else {
428  anElectron.setEcalPFClusterIso(-999.);
429  anElectron.setHcalPFClusterIso(-999.);
430  }
431 
432  std::vector<DetId> selectedCells;
433  bool barrel = itElectron->isEB();
434  //loop over sub clusters
435  if (embedBasicClusters_) {
436  for (reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin(); clusIt!=itElectron->superCluster()->clustersEnd(); ++clusIt) {
437  //get seed (max energy xtal)
438  DetId seed = lazyTools.getMaximum(**clusIt).first;
439  //get all xtals in 5x5 window around the seed
440  std::vector<DetId> dets5x5 = (barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5):
442  selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
443 
444  //get all xtals belonging to cluster
445  for (const std::pair<DetId, float> &hit : (*clusIt)->hitsAndFractions()) {
446  selectedCells.push_back(hit.first);
447  }
448  }
449  }
450 
451  if (embedPflowBasicClusters_ && itElectron->parentSuperCluster().isNonnull()) {
452  for (reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin(); clusIt!=itElectron->parentSuperCluster()->clustersEnd(); ++clusIt) {
453  //get seed (max energy xtal)
454  DetId seed = lazyTools.getMaximum(**clusIt).first;
455  //get all xtals in 5x5 window around the seed
456  std::vector<DetId> dets5x5 = (barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5):
458  selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
459 
460  //get all xtals belonging to cluster
461  for (const std::pair<DetId, float> &hit : (*clusIt)->hitsAndFractions()) {
462  selectedCells.push_back(hit.first);
463  }
464  }
465  }
466 
467  //remove duplicates
468  std::sort(selectedCells.begin(),selectedCells.end());
469  std::unique(selectedCells.begin(),selectedCells.end());
470 
471 
472  // Retrieve the corresponding RecHits
473 
475  if(barrel)
477  else
479 
480  EcalRecHitCollection selectedRecHits;
481  const EcalRecHitCollection *recHits = rechitsH.product();
482 
483  unsigned nSelectedCells = selectedCells.size();
484  for (unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
485  EcalRecHitCollection::const_iterator it = recHits->find( selectedCells[icell] );
486  if ( it != recHits->end() ) {
487  selectedRecHits.push_back(*it);
488  }
489  }
490  selectedRecHits.sort();
491  if (embedRecHits_) anElectron.embedRecHits(& selectedRecHits);
492 
493  // set conversion veto selection
494  bool passconversionveto = false;
495  if( hConversions.isValid()){
496  // this is recommended method
497  passconversionveto = !ConversionTools::hasMatchedConversion( *itElectron, hConversions, beamSpotHandle->position());
498  }else{
499  // use missing hits without vertex fit method
500  passconversionveto = itElectron->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < 1;
501  }
502 
503  anElectron.setPassConversionVeto( passconversionveto );
504 
505 
506 // fillElectron(anElectron,elecsRef,pfBaseRef,
507 // genMatches, deposits, isolationValues);
508 
509  //COLIN small warning !
510  // we are currently choosing to take the 4-momentum of the PFCandidate;
511  // the momentum of the GsfElectron is saved though
512  // we must therefore match the GsfElectron.
513  // because of this, we should not change the source of the electron matcher
514  // to the collection of PFElectrons in the python configuration
515  // I don't know what to do with the efficiencyLoader, since I don't know
516  // what this class is for.
517  fillElectron2( anElectron,
518  ptrToPFElectron,
519  ptrToGsfElectron,
520  ptrToGsfElectron,
521  genMatches, deposits, isolationValues );
522 
523  //COLIN need to use fillElectron2 in the non-pflow case as well, and to test it.
524 
525  patElectrons->push_back(anElectron);
526  }
527  }
528  //if( !Matched && !MatchedToAmbiguousGsfTrack) std::cout << "!!!!A pf electron could not be matched to a gsf!!!!" << std::endl;
529  }
530  }
531 
532  else{
533  // Try to access PF electron collection
535  bool valMapPresent = iEvent.getByToken(pfCandidateMapToken_,ValMapH);
536  // Try to access a PFCandidate collection, as supplied by the user
538  bool pfCandsPresent = iEvent.getByToken(pfElecToken_, pfElectrons);
539 
540  for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end(); ++itElectron) {
541  // construct the Electron from the ref -> save ref to original object
542  //FIXME: looks like a lot of instances could be turned into const refs
543  unsigned int idx = itElectron - electrons->begin();
544  edm::RefToBase<reco::GsfElectron> elecsRef = electrons->refAt(idx);
545  reco::CandidateBaseRef elecBaseRef(elecsRef);
546  Electron anElectron(elecsRef);
547  auto elePtr = electrons -> ptrAt(idx);
548 
549  // Is this GsfElectron also identified as an e- in the particle flow?
550  bool pfId = false;
551 
552  if ( pfCandsPresent ) {
553  // PF electron collection not available.
554  const reco::GsfTrackRef& trkRef = itElectron->gsfTrack();
555  int index = 0;
556  for( reco::PFCandidateConstIterator ie = pfElectrons->begin();
557  ie != pfElectrons->end(); ++ie, ++index) {
558  if(ie->particleId()!=reco::PFCandidate::e) continue;
559  const reco::GsfTrackRef& pfTrkRef= ie->gsfTrackRef();
560  if( trkRef == pfTrkRef ) {
561  pfId = true;
562  reco::PFCandidateRef pfRef(pfElectrons, index);
563  anElectron.setPFCandidateRef( pfRef );
564  break;
565  }
566  }
567  }
568  else if( valMapPresent ) {
569  // use value map if PF collection not available
570  const edm::ValueMap<reco::PFCandidatePtr> & myValMap(*ValMapH);
571  // Get the PFCandidate
572  const reco::PFCandidatePtr& pfElePtr(myValMap[elecsRef]);
573  pfId= pfElePtr.isNonnull();
574  }
575  // set PFId function
576  anElectron.setIsPF( pfId );
577 
578  // add resolution info
579 
580  // Isolation
581  if (isolator_.enabled()) {
582  isolator_.fill(*electrons, idx, isolatorTmpStorage_);
583  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
584  // better to loop backwards, so the vector is resized less times
585  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(), ed = isolatorTmpStorage_.rend(); it != ed; ++it) {
586  anElectron.setIsolation(it->first, it->second);
587  }
588  }
589 
590  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
591  anElectron.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[elecsRef]);
592  }
593 
594  // add electron ID info
595  if (addElecID_) {
596  for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
597  ids[i].second = (*idhandles[i])[elecsRef];
598  }
599  anElectron.setElectronIDs(ids);
600  }
601 
602 
603  if ( useUserData_ ) {
604  userDataHelper_.add( anElectron, iEvent, iSetup );
605  }
606 
607 
608  double ip3d = -999; //for mva variable
609 
610  // embed high level selection
611  if ( embedHighLevelSelection_ ) {
612  // get the global track
613  reco::GsfTrackRef track = itElectron->gsfTrack();
614 
615  // Make sure the collection it points to is there
616  if ( track.isNonnull() && track.isAvailable() ) {
617 
618  reco::TransientTrack tt = trackBuilder->build(track);
619  embedHighLevel( anElectron,
620  track,
621  tt,
622  primaryVertex,
623  primaryVertexIsValid,
624  beamSpot,
625  beamSpotIsValid );
626 
627  std::pair<bool,Measurement1D> ip3dpv = IPTools::absoluteImpactParameter3D(tt, primaryVertex);
628  ip3d = ip3dpv.second.value(); // for mva variable
629 
630  }
631  }
632 
633  // add mva variables
634  std::vector<float> vCov = lazyTools.localCovariances(*( itElectron->superCluster()->seed()));
635  anElectron.setMvaVariables(vCov[1], ip3d);
636  // PFCluster Isolation
637  if (addPFClusterIso_) {
638  // Get PFCluster Isolation
639  edm::Handle<edm::ValueMap<float> > ecalPFClusterIsoMapH;
640  iEvent.getByToken(ecalPFClusterIsoT_, ecalPFClusterIsoMapH);
641  edm::Handle<edm::ValueMap<float> > hcalPFClusterIsoMapH;
642  iEvent.getByToken(hcalPFClusterIsoT_, hcalPFClusterIsoMapH);
643 
644  anElectron.setEcalPFClusterIso((*ecalPFClusterIsoMapH)[elecsRef]);
645  anElectron.setHcalPFClusterIso((*hcalPFClusterIsoMapH)[elecsRef]);
646  } else {
647  anElectron.setEcalPFClusterIso(-999.);
648  anElectron.setHcalPFClusterIso(-999.);
649  }
650  if (addPuppiIsolation_) {
651  anElectron.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[elePtr], (*PUPPIIsolation_neutral_hadrons)[elePtr], (*PUPPIIsolation_photons)[elePtr]);
652  anElectron.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[elePtr], (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr], (*PUPPINoLeptonsIsolation_photons)[elePtr]);
653  }
654  else {
655  anElectron.setIsolationPUPPI(-999., -999.,-999.);
656  anElectron.setIsolationPUPPINoLeptons(-999., -999.,-999.);
657  }
658 
659  std::vector<DetId> selectedCells;
660  bool barrel = itElectron->isEB();
661  //loop over sub clusters
662  if (embedBasicClusters_) {
663  for (reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin(); clusIt!=itElectron->superCluster()->clustersEnd(); ++clusIt) {
664  //get seed (max energy xtal)
665  DetId seed = lazyTools.getMaximum(**clusIt).first;
666  //get all xtals in 5x5 window around the seed
667  std::vector<DetId> dets5x5 = (barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5):
669  selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
670 
671  //get all xtals belonging to cluster
672  for (const std::pair<DetId, float> &hit : (*clusIt)->hitsAndFractions()) {
673  selectedCells.push_back(hit.first);
674  }
675  }
676  }
677 
678  if (embedPflowBasicClusters_ && itElectron->parentSuperCluster().isNonnull()) {
679  for (reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin(); clusIt!=itElectron->parentSuperCluster()->clustersEnd(); ++clusIt) {
680  //get seed (max energy xtal)
681  DetId seed = lazyTools.getMaximum(**clusIt).first;
682  //get all xtals in 5x5 window around the seed
683  std::vector<DetId> dets5x5 = (barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal,EcalBarrel)->getWindow(seed,5,5):
685  selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
686 
687  //get all xtals belonging to cluster
688  for (const std::pair<DetId, float> &hit : (*clusIt)->hitsAndFractions()) {
689  selectedCells.push_back(hit.first);
690  }
691  }
692  }
693 
694  //remove duplicates
695  std::sort(selectedCells.begin(),selectedCells.end());
696  std::unique(selectedCells.begin(),selectedCells.end());
697 
698  // Retrieve the corresponding RecHits
699 
701  if(barrel)
703  else
705 
706  EcalRecHitCollection selectedRecHits;
707  const EcalRecHitCollection *recHits = rechitsH.product();
708 
709  unsigned nSelectedCells = selectedCells.size();
710  for (unsigned icell = 0 ; icell < nSelectedCells ; ++icell) {
711  EcalRecHitCollection::const_iterator it = recHits->find( selectedCells[icell] );
712  if ( it != recHits->end() ) {
713  selectedRecHits.push_back(*it);
714  }
715  }
716  selectedRecHits.sort();
717  if (embedRecHits_) anElectron.embedRecHits(& selectedRecHits);
718 
719  // set conversion veto selection
720  bool passconversionveto = false;
721  if( hConversions.isValid()){
722  // this is recommended method
723  passconversionveto = !ConversionTools::hasMatchedConversion( *itElectron, hConversions, beamSpotHandle->position());
724  }else{
725  // use missing hits without vertex fit method
726  passconversionveto = itElectron->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < 1;
727  }
728  anElectron.setPassConversionVeto( passconversionveto );
729 
730  // add sel to selected
731  fillElectron( anElectron, elecsRef,elecBaseRef,
732  genMatches, deposits, pfId, isolationValues, isolationValuesNoPFId);
733  patElectrons->push_back(anElectron);
734  }
735  }
736 
737  // sort electrons in pt
738  std::sort(patElectrons->begin(), patElectrons->end(), pTComparator_);
739 
740  // add the electrons to the event output
741  std::unique_ptr<std::vector<Electron> > ptr(patElectrons);
742  iEvent.put(std::move(ptr));
743 
744  // clean up
746 
747 }
748 
750  const edm::RefToBase<reco::GsfElectron>& elecRef,
751  const reco::CandidateBaseRef& baseRef,
752  const GenAssociations& genMatches,
753  const IsoDepositMaps& deposits,
754  const bool pfId,
757  ) const {
758 
759  //COLIN: might want to use the PFCandidate 4-mom. Which one is in use now?
760  // if (useParticleFlow_)
761  // aMuon.setP4( aMuon.pfCandidateRef()->p4() );
762 
763  //COLIN:
764  //In the embedding case, the reference cannot be used to look into a value map.
765  //therefore, one has to had the PFCandidateRef to this function, which becomes a bit
766  //too much specific.
767 
768  // in fact, this function needs a baseref or ptr for genmatch
769  // and a baseref or ptr for isodeposits and isolationvalues.
770  // baseref is not needed
771  // the ptrForIsolation and ptrForMatching should be defined upstream.
772 
773  // is the concrete elecRef needed for the efficiency loader? what is this loader?
774  // how can we make it compatible with the particle flow electrons?
775 
777  if (embedGsfTrack_) anElectron.embedGsfTrack();
778  if (embedSuperCluster_) anElectron.embedSuperCluster();
780  if (embedSeedCluster_) anElectron.embedSeedCluster();
781  if (embedBasicClusters_) anElectron.embedBasicClusters();
785  if (embedTrack_) anElectron.embedTrack();
786 
787  // store the match to the generated final state muons
788  if (addGenMatch_) {
789  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
790  if(useParticleFlow_) {
791  reco::GenParticleRef genElectron = (*genMatches[i])[anElectron.pfCandidateRef()];
792  anElectron.addGenParticleRef(genElectron);
793  }
794  else {
795  reco::GenParticleRef genElectron = (*genMatches[i])[elecRef];
796  anElectron.addGenParticleRef(genElectron);
797  }
798  }
799  if (embedGenMatch_) anElectron.embedGenParticle();
800  }
801 
802  if (efficiencyLoader_.enabled()) {
803  efficiencyLoader_.setEfficiencies( anElectron, elecRef );
804  }
805 
806  if (resolutionLoader_.enabled()) {
807  resolutionLoader_.setResolutions(anElectron);
808  }
809 
810  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
811  if(useParticleFlow_) {
812 
813  reco::PFCandidateRef pfcandref = anElectron.pfCandidateRef();
814  assert(!pfcandref.isNull());
815  reco::CandidatePtr source = pfcandref->sourceCandidatePtr(0);
816  anElectron.setIsoDeposit(isoDepositLabels_[j].first,
817  (*deposits[j])[source]);
818  }
819  else
820  anElectron.setIsoDeposit(isoDepositLabels_[j].first,
821  (*deposits[j])[elecRef]);
822  }
823 
824  for (size_t j = 0; j<isolationValues.size(); ++j) {
825  if(useParticleFlow_) {
826  reco::CandidatePtr source = anElectron.pfCandidateRef()->sourceCandidatePtr(0);
828  (*isolationValues[j])[source]);
829  }
830  else
831  if(pfId){
832  anElectron.setIsolation(isolationValueLabels_[j].first,(*isolationValues[j])[elecRef]);
833  }
834  }
835 
836  //for electrons not identified as PF electrons
837  for (size_t j = 0; j<isolationValuesNoPFId.size(); ++j) {
838  if( !pfId) {
839  anElectron.setIsolation(isolationValueLabelsNoPFId_[j].first,(*isolationValuesNoPFId[j])[elecRef]);
840  }
841  }
842 
843 }
844 
846  const reco::CandidatePtr& candPtrForIsolation,
847  const reco::CandidatePtr& candPtrForGenMatch,
848  const reco::CandidatePtr& candPtrForLoader,
849  const GenAssociations& genMatches,
850  const IsoDepositMaps& deposits,
851  const IsolationValueMaps& isolationValues) const {
852 
853  //COLIN/Florian: use the PFCandidate 4-mom.
854  anElectron.setEcalDrivenMomentum(anElectron.p4()) ;
855  anElectron.setP4( anElectron.pfCandidateRef()->p4() );
856 
857 
858  // is the concrete elecRef needed for the efficiency loader? what is this loader?
859  // how can we make it compatible with the particle flow electrons?
860 
862  if (embedGsfTrack_) anElectron.embedGsfTrack();
863  if (embedSuperCluster_) anElectron.embedSuperCluster();
865  if (embedSeedCluster_) anElectron.embedSeedCluster();
866  if (embedBasicClusters_) anElectron.embedBasicClusters();
870  if (embedTrack_) anElectron.embedTrack();
871 
872  // store the match to the generated final state muons
873 
874  if (addGenMatch_) {
875  for(size_t i = 0, n = genMatches.size(); i < n; ++i) {
876  reco::GenParticleRef genElectron = (*genMatches[i])[candPtrForGenMatch];
877  anElectron.addGenParticleRef(genElectron);
878  }
879  if (embedGenMatch_) anElectron.embedGenParticle();
880  }
881 
882  //COLIN what's this? does it have to be GsfElectron specific?
883  if (efficiencyLoader_.enabled()) {
884  efficiencyLoader_.setEfficiencies( anElectron, candPtrForLoader );
885  }
886 
887  if (resolutionLoader_.enabled()) {
888  resolutionLoader_.setResolutions(anElectron);
889  }
890 
891  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
895  deposits[j]->contains(candPtrForGenMatch.id())) {
896  anElectron.setIsoDeposit(isoDepositLabels_[j].first,
897  (*deposits[j])[candPtrForGenMatch]);
898  }
899  else if (deposits[j]->contains(candPtrForIsolation.id())) {
900  anElectron.setIsoDeposit(isoDepositLabels_[j].first,
901  (*deposits[j])[candPtrForIsolation]);
902  }
903  else {
904  anElectron.setIsoDeposit(isoDepositLabels_[j].first,
905  (*deposits[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
906  }
907  }
908 
909  for (size_t j = 0; j<isolationValues.size(); ++j) {
913  isolationValues[j]->contains(candPtrForGenMatch.id())) {
915  (*isolationValues[j])[candPtrForGenMatch]);
916  }
917  else if (isolationValues[j]->contains(candPtrForIsolation.id())) {
919  (*isolationValues[j])[candPtrForIsolation]);
920  }
921  else {
923  (*isolationValues[j])[candPtrForIsolation->sourceCandidatePtr(0)]);
924  }
925  }
926 }
927 
928 
929 // ParameterSet description for module
931 {
933  iDesc.setComment("PAT electron producer module");
934 
935  // input source
936  iDesc.add<edm::InputTag>("pfCandidateMap", edm::InputTag("no default"))->setComment("input collection");
937  iDesc.add<edm::InputTag>("electronSource", edm::InputTag("no default"))->setComment("input collection");
938 
939  iDesc.ifValue(edm::ParameterDescription<bool>("addPFClusterIso", false, true),
940  true >> (edm::ParameterDescription<edm::InputTag>("ecalPFClusterIsoMap", edm::InputTag("electronEcalPFClusterIsolationProducer"), true) and
941  edm::ParameterDescription<edm::InputTag>("hcalPFClusterIsoMap", edm::InputTag("electronHcalPFClusterIsolationProducer"),true)) or
942  false >> (edm::ParameterDescription<edm::InputTag>("ecalPFClusterIsoMap", edm::InputTag(""), true) and
943  edm::ParameterDescription<edm::InputTag>("hcalPFClusterIsoMap", edm::InputTag(""),true)));
944 
945  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
946  true >> (edm::ParameterDescription<edm::InputTag>("puppiIsolationChargedHadrons", edm::InputTag("egmElectronPUPPIIsolation","h+-DR030-BarVeto000-EndVeto001"), true) and
947  edm::ParameterDescription<edm::InputTag>("puppiIsolationNeutralHadrons", edm::InputTag("egmElectronPUPPIIsolation","h0-DR030-BarVeto000-EndVeto000"), true) and
948  edm::ParameterDescription<edm::InputTag>("puppiIsolationPhotons", edm::InputTag("egmElectronPUPPIIsolation","gamma-DR030-BarVeto000-EndVeto008"), true) and
949  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons", edm::InputTag("egmElectronPUPPINoLeptonsIsolation","gamma-DR030-BarVeto000-EndVeto008"), true) and
950  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons", edm::InputTag("egmElectronPUPPINoLeptonsIsolation","gamma-DR030-BarVeto000-EndVeto008"), true) and
951  edm::ParameterDescription<edm::InputTag>("puppiNoLeptonsIsolationPhotons", edm::InputTag("egmElectronPUPPINoLeptonsIsolation","gamma-DR030-BarVeto000-EndVeto008"), true)) or
952  false >> edm::EmptyGroupDescription());
953 
954 
955  // embedding
956  iDesc.add<bool>("embedGsfElectronCore", true)->setComment("embed external gsf electron core");
957  iDesc.add<bool>("embedGsfTrack", true)->setComment("embed external gsf track");
958  iDesc.add<bool>("embedSuperCluster", true)->setComment("embed external super cluster");
959  iDesc.add<bool>("embedPflowSuperCluster", true)->setComment("embed external super cluster");
960  iDesc.add<bool>("embedSeedCluster", true)->setComment("embed external seed cluster");
961  iDesc.add<bool>("embedBasicClusters", true)->setComment("embed external basic clusters");
962  iDesc.add<bool>("embedPreshowerClusters", true)->setComment("embed external preshower clusters");
963  iDesc.add<bool>("embedPflowBasicClusters", true)->setComment("embed external pflow basic clusters");
964  iDesc.add<bool>("embedPflowPreshowerClusters", true)->setComment("embed external pflow preshower clusters");
965  iDesc.add<bool>("embedTrack", false)->setComment("embed external track");
966  iDesc.add<bool>("embedRecHits", true)->setComment("embed external RecHits");
967 
968  // pf specific parameters
969  iDesc.add<edm::InputTag>("pfElectronSource", edm::InputTag("pfElectrons"))->setComment("particle flow input collection");
970  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
971  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
972 
973  // MC matching configurables
974  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
975  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
976  std::vector<edm::InputTag> emptySourceVector;
977  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
978  edm::ParameterDescription<std::vector<edm::InputTag> >("genParticleMatch", emptySourceVector, true)
979  )->setComment("input with MC match information");
980 
981  // electron ID configurables
982  iDesc.add<bool>("addElectronID",true)->setComment("add electron ID variables");
983  edm::ParameterSetDescription electronIDSourcesPSet;
984  electronIDSourcesPSet.setAllowAnything();
985  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("electronIDSource", edm::InputTag(), true) xor
986  edm::ParameterDescription<edm::ParameterSetDescription>("electronIDSources", electronIDSourcesPSet, true)
987  )->setComment("input with electron ID variables");
988 
989 
990  // IsoDeposit configurables
991  edm::ParameterSetDescription isoDepositsPSet;
992  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
993  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
994  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
995  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
996  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
997  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
998  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
999  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1000  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
1001  isoDepositsPSet.addOptional<std::vector<edm::InputTag> >("user");
1002  iDesc.addOptional("isoDeposits", isoDepositsPSet);
1003 
1004  // isolation values configurables
1005  edm::ParameterSetDescription isolationValuesPSet;
1006  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
1007  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
1008  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
1009  isolationValuesPSet.addOptional<edm::InputTag>("pfAllParticles");
1010  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1011  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
1012  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1013  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1014  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
1015  isolationValuesPSet.addOptional<std::vector<edm::InputTag> >("user");
1016  iDesc.addOptional("isolationValues", isolationValuesPSet);
1017 
1018  // isolation values configurables
1019  edm::ParameterSetDescription isolationValuesNoPFIdPSet;
1020  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("tracker");
1021  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("ecal");
1022  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("hcal");
1023  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfAllParticles");
1024  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1025  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfChargedAll");
1026  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1027  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1028  isolationValuesNoPFIdPSet.addOptional<edm::InputTag>("pfPhotons");
1029  isolationValuesNoPFIdPSet.addOptional<std::vector<edm::InputTag> >("user");
1030  iDesc.addOptional("isolationValuesNoPFId", isolationValuesNoPFIdPSet);
1031 
1032  // Efficiency configurables
1033  edm::ParameterSetDescription efficienciesPSet;
1034  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1035  iDesc.add("efficiencies", efficienciesPSet);
1036  iDesc.add<bool>("addEfficiencies", false);
1037 
1038  // Check to see if the user wants to add user data
1039  edm::ParameterSetDescription userDataPSet;
1041  iDesc.addOptional("userData", userDataPSet);
1042 
1043 
1044  // electron shapes
1045  iDesc.add<bool>("addElectronShapes", true);
1046  iDesc.add<edm::InputTag>("reducedBarrelRecHitCollection", edm::InputTag("reducedEcalRecHitsEB"));
1047  iDesc.add<edm::InputTag>("reducedEndcapRecHitCollection", edm::InputTag("reducedEcalRecHitsEE"));
1048 
1049  edm::ParameterSetDescription isolationPSet;
1050  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1051  iDesc.add("userIsolation", isolationPSet);
1052 
1053  // Resolution configurables
1055 
1056  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
1057  edm::ParameterSetDescription highLevelPSet;
1058  highLevelPSet.setAllowAnything();
1059  iDesc.addNode( edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true)
1060  )->setComment("input with high level selection");
1062  )->setComment("input with high level selection");
1063 
1064  descriptions.add("PATElectronProducer", iDesc);
1065 
1066 }
1067 
1068 
1069 // embed various impact parameters with errors
1070 // embed high level selection
1075  bool primaryVertexIsValid,
1077  bool beamspotIsValid
1078  )
1079 {
1080  // Correct to PV
1081 
1082  // PV2D
1083  std::pair<bool,Measurement1D> result =
1085  GlobalVector(track->px(),
1086  track->py(),
1087  track->pz()),
1088  primaryVertex);
1089  double d0_corr = result.second.value();
1090  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1091  anElectron.setDB( d0_corr, d0_err, pat::Electron::PV2D);
1092 
1093 
1094  // PV3D
1095  result =
1097  GlobalVector(track->px(),
1098  track->py(),
1099  track->pz()),
1100  primaryVertex);
1101  d0_corr = result.second.value();
1102  d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1103  anElectron.setDB( d0_corr, d0_err, pat::Electron::PV3D);
1104 
1105 
1106  // Correct to beam spot
1107  // make a fake vertex out of beam spot
1108  reco::Vertex vBeamspot(beamspot.position(), beamspot.covariance3D());
1109 
1110  // BS2D
1111  result =
1113  GlobalVector(track->px(),
1114  track->py(),
1115  track->pz()),
1116  vBeamspot);
1117  d0_corr = result.second.value();
1118  d0_err = beamspotIsValid ? result.second.error() : -1.0;
1119  anElectron.setDB( d0_corr, d0_err, pat::Electron::BS2D);
1120 
1121  // BS3D
1122  result =
1124  GlobalVector(track->px(),
1125  track->py(),
1126  track->pz()),
1127  vBeamspot);
1128  d0_corr = result.second.value();
1129  d0_err = beamspotIsValid ? result.second.error() : -1.0;
1130  anElectron.setDB( d0_corr, d0_err, pat::Electron::BS3D);
1131 }
1132 
1134 
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T > > > &tokens)
void setMvaVariables(double sigmaIetaIphi, double ip3d)
set missing mva input variables
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
bool isAvailable() const
Definition: Ref.h:576
T getParameter(std::string const &) const
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
void embedRecHits(const EcalRecHitCollection *rechits)
method to store the RecHits internally - can be called from the PATElectronProducer ...
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:199
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::ConversionCollection > hConversionsToken_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:98
const GreaterByPt< Electron > pTComparator_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
const bool useParticleFlow_
pflow specific
void setElectronIDs(const std::vector< IdPair > &ids)
Store multiple electron ID values, discarding existing ones. The first one in the list becomes the &#39;d...
Definition: Electron.h:146
static const HistoName names[]
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:118
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
const edm::EDGetTokenT< reco::PFCandidateCollection > pfElecToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
const edm::EDGetTokenT< edm::ValueMap< float > > ecalPFClusterIsoT_
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
void embedSuperCluster()
method to store the electron&#39;s SuperCluster internally
void embedHighLevel(pat::Electron &anElectron, reco::GsfTrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
std::vector< EcalRecHit >::const_iterator const_iterator
reco::TransientTrack build(const reco::Track *p) const
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
Definition: Electron.h:193
void fillElectron(Electron &aElectron, const ElectronBaseRef &electronRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const bool pfId, const IsolationValueMaps &isolationValues, const IsolationValueMaps &isolationValuesNoPFId) const
common electron filling, for both the standard and PF2PAT case
void push_back(T const &t)
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
void embedGsfElectronCore()
method to store the electron&#39;s core internally
void setPassConversionVeto(bool flag)
Definition: Electron.h:267
const edm::EDGetTokenT< edm::ValueMap< float > > hcalPFClusterIsoT_
void setHcalPFClusterIso(float hcalPFClus)
Definition: Electron.h:161
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setEcalDrivenMomentum(const Candidate::LorentzVector &mom)
Definition: Electron.h:220
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > elecIDTokens_
bool isRealData() const
Definition: EventBase.h:62
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > electronToken_
void embedPflowSuperCluster()
method to store the electron&#39;s PflowSuperCluster internally
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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:175
Definition: HeavyIon.h:7
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:50
const edm::EDGetTokenT< edm::ValueMap< reco::PFCandidatePtr > > pfCandidateMapToken_
void setComment(std::string const &value)
pat::helper::MultiIsolator isolator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
void setDB(double dB, double edB, IPTYPE type)
Set impact parameter of a certain type and its uncertainty.
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
int iEvent
Definition: GenABIO.cc:230
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
Produces pat::Electron&#39;s.
void embedSeedCluster()
method to store the electron&#39;s seedcluster internally
PATElectronProducer(const edm::ParameterSet &iConfig)
const bool embedHighLevelSelection_
embed high level selection variables?
reco::PFCandidateRef pfCandidateRef() const
reference to the source PFCandidates; null if this has been built from a standard electron ...
void embedGenParticle()
Definition: PATObject.h:694
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
def unique(seq, keepstr=True)
Definition: tier0.py:24
void setIsolationPUPPINoLeptons(float chargedhadrons_, float neutralhadrons_, float photons_)
sets PUPPINoLeptons isolations
Definition: Electron.h:179
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
const edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
void embedPflowBasicClusters()
method to store the electron&#39;s pflow basic clusters
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void embedBasicClusters()
method to store the electron&#39;s basic clusters
bool isValid() const
Definition: HandleBase.h:74
std::pair< std::string, edm::InputTag > NameTag
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_photons_
static bool hasMatchedConversion(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)
bool isNull() const
Checks for null.
Definition: Ref.h:249
void embedGsfTrack()
method to store the electron&#39;s GsfTrack internally
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
std::vector< Conversion > ConversionCollection
Definition: Conversion.h:13
const_iterator end() const
Definition: DetId.h:18
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
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:678
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueNoPFIdTokens_
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void setEcalPFClusterIso(float ecalPFClus)
Definition: Electron.h:160
pat::helper::EfficiencyLoader efficiencyLoader_
const edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
void setIsPF(bool hasPFCandidate)
Definition: Electron.h:188
const T & get() const
Definition: EventSetup.h:56
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.
Analysis-level electron class.
Definition: Electron.h:52
const CaloTopology * ecalTopology_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:26
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:181
IsolationLabels isolationValueLabelsNoPFId_
void embedPreshowerClusters()
method to store the electron&#39;s preshower clusters
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
iterator find(key_type k)
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
IsolationLabels isolationValueLabels_
size_type size() const
pat::helper::KinResolutionsLoader resolutionLoader_
const Point & position() const
position
Definition: BeamSpot.h:62
void embedPflowPreshowerClusters()
method to store the electron&#39;s pflow preshower clusters
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
void embedTrack()
method to store the electron&#39;s Track internally
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
void setIsolationPUPPI(float chargedhadrons_, float neutralhadrons_, float photons_)
sets PUPPI isolations
Definition: Electron.h:171
static std::string const source
Definition: EdmProvDump.cc:43
def move(src, dest)
Definition: eostools.py:510
void embedPFCandidate()
embed the PFCandidate pointed to by pfCandidateRef_
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
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps