CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFCluster.cc
Go to the documentation of this file.
2 
3 #include "vdt/vdtMath.h"
4 #include "Math/GenVector/etaMax.h"
5 
6 namespace {
7 
8  // an implementation of Eta_FromRhoZ of root libraries using vdt
9  template<typename Scalar>
10  inline Scalar Eta_FromRhoZ_fast(Scalar rho, Scalar z) {
11  using namespace ROOT::Math;
12  // value to control Taylor expansion of sqrt
13  const Scalar big_z_scaled =
14  std::pow(std::numeric_limits<Scalar>::epsilon(),static_cast<Scalar>(-.25));
15  if (rho > 0) {
16  Scalar z_scaled = z/rho;
17  if (std::fabs(z_scaled) < big_z_scaled) {
18  return vdt::fast_log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0));
19  } else {
20  // apply correction using first order Taylor expansion of sqrt
21  return z>0 ? vdt::fast_log(2.0*z_scaled + 0.5/z_scaled) : -vdt::fast_log(-2.0*z_scaled);
22  }
23  }
24  // case vector has rho = 0
25  else if (z==0) {
26  return 0;
27  }
28  else if (z>0) {
29  return z + etaMax<Scalar>();
30  }
31  else {
32  return z - etaMax<Scalar>();
33  }
34  }
35 
36  inline void calculateREP(const math::XYZPoint& pos, double& rho, double& eta, double& phi) {
37  const double z = pos.z();
38  rho = pos.Rho();
39  eta = Eta_FromRhoZ_fast<double>(rho,z);
40  phi = (pos.x()==0 && pos.y()==0) ? 0 : vdt::fast_atan2(pos.y(), pos.x());
41  }
42 
43 }
44 
45 using namespace std;
46 using namespace reco;
47 
48 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
49 std::atomic<int> PFCluster::depthCorMode_{0};
50 std::atomic<double> PFCluster::depthCorA_{0.89};
51 std::atomic<double> PFCluster::depthCorB_{7.3};
52 std::atomic<double> PFCluster::depthCorAp_{0.89};
53 std::atomic<double> PFCluster::depthCorBp_{4.0};
54 #else
55 int PFCluster::depthCorMode_ = 0;
56 double PFCluster::depthCorA_ = 0.89;
57 double PFCluster::depthCorB_ = 7.3;
58 double PFCluster::depthCorAp_ = 0.89;
59 double PFCluster::depthCorBp_ = 4.0;
60 #endif
61 
62 
63 const math::XYZPoint PFCluster::dummyVtx_(0,0,0);
64 
65 PFCluster::PFCluster(PFLayer::Layer layer, double energy,
66  double x, double y, double z ) :
67  CaloCluster( energy,
68  math::XYZPoint(x,y,z),
69  PFLayer::toCaloID(layer),
71  posrep_( position_.Rho(), position_.Eta(), position_.Phi() ),
72  time_(-99.),
73  depth_(0.),
74  layer_(layer),
75  color_(2)
76 { }
77 
78 
80 
81  energy_ = 0;
82  position_ *= 0;
83  posrep_ *= 0;
84  time_=-99.;
86  rechits_.clear();
87 
89 
90 }
91 
93 
94  rechits_.clear();
95  hitsAndFractions_.clear();
96 
97 }
98 
100 
101  rechits_.push_back( frac );
102 
103  addHitAndFraction( frac.recHitRef()->detId(),
104  frac.fraction() );
105 }
106 
107 
108 double PFCluster::getDepthCorrection(double energy, bool isBelowPS,
109  bool isHadron)
110 {
111  double corrA = depthCorA_;
112  double corrB = depthCorB_;
113  if (isBelowPS) {
114  corrA = depthCorAp_;
115  corrB = depthCorBp_;
116  }
117  return isHadron ? corrA : corrA*(corrB + log(energy));
118 }
119 
121  // cout<<"calling PFCluster::setLayer "<<layer<<endl;
122  layer_ = layer;
123  caloID_ = PFLayer::toCaloID( layer );
124  // cout<<"done "<<caloID_<<endl;
125 }
126 
127 
129 
130  // cout<<"calling PFCluster::layer "<<caloID()<<" "<<PFLayer::fromCaloID( caloID() )<<endl;
131  if( layer_ != PFLayer::NONE ) return layer_;
132  return PFLayer::fromCaloID( caloID() );
133 }
134 
135 
137 
138  CaloCluster::operator=(other);
139  rechits_ = other.rechits_;
140  energy_ = other.energy_;
141  position_ = other.position_;
142  posrep_ = other.posrep_;
143  color_ = other.color_;
144 
145  return *this;
146 }
147 
148 
149 std::ostream& reco::operator<<(std::ostream& out,
150  const PFCluster& cluster) {
151 
152  if(!out) return out;
153 
154  const math::XYZPoint& pos = cluster.position();
155  const PFCluster::REPPoint& posrep = cluster.positionREP();
156  const std::vector< reco::PFRecHitFraction >& fracs =
157  cluster.recHitFractions();
158 
159  out<<"PFcluster "
160  <<", layer: "<<cluster.layer()
161  <<"\tE = "<<cluster.energy()
162  <<"\tXYZ: "
163  <<pos.X()<<","<<pos.Y()<<","<<pos.Z()<<" | "
164  <<"\tREP: "
165  <<posrep.Rho()<<","<<posrep.Eta()<<","<<posrep.Phi()<<" | "
166  <<fracs.size()<<" rechits";
167 
168  for(unsigned i=0; i<fracs.size(); i++) {
169  // PFRecHit is not available, print the detID
170  if( !fracs[i].recHitRef().isAvailable() )
171  out<<cluster.printHitAndFraction(i)<<", ";
172  else
173  out<<fracs[i]<<", ";
174  }
175 
176  return out;
177 }
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:128
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:120
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
int i
Definition: DBlmapReader.cc:9
math::XYZPoint position_
cluster centroid position
Definition: CaloCluster.h:212
static const char layer_[]
CaloID caloID_
bitmask for detector information
Definition: CaloCluster.h:215
void addHitAndFraction(DetId id, float fraction)
Definition: CaloCluster.h:185
double energy_
cluster energy
Definition: CaloCluster.h:207
static std::atomic< double > depthCorAp_
Definition: PFCluster.h:200
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:47
double Scalar
Definition: Definitions.h:27
std::vector< reco::PFRecHitFraction > rechits_
vector of rechit fractions (transient)
Definition: PFCluster.h:177
PFLayer::Layer layer_
transient layer
Definition: PFCluster.h:187
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
PFCluster & operator=(const PFCluster &)
Definition: PFCluster.cc:136
std::vector< std::pair< DetId, float > > hitsAndFractions_
Definition: CaloCluster.h:218
static std::atomic< double > depthCorB_
Definition: PFCluster.h:197
double fraction() const
tuple particleFlow
Definition: pfLinker_cff.py:5
float float float z
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:71
const CaloID & caloID() const
Definition: CaloCluster.h:183
T sqrt(T t)
Definition: SSEVec.h:18
const REPPoint & positionREP() const
cluster position: rho, eta, phi
Definition: PFCluster.h:93
layer definition for PFRecHit and PFCluster
Definition: PFLayer.h:21
double time_
Michalis :Add timing and depth information.
Definition: PFCluster.h:183
void reset()
resets clusters parameters
Definition: PFCluster.cc:79
double energy() const
cluster energy
Definition: PFCluster.h:82
void resetHitsAndFractions()
reset only hits and fractions
Definition: PFCluster.cc:92
std::string printHitAndFraction(unsigned i) const
print hitAndFraction
Definition: CaloCluster.cc:17
Layer
layer definition
Definition: PFLayer.h:31
static reco::CaloID toCaloID(Layer layer)
Definition: PFLayer.cc:11
static double getDepthCorrection(double energy, bool isBelowPS=false, bool isHadron=false)
Definition: PFCluster.cc:108
REPPoint posrep_
cluster position: rho, eta, phi (transient)
Definition: PFCluster.h:180
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Geom::Phi< T > phi() const
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:99
static std::atomic< double > depthCorBp_
Definition: PFCluster.h:203
int color_
color (transient)
Definition: PFCluster.h:224
static std::atomic< double > depthCorA_
Definition: PFCluster.h:194
static Layer fromCaloID(const reco::CaloID &id)
Definition: PFLayer.cc:29
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
Definition: PFCluster.h:54
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:72
const PFRecHitRef & recHitRef() const
void reset()
resets the CaloCluster (position, energy, hitsAndFractions)
Definition: CaloCluster.cc:11
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40