CMS 3D CMS Logo

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