test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
71  if(abs(CrysIEta_)==1 || abs(CrysIEta_)==2 )
72  CrysIEtaCrack_=abs(CrysIEta_);
73  if(abs(CrysIEta_)>2 && abs(CrysIEta_)<24)
75  if(abs(CrysIEta_)==24)
77  if(abs(CrysIEta_)==25)
79  if(abs(CrysIEta_)==26)
81  if(abs(CrysIEta_)==27)
83  if(abs(CrysIEta_)>27 && abs(CrysIEta_)<44)
85  if(abs(CrysIEta_)==44)
87  if(abs(CrysIEta_)==45)
88  CrysIEtaCrack_=10;
89  if(abs(CrysIEta_)==46)
90  CrysIEtaCrack_=11;
91  if(abs(CrysIEta_)==47)
92  CrysIEtaCrack_=12;
93  if(abs(CrysIEta_)>47 && abs(CrysIEta_)<64)
94  CrysIEtaCrack_=13;
95  if(abs(CrysIEta_)==64)
96  CrysIEtaCrack_=14;
97  if(abs(CrysIEta_)==65)
98  CrysIEtaCrack_=15;
99  if(abs(CrysIEta_)==66)
100  CrysIEtaCrack_=16;
101  if(abs(CrysIEta_)==67)
102  CrysIEtaCrack_=17;
103  if(abs(CrysIEta_)>67 && abs(CrysIEta_)<84)
104  CrysIEtaCrack_=18;
105  if(abs(CrysIEta_)==84)
106  CrysIEtaCrack_=19;
107  if(abs(CrysIEta_)==85)
108  CrysIEtaCrack_=20;
109  }
110  else{
111  isEB_=false;
112  EEDetId EEidSeed=EEDetId(idseed_.rawId());
113  CrysIX_=EEidSeed.ix();
114  CrysIY_=EEidSeed.iy();
115  float X0 = 0.89; float T0 = 1.2;
116  if(fabs(PFClusterRef_->eta())>1.653)T0=3.1;
117  double depth = X0 * (T0 + log(PFClusterRef_->energy()));
118  math::XYZVector center_pos=(seedPosition_)+depth*seedAxis_;
119  double XCentr = center_pos.x();
120  double YCentr = center_pos.y();
121  double XWidth = 2.59;
122  double YWidth = 2.59;
123 
124  CrysX_=(PFClusterRef_->x()-XCentr)/XWidth;
125  CrysY_=(PFClusterRef_->y()-YCentr)/YWidth;
126  }
127 }
128 
130  const std::vector< reco::PFRecHitFraction >& PFRecHits=PFClusterRef_->recHitFractions();
131  for(std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin(); it != PFRecHits.end(); ++it){
132  const PFRecHitRef& RefPFRecHit = it->recHitRef();
133  DetId id=RefPFRecHit->detId();
134  double frac=it->fraction();
135  float E=RefPFRecHit->energy()*frac;
136  if(isEB_){
137  int deta=EBDetId::distanceEta(id,idseed_);
138  int dphi=EBDetId::distancePhi(id,idseed_);
139 
140  if(abs(deta)>2 ||abs(dphi)>2)continue;
141 
142  //f(abs(dphi)<=2 && abs(deta)<=2){
143  EBDetId EBidSeed=EBDetId(idseed_.rawId());
144  EBDetId EBid=EBDetId(id.rawId());
145  int ind1=EBidSeed.ieta()-EBid.ieta();
146  int ind2=EBidSeed.iphi()-EBid.iphi();
147  if(EBidSeed.ieta() * EBid.ieta() > 0){
148  ind1=EBid.ieta()-EBidSeed.ieta();
149  }
150  else{ //near EB+ EB-
151  int shift(EBidSeed.ieta()>0 ? -1 : 1);
152  ind1=EBidSeed.ieta()-EBid.ieta()+shift;
153  }
154 
155  // more tricky edges in phi. Note that distance is already <2 at this point
156  if( (EBidSeed.iphi()<5&&EBid.iphi()>355) || (EBidSeed.iphi()>355&&EBid.iphi()<5)) {
157  int shift(EBidSeed.iphi()<180 ? EBDetId::MAX_IPHI:-EBDetId::MAX_IPHI) ;
158  ind2 = shift + EBidSeed.iphi() - EBid.iphi();
159  // std::cout << " Phi check " << EBidSeed.iphi() << " " << EBid.iphi() << " " << ind2 << std::endl;
160  }
161 
162  int iEta=ind1+2;
163  int iPhi=ind2+2;
164  //std::cout<<"IEta, IPhi "<<iEta<<", "<<iPhi<<std::endl;
165 // if(iPhi >= 5 || iPhi <0) {
166 // std::cout << "dphi "<< EBDetId::distancePhi(id,idseed_) << " iphi " << EBid.iphi() << " iphiseed " << EBidSeed.iphi() << " iPhi " << iPhi << std::endl;}
167 // if(iEta >= 5 || iEta <0) {
168 // std::cout << "deta "<< EBDetId::distanceEta(id,idseed_) << " ieta " << EBid.ieta() << " ietaseed " << EBidSeed.ieta() << "ind1 " << ind1 << " iEta " << iEta << " " ;
169 // ind1=ind1prime;
170 // iEta=ind1+2;
171 // std::cout << " new iEta " << iEta << std::endl;
172 // }
173 // assert(iEta < 5);
174 // assert(iEta >= 0);
175 // assert(iPhi < 5);
176 // assert(iPhi >= 0);
177  e5x5_[iEta][iPhi]=E;
178  }
179  else{
180  int dx=EEDetId::distanceX(id,idseed_);
181  int dy=EEDetId::distanceY(id,idseed_);
182  if(abs(dx)>2 ||abs(dy>2))continue;
183  EEDetId EEidSeed=EEDetId(idseed_.rawId());
184  EEDetId EEid=EEDetId(id.rawId());
185  int ind1=EEid.ix()-EEidSeed.ix();
186  int ind2=EEid.iy()-EEidSeed.iy();
187  int ix=ind1+2;
188  int iy=ind2+2;
189  //std::cout<<"IX, IY "<<ix<<", "<<iy<<std::endl;
190 // assert(ix < 5);
191 // assert(ix >= 0);
192 // assert(iy < 5);
193 // assert(iy >= 0);
194  e5x5_[ix][iy]=E;
195  }
196  }
197 }
198 
200  double numeratorEtaWidth = 0.;
201  double numeratorPhiWidth = 0.;
202  double numeratorEtaPhiWidth = 0.;
203  double ClustEta=PFClusterRef_->eta();
204  double ClustPhi=PFClusterRef_->phi();
205  const std::vector< reco::PFRecHitFraction >& PFRecHits=PFClusterRef_->recHitFractions();
206  for(std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin(); it != PFRecHits.end(); ++it){
207  const PFRecHitRef& RefPFRecHit = it->recHitRef();
208  float E=RefPFRecHit->energy() * it->fraction();
209  double dEta = RefPFRecHit->position().eta() - ClustEta;
210  double dPhi = RefPFRecHit->position().phi() - ClustPhi;
211  if (dPhi > + TMath::Pi()) { dPhi = TMath::TwoPi() - dPhi; }
212  if (dPhi < - TMath::Pi()) { dPhi = TMath::TwoPi() + dPhi; }
213  numeratorEtaWidth += E * dEta * dEta;
214  numeratorPhiWidth += E * dPhi * dPhi;
215  numeratorEtaPhiWidth += E * fabs(dPhi) * fabs(dEta);
216  }
217  double denominator=PFClusterRef_->energy();
218  sigetaeta_ = sqrt(numeratorEtaWidth / denominator);
219  sigphiphi_ = sqrt(numeratorPhiWidth / denominator);
220  sigetaphi_ = sqrt(numeratorEtaPhiWidth / denominator);
221 }
const double TwoPi
const double Pi
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:76
static int distanceX(const EEDetId &a, const EEDetId &b)
Definition: EEDetId.cc:577
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
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
list denominator
Definition: cuy.py:484
math::XYZVector seedAxis_
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
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
int j
Definition: DBlmapReader.cc:9
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
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...
static int position[264][3]
Definition: ReadPGInfo.cc:509
static unsigned int const shift
static const double X0
math::XYZVector seedPosition_