CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTElectronDetaDphiProducer.cc
Go to the documentation of this file.
1 
10 
11 //#include "FWCore/Framework/interface/ESHandle.h"
12 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
13 //#include "FWCore/Utilities/interface/Exception.h"
14 
19 
25 
27 
34 
36 
37  electronProducer_ = consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("electronProducer"));
38  bsProducer_ = consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("BSProducer"));
39  recoEcalCandidateProducer_ = consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"));
40 
41  useSCRefs_ = config.getParameter<bool>("useSCRefs");
42  useTrackProjectionToEcal_ = config.getParameter<bool>("useTrackProjectionToEcal");
43  variablesAtVtx_ = config.getParameter<bool>("variablesAtVtx");
44 
45  //register your products
46  if(!useSCRefs_){
47  produces < reco::ElectronIsolationMap >( "Deta" ).setBranchAlias( "deta" );
48  produces < reco::ElectronIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
49  }else{
50  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
51  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
52  }
53 }
54 
56 {}
57 
60  desc.add<edm::InputTag>(("electronProducer"), edm::InputTag("hltEleAnyWP80PixelMatchElectronsL1Seeded"));
61  desc.add<edm::InputTag>(("BSProducer"), edm::InputTag("hltOnlineBeamSpot"));
62  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag());
63  desc.add<bool>(("useSCRefs"), false);
64  desc.add<bool>(("useTrackProjectionToEcal"), false);
65  desc.add<bool>(("variablesAtVtx"), true);
66  descriptions.add(("hltEgammaHLTElectronDetaDphiProducer"), desc);
67 }
68 
70  // Get the HLT filtered objects
72  iEvent.getByToken(electronProducer_,electronHandle);
73 
74  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
75  iEvent.getByToken(bsProducer_,recoBeamSpotHandle);
76  // gets its position
77  const reco::BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
78 
79  edm::ESHandle<MagneticField> theMagField;
80  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
81 
86 
87  if(!useSCRefs_){
88 
89  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
90 
91  reco::ElectronRef eleref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
92  std::pair<float,float> dEtaDPhi = calDEtaDPhiSCTrk(eleref,bsPosition,theMagField.product());
93 
94  detaMap.insert(eleref, dEtaDPhi.first);
95  dphiMap.insert(eleref, dEtaDPhi.second);
96  }
97  }else { //we loop over reco ecal candidates
99  iEvent.getByToken(recoEcalCandidateProducer_,recoEcalCandHandle);
100  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
101 
102  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
103 
104  reco::ElectronRef eleRef = getEleRef(recoEcalCandRef,electronHandle);
105  std::pair<float,float> dEtaDPhi(999999,999999);
106  if(eleRef.isNonnull()) dEtaDPhi = calDEtaDPhiSCTrk(eleRef,bsPosition,theMagField.product());
107  detaCandMap.insert(recoEcalCandRef, dEtaDPhi.first);
108  dphiCandMap.insert(recoEcalCandRef, dEtaDPhi.second);
109  }//end loop over reco ecal candidates
110  }//end if between electrons or reco ecal candidates
111 
112  if(!useSCRefs_){
113  std::auto_ptr<reco::ElectronIsolationMap> detMap(new reco::ElectronIsolationMap(detaMap));
114  std::auto_ptr<reco::ElectronIsolationMap> dphMap(new reco::ElectronIsolationMap(dphiMap));
115  iEvent.put(detMap, "Deta" );
116  iEvent.put(dphMap, "Dphi" );
117  }else{
118  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> detaCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(detaCandMap));
119  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dphiCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(dphiCandMap));
120  iEvent.put(detaCandMapForEvent, "Deta" );
121  iEvent.put(dphiCandMapForEvent, "Dphi" );
122  }
123 }
124 
125 std::pair<float,float> EgammaHLTElectronDetaDphiProducer::calDEtaDPhiSCTrk(reco::ElectronRef& eleref, const reco::BeamSpot::Point& bsPosition,const MagneticField *magField) {
126 
127  const reco::SuperClusterRef theClus = eleref->superCluster();
128  const math::XYZVector trackMom = eleref->track()->momentum();
129 
130  math::XYZPoint SCcorrPosition(theClus->x()-bsPosition.x(), theClus->y()-bsPosition.y() , theClus->z()-eleref->track()->vz() );
131  float deltaeta = fabs(SCcorrPosition.eta()-eleref->track()->eta());
132  float deltaphi = 999.;
133 
134  bool recoveryForFailingPropagation = false;
135  if (variablesAtVtx_) {
136  reco::TrackRef track = eleref->track();
138  TrajectoryStateOnSurface sclTSOS = tt.stateOnSurface(GlobalPoint(theClus->x(),theClus->y(),theClus->z()));
139 
140  if (sclTSOS.isValid()) {
141  EleRelPointPair scAtVtx(theClus->position(), sclTSOS.globalPosition(), bsPosition);
142  deltaeta = fabs(scAtVtx.dEta());
143  deltaphi = fabs(scAtVtx.dPhi());
144  } else {
145  recoveryForFailingPropagation = true;
146  }
147  } else if (useTrackProjectionToEcal_ or recoveryForFailingPropagation) {
148  ECALPositionCalculator posCalc;
149  const math::XYZPoint vertex(bsPosition.x(),bsPosition.y(),eleref->track()->vz());
150 
151  float phi1= posCalc.ecalPhi(magField,trackMom,vertex,1);
152  float phi2= posCalc.ecalPhi(magField,trackMom,vertex,-1);
153 
154  float deltaphi1=fabs( phi1 - theClus->position().phi() );
155  if(deltaphi1>6.283185308) deltaphi1 -= 6.283185308;
156  if(deltaphi1>3.141592654) deltaphi1 = 6.283185308-deltaphi1;
157 
158  float deltaphi2=fabs( phi2 - theClus->position().phi() );
159  if(deltaphi2>6.283185308) deltaphi2 -= 6.283185308;
160  if(deltaphi2>3.141592654) deltaphi2 = 6.283185308-deltaphi2;
161 
162  deltaphi = deltaphi1;
163  if(deltaphi2<deltaphi1){ deltaphi = deltaphi2;}
164  } else {
165  deltaphi=fabs(eleref->track()->outerPosition().phi()-theClus->phi());
166  if(deltaphi>6.283185308) deltaphi -= 6.283185308;
167  if(deltaphi>3.141592654) deltaphi = 6.283185308-deltaphi;
168  }
169 
170  return std::make_pair(deltaeta,deltaphi);
171 }
172 
174 {
175  reco::ElectronRef eleRef;
176  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
177  if(eleIt->superCluster()==recoEcalCandRef->superCluster()){
178  eleRef = reco::ElectronRef(electronHandle,eleIt - electronHandle->begin());
179  break;
180  }
181  }
182  return eleRef;
183 }
184 
185 
187  using namespace edm;
188 
189  ESHandle<MagneticField> magneticField;
190  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
191  magField_ = magneticField.product();
192 
193 }
194 
195 //define this as a plug-in
196 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
T getParameter(std::string const &) const
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::pair< float, float > calDEtaDPhiSCTrk(reco::ElectronRef &eleref, const reco::BeamSpot::Point &BSPosition, const MagneticField *magField)
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
edm::Ref< ElectronCollection > ElectronRef
reference to an object in a collection of Electron objects
Definition: ElectronFwd.h:15
edm::EDGetTokenT< reco::BeamSpot > bsProducer_
double ecalPhi(const MagneticField *magField, const math::XYZVector &momentum, const math::XYZPoint &vertex, const int charge)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ParameterDescriptionBase * add(U const &iLabel, T const &value)
EgammaHLTElectronDetaDphiProducer(const edm::ParameterSet &)
void insert(const key_type &k, const data_type &v)
insert an association
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrajectoryStateOnSurface stateOnSurface(const GlobalPoint &point) const
static reco::ElectronRef getEleRef(const reco::RecoEcalCandidateRef &recoEcalCandRef, const edm::Handle< reco::ElectronCollection > &electronHandle)
virtual void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:41