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 
9 
10 // Framework
17 
20 
23 
25 
26 
30 
31 
33 {
34 
35  electronProducer_ = conf_.getParameter<edm::InputTag>("electronProducer");
36  recoEcalCandidateProducer_ = conf_.getParameter<edm::InputTag>("recoEcalCandidateProducer");
37 
38  CaloIsolTag_ = conf_.getParameter< std::vector<edm::InputTag> > ("CaloIsolationMapTags");
39  //need to be in the order EcalIso, HcalIso, EleTrackIso
40  CaloIsolWeight_ = conf_.getParameter< std::vector<double> > ("CaloIsolationWeight");
41 
42  TrackIsolTag_ = conf_.getParameter<edm::InputTag>("TrackIsolationMapTag");
43  TrackIsolWeight_ = conf_.getParameter<double>("TrackIsolationWeight");
44 
45  if ( CaloIsolTag_.size() != CaloIsolWeight_.size()){
46  throw cms::Exception("BadConfig") << "vectors CaloIsolationMapTags and CaloIsolationWeight need to have size 3";
47  }
48 
49 
50  // SCProducer_ = conf_.getParameter<edm::InputTag>("electronProducer");
51 
52  //register your products
53  produces < reco::ElectronIsolationMap >();
54 
55 }
57 
58 
60 {
61 
62  using namespace std;
63 
65  iEvent.getByLabel(electronProducer_,electronHandle);
66 
68  iEvent.getByLabel(recoEcalCandidateProducer_,recoecalcandHandle);
69 
70  std::vector< edm::Handle<reco::RecoEcalCandidateIsolationMap> > CaloIsoMap;
71  for( unsigned int u=0; u < CaloIsolTag_.size(); u++){
73  if(CaloIsolWeight_[u] != 0){ iEvent.getByLabel (CaloIsolTag_[u],depMapTemp);}
74  CaloIsoMap.push_back(depMapTemp);
75  }
76 
78  if(TrackIsolWeight_ != 0){ iEvent.getByLabel (TrackIsolTag_,TrackIsoMap);}
79 
80  reco::ElectronIsolationMap TotalIsolMap;
81  double TotalIso=0;
82  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
83  TotalIso=0;
84  reco::ElectronRef electronref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
85  const reco::SuperClusterRef theEleClus = electronref->superCluster();
86 
87  //look for corresponding recoecal candidates to search for in the ecal and Hcal iso map
88  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoecalcandHandle->begin(); iRecoEcalCand != recoecalcandHandle->end(); iRecoEcalCand++){
89  reco::RecoEcalCandidateRef recoecalcandref(recoecalcandHandle,iRecoEcalCand-recoecalcandHandle->begin());
90  const reco::SuperClusterRef cluster = recoecalcandref->superCluster();
91  if(&(*cluster) == &(*theEleClus)) {//recoecalcand and electron have the same SC
92  for(unsigned int u=0; u < CaloIsolTag_.size() ;u++){
93  if(CaloIsolWeight_[u]==0){continue;}
94  reco::RecoEcalCandidateIsolationMap::const_iterator mapi = (*CaloIsoMap[u]).find( recoecalcandref );
95  TotalIso += mapi->val * CaloIsolWeight_[u];
96  }
97  break;
98  }
99  }
100 
101  //add the track isolation
102  if(TrackIsolWeight_ != 0){
103  reco::ElectronIsolationMap::const_iterator mapi = (*TrackIsoMap).find( electronref );
104  TotalIso += mapi->val * TrackIsolWeight_;
105  }
106  TotalIsolMap.insert(electronref, TotalIso);
107 
108  }
109 
110  std::auto_ptr<reco::ElectronIsolationMap> isolMap(new reco::ElectronIsolationMap(TotalIsolMap));
111  iEvent.put(isolMap);
112 
113 }
114 
T getParameter(std::string const &) const
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:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356