CMS 3D CMS Logo

EgammaHLTElectronDetaDphiProducer.cc
Go to the documentation of this file.
1 
10 
15 
21 
23 
30 
32  electronProducer_ (consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("electronProducer"))),
33  bsProducer_ (consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("BSProducer"))),
34  recoEcalCandidateProducer_ (consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
35  useSCRefs_ (config.getParameter<bool>("useSCRefs")),
36  useTrackProjectionToEcal_ (config.getParameter<bool>("useTrackProjectionToEcal")),
37  variablesAtVtx_ (config.getParameter<bool>("variablesAtVtx")) {
38 
39  //register your products
40  if(!useSCRefs_){
41  produces < reco::ElectronIsolationMap >( "Deta" ).setBranchAlias( "deta" );
42  produces < reco::ElectronIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
43  }else{
44  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
45  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
46  }
47 }
48 
50 {}
51 
54  desc.add<edm::InputTag>(("electronProducer"), edm::InputTag("hltEleAnyWP80PixelMatchElectronsL1Seeded"));
55  desc.add<edm::InputTag>(("BSProducer"), edm::InputTag("hltOnlineBeamSpot"));
56  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag());
57  desc.add<bool>(("useSCRefs"), false);
58  desc.add<bool>(("useTrackProjectionToEcal"), false);
59  desc.add<bool>(("variablesAtVtx"), true);
60  descriptions.add(("hltEgammaHLTElectronDetaDphiProducer"), desc);
61 }
62 
64  // Get the HLT filtered objects
66  iEvent.getByToken(electronProducer_,electronHandle);
67 
68  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
69  iEvent.getByToken(bsProducer_,recoBeamSpotHandle);
70  // gets its position
71  const reco::BeamSpot::Point& bsPosition = recoBeamSpotHandle->position();
72 
73  edm::ESHandle<MagneticField> theMagField;
74  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
75 
76  reco::ElectronIsolationMap detaMap(electronHandle);
77  reco::ElectronIsolationMap dphiMap(electronHandle);
78 
79  if(!useSCRefs_){
80 
81  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
82 
83  reco::ElectronRef eleref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
84  std::pair<float,float> dEtaDPhi = calDEtaDPhiSCTrk(eleref,bsPosition,theMagField.product());
85 
86  detaMap.insert(eleref, dEtaDPhi.first);
87  dphiMap.insert(eleref, dEtaDPhi.second);
88  }
89  }else { //we loop over reco ecal candidates
91  iEvent.getByToken(recoEcalCandidateProducer_,recoEcalCandHandle);
92  reco::RecoEcalCandidateIsolationMap detaCandMap(recoEcalCandHandle);
93  reco::RecoEcalCandidateIsolationMap dphiCandMap(recoEcalCandHandle);
94 
95  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
96 
97  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
98 
99  reco::ElectronRef eleRef = getEleRef(recoEcalCandRef,electronHandle);
100  std::pair<float,float> dEtaDPhi(999999,999999);
101  if(eleRef.isNonnull()) dEtaDPhi = calDEtaDPhiSCTrk(eleRef,bsPosition,theMagField.product());
102  detaCandMap.insert(recoEcalCandRef, dEtaDPhi.first);
103  dphiCandMap.insert(recoEcalCandRef, dEtaDPhi.second);
104  }//end loop over reco ecal candidates
105 
106  iEvent.put(std::make_unique<reco::RecoEcalCandidateIsolationMap>(detaCandMap), "Deta" );
107  iEvent.put(std::make_unique<reco::RecoEcalCandidateIsolationMap>(dphiCandMap), "Dphi" );
108 
109  }//end if between electrons or reco ecal candidates
110 
111  if(!useSCRefs_){
112  iEvent.put(std::make_unique<reco::ElectronIsolationMap>(detaMap), "Deta" );
113  iEvent.put(std::make_unique<reco::ElectronIsolationMap>(dphiMap), "Dphi" );
114  }
115 }
116 
117 std::pair<float,float> EgammaHLTElectronDetaDphiProducer::calDEtaDPhiSCTrk(reco::ElectronRef& eleref, const reco::BeamSpot::Point& bsPosition,const MagneticField *magField) {
118 
119  const reco::SuperClusterRef theClus = eleref->superCluster();
120  const math::XYZVector trackMom = eleref->track()->momentum();
121 
122  math::XYZPoint SCcorrPosition(theClus->x()-bsPosition.x(), theClus->y()-bsPosition.y() , theClus->z()-eleref->track()->vz() );
123  float deltaeta = fabs(SCcorrPosition.eta()-eleref->track()->eta());
124  float deltaphi = 999.;
125 
126  if (variablesAtVtx_) {
127  reco::TrackRef track = eleref->track();
129  TrajectoryStateOnSurface sclTSOS = tt.stateOnSurface(GlobalPoint(theClus->x(),theClus->y(),theClus->z()));
130 
131  if (sclTSOS.isValid()) {
132  EleRelPointPair scAtVtx(theClus->position(), sclTSOS.globalPosition(), bsPosition);
133  deltaeta = fabs(scAtVtx.dEta());
134  deltaphi = fabs(scAtVtx.dPhi());
135  }
136  } else if (useTrackProjectionToEcal_) {
137  const math::XYZPoint vertex(bsPosition.x(),bsPosition.y(),eleref->track()->vz());
138 
139  float phi1 = egammaTools::ecalPhi(*magField,trackMom,vertex,1);
140  float phi2 = egammaTools::ecalPhi(*magField,trackMom,vertex,-1);
141 
142  float deltaphi1=fabs( phi1 - theClus->position().phi() );
143  if(deltaphi1>6.283185308) deltaphi1 -= 6.283185308;
144  if(deltaphi1>3.141592654) deltaphi1 = 6.283185308-deltaphi1;
145 
146  float deltaphi2=fabs( phi2 - theClus->position().phi() );
147  if(deltaphi2>6.283185308) deltaphi2 -= 6.283185308;
148  if(deltaphi2>3.141592654) deltaphi2 = 6.283185308-deltaphi2;
149 
150  deltaphi = deltaphi1;
151  if(deltaphi2<deltaphi1){ deltaphi = deltaphi2;}
152  } else {
153  deltaphi=fabs(eleref->track()->outerPosition().phi()-theClus->phi());
154  if(deltaphi>6.283185308) deltaphi -= 6.283185308;
155  if(deltaphi>3.141592654) deltaphi = 6.283185308-deltaphi;
156  }
157 
158  return std::make_pair(deltaeta,deltaphi);
159 }
160 
162 {
163  reco::ElectronRef eleRef;
164  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
165  if(eleIt->superCluster()==recoEcalCandRef->superCluster()){
166  eleRef = reco::ElectronRef(electronHandle,eleIt - electronHandle->begin());
167  break;
168  }
169  }
170  return eleRef;
171 }
172 
173 
175  using namespace edm;
176 
178  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
179  magField_ = magneticField.product();
180 
181 }
182 
183 //define this as a plug-in
184 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::pair< float, float > calDEtaDPhiSCTrk(reco::ElectronRef &eleref, const reco::BeamSpot::Point &BSPosition, const MagneticField *magField)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
Definition: config.py:1
edm::Ref< ElectronCollection > ElectronRef
reference to an object in a collection of Electron objects
Definition: ElectronFwd.h:15
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< reco::BeamSpot > bsProducer_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
fixed size matrix
HLT enums.
TrajectoryStateOnSurface stateOnSurface(const GlobalPoint &point) const
T get() const
Definition: EventSetup.h:71
static reco::ElectronRef getEleRef(const reco::RecoEcalCandidateRef &recoEcalCandRef, const edm::Handle< reco::ElectronCollection > &electronHandle)
const Point & position() const
position
Definition: BeamSpot.h:62
const edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: ESHandle.h:86
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45
double ecalPhi(const MagneticField &magField, const math::XYZVector &momentum, const math::XYZPoint &vertex, const int charge)