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 // Framework
18 
23 
25 
27 
33 
36 
37 //#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"//needed?
38 //#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"//needed?
39 
40 
42 
44 
48 
50 {
51 
52  electronProducer_ = config.getParameter<edm::InputTag>("electronProducer");
53  bsProducer_ = config.getParameter<edm::InputTag>("BSProducer");
54  useTrackProjectionToEcal_ = config.getParameter<bool>("useTrackProjectionToEcal");
55  variablesAtVtx_ = config.getParameter<bool>("variablesAtVtx");
56  recoEcalCandidateProducer_ = config.getParameter<edm::InputTag>("recoEcalCandidateProducer");
57  useSCRefs_ = config.getParameter<bool>("useSCRefs");
58 
59  //register your products
60  if(!useSCRefs_){
61  produces < reco::ElectronIsolationMap >( "Deta" ).setBranchAlias( "deta" );
62  produces < reco::ElectronIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
63  }else{
64  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
65  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
66  }
67 }
68 
70 
71 
72 //
73 // member functions
74 //
75 
76 // ------------ method called to produce the data ------------
78 
79  // Get the HLT filtered objects
81  iEvent.getByLabel(electronProducer_,electronHandle);
82 
83  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
84  iEvent.getByLabel(bsProducer_,recoBeamSpotHandle);
85  // gets its position
86  const reco::BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
87 
88  edm::ESHandle<MagneticField> theMagField;
89  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
90 
95 
96  if(!useSCRefs_){
97  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
98 
99  reco::ElectronRef eleref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
100  std::pair<float,float> dEtaDPhi = calDEtaDPhiSCTrk(eleref,bsPosition,theMagField.product());
101 
102  detaMap.insert(eleref, dEtaDPhi.first);
103  dphiMap.insert(eleref, dEtaDPhi.second);
104  }
105  }else { //we loop over reco ecal candidates
107  iEvent.getByLabel(recoEcalCandidateProducer_,recoEcalCandHandle);
108  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
109 
110  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
111 
112  reco::ElectronRef eleRef = getEleRef(recoEcalCandRef,electronHandle);
113  std::pair<float,float> dEtaDPhi(999999,999999);
114  if(eleRef.isNonnull()) dEtaDPhi = calDEtaDPhiSCTrk(eleRef,bsPosition,theMagField.product());
115  detaCandMap.insert(recoEcalCandRef, dEtaDPhi.first);
116  dphiCandMap.insert(recoEcalCandRef, dEtaDPhi.second);
117  }//end loop over reco ecal candidates
118  }//end if between electrons or reco ecal candidates
119 
120  if(!useSCRefs_){
121  std::auto_ptr<reco::ElectronIsolationMap> detMap(new reco::ElectronIsolationMap(detaMap));
122  std::auto_ptr<reco::ElectronIsolationMap> dphMap(new reco::ElectronIsolationMap(dphiMap));
123  iEvent.put(detMap, "Deta" );
124  iEvent.put(dphMap, "Dphi" );
125  }else{
126  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> detaCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(detaCandMap));
127  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dphiCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(dphiCandMap));
128  iEvent.put(detaCandMapForEvent, "Deta" );
129  iEvent.put(dphiCandMapForEvent, "Dphi" );
130  }
131 }
132 
133 std::pair<float,float> EgammaHLTElectronDetaDphiProducer::calDEtaDPhiSCTrk(reco::ElectronRef& eleref, const reco::BeamSpot::Point& bsPosition,const MagneticField *magField) {
134 
135  const reco::SuperClusterRef theClus = eleref->superCluster();
136  const math::XYZVector trackMom = eleref->track()->momentum();
137 
138  math::XYZPoint SCcorrPosition(theClus->x()-bsPosition.x(), theClus->y()-bsPosition.y() , theClus->z()-eleref->track()->vz() );
139  float deltaeta = fabs(SCcorrPosition.eta()-eleref->track()->eta());
140  float deltaphi = 999.;
141 
142  bool recoveryForFailingPropagation = false;
143  if (variablesAtVtx_) {
144  reco::TrackRef track = eleref->track();
146  TrajectoryStateOnSurface sclTSOS = tt.stateOnSurface(GlobalPoint(theClus->x(),theClus->y(),theClus->z()));
147 
148  if (sclTSOS.isValid()) {
149  EleRelPointPair scAtVtx(theClus->position(), sclTSOS.globalPosition(), bsPosition);
150  deltaeta = fabs(scAtVtx.dEta());
151  deltaphi = fabs(scAtVtx.dPhi());
152  } else {
153  recoveryForFailingPropagation = true;
154  }
155  } else if (useTrackProjectionToEcal_ or recoveryForFailingPropagation) {
156  ECALPositionCalculator posCalc;
157  const math::XYZPoint vertex(bsPosition.x(),bsPosition.y(),eleref->track()->vz());
158 
159  float phi1= posCalc.ecalPhi(magField,trackMom,vertex,1);
160  float phi2= posCalc.ecalPhi(magField,trackMom,vertex,-1);
161 
162  float deltaphi1=fabs( phi1 - theClus->position().phi() );
163  if(deltaphi1>6.283185308) deltaphi1 -= 6.283185308;
164  if(deltaphi1>3.141592654) deltaphi1 = 6.283185308-deltaphi1;
165 
166  float deltaphi2=fabs( phi2 - theClus->position().phi() );
167  if(deltaphi2>6.283185308) deltaphi2 -= 6.283185308;
168  if(deltaphi2>3.141592654) deltaphi2 = 6.283185308-deltaphi2;
169 
170  deltaphi = deltaphi1;
171  if(deltaphi2<deltaphi1){ deltaphi = deltaphi2;}
172  } else {
173  deltaphi=fabs(eleref->track()->outerPosition().phi()-theClus->phi());
174  if(deltaphi>6.283185308) deltaphi -= 6.283185308;
175  if(deltaphi>3.141592654) deltaphi = 6.283185308-deltaphi;
176  }
177 
178  return std::make_pair(deltaeta,deltaphi);
179 }
180 
182 {
183  reco::ElectronRef eleRef;
184  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
185  if(eleIt->superCluster()==recoEcalCandRef->superCluster()){
186  eleRef = reco::ElectronRef(electronHandle,eleIt - electronHandle->begin());
187  break;
188  }
189  }
190  return eleRef;
191 }
192 
193 
195  using namespace edm;
196 
197  ESHandle<MagneticField> magneticField;
198  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
199  magField_ = magneticField.product();
200 
201 }
202 
204 
205 //define this as a plug-in
206 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
T getParameter(std::string const &) const
virtual void endRun(edm::Run &, edm::EventSetup const &)
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)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:30
virtual void beginRun(edm::Run &, edm::EventSetup const &)
edm::Ref< ElectronCollection > ElectronRef
reference to an object in a collection of Electron objects
Definition: ElectronFwd.h:15
double ecalPhi(const MagneticField *magField, const math::XYZVector &momentum, const math::XYZPoint &vertex, const int charge)
int iEvent
Definition: GenABIO.cc:243
virtual void produce(edm::Event &, const edm::EventSetup &)
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
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:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
TrajectoryStateOnSurface stateOnSurface(const GlobalPoint &point) const
static reco::ElectronRef getEleRef(const reco::RecoEcalCandidateRef &recoEcalCandRef, const edm::Handle< reco::ElectronCollection > &electronHandle)
Definition: Run.h:33