CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GainSwitchTools.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EGammaTools_GainSwitchTools_h
2 #define RecoEgamma_EGammaTools_GainSwitchTools_h
3 
8 
11 
12 #include <vector>
13 
14 class DetId;
15 namespace reco{
16  class SuperCluster;
17 }
18 class CaloTopology;
19 class CaloGeometry;
20 
22 
23 public:
24 
25  enum class ShowerShapeType{
26  Full5x5=0,Fractions //Full 5x5 would be better known as "NoFractions", its not a full 5x5, fractions is the standard showershape
27  };
28 
29  //this should really live in EcalClusterTools
30  static int nrCrysWithFlagsIn5x5(const DetId& id,const std::vector<int>& flags,const EcalRecHitCollection* recHits,const CaloTopology *topology);
31 
32  //note, right now the weights are showing the GS flags so the collections here have to be pure multifit
33  static bool hasEBGainSwitch(const reco::SuperCluster& superClus,const EcalRecHitCollection* recHits);
35  static bool hasEBGainSwitch(const EcalRecHitCollection* recHits);
36 
37  static const std::vector<int> gainSwitchFlags(){return gainSwitchFlags_;}
38  static float newRawEnergyNoFracs(const reco::SuperCluster& superClus,const std::vector<DetId> gainSwitchedHitIds,const EcalRecHitCollection* oldRecHits,const EcalRecHitCollection* newRecHits);
39 
40  //needs to be multifit rec-hits currently as weights dont have gs flags set
41  static std::vector<DetId> gainSwitchedIdsIn5x5(const DetId& id,const EcalRecHitCollection* recHits,const CaloTopology* topology);
42 
43  template<typename HANDLE>
44  static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster&, HANDLE const&);
45  template<typename HANDLE>
46  static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster&, HANDLE const&, int maxDEta, int maxDPhi);
47 
48  // find an entry in H::element_type (a collection) that maps in M to R
49  template<typename R, typename H, typename M>
50  static edm::Ref<typename H::element_type> findNewRef(R const&, H const&, M const&);
51 
52  template<bool noZS>
55  template<bool noZS>
58 
59 
60  //so the no fractions showershape for electrons had hcalDepth1/2 corrected by the regression energy, hence we need to know the type
61  static void
62  correctHadem(reco::GsfElectron::ShowerShape& showerShape,float eNewOverEOld,
64 
65  static void
66  correctHadem(reco::Photon::ShowerShape& showerShape,float eNewOverEOld);
67 
68 
69 private:
70  static int calDIEta(int lhs,int rhs);
71  static int calDIPhi(int lhs,int rhs);
72 private:
73  static const std::vector<int> gainSwitchFlags_;
74 
75 
76 };
77 
78 template<typename R, typename H, typename M>
80 GainSwitchTools::findNewRef(R const& _oldRef, H const& _newHandle, M const& _map)
81 {
82  for (unsigned iC(0); iC != _newHandle->size(); ++iC) {
83  edm::Ref<typename H::element_type> ref(_newHandle, iC);
84  auto&& mappedRef(_map[ref]);
85  if (mappedRef.id() == _oldRef.id() && mappedRef.key() == _oldRef.key())
86  return ref;
87  }
88  return edm::Ref<typename H::element_type>(_newHandle.id());
89 }
90 
91 template<typename HANDLE>
94 {
95  for(size_t scNr=0;scNr<scColl->size();scNr++){
96  if(scColl->at(scNr).seed()->seed().rawId() ==sc.seed()->seed().rawId())
97  return reco::SuperClusterRef(scColl,scNr);
98  }
99  return reco::SuperClusterRef(nullptr,0);
100 }
101 
102 template<typename HANDLE>
104 GainSwitchTools::matchSCBySeedCrys(const reco::SuperCluster& sc, HANDLE const& scColl,int maxDEta,int maxDPhi)
105 {
106  reco::SuperClusterRef bestRef(scColl.id());
107 
108  int bestDIR2 = maxDEta*maxDEta+maxDPhi*maxDPhi+1; //+1 is to make it slightly bigger than max allowed
109 
110  if(sc.seed()->seed().subdetId()==EcalBarrel){
111  EBDetId scDetId(sc.seed()->seed());
112 
113  for(size_t scNr=0;scNr<scColl->size();scNr++){
114  reco::SuperClusterRef matchRef(scColl,scNr);
115  if(matchRef->seed()->seed().subdetId()==EcalBarrel){
116  EBDetId matchDetId(matchRef->seed()->seed());
117  int dIEta = calDIEta(scDetId.ieta(),matchDetId.ieta());
118  int dIPhi = calDIPhi(scDetId.iphi(),matchDetId.iphi());
119  int dIR2 = dIEta*dIEta+dIPhi*dIPhi;
120  if(dIR2<bestDIR2){
121  bestDIR2=dIR2;
122  bestRef = reco::SuperClusterRef(scColl,scNr);
123  }
124  }
125  }
126 
127 
128  }
129  return bestRef;
130 }
131 
132 template<bool noZS>
135 {
136  const reco::CaloCluster & seedClus = *(superClus->seed());
137 
138  std::vector<float> covariances = EcalClusterToolsT<noZS>::covariances(seedClus,recHits,topology,geometry);
139  std::vector<float> localCovariances = EcalClusterToolsT<noZS>::localCovariances(seedClus,recHits,topology);
140  showerShape.sigmaEtaEta = sqrt(covariances[0]);
141  showerShape.sigmaIetaIeta = sqrt(localCovariances[0]);
142  showerShape.sigmaIphiIphi =!edm::isNotFinite(localCovariances[2]) ? sqrt(localCovariances[2]) : 0;
143  showerShape.e1x5 = EcalClusterToolsT<noZS>::e1x5(seedClus,recHits,topology);
144  showerShape.e2x5Max = EcalClusterToolsT<noZS>::e2x5Max(seedClus,recHits,topology);
145  showerShape.e5x5 = EcalClusterToolsT<noZS>::e5x5(seedClus,recHits,topology);
146  showerShape.r9 = EcalClusterToolsT<noZS>::e3x3(seedClus,recHits,topology)/superClus->rawEnergy();
147  const float see_by_spp = showerShape.sigmaIetaIeta*showerShape.sigmaIphiIphi;
148  if( see_by_spp > 0 ) {
149  showerShape.sigmaIetaIphi = localCovariances[1] / see_by_spp;
150  } else if ( localCovariances[1] > 0 ) {
151  showerShape.sigmaIetaIphi = 1.f;
152  } else {
153  showerShape.sigmaIetaIphi = -1.f;
154  }
155  showerShape.eMax = EcalClusterTools::eMax(seedClus,recHits);
156  showerShape.e2nd = EcalClusterTools::e2nd(seedClus,recHits);
157  showerShape.eTop = EcalClusterTools::eTop(seedClus,recHits,topology);
158  showerShape.eLeft = EcalClusterTools::eLeft(seedClus,recHits,topology);
159  showerShape.eRight = EcalClusterTools::eRight(seedClus,recHits,topology);
160  showerShape.eBottom = EcalClusterTools::eBottom(seedClus,recHits,topology);
161  return showerShape;
162 }
163 
164 template<bool noZS>
167 {
168  const reco::CaloCluster & seedClus = *(superClus->seed());
169 
170  std::vector<float> covariances = EcalClusterToolsT<noZS>::covariances(seedClus,recHits,topology,geometry);
171  std::vector<float> localCovariances = EcalClusterToolsT<noZS>::localCovariances(seedClus,recHits,topology);
172  showerShape.sigmaEtaEta = sqrt(covariances[0]);
173  showerShape.e1x5 = EcalClusterToolsT<noZS>::e1x5(seedClus,recHits,topology);
174  showerShape.e2x5 = EcalClusterToolsT<noZS>::e2x5Max(seedClus,recHits,topology);
175  showerShape.e3x3 = EcalClusterToolsT<noZS>::e3x3(seedClus,recHits,topology);
176  showerShape.e5x5 = EcalClusterToolsT<noZS>::e5x5(seedClus,recHits,topology);
177  showerShape.maxEnergyXtal = EcalClusterToolsT<noZS>::eMax(seedClus,recHits);
178  //showerShape.effSigmaRR fine as its preshower, this only does ECAL shapes
179  showerShape.sigmaIetaIeta = sqrt(localCovariances[0]);
180  showerShape.sigmaIphiIphi =!edm::isNotFinite(localCovariances[2]) ? sqrt(localCovariances[2]) : 0;
181  showerShape.e2nd = EcalClusterToolsT<noZS>::e2nd(seedClus,recHits);
182  showerShape.eTop = EcalClusterToolsT<noZS>::eTop(seedClus,recHits,topology);
183  showerShape.eLeft = EcalClusterToolsT<noZS>::eLeft(seedClus,recHits,topology);
184  showerShape.eRight = EcalClusterToolsT<noZS>::eRight(seedClus,recHits,topology);
185  showerShape.eBottom = EcalClusterToolsT<noZS>::eBottom(seedClus,recHits,topology);
186  showerShape.e1x3 = EcalClusterToolsT<noZS>::e1x3(seedClus,recHits,topology);
187  showerShape.e2x2 = EcalClusterToolsT<noZS>::e2x2(seedClus,recHits,topology);
188  showerShape.e2x5Max = EcalClusterToolsT<noZS>::e2x5Max(seedClus,recHits,topology);
189  showerShape.e2x5Left = EcalClusterToolsT<noZS>::e2x5Left(seedClus,recHits,topology);
190  showerShape.e2x5Right = EcalClusterToolsT<noZS>::e2x5Right(seedClus,recHits,topology);
191  showerShape.e2x5Top = EcalClusterToolsT<noZS>::e2x5Top(seedClus,recHits,topology);
192  showerShape.e2x5Bottom = EcalClusterToolsT<noZS>::e2x5Bottom(seedClus,recHits,topology);
193 
194  return showerShape;
195 }
196 
197 
198 
199 #endif
static int calDIEta(int lhs, int rhs)
static float e2x5Bottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static std::vector< float > covariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, const CaloGeometry *geometry, float w0=4.7)
CaloTopology const * topology(0)
static float eMax(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
static reco::GsfElectron::ShowerShape redoEcalShowerShape(reco::GsfElectron::ShowerShape showerShape, const reco::SuperClusterRef &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology, const CaloGeometry *geometry)
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster &, HANDLE const &)
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
static float e2x5Top(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static const std::vector< int > gainSwitchFlags()
bool isNotFinite(T x)
Definition: isFinite.h:10
static float e2x2(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
T sqrt(T t)
Definition: SSEVec.h:18
static float e2nd(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
static float e2x5Max(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eBottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e2x5Right(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static void correctHadem(reco::GsfElectron::ShowerShape &showerShape, float eNewOverEOld, const GainSwitchTools::ShowerShapeType ssType)
static float eTop(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
Definition: DetId.h:18
static float newRawEnergyNoFracs(const reco::SuperCluster &superClus, const std::vector< DetId > gainSwitchedHitIds, const EcalRecHitCollection *oldRecHits, const EcalRecHitCollection *newRecHits)
static bool hasEBGainSwitch(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits)
static std::vector< DetId > gainSwitchedIdsIn5x5(const DetId &id, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e2x5Left(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
ESHandle< TrackerGeometry > geometry
static const std::vector< int > gainSwitchFlags_
static int nrCrysWithFlagsIn5x5(const DetId &id, const std::vector< int > &flags, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static bool hasEBGainSwitchIn5x5(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eRight(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static int calDIPhi(int lhs, int rhs)
static float e3x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
static float e1x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eLeft(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static std::vector< float > localCovariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, float w0=4.7)
static float e1x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static edm::Ref< typename H::element_type > findNewRef(R const &, H const &, M const &)
static float e5x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)