19 const float Chi2Cut1D,
20 const float Chi2Cut2D,
21 const std::vector<double>& anAnnealingProgram,
24 theHitPropagator(hitpropagator),
25 theChi2Cut1D(Chi2Cut1D),
26 theChi2Cut2D(Chi2Cut2D),
27 theAnnealingProgram(anAnnealingProgram),
37 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::buildMultiRecHit with AnnealingFactor: " << annealing;
40 for (std::vector<const TrackingRecHit*>::const_iterator iter = rhv.begin(); iter != rhv.end(); iter++){
43 if(transient->isValid()) tcomponents.push_back(
transient);
46 return update(tcomponents, tsos, measDet, annealing);
52 double annealing )
const{
54 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::update with AnnealingFactor: " << annealing;
58 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"!!! MultiRecHitUpdator::update(..): tsos NOT valid!!! ";
62 if(original->isValid()){
63 if (original->transientHits().empty()){
71 return update(tcomponents, tsos, measDet, annealing);
79 if (tcomponents.empty()){
80 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Empty components vector passed to SiTrackerMultiRecHitUpdator::update, returning an InvalidTransientRecHit ";
85 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::update: tsos NOT valid!!!, returning an InvalidTransientRecHit";
89 std::vector<TransientTrackingRecHit::RecHitPointer> updatedcomponents;
90 const GeomDet* geomdet =
nullptr;
93 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator iter = tcomponents.begin(); iter != tcomponents.end(); iter++){
96 if (iter == tcomponents.begin()) {
98 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
99 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"the Trajectory state and the first rechit " 100 "passed to the SiTrackerMultiRecHitUpdator lay on different surfaces!: state lays on surface " 101 << tsos.
surface().
position() <<
" hit with detid " << (*iter)->det()->geographicalId().rawId()
102 <<
" lays on surface " << (*iter)->det()->surface().position();
105 geomdet = (*iter)->det();
111 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
116 if (cloned->isValid()) updatedcomponents.push_back(cloned);
120 if (cloned->isValid()){
121 updatedcomponents.push_back(cloned);
126 std::vector<std::pair<const TrackingRecHit*, float> > mymap;
127 std::vector<std::pair<const TrackingRecHit*, float> >
normmap;
129 double a_sum=0, c_sum=0;
132 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
133 ihit != updatedcomponents.end(); ihit++) {
135 double a_i =
ComputeWeight(tsos, *(*ihit),
false, annealing);
136 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t a_i:" << a_i ;
139 mymap.push_back(std::pair<const TrackingRecHit*, float>((*ihit)->hit(), a_i));
143 if( ihit == updatedcomponents.begin() ) c_sum =
ComputeWeight(tsos, *(*ihit),
true, annealing);
145 double total_sum = a_sum + c_sum;
146 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t c_sum:" << c_sum ;
147 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t total sum:" << total_sum ;
151 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
152 ihit != updatedcomponents.end(); ihit++) {
154 double p = ((mymap[
counter].second)/total_sum > 1.
e-12 ? (mymap[counter].
second)/total_sum : 1.e-12);
160 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
" Component hit type " <<
typeid(
tmp).
name()
161 <<
" and dim:" <<
tmp.dimension()
162 <<
" position (PRECISE!!!)" <<
tmp.localPosition()
163 <<
" error " <<
tmp.localPositionError()
164 <<
" with weight " <<
p ;
169 normmap.push_back(std::pair<const TrackingRecHit*,float>(mymap[counter].
first, p));
179 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" Updated Hit position " << updated.localPosition()
180 <<
" updated error " << updated.localPositionError() << std::endl;
182 return std::make_shared<SiTrackerMultiRecHit>(param.first, param.second, *normmap.front().first->det(),
normmap, annealing);
185 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" No hits with weight (> 10e-6) have been found for this MRH." << std::endl;
195 case 1:
return ComputeWeight<1>(tsos,aRecHit,CutWeight,annealing);
196 case 2:
return ComputeWeight<2>(tsos,aRecHit,CutWeight,annealing);
197 case 3:
return ComputeWeight<3>(tsos,aRecHit,CutWeight,annealing);
198 case 4:
return ComputeWeight<4>(tsos,aRecHit,CutWeight,annealing);
199 case 5:
return ComputeWeight<5>(tsos,aRecHit,CutWeight,annealing);
201 throw cms::Exception(
"Rec hit of invalid dimension (not 1,2,3,4,5)") <<
202 "The value was " << aRecHit.
dimension() <<
203 ", type is " <<
typeid(aRecHit).
name() <<
"\n";
207 template <
unsigned int N>
225 holder.template setup<N>(&
r, &
R, &
pf, &rMeas, &RMeas,
x,
C);
231 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t r:" <<
r ;
232 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t tsospos:" << rMeas ;
233 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t diff:" <<
diff ;
234 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R:" <<
R ;
235 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t RMeas:" << RMeas ;
239 if(!CutWeight)
LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R+RMeas:" <<
R ;
257 bool ierr = R.Det2(det);
260 double Chi2 = ROOT::Math::Similarity(diff, R);
262 if( !ierr || !ierr2 ) {
263 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::ComputeWeight: W not valid!"<<std::endl;
264 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"V: "<<R<<
" AnnealingFactor: "<<annealing<<std::endl;
269 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t det:" << det;
270 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2:" <<
Chi2;
271 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2/ann:" << Chi2/annealing;
274 double temp_weight = 0.0;
275 if( CutWeight &&
N == 1 ){
278 }
else if( CutWeight &&
N == 2 ) {
284 temp_weight =
exp(-0.5*Chi2/annealing);
295 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::LocalParameters: dim first recHit: " << aHitMap[0].first->dimension() <<std::endl;
296 switch (aHitMap[0].
first->dimension()) {
297 case 1:
return calcParameters<1>(tsos,aHitMap);
298 case 2:
return calcParameters<2>(tsos,aHitMap);
300 throw cms::Exception(
"Rec hit of invalid dimension for computing MRH (not 1,2)") <<
301 "The value was " << aHitMap[0].first->dimension() <<
302 ", type is " <<
typeid(aHitMap[0].first).
name() <<
"\n";
307 template <
unsigned int N>
321 for( std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator ihit = aHitMap.begin();
322 ihit != aHitMap.end(); ihit++ ){
333 holder.template setup<N>(&
r, &V, &
pf, &rMeas, &VMeas,
x,
C);
334 (ihit->first)->getKfComponents(holder);
336 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t position: " <<
r;
337 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error: " << V;
341 V(0,1) = V(1,0) = V(0,1)*
s;
343 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error scorr: " << V;
348 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: V not valid!";
350 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse error: " << V;
353 m_sum += (ihit->second*V*
r);
354 W_sum += (ihit->second*V);
360 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: W_sum not valid!";
363 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse total error: " << W_sum;
373 else error =
LocalError(W_sum(0,0), W_sum(0,1), W_sum(1,1));
377 return std::make_pair(position,error);
virtual void getKfComponents(KfComponentsHolder &holder) const
Point3DBase< Scalar, LocalTag > LocalPoint
ROOT::Math::SMatrix< double, D1, D1, ROOT::Math::MatRepSym< double, D1 > > SymMatrix
const LocalTrajectoryParameters & localParameters() const
virtual TransientTrackingRecHit::RecHitPointer buildMultiRecHit(const std::vector< const TrackingRecHit * > &rhv, const TrajectoryStateOnSurface &tsos, MeasurementDetWithData &measDet, float annealing=1.) const
virtual const GeomDet & geomDet() 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
std::pair< LocalPoint, LocalError > LocalParameters
const TrackingRecHitPropagator * theHitPropagator
TrackingRecHit::ConstRecHitPointer makeShared(SiPixelRecHit const &hit, TrajectoryStateOnSurface const &tsos) const override
U second(std::pair< T, U > const &p)
AlgebraicVector5 vector() const
const SurfaceType & surface() const
TkClonerImpl theHitCloner
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual int dimension() const =0
const TransientTrackingRecHitBuilder * theBuilder
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
const MeasurementDet & mdet() const
SiTrackerMultiRecHitUpdator(const TransientTrackingRecHitBuilder *builder, const TrackingRecHitPropagator *hitpropagator, const float Chi2Cut1D, const float Chi2Cut2D, const std::vector< double > &anAnnealingProgram, bool debug)
std::shared_ptr< TrackingRecHit const > RecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual TransientTrackingRecHit::RecHitPointer update(TransientTrackingRecHit::ConstRecHitPointer original, const TrajectoryStateOnSurface &tsos, MeasurementDetWithData &measDet, double annealing=1.) const
ROOT::Math::SVector< double, D1 > Vector
ROOT::Math::SVector< double, 5 > AlgebraicVector5
bool TIDorTEChit(const TrackingRecHit *const &hit) const
std::vector< std::vector< double > > tmp
static std::atomic< unsigned int > counter
static int position[264][3]
DetId geographicalId() const
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
constexpr Detector det() const
get the detector field from this detid