CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaselinePFSCRegression.cc
Go to the documentation of this file.
4 
5 #include "TVector2.h"
7 
9  const CaloTopologyRecord& topofrom_es = es.get<CaloTopologyRecord>();
10  if( !topo_record ||
11  topofrom_es.cacheIdentifier() != topo_record->cacheIdentifier() ) {
12  topo_record = &topofrom_es;
14  }
15  const CaloGeometryRecord& geomfrom_es = es.get<CaloGeometryRecord>();
16  if( !geom_record ||
17  geomfrom_es.cacheIdentifier() != geom_record->cacheIdentifier() ) {
18  geom_record = &geomfrom_es;
20  }
21 }
22 
24  std::vector<float>& vars ) const {
25  vars.clear();
26  vars.resize(33);
27  const double rawEnergy = sc.rawEnergy(), calibEnergy = sc.correctedEnergy();
28  const edm::Ptr<reco::CaloCluster> &seed = sc.seed();
29  const size_t nVtx = vertices->size();
30  float maxDR=999., maxDRDPhi=999., maxDRDEta=999., maxDRRawEnergy=0.;
31  float subClusRawE[3], subClusDPhi[3], subClusDEta[3];
32  memset(subClusRawE,0,3*sizeof(float));
33  memset(subClusDPhi,0,3*sizeof(float));
34  memset(subClusDEta,0,3*sizeof(float));
35  size_t iclus=0;
36  for( auto clus = sc.clustersBegin()+1; clus != sc.clustersEnd(); ++clus ) {
37  const float this_deta = (*clus)->eta() - seed->eta();
38  const float this_dphi = TVector2::Phi_mpi_pi((*clus)->phi() - seed->phi());
39  const float this_dr = std::hypot(this_deta,this_dphi);
40  if(this_dr > maxDR || maxDR == 999.0f) {
41  maxDR = this_dr;
42  maxDRDEta = this_deta;
43  maxDRDPhi = this_dphi;
44  maxDRRawEnergy = (*clus)->energy();
45  }
46  if( iclus++ < 3 ) {
47  subClusRawE[iclus] = (*clus)->energy();
48  subClusDEta[iclus] = this_deta;
49  subClusDPhi[iclus] = this_dphi;
50  }
51  }
52  float scPreshowerSum = sc.preshowerEnergy();
53  switch( seed->hitsAndFractions().at(0).first.subdetId() ) {
54  case EcalBarrel:
55  {
56  const float eMax = EcalClusterTools::eMax( *seed, &*rechitsEB );
57  const float e2nd = EcalClusterTools::e2nd( *seed, &*rechitsEB );
58  const float e3x3 = EcalClusterTools::e3x3( *seed,
59  &*rechitsEB,
60  &*calotopo );
61  const float eTop = EcalClusterTools::eTop( *seed,
62  &*rechitsEB,
63  &*calotopo );
64  const float eBottom = EcalClusterTools::eBottom( *seed,
65  &*rechitsEB,
66  &*calotopo );
67  const float eLeft = EcalClusterTools::eLeft( *seed,
68  &*rechitsEB,
69  &*calotopo );
70  const float eRight = EcalClusterTools::eRight( *seed,
71  &*rechitsEB,
72  &*calotopo );
73  const float eLpeR = eLeft + eRight;
74  const float eTpeB = eTop + eBottom;
75  const float eLmeR = eLeft - eRight;
76  const float eTmeB = eTop - eBottom;
77  std::vector<float> vCov =
78  EcalClusterTools::localCovariances( *seed, &*rechitsEB, &*calotopo );
79  const float see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
80  const float spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2]));
81  float sep = 0.;
82  if (see*spp > 0)
83  sep = vCov[1] / (see * spp);
84  else if (vCov[1] > 0)
85  sep = 1.0;
86  else
87  sep = -1.0;
88  float cryPhi, cryEta, thetatilt, phitilt;
89  int ieta, iphi;
90  ecl_.localCoordsEB(*seed, *calogeom, cryEta, cryPhi,
91  ieta, iphi, thetatilt, phitilt);
92  vars[0] = nVtx; //nVtx
93  vars[1] = sc.eta(); //scEta
94  vars[2] = sc.phi(); //scPhi
95  vars[3] = sc.etaWidth(); //scEtaWidth
96  vars[4] = sc.phiWidth(); //scPhiWidth
97  vars[5] = e3x3/rawEnergy; //scSeedR9
98  vars[6] = sc.seed()->energy()/rawEnergy; //scSeedRawEnergy/scRawEnergy
99  vars[7] = eMax/rawEnergy; //scSeedEmax/scRawEnergy
100  vars[8] = e2nd/rawEnergy; //scSeedE2nd/scRawEnergy
101  vars[9] = (eLpeR!=0. ? eLmeR/eLpeR : 0.);//scSeedLeftRightAsym
102  vars[10] = (eTpeB!=0.? eTmeB/eTpeB : 0.);//scSeedTopBottomAsym
103  vars[11] = see; //scSeedSigmaIetaIeta
104  vars[12] = sep; //scSeedSigmaIetaIphi
105  vars[13] = spp; //scSeedSigmaIphiIphi
106  vars[14] = sc.clustersSize()-1; //N_ECALClusters
107  vars[15] = maxDR; //clusterMaxDR
108  vars[16] = maxDRDPhi; //clusterMaxDRDPhi
109  vars[17] = maxDRDEta; //clusterMaxDRDEta
110  vars[18] = maxDRRawEnergy/rawEnergy; //clusMaxDRRawEnergy/scRawEnergy
111  vars[19] = subClusRawE[0]/rawEnergy; //clusterRawEnergy[0]/scRawEnergy
112  vars[20] = subClusRawE[1]/rawEnergy; //clusterRawEnergy[1]/scRawEnergy
113  vars[21] = subClusRawE[2]/rawEnergy; //clusterRawEnergy[2]/scRawEnergy
114  vars[22] = subClusDPhi[0]; //clusterDPhiToSeed[0]
115  vars[23] = subClusDPhi[1]; //clusterDPhiToSeed[1]
116  vars[24] = subClusDPhi[2]; //clusterDPhiToSeed[2]
117  vars[25] = subClusDEta[0]; //clusterDEtaToSeed[0]
118  vars[26] = subClusDEta[1]; //clusterDEtaToSeed[1]
119  vars[27] = subClusDEta[2]; //clusterDEtaToSeed[2]
120  vars[28] = cryEta; //scSeedCryEta
121  vars[29] = cryPhi; //scSeedCryPhi
122  vars[30] = ieta; //scSeedCryIeta
123  vars[31] = iphi; //scSeedCryIphi
124  vars[32] = calibEnergy; //scCalibratedEnergy
125  }
126  break;
127  case EcalEndcap:
128  {
129  const float eMax = EcalClusterTools::eMax( *seed, &*rechitsEE );
130  const float e2nd = EcalClusterTools::e2nd( *seed, &*rechitsEE );
131  const float e3x3 = EcalClusterTools::e3x3( *seed,
132  &*rechitsEE,
133  &*calotopo );
134  const float eTop = EcalClusterTools::eTop( *seed,
135  &*rechitsEE,
136  &*calotopo );
137  const float eBottom = EcalClusterTools::eBottom( *seed,
138  &*rechitsEE,
139  &*calotopo );
140  const float eLeft = EcalClusterTools::eLeft( *seed,
141  &*rechitsEE,
142  &*calotopo );
143  const float eRight = EcalClusterTools::eRight( *seed,
144  &*rechitsEE,
145  &*calotopo );
146  const float eLpeR = eLeft + eRight;
147  const float eTpeB = eTop + eBottom;
148  const float eLmeR = eLeft - eRight;
149  const float eTmeB = eTop - eBottom;
150  std::vector<float> vCov =
151  EcalClusterTools::localCovariances( *seed, &*rechitsEE, &*calotopo );
152  const float see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
153  const float spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2]));
154  float sep = 0.;
155  if (see*spp > 0)
156  sep = vCov[1] / (see * spp);
157  else if (vCov[1] > 0)
158  sep = 1.0;
159  else
160  sep = -1.0;
161  vars[0] = nVtx; //nVtx
162  vars[1] = sc.eta(); //scEta
163  vars[2] = sc.phi(); //scPhi
164  vars[3] = sc.etaWidth(); //scEtaWidth
165  vars[4] = sc.phiWidth(); //scPhiWidth
166  vars[5] = e3x3/rawEnergy; //scSeedR9
167  vars[6] = sc.seed()->energy()/rawEnergy; //scSeedRawEnergy/scRawEnergy
168  vars[7] = eMax/rawEnergy; //scSeedEmax/scRawEnergy
169  vars[8] = e2nd/rawEnergy; //scSeedE2nd/scRawEnergy
170  vars[9] = (eLpeR!=0. ? eLmeR/eLpeR : 0.);//scSeedLeftRightAsym
171  vars[10] = (eTpeB!=0.? eTmeB/eTpeB : 0.);//scSeedTopBottomAsym
172  vars[11] = see; //scSeedSigmaIetaIeta
173  vars[12] = sep; //scSeedSigmaIetaIphi
174  vars[13] = spp; //scSeedSigmaIphiIphi
175  vars[14] = sc.clustersSize()-1; //N_ECALClusters
176  vars[15] = maxDR; //clusterMaxDR
177  vars[16] = maxDRDPhi; //clusterMaxDRDPhi
178  vars[17] = maxDRDEta; //clusterMaxDRDEta
179  vars[18] = maxDRRawEnergy/rawEnergy; //clusMaxDRRawEnergy/scRawEnergy
180  vars[19] = subClusRawE[0]/rawEnergy; //clusterRawEnergy[0]/scRawEnergy
181  vars[20] = subClusRawE[1]/rawEnergy; //clusterRawEnergy[1]/scRawEnergy
182  vars[21] = subClusRawE[2]/rawEnergy; //clusterRawEnergy[2]/scRawEnergy
183  vars[22] = subClusDPhi[0]; //clusterDPhiToSeed[0]
184  vars[23] = subClusDPhi[1]; //clusterDPhiToSeed[1]
185  vars[24] = subClusDPhi[2]; //clusterDPhiToSeed[2]
186  vars[25] = subClusDEta[0]; //clusterDEtaToSeed[0]
187  vars[26] = subClusDEta[1]; //clusterDEtaToSeed[1]
188  vars[27] = subClusDEta[2]; //clusterDEtaToSeed[2]
189  vars[28] = scPreshowerSum/rawEnergy; //scPreshowerEnergy/scRawEnergy
190  vars[29] = calibEnergy; //scCalibratedEnergy
191  }
192  break;
193  default:
194  throw cms::Exception("PFECALSuperClusterProducer::calculateRegressedEnergy")
195  << "Supercluster seed is either EB nor EE!" << std::endl;
196  }
197 }
198 
201  const edm::InputTag rceb = ps.getParameter<edm::InputTag>("ecalRecHitsEB");
202  const edm::InputTag rcee = ps.getParameter<edm::InputTag>("ecalRecHitsEE");
203  const edm::InputTag vtx = ps.getParameter<edm::InputTag>("vertexCollection");
204  inputTagEBRecHits_ = cc.consumes<EcalRecHitCollection>(rceb);
205  inputTagEERecHits_ = cc.consumes<EcalRecHitCollection>(rcee);
206  inputTagVertices_ = cc.consumes<reco::VertexCollection>(vtx);
207 }
208 
213 }
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
edm::EDGetTokenT< EcalRecHitCollection > inputTagEERecHits_
double correctedEnergy() const
Definition: CaloCluster.h:121
void setTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
double phiWidth() const
obtain phi and eta width of the Super Cluster
Definition: SuperCluster.h:55
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::Handle< reco::VertexCollection > vertices
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::Handle< EcalRecHitCollection > rechitsEB
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
edm::EDGetTokenT< EcalRecHitCollection > inputTagEBRecHits_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:161
double etaWidth() const
Definition: SuperCluster.h:56
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:48
void get(HolderT &iHolder) const
edm::ESHandle< CaloTopology > calotopo
void update(const edm::EventSetup &)
double f[11][100]
edm::EDGetTokenT< reco::VertexCollection > inputTagVertices_
void setEvent(const edm::Event &)
const CaloTopologyRecord * topo_record
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:47
edm::ESHandle< CaloGeometry > calogeom
size_t clustersSize() const
number of BasicCluster constituents
Definition: SuperCluster.h:87
const T & get() const
Definition: EventSetup.h:55
void localCoordsEB(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt) const
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
const CaloGeometryRecord * geom_record
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
double preshowerEnergy() const
energy deposited in preshower
Definition: SuperCluster.h:50
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:164
edm::Handle< EcalRecHitCollection > rechitsEE
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78
void set(const reco::SuperCluster &, std::vector< float > &) const