21 const float Chi2Cut1D,
22 const float Chi2Cut2D,
23 const std::vector<double>& anAnnealingProgram,
26 theHitPropagator(hitpropagator),
27 theChi2Cut1D(Chi2Cut1D),
28 theChi2Cut2D(Chi2Cut2D),
29 theAnnealingProgram(anAnnealingProgram),
39 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::buildMultiRecHit with AnnealingFactor: " << annealing;
42 for (std::vector<const TrackingRecHit*>::const_iterator iter = rhv.begin(); iter != rhv.end(); iter++){
45 if(transient->isValid()) tcomponents.push_back(
transient);
48 return update(tcomponents, tsos, measDet, annealing);
54 double annealing )
const{
56 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Calling SiTrackerMultiRecHitUpdator::update with AnnealingFactor: " << annealing;
60 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"!!! MultiRecHitUpdator::update(..): tsos NOT valid!!! ";
64 if(original->isValid()){
65 if (original->transientHits().empty()){
73 return update(tcomponents, tsos, measDet, annealing);
81 if (tcomponents.empty()){
82 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"Empty components vector passed to SiTrackerMultiRecHitUpdator::update, returning an InvalidTransientRecHit ";
87 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::update: tsos NOT valid!!!, returning an InvalidTransientRecHit";
91 std::vector<TransientTrackingRecHit::RecHitPointer> updatedcomponents;
95 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator iter = tcomponents.begin(); iter != tcomponents.end(); iter++){
98 if (iter == tcomponents.begin()) {
100 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
101 throw cms::Exception(
"SiTrackerMultiRecHitUpdator") <<
"the Trajectory state and the first rechit "
102 "passed to the SiTrackerMultiRecHitUpdator lay on different surfaces!: state lays on surface "
103 << tsos.
surface().
position() <<
" hit with detid " << (*iter)->det()->geographicalId().rawId()
104 <<
" lays on surface " << (*iter)->det()->surface().position();
107 geomdet = (*iter)->det();
113 if (&((*iter)->det()->surface())!=&(tsos.
surface())){
118 if (cloned->isValid()) updatedcomponents.push_back(cloned);
122 if (cloned->isValid()){
123 updatedcomponents.push_back(cloned);
128 std::vector<std::pair<const TrackingRecHit*, float> > mymap;
129 std::vector<std::pair<const TrackingRecHit*, float> >
normmap;
131 double a_sum=0, c_sum=0;
134 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
135 ihit != updatedcomponents.end(); ihit++) {
137 double a_i =
ComputeWeight(tsos, *(*ihit),
false, annealing);
138 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t a_i:" << a_i ;
141 mymap.push_back(std::pair<const TrackingRecHit*, float>((*ihit)->hit(), a_i));
145 if( ihit == updatedcomponents.begin() ) c_sum =
ComputeWeight(tsos, *(*ihit),
true, annealing);
147 double total_sum = a_sum + c_sum;
148 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t c_sum:" << c_sum ;
149 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t total sum:" << total_sum ;
153 for(std::vector<TransientTrackingRecHit::RecHitPointer>::iterator ihit = updatedcomponents.begin();
154 ihit != updatedcomponents.end(); ihit++) {
156 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(*mymap[
counter].first).
name()
161 <<
" and dim:" << mymap[
counter].first->dimension()
162 <<
" position (PRECISE!!!)" << mymap[
counter].first->localPosition()
163 <<
" error " << mymap[
counter].first->localPositionError()
164 <<
" with weight " <<
p ;
168 normmap.push_back(std::pair<const TrackingRecHit*,float>(mymap[counter].
first, p));
178 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" Updated Hit position " << updated.localPosition()
179 <<
" updated error " << updated.localPositionError() << std::endl;
181 return std::make_shared<SiTrackerMultiRecHit>(param.first, param.second, *normmap.front().first->det(),
normmap, annealing);
184 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
" No hits with weight (> 10e-6) have been found for this MRH." << std::endl;
194 case 1:
return ComputeWeight<1>(tsos,aRecHit,CutWeight,annealing);
195 case 2:
return ComputeWeight<2>(tsos,aRecHit,CutWeight,annealing);
196 case 3:
return ComputeWeight<3>(tsos,aRecHit,CutWeight,annealing);
197 case 4:
return ComputeWeight<4>(tsos,aRecHit,CutWeight,annealing);
198 case 5:
return ComputeWeight<5>(tsos,aRecHit,CutWeight,annealing);
200 throw cms::Exception(
"Rec hit of invalid dimension (not 1,2,3,4,5)") <<
201 "The value was " << aRecHit.
dimension() <<
202 ", type is " <<
typeid(aRecHit).
name() <<
"\n";
206 template <
unsigned int N>
224 holder.template setup<N>(&
r, &
R, &pf, &rMeas, &RMeas,
x,
C);
230 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t r:" <<
r ;
231 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t tsospos:" << rMeas ;
232 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t diff:" <<
diff ;
233 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R:" <<
R ;
234 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t RMeas:" << RMeas ;
238 if(!CutWeight)
LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t R+RMeas:" <<
R ;
256 bool ierr = R.Det2(det);
259 double Chi2 = ROOT::Math::Similarity(diff, R);
261 if( !ierr || !ierr2 ) {
262 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::ComputeWeight: W not valid!"<<std::endl;
263 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"V: "<<R<<
" AnnealingFactor: "<<annealing<<std::endl;
268 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t det:" << det;
269 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2:" << Chi2;
270 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"\t\t Chi2/ann:" << Chi2/annealing;
273 double temp_weight = 0.0;
274 if( CutWeight &&
N == 1 ){
277 }
else if( CutWeight &&
N == 2 ) {
283 temp_weight =
exp(-0.5*Chi2/annealing);
294 LogTrace(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::LocalParameters: dim first recHit: " << aHitMap[0].first->dimension() <<std::endl;
295 switch (aHitMap[0].
first->dimension()) {
296 case 1:
return calcParameters<1>(tsos,aHitMap);
297 case 2:
return calcParameters<2>(tsos,aHitMap);
299 throw cms::Exception(
"Rec hit of invalid dimension for computing MRH (not 1,2)") <<
300 "The value was " << aHitMap[0].first->dimension() <<
301 ", type is " <<
typeid(aHitMap[0].first).
name() <<
"\n";
306 template <
unsigned int N>
320 for( std::vector<std::pair<const TrackingRecHit*, float> >::const_iterator ihit = aHitMap.begin();
321 ihit != aHitMap.end(); ihit++ ){
332 holder.template setup<N>(&
r, &V, &pf, &rMeas, &VMeas,
x,
C);
333 (ihit->first)->getKfComponents(holder);
335 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t position: " <<
r;
336 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error: " << V;
340 V(0,1) = V(1,0) = V(0,1)*
s;
342 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t error scorr: " << V;
347 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: V not valid!";
349 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse error: " << V;
352 m_sum += (ihit->second*V*
r);
353 W_sum += (ihit->second*V);
359 edm::LogError(
"SiTrackerMultiRecHitUpdator")<<
"SiTrackerMultiRecHitUpdator::calcParameters: W_sum not valid!";
362 LogTrace(
"SiTrackerMultiRecHitUpdator") <<
"\t inverse total error: " << W_sum;
372 else error =
LocalError(W_sum(0,0), W_sum(0,1), W_sum(1,1));
376 return std::make_pair(position,error);
virtual int dimension() const =0
virtual void getKfComponents(KfComponentsHolder &holder) const
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
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
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
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
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