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);
158 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
" Component hit type " <<
typeid(*mymap[
counter].first).
name()
159 <<
" and dim:" << mymap[
counter].first->dimension()
160 <<
" position (PRECISE!!!)" << mymap[
counter].first->localPosition()
161 <<
" error " << mymap[
counter].first->localPositionError()
162 <<
" with weight " <<
p ;
166 normmap.push_back(std::pair<const TrackingRecHit*,float>(mymap[counter].
first, p));
176 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" Updated Hit position " << updated.localPosition()
177 <<
" updated error " << updated.localPositionError() << std::endl;
179 return std::make_shared<SiTrackerMultiRecHit>(param.first, param.second, *normmap.front().first->det(),
normmap, annealing);
182 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" No hits with weight (> 10e-6) have been found for this MRH." << std::endl;
192 case 1:
return ComputeWeight<1>(tsos,aRecHit,CutWeight,annealing);
193 case 2:
return ComputeWeight<2>(tsos,aRecHit,CutWeight,annealing);
194 case 3:
return ComputeWeight<3>(tsos,aRecHit,CutWeight,annealing);
195 case 4:
return ComputeWeight<4>(tsos,aRecHit,CutWeight,annealing);
196 case 5:
return ComputeWeight<5>(tsos,aRecHit,CutWeight,annealing);
198 throw cms::Exception(
"Rec hit of invalid dimension (not 1,2,3,4,5)") <<
199 "The value was " << aRecHit.
dimension() <<
200 ", type is " <<
typeid(aRecHit).
name() <<
"\n";
204 template <
unsigned int N>
222 holder.template setup<N>(&
r, &
R, &
pf, &rMeas, &RMeas,
x,
C);
228 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t r:" <<
r ;
229 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t tsospos:" << rMeas ;
230 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t diff:" <<
diff ;
231 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R:" <<
R ;
232 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t RMeas:" << RMeas ;
236 if(!CutWeight)
LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R+RMeas:" <<
R ;
254 bool ierr = R.Det2(det);
257 double Chi2 = ROOT::Math::Similarity(diff, R);
259 if( !ierr || !ierr2 ) {
260 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::ComputeWeight: W not valid!"<<std::endl;
261 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"V: "<<R<<
" AnnealingFactor: "<<annealing<<std::endl;
266 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t det:" << det;
267 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2:" <<
Chi2;
268 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2/ann:" << Chi2/annealing;
271 double temp_weight = 0.0;
272 if( CutWeight &&
N == 1 ){
275 }
else if( CutWeight &&
N == 2 ) {
281 temp_weight =
exp(-0.5*Chi2/annealing);
292 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::LocalParameters: dim first recHit: " << aHitMap[0].first->dimension() <<std::endl;
293 switch (aHitMap[0].
first->dimension()) {
294 case 1:
return calcParameters<1>(tsos,aHitMap);
295 case 2:
return calcParameters<2>(tsos,aHitMap);
297 throw cms::Exception(
"Rec hit of invalid dimension for computing MRH (not 1,2)") <<
298 "The value was " << aHitMap[0].first->dimension() <<
299 ", type is " <<
typeid(aHitMap[0].first).
name() <<
"\n";
304 template <
unsigned int N>
318 for( std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator ihit = aHitMap.begin();
319 ihit != aHitMap.end(); ihit++ ){
330 holder.template setup<N>(&
r, &V, &
pf, &rMeas, &VMeas,
x,
C);
331 (ihit->first)->getKfComponents(holder);
333 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t position: " <<
r;
334 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error: " << V;
338 V(0,1) = V(1,0) = V(0,1)*
s;
340 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error scorr: " << V;
345 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: V not valid!";
347 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse error: " << V;
350 m_sum += (ihit->second*V*
r);
351 W_sum += (ihit->second*V);
357 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: W_sum not valid!";
360 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse total error: " << W_sum;
370 else error =
LocalError(W_sum(0,0), W_sum(0,1), W_sum(1,1));
374 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
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)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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
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
Detector det() const
get the detector field from this detid
const PositionType & position() const
LocalParameters calcParameters(const TrajectoryStateOnSurface &tsos, std::vector< std::pair< const TrackingRecHit *, float > > &aHitMap) const