15 #include <dataharvester/Writer.h>
21 void sortTracksByPt(std::vector<reco::TransientTrack>&
cont) {
26 for (
auto const& tk : cont) {
28 pt2[i++] = tk.impactPointState().globalMomentum().perp2();
32 std::sort(ind, ind +
s, [p_pt2](
int i,
int j) {
return p_pt2[
i] > p_pt2[
j]; });
33 std::vector<reco::TransientTrack>
tmp;
35 for (
auto i = 0U; i <
s; ++
i)
36 tmp.emplace_back(
std::move(cont[ind[i]]));
45 const float initialError = 10000;
47 ret(0, 0) = initialError;
48 ret(1, 1) = initialError;
49 ret(2, 2) = initialError;
66 GlobalError const linPointError = initLinePointError();
68 void sortByDistanceToRefPoint(std::vector<RefCountedVertexTrack>& cont,
const GlobalPoint ref) {
73 for (
auto const& tk : cont) {
75 d2[i++] = (tk->linearizedTrack()->track().initialFreeState().position() - ref).
mag2();
79 std::sort(ind, ind + s, [p_d2](
int i,
int j) {
return p_d2[
i] < p_d2[
j]; });
80 std::vector<RefCountedVertexTrack>
tmp;
82 for (
auto i = 0U; i <
s; ++
i)
83 tmp.emplace_back(
std::move(cont[ind[i]]));
89 map<RefCountedLinearizedTrackState, int> ids;
92 int getId(
const RefCountedLinearizedTrackState&
r) {
94 if (ids.count(r) == 0) {
109 theLinP(linP.
clone()),
110 theUpdator(updator.
clone()),
111 theSmoother(smoother.
clone()),
112 theAssProbComputer(ann.
clone()),
113 theComp(crit.
clone()),
114 theLinTrkFactory(ltsf.
clone()),
115 gsfIntermediarySmoothing_(
false) {
122 : theMaxShift(o.theMaxShift),
123 theMaxLPShift(o.theMaxLPShift),
124 theMaxStep(o.theMaxStep),
125 theWeightThreshold(o.theWeightThreshold),
127 theLinP(o.theLinP->
clone()),
128 theUpdator(o.theUpdator->
clone()),
129 theSmoother(o.theSmoother->
clone()),
130 theAssProbComputer(o.theAssProbComputer->
clone()),
131 theComp(o.theComp->
clone()),
132 theLinTrkFactory(o.theLinTrkFactory->
clone()),
133 gsfIntermediarySmoothing_(o.gsfIntermediarySmoothing_) {}
159 if (unstracks.size() < 2) {
160 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
163 vector<reco::TransientTrack>
tracks = unstracks;
164 sortTracksByPt(tracks);
169 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
172 return fit(vtContainer, seed,
false);
176 if (tracks.size() < 2) {
177 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
181 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
183 return fit(tracks, seed,
false);
188 if (tracks.empty()) {
189 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
193 return fit(tracks, beamSpotState,
true);
201 if (tracks.size() < 2) {
202 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied fewer than two tracks. Vertex is invalid.";
207 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
209 return fit(vtContainer, fitseed,
false);
218 if (unstracks.empty()) {
219 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
224 vector<RefCountedVertexTrack> vtContainer;
226 vector<reco::TransientTrack>
tracks = unstracks;
227 sortTracksByPt(tracks);
229 if (tracks.size() > 1) {
239 return fit(vtContainer, beamSpotState,
true);
252 if (tracks.empty()) {
253 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
257 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
258 return fit(vtContainer, seed,
true);
268 if (tracks.empty()) {
269 LogError(
"RecoVertex|AdaptiveVertexFitter") <<
"Supplied no tracks. Vertex is invalid.";
273 return fit(tracks, seed,
true);
286 vector<RefCountedLinearizedTrackState> lTracks;
287 for (vector<reco::TransientTrack>::const_iterator i = tracks.begin(); i != tracks.end(); ++
i) {
290 lTracks.push_back(lTrData);
292 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Exception " << e.what() <<
" in ::linearizeTracks."
293 <<
"Your future vertex has just lost a track.";
308 vector<RefCountedLinearizedTrackState> lTracks;
309 for (vector<RefCountedVertexTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
317 lTracks.push_back(lTrData);
319 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
320 <<
"Will not relinearize this track.";
321 lTracks.push_back((**i).linearizedTrack());
333 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
337 if (weight < 1
e-20) {
345 const vector<RefCountedLinearizedTrackState>& lTracks,
const CachingVertex<5>& vertex)
const {
351 vector<RefCountedVertexTrack> finalTracks;
356 for (vector<RefCountedLinearizedTrackState>::const_iterator i = lTracks.begin(); i != lTracks.end(); i++) {
359 pair<bool, double> chi2Res(
false, 0.);
365 if (!chi2Res.first) {
367 LogInfo(
"AdaptiveVertexFitter") <<
"When reweighting, chi2<0. Will add this track with w=0.";
373 RefCountedVertexTrack vTrData = vTrackFactory.
vertexTrack(*i, seed, weight);
376 map<string, dataharvester::MultiType>
m;
381 m[
"pos"] =
"reweight";
386 finalTracks.push_back(vTrData);
388 sortByDistanceToRefPoint(finalTracks, vertex.
position());
394 const vector<RefCountedLinearizedTrackState>& lTracks,
const VertexState&
seed)
const {
401 vector<RefCountedVertexTrack> finalTracks;
406 for (vector<RefCountedLinearizedTrackState>::const_iterator i = lTracks.begin(); i != lTracks.end(); i++) {
409 if (!chi2Res.first) {
411 LogInfo(
"AdaptiveVertexFitter") <<
"When weighting a track, chi2 calculation failed;"
412 <<
" will add with w=0.";
416 RefCountedVertexTrack vTrData = vTrackFactory.
vertexTrack(*i, seed, weight);
418 map<string, dataharvester::MultiType>
m;
427 finalTracks.push_back(vTrData);
439 vector<RefCountedLinearizedTrackState> lTracks;
440 for (vector<RefCountedVertexTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
441 lTracks.push_back((**i).linearizedTrack());
453 bool withPrior)
const {
457 vector<RefCountedVertexTrack> initialTracks;
461 CachingVertex<5> returnVertex(priorVertexPosition, priorVertexError, initialTracks, 0);
464 priorVertexPosition, priorVertexError, priorVertexPosition, priorVertexError, initialTracks, 0);
467 std::vector<RefCountedVertexTrack> globalVTracks =
tracks;
469 sortByDistanceToRefPoint(globalVTracks, priorSeed.
position());
494 if ((previousPosition - newPosition).transverse() >
theMaxLPShift) {
512 for (vector<RefCountedVertexTrack>::const_iterator i = globalVTracks.begin(); i != globalVTracks.end(); i++) {
513 if ((**i).weight() > 0.)
523 LogInfo(
"AdaptiveVertexFitter")
524 <<
"Vertex candidate just took off to " << nVertex.
position() <<
"! Will discard this update!";
536 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
537 <<
"The updator returned an invalid vertex when adding track " << i - globalVTracks.begin()
538 <<
".\n Your vertex might just have lost one good track.";
541 previousPosition = newPosition;
543 returnVertex = fVertex;
557 <<
" Fitted vertex is invalid.";
562 map<string, dataharvester::MultiType>
m;
virtual bool isAnnealed() const =0
AdaptiveVertexFitter * clone() const override
tuple ret
prodAgent to be discontinued
static unsigned int getId()
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
tuple cont
load Luminosity info ##
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
LinearizationPointFinder * theLinP
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
VertexState const & vertexState() const
VertexUpdator< 5 > * theUpdator
auto const & tracks
cannot be loose
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
Log< level::Error, false > LogError
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
GlobalPoint position() const
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
void setWeightThreshold(float w)
virtual CachingVertex< N > add(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
Log< level::Info, false > LogInfo
virtual double currentTemp() const =0
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
double getWeight(float chi2) const
AdaptiveVertexFitter(const AnnealingSchedule &ann=GeometricAnnealing(), const LinearizationPointFinder &linP=DefaultLinearizationPointFinder(), const VertexUpdator< 5 > &updator=KalmanVertexUpdator< 5 >(), const VertexTrackCompatibilityEstimator< 5 > &estor=KalmanVertexTrackCompatibilityEstimator< 5 >(), const VertexSmoother< 5 > &smoother=DummyVertexSmoother< 5 >(), const AbstractLTSFactory< 5 > <sf=LinearizedTrackStateFactory())
virtual CachingVertex< N > smooth(const CachingVertex< N > &vertex) const =0
T getParameter(std::string const &) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
GlobalPoint position() const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
virtual void resetAnnealing()=0
double theWeightThreshold
GlobalError error() const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
~AdaptiveVertexFitter() override
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
virtual double weight(double chi2) const =0
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp
bool gsfIntermediarySmoothing_