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 
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 
80 
81  if(!useSCRefs_){
82 
83  for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
84 
85  reco::ElectronRef eleref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
86  std::pair<float,float> dEtaDPhi = calDEtaDPhiSCTrk(eleref,bsPosition,theMagField.product());
87 
88  detaMap.insert(eleref, dEtaDPhi.first);
89  dphiMap.insert(eleref, dEtaDPhi.second);
90  }
91  }else { //we loop over reco ecal candidates
93  iEvent.getByToken(recoEcalCandidateProducer_,recoEcalCandHandle);
94  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
95 
96  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
97 
98  reco::ElectronRef eleRef = getEleRef(recoEcalCandRef,electronHandle);
99  std::pair<float,float> dEtaDPhi(999999,999999);
100  if(eleRef.isNonnull()) dEtaDPhi = calDEtaDPhiSCTrk(eleRef,bsPosition,theMagField.product());
101  detaCandMap.insert(recoEcalCandRef, dEtaDPhi.first);
102  dphiCandMap.insert(recoEcalCandRef, dEtaDPhi.second);
103  }//end loop over reco ecal candidates
104  }//end if between electrons or reco ecal candidates
105 
106  if(!useSCRefs_){
107  std::auto_ptr<reco::ElectronIsolationMap> detMap(new reco::ElectronIsolationMap(detaMap));
108  std::auto_ptr<reco::ElectronIsolationMap> dphMap(new reco::ElectronIsolationMap(dphiMap));
109  iEvent.put(detMap, "Deta" );
110  iEvent.put(dphMap, "Dphi" );
111  }else{
112  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> detaCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(detaCandMap));
113  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dphiCandMapForEvent(new reco::RecoEcalCandidateIsolationMap(dphiCandMap));
114  iEvent.put(detaCandMapForEvent, "Deta" );
115  iEvent.put(dphiCandMapForEvent, "Dphi" );
116  }
117 }
118 
119 std::pair<float,float> EgammaHLTElectronDetaDphiProducer::calDEtaDPhiSCTrk(reco::ElectronRef& eleref, const reco::BeamSpot::Point& bsPosition,const MagneticField *magField) {
120 
121  const reco::SuperClusterRef theClus = eleref->superCluster();
122  const math::XYZVector trackMom = eleref->track()->momentum();
123 
124  math::XYZPoint SCcorrPosition(theClus->x()-bsPosition.x(), theClus->y()-bsPosition.y() , theClus->z()-eleref->track()->vz() );
125  float deltaeta = fabs(SCcorrPosition.eta()-eleref->track()->eta());
126  float deltaphi = 999.;
127 
128  bool recoveryForFailingPropagation = false;
129  if (variablesAtVtx_) {
130  reco::TrackRef track = eleref->track();
132  TrajectoryStateOnSurface sclTSOS = tt.stateOnSurface(GlobalPoint(theClus->x(),theClus->y(),theClus->z()));
133 
134  if (sclTSOS.isValid()) {
135  EleRelPointPair scAtVtx(theClus->position(), sclTSOS.globalPosition(), bsPosition);
136  deltaeta = fabs(scAtVtx.dEta());
137  deltaphi = fabs(scAtVtx.dPhi());
138  } else {
139  recoveryForFailingPropagation = true;
140  }
141  } else if (useTrackProjectionToEcal_ or recoveryForFailingPropagation) {
142  ECALPositionCalculator posCalc;
143  const math::XYZPoint vertex(bsPosition.x(),bsPosition.y(),eleref->track()->vz());
144 
145  float phi1= posCalc.ecalPhi(magField,trackMom,vertex,1);
146  float phi2= posCalc.ecalPhi(magField,trackMom,vertex,-1);
147 
148  float deltaphi1=fabs( phi1 - theClus->position().phi() );
149  if(deltaphi1>6.283185308) deltaphi1 -= 6.283185308;
150  if(deltaphi1>3.141592654) deltaphi1 = 6.283185308-deltaphi1;
151 
152  float deltaphi2=fabs( phi2 - theClus->position().phi() );
153  if(deltaphi2>6.283185308) deltaphi2 -= 6.283185308;
154  if(deltaphi2>3.141592654) deltaphi2 = 6.283185308-deltaphi2;
155 
156  deltaphi = deltaphi1;
157  if(deltaphi2<deltaphi1){ deltaphi = deltaphi2;}
158  } else {
159  deltaphi=fabs(eleref->track()->outerPosition().phi()-theClus->phi());
160  if(deltaphi>6.283185308) deltaphi -= 6.283185308;
161  if(deltaphi>3.141592654) deltaphi = 6.283185308-deltaphi;
162  }
163 
164  return std::make_pair(deltaeta,deltaphi);
165 }
166 
168 {
169  reco::ElectronRef eleRef;
170  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
171  if(eleIt->superCluster()==recoEcalCandRef->superCluster()){
172  eleRef = reco::ElectronRef(electronHandle,eleIt - electronHandle->begin());
173  break;
174  }
175  }
176  return eleRef;
177 }
178 
179 
181  using namespace edm;
182 
185  magField_ = magneticField.product();
186 
187 }
188 
189 //define this as a plug-in
190 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
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)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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
double ecalPhi(const MagneticField *magField, const math::XYZVector &momentum, const math::XYZPoint &vertex, const int charge)
int iEvent
Definition: GenABIO.cc:230
const edm::EDGetTokenT< reco::BeamSpot > bsProducer_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
TrajectoryStateOnSurface stateOnSurface(const GlobalPoint &point) const
static reco::ElectronRef getEleRef(const reco::RecoEcalCandidateRef &recoEcalCandRef, const edm::Handle< reco::ElectronCollection > &electronHandle)
const edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:41