21 const vector<reco::TransientTrack> &
tracks
25 for(vector<reco::TransientTrack>::const_iterator it=tracks.begin(); it!=tracks.end(); it++){
27 t.
z=((*it).stateAtBeamLine().trackStateAtPCA()).
position().z();
28 double tantheta=
tan(((*it).stateAtBeamLine().trackStateAtPCA()).momentum().theta());
29 double phi=((*it).stateAtBeamLine().trackStateAtPCA()).momentum().phi();
32 t.
dz2=
pow((*it).track().dzError(),2)
61 vector<track_t> & tks,
68 unsigned int nt=tks.size();
72 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
73 k->se=0;
k->sw=0;
k->swz=0;
79 for(
unsigned int i=0;
i<
nt;
i++){
83 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
84 k->ei=
exp(-beta*Eik(tks[
i],*
k));
93 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
94 k->se += tks[
i].pi*
k->ei / Zi;
95 double w =
k->pk * tks[
i].pi*
k->ei / Zi / tks[
i].dz2;
97 k->swz += w * tks[
i].z;
98 k->swE+= w*Eik(tks[
i],*
k);
110 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
112 double znew=
k->swz/
k->sw;
113 delta+=
pow(
k->z-znew,2);
115 k->Tc=2*
k->swE/
k->sw;
117 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " <<
k->sw << endl;
118 if(verbose_){
cout <<
" a cluster melted away ? pk=" <<
k->pk <<
" sumw=" <<
k->sw << endl;}
122 k->pk =
k->pk *
k->se / sumpi;
135 vector<track_t> & tks,
136 vector<vertex_t> &
y,
142 unsigned int nt=tks.size();
145 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
146 k->se=0;
k->sw=0;
k->swz=0;
152 for(
unsigned int i=0;
i<
nt;
i++){
155 double Zi=rho0*
exp(-beta*dzCutOff_*dzCutOff_);
156 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
157 k->ei=
exp(-beta*Eik(tks[
i],*
k));
165 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
166 k->se += tks[
i].pi*
k->ei / Zi;
167 double w =
k->pk * tks[
i].pi*
k->ei / Zi / tks[
i].dz2;
169 k->swz += w * tks[
i].z;
170 k->swE+= w*Eik(tks[
i],*
k);
180 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
182 double znew=
k->swz/
k->sw;
183 delta+=
pow(
k->z-znew,2);
185 k->Tc=2*
k->swE/
k->sw;
187 edm::LogInfo(
"sumw") <<
"invalid sum of weights in fit: " <<
k->sw << endl;
188 if(verbose_){
cout <<
" a cluster melted away ? pk=" <<
k->pk <<
" sumw=" <<
k->sw << endl;}
205 if(y.size()<2)
return false;
207 for(vector<vertex_t>::iterator
k=y.begin(); (
k+1)!=y.end();
k++){
208 if( fabs( (
k+1)->
z -
k->z ) < 1.e-3 ){
209 double rho=
k->pk + (
k+1)->pk;
211 k->z=(
k->pk *
k->z + (
k+1)->
z * (
k+1)->pk)/rho;
213 k->z=0.5*(
k->z + (
k+1)->
z);
232 if(y.size()<2)
return false;
234 for(vector<vertex_t>::iterator
k=y.begin(); (
k+1)!=y.end();
k++){
235 if (fabs((
k+1)->
z -
k->z)<2.e-3){
236 double rho=
k->pk + (
k+1)->pk;
237 double swE=
k->swE+(
k+1)->swE -
k->pk * (
k+1)->pk /rho *
pow((
k+1)->
z -
k->z,2);
238 double Tc=2*swE/(
k->sw+(
k+1)->sw);
242 k->z=(
k->pk *
k->z + (
k+1)->
z * (
k+1)->pk)/rho;
244 k->z=0.5*(
k->z + (
k+1)->
z);
265 if(y.size()<2)
return false;
267 unsigned int nt=tks.size();
269 vector<vertex_t>::iterator
k0=y.end();
270 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
273 double pmax=
k->pk/(
k->pk+rho0*
exp(-beta*dzCutOff_*dzCutOff_));
274 for(
unsigned int i=0;
i<
nt;
i++){
276 double p=
k->pk *
exp(-beta*Eik(tks[
i],*
k)) / tks[
i].Z;
278 if( (p > 0.9*pmax) && (tks[i].
pi>0) ){ nUnique++; }
282 if((nUnique<2)&&(sump<sumpmin)){
289 if(verbose_){
cout <<
"eliminating prototype at " << k0->z <<
" with sump=" << sumpmin << endl;}
303 vector<track_t> & tks,
309 unsigned int nt=tks.size();
311 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
316 for(
unsigned int i=0;
i<
nt;
i++){
317 double w=tks[
i].pi/tks[
i].dz2;
325 for(
unsigned int i=0;
i<
nt;
i++){
326 double dx=tks[
i].z-(
k->z);
327 double w=tks[
i].pi/tks[
i].dz2;
328 a+=w*
pow(dx,2)/tks[
i].dz2;
336 return betamax/
pow(coolingFactor_,
int(
log(T0*betamax)/
log(coolingFactor_))-1 );
339 return betamax/coolingFactor_;
349 vector<track_t> & tks,
350 vector<vertex_t> &
y,
363 std::vector<std::pair<double, unsigned int> >
critical;
364 for(
unsigned int ik=0; ik<y.size(); ik++){
365 if (beta*y[ik].Tc > 1.){
366 critical.push_back( make_pair(y[ik].Tc, ik));
369 stable_sort(critical.begin(), critical.end(), std::greater<std::pair<double, unsigned int> >() );
372 for(
unsigned int ic=0; ic<critical.size(); ic++){
373 unsigned int ik=critical[ic].second;
375 double p1=0, z1=0, w1=0;
376 double p2=0, z2=0,
w2=0;
378 for(
unsigned int i=0;
i<tks.size();
i++){
381 double p=y[ik].pk *
exp(-beta*Eik(tks[
i],y[ik])) / tks[
i].Z*tks[
i].pi;
382 double w=p/tks[
i].dz2;
383 if(tks[i].
z<y[ik].
z){
384 p1+=
p; z1+=w*tks[
i].z; w1+=
w;
386 p2+=
p; z2+=w*tks[
i].z;
w2+=
w;
390 if(w1>0){ z1=z1/w1;}
else{z1=y[ik].z-
epsilon;}
394 if( ( ik > 0 ) && ( y[ik-1].
z>=z1 ) ){ z1=0.5*(y[ik].z+y[ik-1].z); }
395 if( ( ik+1 < y.size()) && ( y[ik+1].
z<=z2 ) ){ z2=0.5*(y[ik].z+y[ik+1].z); }
401 vnew.
pk = p1*y[ik].pk/(p1+
p2);
402 y[ik].pk= p2*y[ik].pk/(p1+
p2);
405 y.insert(y.begin()+ik, vnew);
408 for(
unsigned int jc=ic; jc<critical.size(); jc++){
409 if (critical[jc].
second>ik) {critical[jc].second++;}
431 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
432 if ( ( (
k==y.begin())|| (
k-1)->z <
k->z - zsep) && (((
k+1)==y.end() )|| (
k+1)->z >
k->z + zsep)) {
437 vnew.
pk= 0.5* (*k).pk;
438 (*k).pk= 0.5* (*k).pk;
442 }
else if( y1.empty() || (y1.back().z <
k->z -zsep)){
471 coolingFactor_ = conf.
getParameter<
double>(
"coolingFactor");
476 cout <<
"DAClusterizerInZ: invalid Tmin" << Tmin <<
" reset do default " << 1./betamax_ << endl;
482 if(coolingFactor_<0){
483 coolingFactor_=-coolingFactor_; useTc_=
false;
493 for(vector<track_t>::const_iterator
t=tks0.begin();
t!=tks0.end();
t++){tks.push_back(*
t); }
494 stable_sort(tks.begin(), tks.end(), recTrackLessZ1);
496 cout <<
"-----DAClusterizerInZ::dump ----" << endl;
497 cout <<
"beta=" << beta <<
" betamax= " << betamax_ << endl;
500 for(vector<vertex_t>::const_iterator
k=y.begin();
k!=y.end();
k++){
501 cout << setw(8) << fixed <<
k->z ;
503 cout << endl <<
"T=" << setw(15) << 1./beta <<
" Tc= ";
504 for(vector<vertex_t>::const_iterator
k=y.begin();
k!=y.end();
k++){
505 cout << setw(8) << fixed <<
k->Tc ;
508 cout << endl <<
" pk=";
510 for(vector<vertex_t>::const_iterator
k=y.begin();
k!=y.end();
k++){
511 cout << setw(8) << setprecision(3) << fixed <<
k->pk;
519 cout <<
"---- z +/- dz ip +/-dip pt phi eta weights ----" << endl;
521 for(
unsigned int i=0;
i<tks.size();
i++){
524 cout << setw (3)<<
i <<
")" << setw (8) << fixed << setprecision(4)<< tz <<
" +/-" << setw (6)<<
sqrt(tks[
i].dz2);
527 if(tks[
i].
tt->track().hitPattern().hasValidHitInFirstPixelBarrel()){
cout <<
"+"; }
else{
cout <<
"-"; }
528 cout << setw(1) << tks[
i].tt->track().hitPattern().pixelBarrelLayersWithMeasurement();
529 cout << setw(1) << tks[
i].tt->track().hitPattern().pixelEndcapLayersWithMeasurement();
530 cout << setw(1) << hex << tks[
i].tt->track().hitPattern().trackerLayersWithMeasurement() -
531 tks[
i].tt->track().hitPattern().pixelLayersWithMeasurement() <<
dec;
535 cout << setw (8) << IP.
value() <<
"+/-" << setw (6) << IP.
error();
536 cout <<
" " << setw(6) << setprecision(2) << tks[
i].tt->track().pt()*tks[
i].tt->track().charge();
537 cout <<
" " << setw(5) << setprecision(2) << tks[
i].tt->track().phi()
538 <<
" " << setw(5) << setprecision(2) << tks[
i].tt->track().eta() ;
541 for(vector<vertex_t>::const_iterator
k=y.begin();
k!=y.end();
k++){
542 if((tks[
i].
pi>0)&&(tks[
i].Z>0)){
544 double p=
k->pk *
exp(-beta*Eik(tks[
i],*
k)) / tks[
i].Z;
546 cout << setw (8) << setprecision(3) <<
p;
558 cout << endl <<
"T=" << 1/beta <<
" E=" << E <<
" n="<< y.size() <<
" F= " <<
F << endl <<
"----------" << endl;
566 vector< TransientVertex >
571 vector<track_t> tks=
fill(tracks);
572 unsigned int nt=tracks.size();
576 if (tks.empty())
return clusters;
589 double beta=beta0(betamax_, tks, y);
590 niter=0;
while((
update(beta, tks,y)>1.
e-6) && (niter++ < maxIterations_)){ }
594 while(beta<betamax_){
599 split(beta, tks,y, 1.);
600 beta=beta/coolingFactor_;
602 beta=beta/coolingFactor_;
608 niter=0;
while((
update(beta, tks,y)>1.
e-6) && (niter++ < maxIterations_)){ }
617 while(
split(beta, tks,y,1.) && (ntry++<10) ){
619 while((
update(beta, tks,y)>1.
e-6) && (niter++ < maxIterations_)){}
626 if(verbose_ ){
cout <<
"dump after 1st merging " << endl;
dump(beta,y,tks,2);}
633 rho0=1./
nt;
for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
k->pk =1.; }
634 niter=0;
while((
update(beta, tks,y,rho0) > 1.
e-8) && (niter++ < maxIterations_)){ }
635 if(verbose_ ){
cout <<
"rho0=" << rho0 <<
" niter=" << niter << endl;
dump(beta,y,tks,2);}
639 while(
merge(y,tks.size())){}
640 if(verbose_ ){
cout <<
"dump after 2nd merging " << endl;
dump(beta,y,tks,2);}
644 while(beta<=betastop_){
645 while(purge(y,tks,rho0, beta)){
646 niter=0;
while((
update(beta, tks,y,rho0) > 1.
e-6) && (niter++ < maxIterations_)){ }
648 beta/=coolingFactor_;
649 niter=0;
while((
update(beta, tks,y,rho0) > 1.
e-6) && (niter++ < maxIterations_)){ }
660 cout <<
"Final result, rho0=" << rho0 << endl;
670 for(
unsigned int i=0;
i<
nt;
i++){
671 tks[
i].Z=rho0*
exp(-beta*dzCutOff_*dzCutOff_);
672 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
673 tks[
i].Z+=
k->pk *
exp(-beta*Eik(tks[
i],*
k));
678 for(vector<vertex_t>::iterator
k=y.begin();
k!=y.end();
k++){
680 vector< reco::TransientTrack > vertexTracks;
681 for(
unsigned int i=0;
i<
nt;
i++){
683 double p=
k->pk *
exp(-beta*Eik(tks[
i],*
k)) / tks[
i].Z;
684 if( (tks[i].
pi>0) && ( p > 0.5 ) ){ vertexTracks.push_back(*(tks[i].
tt)); tks[
i].Z=0; }
688 clusters.push_back(v);
700 vector< vector<reco::TransientTrack> >
705 cout <<
"###################################################" << endl;
706 cout <<
"# DAClusterizerInZ::clusterize nt="<<tracks.size() << endl;
707 cout <<
"###################################################" << endl;
710 vector< vector<reco::TransientTrack> >
clusters;
711 vector< TransientVertex >
pv=
vertices(tracks);
713 if(verbose_){
cout <<
"# DAClusterizerInZ::clusterize pv.size="<<pv.size() << endl; }
714 if (pv.size()==0){
return clusters;}
718 vector< reco::TransientTrack> aCluster=pv.begin()->originalTracks();
720 for(vector<TransientVertex>::iterator
k=pv.begin()+1;
k!=pv.end();
k++){
721 if ( fabs(
k->position().z() - (
k-1)->
position().z()) > (2*vertexSize_) ){
723 clusters.push_back(aCluster);
726 for(
unsigned int i=0;
i<
k->originalTracks().size();
i++){ aCluster.push_back(
k->originalTracks().at(
i)); }
729 clusters.push_back(aCluster);
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
common ppss p3p6s2 common epss epspn46 common const1 w2
Sin< T >::type sin(const T &t)
std::vector< track_t > fill(const std::vector< reco::TransientTrack > &tracks) const
U second(std::pair< T, U > const &p)
bool merge(std::vector< vertex_t > &, int) const
bool split(double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y, double threshold) const
Cos< T >::type cos(const T &t)
std::vector< std::vector< reco::TransientTrack > > clusterize(const std::vector< reco::TransientTrack > &tracks) const
Tan< T >::type tan(const T &t)
double BeamWidthX() const
beam width X
DAClusterizerInZ(const edm::ParameterSet &conf)
double BeamWidthY() const
beam width Y
const reco::TransientTrack * tt
void dump(const double beta, const std::vector< vertex_t > &y, const std::vector< track_t > &tks, const int verbosity=0) const
void splitAll(std::vector< vertex_t > &y) const
double update(double beta, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
double Eik(const track_t &t, const vertex_t &k) const
static int position[264][3]
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
double beta0(const double betamax, std::vector< track_t > &tks, std::vector< vertex_t > &y) const
bool purge(std::vector< vertex_t > &, std::vector< track_t > &, double &, const double) const
Power< A, B >::type pow(const A &a, const B &b)
std::vector< TransientVertex > vertices(const std::vector< reco::TransientTrack > &tracks, const int verbosity=0) const