CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GainSwitchTools.cc
Go to the documentation of this file.
2 
3 
9 
10  //this should really live in EcalClusterTools
12 {
13  int nrFound=0;
15 
16  for ( int eastNr = -2; eastNr <= 2; ++eastNr ) { //east is eta in barrel
17  for ( int northNr = -2; northNr <= 2; ++northNr ) { //north is phi in barrel
18  cursor.home();
19  cursor.offsetBy( eastNr, northNr);
20  DetId id = *cursor;
21  if (recHits != nullptr) {
22  auto recHitIt = recHits->find(id);
23  if(recHitIt!=recHits->end() &&
24  recHitIt->checkFlags(flags)){
25  nrFound++;
26  }
27  }
28  }
29  }
30  return nrFound;
31 }
32 
34 {
35  if(!recHits || superClus.seed()->seed().subdetId()!=EcalBarrel) return false;
36  for(const auto & clus : superClus.clusters()){
37  for(const auto& hit : clus->hitsAndFractions()){
38  auto recHitIt = recHits->find(hit.first);
39  if(recHitIt!=recHits->end() &&
40  recHitIt->checkFlags(gainSwitchFlags())){
41  return true;
42  }
43  }
44  }
45  return false;
46 }
47 
49 {
50  if(recHits || superClus.seed()->seed().subdetId()!=EcalBarrel) return nrCrysWithFlagsIn5x5(superClus.seed()->seed(),gainSwitchFlags(),recHits,topology)!=0;
51  else return false;
52 }
53 
55 {
56  if(!recHits) return false;
57  for(auto hit : *recHits){
58  if(hit.id().subdetId()==EcalBarrel && hit.checkFlags(gainSwitchFlags())) return true;
59  }
60  return false;
61 }
62 
63 //needs to be multifit rec-hits currently as weights dont have gs flags set
65 {
66  std::vector<DetId> gsDetIds;
68 
69  for ( int eastNr = -2; eastNr <= 2; ++eastNr ) { //east is eta in barrel
70  for ( int northNr = -2; northNr <= 2; ++northNr ) { //north is phi in barrel
71  cursor.home();
72  cursor.offsetBy( eastNr, northNr);
73  DetId id = *cursor;
74  auto recHitIt = recHits->find(id);
75  if(recHitIt!=recHits->end() &&
76  recHitIt->checkFlags(gainSwitchFlags())){
77  gsDetIds.push_back(id);
78  }
79  }
80  }
81  return gsDetIds;
82 }
83 
84 //it should be a reasonable assumption that the GS hits should be in the supercluster with fraction ~1 for
85 //isolated electrons/photons
86 float GainSwitchTools::newRawEnergyNoFracs(const reco::SuperCluster& superClus,const std::vector<DetId> gainSwitchedHitIds,const EcalRecHitCollection* oldRecHits,const EcalRecHitCollection* newRecHits)
87 {
88  double oldEnergy=0.;
89  double newEnergy=0.;
90  for(auto& id : gainSwitchedHitIds){
91  auto oldRecHitIt = oldRecHits->find(id);
92  if(oldRecHitIt!=oldRecHits->end()) oldEnergy+=oldRecHitIt->energy();
93  auto newRecHitIt = newRecHits->find(id);
94  if(newRecHitIt!=newRecHits->end()) newEnergy+=newRecHitIt->energy();
95  }
96 
97  float newRawEnergy = superClus.rawEnergy() - oldEnergy + newEnergy;
98 
99  return newRawEnergy;
100 }
101 
102 
103 void
105 {
106  if(ssType==ShowerShapeType::Full5x5) showerShape.hcalDepth1OverEcal/=eNewOverEOld;
107  if(ssType==ShowerShapeType::Full5x5) showerShape.hcalDepth2OverEcal/=eNewOverEOld;
108  showerShape.hcalDepth1OverEcalBc/=eNewOverEOld;
109  showerShape.hcalDepth2OverEcalBc/=eNewOverEOld;
110 }
111 
112 void
114 {
115  showerShape.hcalDepth1OverEcal/=eNewOverEOld;
116  showerShape.hcalDepth2OverEcal/=eNewOverEOld;
117  showerShape.hcalDepth1OverEcalBc/=eNewOverEOld;
118  showerShape.hcalDepth2OverEcalBc/=eNewOverEOld;
119 }
120 
121 
122 int GainSwitchTools::calDIEta(int lhs,int rhs)
123 {
124  int retVal = lhs - rhs;
125  if(lhs*rhs<0){ //crossing zero
126  if(retVal<0) retVal++;
127  else retVal--;
128  }
129  return retVal;
130 }
131 
132 int GainSwitchTools::calDIPhi(int lhs,int rhs)
133 {
134  int retVal = lhs-rhs;
135  while(retVal>180) retVal-=360;
136  while(retVal<-180) retVal+=360;
137  return retVal;
138 }
static int calDIEta(int lhs, int rhs)
CaloTopology const * topology(0)
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:69
static const std::vector< int > gainSwitchFlags()
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
static void correctHadem(reco::GsfElectron::ShowerShape &showerShape, float eNewOverEOld, const GainSwitchTools::ShowerShapeType ssType)
unsigned int id
const_iterator end() const
void home() const
move the navigator back to the starting point
Definition: DetId.h:18
static float newRawEnergyNoFracs(const reco::SuperCluster &superClus, const std::vector< DetId > gainSwitchedHitIds, const EcalRecHitCollection *oldRecHits, const EcalRecHitCollection *newRecHits)
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:47
static bool hasEBGainSwitch(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits)
static std::vector< DetId > gainSwitchedIdsIn5x5(const DetId &id, const EcalRecHitCollection *recHits, const CaloTopology *topology)
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:26
iterator find(key_type k)
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 int calDIPhi(int lhs, int rhs)
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66