CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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;
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  std::auto_ptr<reco::ElectronIsolationMap> isolMap(new reco::ElectronIsolationMap(TotalIsolMap));
101  iEvent.put(isolMap);
102 
103 }
104 
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void produce(edm::Event &, const edm::EventSetup &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
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_