15 const std::vector<double>& anAnnealingProgram,
18 theHitPropagator(hitpropagator),
20 theAnnealingProgram(anAnnealingProgram),
28 float annealing)
const{
29 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::buildMultiRecHit with AnnealingFactor: " << annealing;
31 for (std::vector<const TrackingRecHit*>::const_iterator
iter = rhv.begin();
iter != rhv.end();
iter++){
33 if (transient->isValid()) tcomponents.push_back(
transient);
35 return update(tcomponents, tsos, annealing);
41 double annealing)
const{
42 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::update with AnnealingFactor: " << annealing;
46 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"!!! MultiRecHitUpdator::update(..): tsos NOT valid!!! ";
50 if(original->isValid()){
51 if (original->transientHits().empty()){
59 return update(tcomponents, tsos, annealing);
65 double annealing)
const{
67 if (tcomponents.empty()){
68 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Empty components vector passed to SiTrackerMultiRecHitUpdator::update, returning an InvalidTransientRecHit ";
69 return std::make_shared<InvalidTrackingRecHitNoDet>();
73 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::update: tsos NOT valid!!!, returning an InvalidTransientRecHit";
74 return std::make_shared<InvalidTrackingRecHitNoDet>();
77 std::vector<TransientTrackingRecHit::RecHitPointer> updatedcomponents;
81 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator
iter = tcomponents.begin();
iter != tcomponents.end();
iter++){
84 if (
iter == tcomponents.begin()) {
86 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
87 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"the Trajectory state and the first rechit passed to the SiTrackerMultiRecHitUpdator lay on different surfaces!: state lays on surface " << tsos.
surface().
position() <<
" hit with detid " << (*iter)->det()->geographicalId().rawId() <<
" lays on surface " << (*iter)->det()->surface().position();
90 geomdet = (*iter)->det();
96 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
100 if (cloned->isValid()) updatedcomponents.push_back(cloned);
104 if (cloned->isValid()){
105 updatedcomponents.push_back(cloned);
110 std::vector<std::pair<const TrackingRecHit*, float> > mymap;
111 std::vector<std::pair<const TrackingRecHit*, float> >
normmap;
113 double a_sum=0, c_sum=0;
116 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
117 ihit != updatedcomponents.end(); ihit++) {
119 double a_i =
ComputeWeight(tsos, *(*ihit),
false, annealing);
121 mymap.push_back(std::pair<const TrackingRecHit*, float>((*ihit)->hit(), a_i));
126 double total_sum = a_sum + c_sum;
129 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
130 ihit != updatedcomponents.end(); ihit++) {
132 double p = ((mymap[
counter].second)/total_sum > 1.
e-6 ? (mymap[counter].
second)/total_sum : 1.e-6);
134 normmap.push_back(std::pair<const TrackingRecHit*,float>(mymap[counter].
first, p));
136 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
" Component hit type " <<
typeid(*mymap[
counter].first).
name()
137 <<
" position " << mymap[
counter].first->localPosition()
138 <<
" error " << mymap[
counter].first->localPositionError()
139 <<
" with weight " <<
p;
146 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" Updated Hit position " << updated.localPosition()
147 <<
" updated error " << updated.localPositionError() << std::endl;
149 return std::make_shared<SiTrackerMultiRecHit>(param.first, param.second, *normmap.front().first->det(),
normmap, annealing);
158 case 1:
return ComputeWeight<1>(tsos,aRecHit,CutWeight,annealing);
159 case 2:
return ComputeWeight<2>(tsos,aRecHit,CutWeight,annealing);
160 case 3:
return ComputeWeight<3>(tsos,aRecHit,CutWeight,annealing);
161 case 4:
return ComputeWeight<4>(tsos,aRecHit,CutWeight,annealing);
162 case 5:
return ComputeWeight<5>(tsos,aRecHit,CutWeight,annealing);
164 throw cms::Exception(
"Rec hit of invalid dimension (not 1,2,3,4,5)") <<
165 "The value was " << aRecHit.
dimension() <<
166 ", type is " <<
typeid(aRecHit).
name() <<
"\n";
170 template <
unsigned int N>
189 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
" TSOS position not correct. Rec hit of invalid dimension (not 1, 2) but "
202 holder.template setup<N>(&
r, &V, &pf, &rMeas, &VMeas,
x,
C);
219 bool ierr2 = V.Det2(det);
221 if( !ierr || !ierr2) {
222 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::ComputeWeight: W not valid!"<<std::endl;
223 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"V: "<<V<<
" AnnealingFactor: "<<annealing<<std::endl;
226 double Chi2 = ROOT::Math::Similarity(diff,W);
230 else temp_weight =
exp(-0.5*Chi2)/(2.*
M_PI*
sqrt(det));
242 for(std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator ihit = aHitMap.begin(); ihit != aHitMap.end(); ihit++){
244 std::pair<AlgebraicVector2,AlgebraicSymMatrix22> PositionAndError22;
247 W_sum += (ihit->second*PositionAndError22.second);
248 m_sum += (ihit->second*(PositionAndError22.second*PositionAndError22.first));
255 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: V_sum not valid!"<<std::endl;
262 return std::make_pair(position,error);
270 case 2:
return ComputeParameters2dim<2>(tsos,aRecHit);
272 case ( 1 || 3 || 4 || 5 ):{
275 dummyMatrix2D(0,0) = dummyMatrix2D(1,0) = dummyMatrix2D(1,1) = 0.0;
276 return std::make_pair(dummyVector2D,dummyMatrix2D);
279 throw cms::Exception(
"Rec hit of invalid dimension (not 1,2,3,4,5)") <<
280 "The value was " << aRecHit.
dimension() <<
281 ", type is " <<
typeid(aRecHit).
name() <<
"\n";
285 template <
unsigned int N>
298 holder.template setup<N>(&
r, &V, &pf, &rMeas, &VMeas,
x,
C);
304 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::ComputeParameters2dim: W not valid!"<<std::endl;
314 W2dim(0,0) = Wtemp(0,0);
315 W2dim(1,0) = Wtemp(1,0);
316 W2dim(1,1) = Wtemp(1,1);
318 return std::make_pair(m2dim,W2dim);
virtual int dimension() const =0
virtual void getKfComponents(KfComponentsHolder &holder) const
std::pair< AlgebraicVector2, AlgebraicSymMatrix22 > ComputeParameters2dim(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit &aRecHit) const
ROOT::Math::SMatrix< double, D1, D1, ROOT::Math::MatRepSym< double, D1 > > SymMatrix
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepSym< double, 2 > > AlgebraicSymMatrix22
const LocalTrajectoryParameters & localParameters() const
virtual TransientTrackingRecHit::RecHitPointer update(TransientTrackingRecHit::ConstRecHitPointer original, const TrajectoryStateOnSurface &tsos, double annealing=1.) const
LocalPoint localPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double ComputeWeight(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit &aRecHit, bool CutWeight, double annealing=1.) const
virtual TrackingRecHit::ConstRecHitPointer makeShared(SiPixelRecHit const &hit, TrajectoryStateOnSurface const &tsos) const override
std::pair< LocalPoint, LocalError > LocalParameters
const TrackingRecHitPropagator * theHitPropagator
U second(std::pair< T, U > const &p)
AlgebraicVector5 vector() const
virtual TransientTrackingRecHit::RecHitPointer buildMultiRecHit(const std::vector< const TrackingRecHit * > &rhv, const TrajectoryStateOnSurface &tsos, float annealing=1.) const
const SurfaceType & surface() const
TkClonerImpl theHitCloner
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const TransientTrackingRecHitBuilder * theBuilder
SiTrackerMultiRecHitUpdator(const TransientTrackingRecHitBuilder *builder, const TrackingRecHitPropagator *hitpropagator, const float Chi2Cut, const std::vector< double > &anAnnealingProgram, bool debug)
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
std::shared_ptr< TrackingRecHit const > RecHitPointer
std::vector< ConstRecHitPointer > ConstRecHitContainer
ROOT::Math::SVector< double, D1 > Vector
ROOT::Math::SVector< double, 5 > AlgebraicVector5
static std::atomic< unsigned int > counter
static int position[264][3]
TrackingRecHit::RecHitPointer project(const TrackingRecHit::ConstRecHitPointer hit, const GeomDet &det, const TrajectoryStateOnSurface ts, const TransientTrackingRecHitBuilder *builder) const
const PositionType & position() const
LocalParameters calcParameters(const TrajectoryStateOnSurface &tsos, std::vector< std::pair< const TrackingRecHit *, float > > &aHitMap) const
ROOT::Math::SVector< double, 2 > AlgebraicVector2