18 for (vector<reco::TransientTrack>::const_iterator it =
tracks.begin(); it !=
tracks.end(); it++) {
20 t.z = ((*it).stateAtBeamLine().trackStateAtPCA()).
position().z();
21 double tantheta =
tan(((*it).stateAtBeamLine().trackStateAtPCA()).momentum().theta());
22 double phi = ((*it).stateAtBeamLine().trackStateAtPCA()).momentum().phi();
25 t.dz2 =
pow((*it).track().dzError(), 2)
28 +
pow(vertexSize_, 2);
31 t.pi = 1. / (1. +
exp(
pow(
IP.value() /
IP.error(), 2) -
pow(d0CutOff_, 2)));
49 unsigned int nt = tks.size();
53 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
62 for (
unsigned int i = 0;
i <
nt;
i++) {
65 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
75 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
76 k->se += tks[
i].pi *
k->ei / Zi;
77 double w =
k->pk * tks[
i].pi *
k->ei / Zi / tks[
i].dz2;
79 k->swz +=
w * tks[
i].z;
80 k->swE +=
w * Eik(tks[
i], *
k);
90 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
92 double znew =
k->swz /
k->sw;
95 k->Tc = 2 *
k->swE /
k->sw;
97 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " <<
k->sw << endl;
99 cout <<
" a cluster melted away ? pk=" <<
k->pk <<
" sumw=" <<
k->sw << endl;
104 k->pk =
k->pk *
k->se / sumpi;
115 unsigned int nt = tks.size();
118 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
127 for (
unsigned int i = 0;
i <
nt;
i++) {
129 double Zi = rho0 *
exp(-
beta * dzCutOff_ * dzCutOff_);
130 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
139 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
140 k->se += tks[
i].pi *
k->ei / Zi;
141 double w =
k->pk * tks[
i].pi *
k->ei / Zi / tks[
i].dz2;
143 k->swz +=
w * tks[
i].z;
144 k->swE +=
w * Eik(tks[
i], *
k);
152 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
154 double znew =
k->swz /
k->sw;
157 k->Tc = 2 *
k->swE /
k->sw;
159 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " <<
k->sw << endl;
161 cout <<
" a cluster melted away ? pk=" <<
k->pk <<
" sumw=" <<
k->sw << endl;
177 for (vector<vertex_t>::iterator
k = y.begin(); (
k + 1) != y.end();
k++) {
178 if (fabs((
k + 1)->z -
k->z) < 1.e-3) {
179 double rho =
k->pk + (
k + 1)->pk;
181 k->z = (
k->pk *
k->z + (
k + 1)->z * (
k + 1)->pk) / rho;
183 k->z = 0.5 * (
k->z + (
k + 1)->z);
202 for (vector<vertex_t>::iterator
k = y.begin(); (
k + 1) != y.end();
k++) {
203 if (fabs((
k + 1)->z -
k->z) < 2.e-3) {
204 double rho =
k->pk + (
k + 1)->pk;
205 double swE =
k->swE + (
k + 1)->swE -
k->pk * (
k + 1)->pk / rho *
pow((
k + 1)->z -
k->z, 2);
206 double Tc = 2 * swE / (
k->sw + (
k + 1)->sw);
210 k->z = (
k->pk *
k->z + (
k + 1)->z * (
k + 1)->pk) / rho;
212 k->z = 0.5 * (
k->z + (
k + 1)->z);
215 k->sw += (
k + 1)->sw;
232 unsigned int nt = tks.size();
234 vector<vertex_t>::iterator
k0 = y.end();
235 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
238 double pmax =
k->pk / (
k->pk + rho0 *
exp(-
beta * dzCutOff_ * dzCutOff_));
239 for (
unsigned int i = 0;
i <
nt;
i++) {
241 double p =
k->pk *
exp(-
beta * Eik(tks[
i], *
k)) / tks[
i].Z;
243 if ((
p > 0.9 * pmax) && (tks[
i].
pi > 0)) {
249 if ((nUnique < 2) && (sump < sumpmin)) {
257 cout <<
"eliminating prototype at " <<
k0->z <<
" with sump=" << sumpmin << endl;
270 unsigned int nt = tks.size();
272 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
276 for (
unsigned int i = 0;
i <
nt;
i++) {
277 double w = tks[
i].pi / tks[
i].dz2;
278 sumwz +=
w * tks[
i].z;
285 for (
unsigned int i = 0;
i <
nt;
i++) {
286 double dx = tks[
i].z - (
k->z);
287 double w = tks[
i].pi / tks[
i].dz2;
291 double Tc = 2. *
a /
b;
296 if (T0 > 1. / betamax) {
297 return betamax /
pow(coolingFactor_,
int(
log(T0 * betamax) /
log(coolingFactor_)) - 1);
300 return betamax / coolingFactor_;
314 std::vector<std::pair<double, unsigned int> >
critical;
315 for (
unsigned int ik = 0; ik < y.size(); ik++) {
316 if (
beta * y[ik].Tc > 1.) {
317 critical.push_back(make_pair(y[ik].Tc, ik));
320 stable_sort(
critical.begin(),
critical.end(), std::greater<std::pair<double, unsigned int> >());
322 for (
unsigned int ic = 0; ic <
critical.size(); ic++) {
323 unsigned int ik =
critical[ic].second;
325 double p1 = 0, z1 = 0,
w1 = 0;
326 double p2 = 0,
z2 = 0,
w2 = 0;
328 for (
unsigned int i = 0;
i < tks.size();
i++) {
331 double p = y[ik].pk *
exp(-
beta * Eik(tks[
i], y[ik])) / tks[
i].Z * tks[
i].pi;
332 double w =
p / tks[
i].dz2;
333 if (tks[
i].z < y[ik].z) {
356 if ((ik > 0) && (y[ik - 1].z >= z1)) {
357 z1 = 0.5 * (y[ik].z + y[ik - 1].z);
359 if ((ik + 1 < y.size()) && (y[ik + 1].z <=
z2)) {
360 z2 = 0.5 * (y[ik].z + y[ik + 1].z);
367 vnew.
pk =
p1 * y[ik].pk / (
p1 +
p2);
368 y[ik].pk =
p2 * y[ik].pk / (
p1 +
p2);
371 y.insert(y.begin() + ik, vnew);
374 for (
unsigned int jc = ic; jc <
critical.size(); jc++) {
391 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
392 if (((
k == y.begin()) || (
k - 1)->z <
k->z - zsep) && (((
k + 1) == y.end()) || (
k + 1)->z >
k->z + zsep)) {
397 vnew.
pk = 0.5 * (*k).pk;
398 (*k).pk = 0.5 * (*k).pk;
402 }
else if (
y1.empty() || (
y1.back().z <
k->z - zsep)) {
420 coolingFactor_ = 0.8;
421 maxIterations_ = 100;
429 coolingFactor_ = conf.
getParameter<
double>(
"coolingFactor");
432 maxIterations_ = 100;
434 cout <<
"DAClusterizerInZ: invalid Tmin" <<
Tmin <<
" reset do default " << 1. / betamax_ << endl;
436 betamax_ = 1. /
Tmin;
440 if (coolingFactor_ < 0) {
441 coolingFactor_ = -coolingFactor_;
447 const vector<vertex_t>& y,
448 const vector<track_t>& tks0,
452 for (vector<track_t>::const_iterator
t = tks0.begin();
t != tks0.end();
t++) {
455 stable_sort(tks.begin(), tks.end(), recTrackLessZ1);
457 cout <<
"-----DAClusterizerInZ::dump ----" << endl;
458 cout <<
"beta=" <<
beta <<
" betamax= " << betamax_ << endl;
461 for (vector<vertex_t>::const_iterator
k = y.begin();
k != y.end();
k++) {
464 cout << endl <<
"T=" << setw(15) << 1. /
beta <<
" Tc= ";
465 for (vector<vertex_t>::const_iterator
k = y.begin();
k != y.end();
k++) {
469 cout << endl <<
" pk=";
471 for (vector<vertex_t>::const_iterator
k = y.begin();
k != y.end();
k++) {
472 cout << setw(8) << setprecision(3) <<
fixed <<
k->pk;
480 cout <<
"---- z +/- dz ip +/-dip pt phi eta weights ----" << endl;
482 for (
unsigned int i = 0;
i < tks.size();
i++) {
486 double tz = tks[
i].z;
487 cout << setw(3) <<
i <<
")" << setw(8) <<
fixed << setprecision(4) << tz <<
" +/-" << setw(6) <<
sqrt(tks[
i].dz2);
503 .pixelBarrelLayersWithMeasurement();
504 cout << setw(1) << tks[
i].tt->track().hitPattern().pixelEndcapLayersWithMeasurement();
505 cout << setw(1) << hex
506 << tks[
i].tt->track().hitPattern().trackerLayersWithMeasurement() -
507 tks[
i].tt->track().hitPattern().pixelLayersWithMeasurement()
509 cout <<
"=" << setw(1) << hex
512 Measurement1D IP = tks[
i].tt->stateAtBeamLine().transverseImpactParameter();
513 cout << setw(8) <<
IP.value() <<
"+/-" << setw(6) <<
IP.error();
514 cout <<
" " << setw(6) << setprecision(2) << tks[
i].tt->track().pt() * tks[
i].tt->track().charge();
515 cout <<
" " << setw(5) << setprecision(2) << tks[
i].tt->track().phi() <<
" " << setw(5) << setprecision(2)
516 << tks[
i].tt->track().eta();
519 for (vector<vertex_t>::const_iterator
k = y.begin();
k != y.end();
k++) {
520 if ((tks[
i].
pi > 0) && (tks[
i].Z > 0)) {
522 double p =
k->pk *
exp(-
beta * Eik(tks[
i], *
k)) / tks[
i].Z;
524 cout << setw(8) << setprecision(3) <<
p;
528 E +=
p * Eik(tks[
i], *
k);
536 cout << endl <<
"T=" << 1 /
beta <<
" E=" << E <<
" n=" << y.size() <<
" F= " <<
F << endl <<
"----------" << endl;
560 double beta = beta0(betamax_, tks, y);
562 while ((
update(
beta, tks, y) > 1.
e-6) && (niter++ < maxIterations_)) {
566 while (
beta < betamax_) {
581 while ((
update(
beta, tks, y) > 1.
e-6) && (niter++ < maxIterations_)) {
591 unsigned int ntry = 0;
592 while (
split(
beta, tks, y, 1.) && (ntry++ < 10)) {
594 while ((
update(
beta, tks, y) > 1.
e-6) && (niter++ < maxIterations_)) {
605 cout <<
"dump after 1st merging " << endl;
612 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
616 while ((
update(
beta, tks, y, rho0) > 1.
e-8) && (niter++ < maxIterations_)) {
619 cout <<
"rho0=" << rho0 <<
" niter=" << niter << endl;
624 while (
merge(y, tks.size())) {
627 cout <<
"dump after 2nd merging " << endl;
632 while (
beta <= betastop_) {
633 while (purge(y, tks, rho0,
beta)) {
635 while ((
update(
beta, tks, y, rho0) > 1.
e-6) && (niter++ < maxIterations_)) {
638 beta /= coolingFactor_;
640 while ((
update(
beta, tks, y, rho0) > 1.
e-6) && (niter++ < maxIterations_)) {
650 cout <<
"Final result, rho0=" << rho0 << endl;
658 for (
unsigned int i = 0;
i <
nt;
i++) {
659 tks[
i].Z = rho0 *
exp(-
beta * dzCutOff_ * dzCutOff_);
660 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
665 for (vector<vertex_t>::iterator
k = y.begin();
k != y.end();
k++) {
667 vector<reco::TransientTrack> vertexTracks;
668 for (
unsigned int i = 0;
i <
nt;
i++) {
670 double p =
k->pk *
exp(-
beta * Eik(tks[
i], *
k)) / tks[
i].Z;
671 if ((tks[
i].
pi > 0) && (
p > 0.5)) {
672 vertexTracks.push_back(*(tks[
i].
tt));
686 cout <<
"###################################################" << endl;
687 cout <<
"# DAClusterizerInZ::clusterize nt=" <<
tracks.size() << endl;
688 cout <<
"###################################################" << endl;
691 vector<vector<reco::TransientTrack> >
clusters;
695 cout <<
"# DAClusterizerInZ::clusterize pv.size=" <<
pv.size() << endl;
702 vector<reco::TransientTrack> aCluster =
pv.begin()->originalTracks();
704 for (vector<TransientVertex>::iterator
k =
pv.begin() + 1;
k !=
pv.end();
k++) {
705 if (fabs(
k->position().z() - (
k - 1)->
position().z()) > (2 * vertexSize_)) {
710 for (
unsigned int i = 0;
i <
k->originalTracks().size();
i++) {
711 aCluster.push_back(
k->originalTracks().at(
i));
T getParameter(std::string const &) const
common ppss p3p6s2 common epss epspn46 common const1 w2
Sin< T >::type sin(const T &t)
bool split(double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y, double threshold) const
double update(double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
void splitAll(std::vector< vertex_t > &y) const
std::vector< track_t > fill(const std::vector< reco::TransientTrack > &tracks) const
bool purge(std::vector< vertex_t > &, std::vector< track_t > &, double &, const double) const
int merge(int argc, char *argv[])
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
double beta0(const double betamax, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
def split(sequence, size)
Log< level::Info, false > LogInfo
auto const & tracks
cannot be loose
weight_default_t w1[2000]
std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const override
DAClusterizerInZ(const edm::ParameterSet &conf)
bool merge(std::vector< vertex_t > &, int) const
static int position[264][3]
void dump(const double beta, const std::vector< vertex_t > &y, const std::vector< track_t > &tks, const int verbosity=0) const
double Eik(const track_t &t, const vertex_t &k) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Power< A, B >::type pow(const A &a, const B &b)