CMS 3D CMS Logo

EgammaHLTElectronCombinedIsolationProducer.cc
Go to the documentation of this file.
1 
12 
14 
15  electronProducer_ = consumes<reco::ElectronCollection>(conf_.getParameter<edm::InputTag>("electronProducer"));
16  recoEcalCandidateProducer_ = consumes<reco::RecoEcalCandidateCollection>(conf_.getParameter<edm::InputTag>("recoEcalCandidateProducer"));
17 
18  for (edm::InputTag const & tag : conf_.getParameter< std::vector<edm::InputTag> > ("CaloIsolationMapTags"))
19  CaloIsolTag_.push_back(consumes<reco::RecoEcalCandidateIsolationMap>(tag));
20 
21  TrackIsolTag_ = consumes<reco::ElectronIsolationMap>(conf_.getParameter<edm::InputTag>("TrackIsolationMapTag"));
22 
23  CaloIsolWeight_ = conf_.getParameter< std::vector<double> > ("CaloIsolationWeight");
24  TrackIsolWeight_ = conf_.getParameter<double>("TrackIsolationWeight");
25 
26  if (CaloIsolTag_.size() != CaloIsolWeight_.size()){
27  throw cms::Exception("BadConfig") << "vectors CaloIsolationMapTags and CaloIsolationWeight need to have size 3";
28  }
29 
30  //register your products
31  produces < reco::ElectronIsolationMap >();
32 }
33 
35 {}
36 
38 
40  desc.add<edm::InputTag>("electronProducer", edm::InputTag(""));
41  desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag(""));
42  desc.add<std::vector<edm::InputTag> >("CaloIsolationMapTags", std::vector<edm::InputTag>());
43  desc.add<edm::InputTag>("TrackIsolationMapTag", edm::InputTag(""));
44 desc.add<std::vector<double> >("CaloIsolationWeight", std::vector<double>());
45  desc.add<double>("TrackIsolationWeight", 0);
46  descriptions.add("hltEgammaHLTElectronCombinedIsolationProducer", desc);
47 }
48 
50 
52  iEvent.getByToken(electronProducer_,electronHandle);
53 
55  iEvent.getByToken(recoEcalCandidateProducer_,recoecalcandHandle);
56 
57  std::vector< edm::Handle<reco::RecoEcalCandidateIsolationMap> > CaloIsoMap;
58  for( unsigned int u=0; u < CaloIsolTag_.size(); u++){
60  if(CaloIsolWeight_[u] != 0)
61  iEvent.getByToken(CaloIsolTag_[u],depMapTemp);
62 
63  CaloIsoMap.push_back(depMapTemp);
64  }
65 
67  if(TrackIsolWeight_ != 0)
68  iEvent.getByToken(TrackIsolTag_,TrackIsoMap);
69 
70  reco::ElectronIsolationMap TotalIsolMap(electronHandle);
71  double TotalIso=0;
72  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
73  TotalIso=0;
74  reco::ElectronRef electronref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
75  const reco::SuperClusterRef theEleClus = electronref->superCluster();
76 
77  //look for corresponding recoecal candidates to search for in the ecal and Hcal iso map
78  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoecalcandHandle->begin(); iRecoEcalCand != recoecalcandHandle->end(); iRecoEcalCand++){
79  reco::RecoEcalCandidateRef recoecalcandref(recoecalcandHandle,iRecoEcalCand-recoecalcandHandle->begin());
80  const reco::SuperClusterRef cluster = recoecalcandref->superCluster();
81  if(&(*cluster) == &(*theEleClus)) {//recoecalcand and electron have the same SC
82  for(unsigned int u=0; u < CaloIsolTag_.size() ;u++){
83  if(CaloIsolWeight_[u]==0){continue;}
84  reco::RecoEcalCandidateIsolationMap::const_iterator mapi = (*CaloIsoMap[u]).find( recoecalcandref );
85  TotalIso += mapi->val * CaloIsolWeight_[u];
86  }
87  break;
88  }
89  }
90 
91  //add the track isolation
92  if(TrackIsolWeight_ != 0){
93  reco::ElectronIsolationMap::const_iterator mapi = (*TrackIsoMap).find( electronref );
94  TotalIso += mapi->val * TrackIsolWeight_;
95  }
96  TotalIsolMap.insert(electronref, TotalIso);
97 
98  }
99 
100  iEvent.put(std::make_unique<reco::ElectronIsolationMap>(TotalIsolMap));
101 
102 }
103 
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
Definition: config.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
std::vector< edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > > CaloIsolTag_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void insert(const key_type &k, const data_type &v)
insert an association
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::ElectronIsolationMap > TrackIsolTag_