CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonGSCrysSimpleFixer.cc
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaElectronProducers_PhotonGSCrysSimpleFixer_h
2 #define RecoEgamma_EgammaElectronProducers_PhotonGSCrysSimpleFixer_h
3 
7 
11 
12 
17 
25 
30 
32 
35 
36 #include <iostream>
37 #include <string>
38 
40 public:
43 
44  void produce(edm::Event&, const edm::EventSetup& ) override;
46  edm::EventSetup const&) override;
47 
48 
49  template<typename T>
51  token=consumes<T>(pset.getParameter<edm::InputTag>(label));
52  }
53 private:
57 
58  const std::vector<int> energyTypesToFix_;
60 
63 };
64 
65 
66 namespace {
67  template<typename T> edm::Handle<T> getHandle(const edm::Event& iEvent,const edm::EDGetTokenT<T>& token){
69  iEvent.getByToken(token,handle);
70  return handle;
71  }
72 }
73 
74 
75 
77  energyTypesToFix_(StringToEnumValue<reco::Photon::P4type>(pset.getParameter<std::vector<std::string> >("energyTypesToFix"))),
78  energyTypeForP4_(static_cast<reco::Photon::P4type>(StringToEnumValue<reco::Photon::P4type>(pset.getParameter<std::string>("energyTypeForP4"))))
79 {
80  getToken(oldPhosToken_,pset,"oldPhos");
81  getToken(ebMultiAndWeightsRecHitsToken_,pset,"ebMultiAndWeightsRecHits");
82  getToken(ebMultiRecHitsToken_,pset,"ebMultiRecHits");
83 
84 
85  produces<reco::PhotonCollection >();
86 }
87 
89 {
90  auto outPhos = std::make_unique<reco::PhotonCollection>();
91 
92 
93  auto phosHandle = getHandle(iEvent,oldPhosToken_);
94  auto& ebMultiRecHits = *getHandle(iEvent,ebMultiRecHitsToken_);
95  auto& ebMultiAndWeightsRecHits = *getHandle(iEvent,ebMultiAndWeightsRecHitsToken_);
96 
97 
98  for(size_t phoNr=0;phoNr<phosHandle->size();phoNr++){
99  reco::PhotonRef phoRef(phosHandle,phoNr);
100  if(GainSwitchTools::hasEBGainSwitchIn5x5(*phoRef->superCluster(),&ebMultiRecHits,topology_)){
101 
102  reco::Photon newPho(*phoRef);
103 
104  std::vector<DetId> gsIds = GainSwitchTools::gainSwitchedIdsIn5x5(phoRef->superCluster()->seed()->seed(),
105  &ebMultiRecHits,topology_);
106  float newRawEnergy = GainSwitchTools::newRawEnergyNoFracs(*phoRef->superCluster(),gsIds,
107  &ebMultiRecHits,&ebMultiAndWeightsRecHits);
108  float energyCorr = newRawEnergy / phoRef->superCluster()->rawEnergy();
109 
110  reco::Photon::ShowerShape full5x5ShowerShape = GainSwitchTools::redoEcalShowerShape<true>(newPho.full5x5_showerShapeVariables(),newPho.superCluster(),&ebMultiAndWeightsRecHits,topology_,geometry_);
111  reco::Photon::ShowerShape showerShape = GainSwitchTools::redoEcalShowerShape<false>(newPho.showerShapeVariables(),newPho.superCluster(),&ebMultiAndWeightsRecHits,topology_,geometry_);
112 
113 
114  GainSwitchTools::correctHadem(showerShape,energyCorr);
115  GainSwitchTools::correctHadem(full5x5ShowerShape,energyCorr);
116 
117  newPho.full5x5_setShowerShapeVariables(full5x5ShowerShape);
118  newPho.setShowerShapeVariables(showerShape);
119 
120  for(int typeAsInt : energyTypesToFix_){
121  auto type = static_cast<reco::Photon::P4type>(typeAsInt);
122  float oldEnergy = newPho.getCorrectedEnergy(type);
123  float oldEnergyErr = newPho.getCorrectedEnergyError(type);
124  newPho.setCorrectedEnergy(type,oldEnergy*energyCorr,oldEnergyErr*energyCorr,false);
125  }
126 
127  //now we set the P4 of the object as appropriate
130 
131 
132  outPhos->push_back(newPho);
133  }else{
134  outPhos->push_back(*phoRef);
135  }
136  }
137 
138  iEvent.put(std::move(outPhos));
139 }
140 
142  edm::EventSetup const& es) {
143  edm::ESHandle<CaloGeometry> caloGeom ;
144  edm::ESHandle<CaloTopology> caloTopo ;
145  es.get<CaloGeometryRecord>().get(caloGeom);
146  es.get<CaloTopologyRecord>().get(caloTopo);
147  geometry_ = caloGeom.product();
148  topology_ = caloTopo.product();
149 }
150 
151 
152 
153 
155 #endif
156 
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
PhotonGSCrysSimpleFixer(const edm::ParameterSet &)
const CaloTopology * topology_
const CaloGeometry * geometry_
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void getToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
const std::vector< int > energyTypesToFix_
def move
Definition: eostools.py:510
edm::EDGetTokenT< reco::PhotonCollection > oldPhosToken_
tuple handle
Definition: patZpeak.py:22
void setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:199
static void correctHadem(reco::GsfElectron::ShowerShape &showerShape, float eNewOverEOld, const GainSwitchTools::ShowerShapeType ssType)
float getCorrectedEnergyError(P4type type) const
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
edm::EDGetTokenT< EcalRecHitCollection > ebMultiAndWeightsRecHitsToken_
float getCorrectedEnergy(P4type type) const
void full5x5_setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:200
int StringToEnumValue(std::string const &enumConstName)
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:197
const reco::Photon::P4type energyTypeForP4_
static bool hasEBGainSwitchIn5x5(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology)
edm::EDGetTokenT< EcalRecHitCollection > ebMultiRecHitsToken_
void produce(edm::Event &, const edm::EventSetup &) override
const ShowerShape & showerShapeVariables() const
Definition: Photon.h:196