CMS 3D CMS Logo

PFPhotonClusters.cc
Go to the documentation of this file.
6 #include <TMath.h>
7 #include <TVector2.h>
8 using namespace reco;
10  PFClusterRef_(PFClusterRef)
11 {
12  if(PFClusterRef_->layer()==PFLayer:: ECAL_BARREL )isEB_=true;
13  else isEB_=false;
14  SetSeed();
15  PFCrystalCoor();
16  for(int i=0; i<5; ++i)
17  for(int j=0; j<5; ++j)e5x5_[i][j]=0;
20 }
21 
23  double PFSeedE=0;
24  math::XYZVector axis;
26  DetId idseed;
27  const auto & PFRecHits=
28  PFClusterRef_->recHitFractions();
29 
30  for(auto it = PFRecHits.begin();
31  it != PFRecHits.end(); ++it){
32  const auto & RefPFRecHit = it->recHitRef();
33  auto frac=it->fraction();
34  float E= RefPFRecHit->energy()* frac;
35  if(E>PFSeedE){
36  PFSeedE=E;
37  // FIXME will optimize later...
38  auto const & pyr = dynamic_cast<TruncatedPyramid const &>(RefPFRecHit->caloCell());
39  axis = pyr.getPosition(1) - pyr.getPosition(0);
40  position=RefPFRecHit->position();
41  idseed = RefPFRecHit->detId();
42  }
43  }
44  idseed_=idseed;
46  seedAxis_=axis;
47 }
48 
50  if(PFClusterRef_->layer()==PFLayer:: ECAL_BARREL ){//is Barrel
51  isEB_=true;
52  EBDetId EBidSeed=EBDetId(idseed_.rawId());
53  CrysIEta_=EBidSeed.ieta();
54  CrysIPhi_=EBidSeed.iphi();
55  double depth = PFClusterRef_->getDepthCorrection(PFClusterRef_->energy(), false, false);
56  math::XYZVector center_pos = seedPosition_+depth*seedAxis_;
57  //Crystal Coordinates:
58  double Pi=TMath::Pi();
59  float Phi=PFClusterRef_->position().phi();
60  double Theta = -(PFClusterRef_->position().theta())+0.5* Pi;
61  double PhiCentr = TVector2::Phi_mpi_pi(center_pos.phi());
62  double PhiWidth = (Pi/180.);
63  double PhiCry = (TVector2::Phi_mpi_pi(Phi-PhiCentr))/PhiWidth;
64  double ThetaCentr = -center_pos.theta()+0.5*Pi;
65  double ThetaWidth = (Pi/180.)*cos(ThetaCentr);
66 
67  double EtaCry = (Theta-ThetaCentr)/ThetaWidth;
68  CrysEta_=EtaCry;
69  CrysPhi_=PhiCry;
70  switch(std::abs(CrysIEta_)) {
71  case 24:
73  break;
74  case 25:
76  break;
77  case 26:
79  break;
80  case 27:
82  break;
83  case 44:
85  break;
86  case 45:
87  CrysIEtaCrack_=10;
88  break;
89  case 46:
90  CrysIEtaCrack_=11;
91  break;
92  case 47:
93  CrysIEtaCrack_=12;
94  break;
95  case 64:
96  CrysIEtaCrack_=14;
97  break;
98  case 65:
99  CrysIEtaCrack_=15;
100  break;
101  case 66:
102  CrysIEtaCrack_=16;
103  break;
104  case 67:
105  CrysIEtaCrack_=17;
106  break;
107  case 84:
108  CrysIEtaCrack_=19;
109  break;
110  case 85:
111  CrysIEtaCrack_=20;
112  break;
113  default:
114  if(std::abs(CrysIEta_)==1 || std::abs(CrysIEta_)==2 )
115  CrysIEtaCrack_=std::abs(CrysIEta_);
116  else if(std::abs(CrysIEta_)>2 && std::abs(CrysIEta_)<24)
117  CrysIEtaCrack_=3;
118  else if(std::abs(CrysIEta_)>27 && std::abs(CrysIEta_)<44)
119  CrysIEtaCrack_=8;
120  else if(std::abs(CrysIEta_)>47 && std::abs(CrysIEta_)<64)
121  CrysIEtaCrack_=13;
122  else if(std::abs(CrysIEta_)>67 && std::abs(CrysIEta_)<84)
123  CrysIEtaCrack_=18;
124  break;
125  }
126  }
127  else{
128  isEB_=false;
129  EEDetId EEidSeed=EEDetId(idseed_.rawId());
130  CrysIX_=EEidSeed.ix();
131  CrysIY_=EEidSeed.iy();
132  float X0 = 0.89; float T0 = 1.2;
133  if(std::abs(PFClusterRef_->eta())>1.653)T0=3.1;
134  double depth = X0 * (T0 + log(PFClusterRef_->energy()));
135  math::XYZVector center_pos=(seedPosition_)+depth*seedAxis_;
136  double XCentr = center_pos.x();
137  double YCentr = center_pos.y();
138  double XWidth = 2.59;
139  double YWidth = 2.59;
140 
141  CrysX_=(PFClusterRef_->x()-XCentr)/XWidth;
142  CrysY_=(PFClusterRef_->y()-YCentr)/YWidth;
143  }
144 }
145 
147  const std::vector< reco::PFRecHitFraction >& PFRecHits=PFClusterRef_->recHitFractions();
148  for(std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin(); it != PFRecHits.end(); ++it){
149  const PFRecHitRef& RefPFRecHit = it->recHitRef();
150  DetId id=RefPFRecHit->detId();
151  double frac=it->fraction();
152  float E=RefPFRecHit->energy()*frac;
153  if(isEB_){
154  int deta=EBDetId::distanceEta(id,idseed_);
155  int dphi=EBDetId::distancePhi(id,idseed_);
156 
157  if(std::abs(deta)>2 ||std::abs(dphi)>2)continue;
158 
159  //if(std::abs(dphi)<=2 && std::abs(deta)<=2){
160  EBDetId EBidSeed=EBDetId(idseed_.rawId());
161  EBDetId EBid=EBDetId(id.rawId());
162  int ind1=EBidSeed.ieta()-EBid.ieta();
163  int ind2=EBidSeed.iphi()-EBid.iphi();
164  if(EBidSeed.ieta() * EBid.ieta() > 0){
165  ind1=EBid.ieta()-EBidSeed.ieta();
166  }
167  else{ //near EB+ EB-
168  int shift(EBidSeed.ieta()>0 ? -1 : 1);
169  ind1=EBidSeed.ieta()-EBid.ieta()+shift;
170  }
171 
172  // more tricky edges in phi. Note that distance is already <2 at this point
173  if( (EBidSeed.iphi()<5&&EBid.iphi()>355) || (EBidSeed.iphi()>355&&EBid.iphi()<5)) {
174  int shift(EBidSeed.iphi()<180 ? EBDetId::MAX_IPHI:-EBDetId::MAX_IPHI) ;
175  ind2 = shift + EBidSeed.iphi() - EBid.iphi();
176  // std::cout << " Phi check " << EBidSeed.iphi() << " " << EBid.iphi() << " " << ind2 << std::endl;
177  }
178 
179  int iEta=ind1+2;
180  int iPhi=ind2+2;
181  //std::cout<<"IEta, IPhi "<<iEta<<", "<<iPhi<<std::endl;
182 // if(iPhi >= 5 || iPhi <0) {
183 // std::cout << "dphi "<< EBDetId::distancePhi(id,idseed_) << " iphi " << EBid.iphi() << " iphiseed " << EBidSeed.iphi() << " iPhi " << iPhi << std::endl;}
184 // if(iEta >= 5 || iEta <0) {
185 // std::cout << "deta "<< EBDetId::distanceEta(id,idseed_) << " ieta " << EBid.ieta() << " ietaseed " << EBidSeed.ieta() << "ind1 " << ind1 << " iEta " << iEta << " " ;
186 // ind1=ind1prime;
187 // iEta=ind1+2;
188 // std::cout << " new iEta " << iEta << std::endl;
189 // }
190 // assert(iEta < 5);
191 // assert(iEta >= 0);
192 // assert(iPhi < 5);
193 // assert(iPhi >= 0);
194  e5x5_[iEta][iPhi]=E;
195  }
196  else{
197  int dx=EEDetId::distanceX(id,idseed_);
198  int dy=EEDetId::distanceY(id,idseed_);
199  if(std::abs(dx)>2 ||std::abs(dy)>2) continue;
200  EEDetId EEidSeed=EEDetId(idseed_.rawId());
201  EEDetId EEid=EEDetId(id.rawId());
202  int ind1=EEid.ix()-EEidSeed.ix();
203  int ind2=EEid.iy()-EEidSeed.iy();
204  int ix=ind1+2;
205  int iy=ind2+2;
206  //std::cout<<"IX, IY "<<ix<<", "<<iy<<std::endl;
207 // assert(ix < 5);
208 // assert(ix >= 0);
209 // assert(iy < 5);
210 // assert(iy >= 0);
211  e5x5_[ix][iy]=E;
212  }
213  }
214 }
215 
217  double numeratorEtaWidth = 0.;
218  double numeratorPhiWidth = 0.;
219  double numeratorEtaPhiWidth = 0.;
220  double ClustEta=PFClusterRef_->eta();
221  double ClustPhi=PFClusterRef_->phi();
222  const std::vector< reco::PFRecHitFraction >& PFRecHits=PFClusterRef_->recHitFractions();
223  for(std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin(); it != PFRecHits.end(); ++it){
224  const PFRecHitRef& RefPFRecHit = it->recHitRef();
225  float E=RefPFRecHit->energy() * it->fraction();
226  double dEta = RefPFRecHit->position().eta() - ClustEta;
227  double dPhi = RefPFRecHit->position().phi() - ClustPhi;
228  if (dPhi > + TMath::Pi()) { dPhi = TMath::TwoPi() - dPhi; }
229  if (dPhi < - TMath::Pi()) { dPhi = TMath::TwoPi() + dPhi; }
230  numeratorEtaWidth += E * dEta * dEta;
231  numeratorPhiWidth += E * dPhi * dPhi;
232  numeratorEtaPhiWidth += E * std::abs(dPhi) * std::abs(dEta);
233  }
234  double denominator=PFClusterRef_->energy();
235  sigetaeta_ = sqrt(numeratorEtaWidth / denominator);
236  sigphiphi_ = sqrt(numeratorPhiWidth / denominator);
237  sigetaphi_ = sqrt(numeratorEtaPhiWidth / denominator);
238 }
const double TwoPi
const double Pi
int ix() const
Definition: EEDetId.h:76
static int distanceX(const EEDetId &a, const EEDetId &b)
Definition: EEDetId.cc:577
reco::PFClusterRef PFClusterRef_
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static int distanceEta(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:135
math::XYZVector seedAxis_
T sqrt(T t)
Definition: SSEVec.h:18
static int distancePhi(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:143
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PFPhotonClusters(reco::PFClusterRef PFClusterRef)
int iy() const
Definition: EEDetId.h:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
static int distanceY(const EEDetId &a, const EEDetId &b)
Definition: EEDetId.cc:582
Definition: DetId.h:18
static const int MAX_IPHI
Definition: EBDetId.h:144
denominator
Definition: cuy.py:484
const GlobalPoint getPosition(CCGFloat depth) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
double e5x5_[5][5]
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
fixed size matrix
static int position[264][3]
Definition: ReadPGInfo.cc:509
static unsigned int const shift
static const double X0
math::XYZVector seedPosition_