CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfEleGSCrysSimpleFixer.cc
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaElectronProducers_GsfEleGSCrysSimpleFixer_h
2 #define RecoEgamma_EgammaElectronProducers_GsfEleGSCrysSimpleFixer_h
3 
7 
11 
12 
17 
27 
32 
34 
36 
37 #include <iostream>
38 #include <string>
39 
41 public:
44 
45  void produce(edm::Event&, const edm::EventSetup& ) override;
47  edm::EventSetup const&) override;
48 
49 
50  template<typename T>
52  token=consumes<T>(pset.getParameter<edm::InputTag>(label));
53  }
54 private:
58 
61 };
62 
63 
64 namespace {
65  template<typename T> edm::Handle<T> getHandle(const edm::Event& iEvent,const edm::EDGetTokenT<T>& token){
67  iEvent.getByToken(token,handle);
68  return handle;
69  }
70 }
71 
72 
73 
75 {
76 
77  getToken(oldGsfElesToken_,pset,"oldEles");
78  getToken(ebMultiAndWeightsRecHitsToken_,pset,"ebMultiAndWeightsRecHits");
79  getToken(ebMultiRecHitsToken_,pset,"ebMultiRecHits");
80 
81 
82  produces<reco::GsfElectronCollection >();
83 }
84 
86 {
87  auto outEles = std::make_unique<reco::GsfElectronCollection>();
88 
89 
90  auto elesHandle = getHandle(iEvent,oldGsfElesToken_);
91  auto& ebMultiRecHits = *getHandle(iEvent,ebMultiRecHitsToken_);
92  auto& ebMultiAndWeightsRecHits = *getHandle(iEvent,ebMultiAndWeightsRecHitsToken_);
93 
94 
95  for(size_t eleNr=0;eleNr<elesHandle->size();eleNr++){
96  reco::GsfElectronRef eleRef(elesHandle,eleNr);
97  if(GainSwitchTools::hasEBGainSwitchIn5x5(*eleRef->superCluster(),&ebMultiRecHits,topology_)){
98 
99  reco::GsfElectron newEle(*eleRef);
100 
101  std::vector<DetId> gsIds = GainSwitchTools::gainSwitchedIdsIn5x5(eleRef->superCluster()->seed()->seed(),
102  &ebMultiRecHits,topology_);
103  float newRawEnergy = GainSwitchTools::newRawEnergyNoFracs(*eleRef->superCluster(),gsIds,
104  &ebMultiRecHits,&ebMultiAndWeightsRecHits);
105  float energyCorr = newRawEnergy / eleRef->superCluster()->rawEnergy();
106 
107  reco::GsfElectron::ShowerShape full5x5ShowerShape = GainSwitchTools::redoEcalShowerShape<true>(newEle.full5x5_showerShape(),newEle.superCluster(),&ebMultiAndWeightsRecHits,topology_,geometry_);
108  reco::GsfElectron::ShowerShape showerShape = GainSwitchTools::redoEcalShowerShape<false>(newEle.showerShape(),newEle.superCluster(),&ebMultiAndWeightsRecHits,topology_,geometry_);
109  //so the no fractions showershape had hcalDepth1/2 corrected by the regression energy, hence we need to know the type
112  newEle.full5x5_setShowerShape(full5x5ShowerShape);
113  newEle.setShowerShape(showerShape);
114 
115  newEle.setCorrectedEcalEnergy(newEle.ecalEnergy()*energyCorr);
116  newEle.setCorrectedEcalEnergyError(newEle.ecalEnergyError()*energyCorr);
117 
118  //meh, somebody else can sort this out
119  //the energy should for gain switch electrons be all from the ECAL so we will assume that
120  //to make my life easier
121  math::XYZTLorentzVector newMom(newEle.p4().x()/newEle.p4().t()*newEle.ecalEnergy(),
122  newEle.p4().y()/newEle.p4().t()*newEle.ecalEnergy(),
123  newEle.p4().z()/newEle.p4().t()*newEle.ecalEnergy(),
124  newEle.ecalEnergy());
125  newEle.correctMomentum(newMom,newEle.trackMomentumError(),newEle.correctedEcalEnergyError());
126 
127 
128  outEles->push_back(newEle);
129  }else{
130  outEles->push_back(*eleRef);
131  }
132  }
133 
134  iEvent.put(std::move(outEles));
135 }
136 
138  edm::EventSetup const& es) {
139  edm::ESHandle<CaloGeometry> caloGeom ;
140  edm::ESHandle<CaloTopology> caloTopo ;
141  es.get<CaloGeometryRecord>().get(caloGeom);
142  es.get<CaloTopologyRecord>().get(caloTopo);
143  geometry_ = caloGeom.product();
144  topology_ = caloTopo.product();
145 }
146 
147 
148 
149 
151 #endif
152 
const ShowerShape & showerShape() const
Definition: GsfElectron.h:429
T getParameter(std::string const &) const
float trackMomentumError() const
Definition: GsfElectron.h:773
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:224
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
const CaloGeometry * geometry_
GsfEleGSCrysSimpleFixer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:795
void setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:448
void getToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< EcalRecHitCollection > ebMultiRecHitsToken_
int iEvent
Definition: GenABIO.cc:230
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:178
edm::EDGetTokenT< EcalRecHitCollection > ebMultiAndWeightsRecHitsToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Definition: GsfElectron.h:182
def move
Definition: eostools.py:510
tuple handle
Definition: patZpeak.py:22
const CaloTopology * topology_
static void correctHadem(reco::GsfElectron::ShowerShape &showerShape, float eNewOverEOld, const GainSwitchTools::ShowerShapeType ssType)
float ecalEnergyError() const
Definition: GsfElectron.h:786
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
static float newRawEnergyNoFracs(const reco::SuperCluster &superClus, const std::vector< DetId > gainSwitchedHitIds, const EcalRecHitCollection *oldRecHits, const EcalRecHitCollection *newRecHits)
static std::vector< DetId > gainSwitchedIdsIn5x5(const DetId &id, const EcalRecHitCollection *recHits, const CaloTopology *topology)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
float ecalEnergy() const
Definition: GsfElectron.h:785
float correctedEcalEnergyError() const
Definition: GsfElectron.h:772
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:181
const ShowerShape & full5x5_showerShape() const
Definition: GsfElectron.h:445
static bool hasEBGainSwitchIn5x5(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void produce(edm::Event &, const edm::EventSetup &) override
void full5x5_setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:449
edm::EDGetTokenT< reco::GsfElectronCollection > oldGsfElesToken_