34 <<
"--------------------------------------------------------------------\n" 35 <<
"dRMax = " << dRMax <<
'\n' 36 <<
"dPhiMax = " << dPhiMax <<
'\n' 37 <<
"dRIntMax = " << dRIntMax <<
'\n' 38 <<
"dPhiIntMax = " << dPhiIntMax <<
'\n' 39 <<
"chi2Max = " << chi2Max <<
'\n' 40 <<
"wideSeg = " << wideSeg <<
'\n' 41 <<
"minLayersApart = " << minLayersApart << std::endl;
58 int recHits_per_layer[6] = {0,0,0,0,0,0};
60 if (rechits.size()>150){
61 return std::vector<CSCSegment>();
64 for(
unsigned int i = 0;
i < rechits.size();
i++) {
65 recHits_per_layer[rechits[
i]->cscDetId().layer()-1]++;
66 layerIndex[
i] = rechits[
i]->cscDetId().layer();
71 reverse(layerIndex.begin(), layerIndex.end());
72 reverse(rechits.begin(), rechits.end());
74 if (rechits.size() < 2) {
75 return std::vector<CSCSegment>();
105 std::vector<CSCSegment> segments;
109 aState.windowScale = 1.;
110 bool search_disp =
false;
111 aState.strip_iadd = 1;
112 aState.chi2D_iadd = 1;
113 int npass = (
wideSeg > 1.)? 3 : 2;
114 for (
int ipass = 0; ipass < npass; ++ipass) {
115 if(aState.windowScale >1.){
117 aState.strip_iadd = 2;
118 aState.chi2D_iadd = 2;
122 if(used[i1-ib])used_rh++;
126 if(aState.doCollisions && search_disp &&
int(rechits.size()-used_rh)>2){
127 aState.doCollisions =
false;
128 aState.windowScale = 1.;
130 aState.dPhiMax = 2*aState.dPhiMax;
131 aState.dRIntMax = 2*aState.dRIntMax;
132 aState.dPhiIntMax = 2*aState.dPhiIntMax;
133 aState.chi2Norm_2D_ = 5*aState.chi2Norm_2D_;
134 aState.chi2_str_ = 100;
135 aState.chi2Max = 2*aState.chi2Max;
140 for(
unsigned int n_seg_min = 6u; n_seg_min > 2u + iadd; --n_seg_min){
142 std::array<BoolContainer, 120> common_used_it = {};
143 for (
unsigned int i = 0;
i < common_used_it.size();
i++) {
144 common_used_it[
i] = common_used;
147 float min_chi[120] = {9999};
149 bool first_proto_segment =
true;
153 if(used[i1-ib] || recHits_per_layer[
int(layerIndex[i1-ib])-1]>25 || (n_seg_min == 3 && used3p[i1-
ib]))
continue;
154 int layer1 = layerIndex[i1-
ib];
157 if(used[i2-ib] || recHits_per_layer[
int(layerIndex[i2-ib])-1]>25 || (n_seg_min == 3 && used3p[i2-
ib]))
continue;
158 int layer2 = layerIndex[i2-
ib];
159 if((
abs(layer2 - layer1) + 1) <
int(n_seg_min))
break;
162 aState.proto_segment.clear();
163 if (!
addHit(aState, h1, layer1))
continue;
164 if (!
addHit(aState, h2, layer2))
continue;
169 if(aState.proto_segment.size() > n_seg_min){
173 if(aState.sfit->chi2() > aState.chi2Norm_2D_*aState.chi2D_iadd || aState.proto_segment.size() < n_seg_min) aState.proto_segment.clear();
174 if (!aState.proto_segment.empty()) {
177 if(first_proto_segment){
179 min_chi[0] = aState.sfit->chi2();
180 best_proto_segment[0] = aState.proto_segment;
181 first_proto_segment =
false;
185 min_chi[common_it] = aState.sfit->chi2();
186 best_proto_segment[common_it] = aState.proto_segment;
188 int iter = common_it;
189 for(iu = ib; iu != ie; ++iu) {
190 for(hi = aState.proto_segment.begin(); hi != aState.proto_segment.end(); ++hi) {
193 for(
int k = 0;
k < iter+1;
k++){
194 if(common_used_it[
k][iu-ib] ==
true){
197 for(ik = ib; ik != ie; ++ik) {
198 if(common_used_it[
k][ik-ib] ==
true){
199 common_used_it[merge_nr][ik-
ib] =
true;
200 common_used_it[
k][ik-
ib] =
false;
204 if(min_chi[
k] < min_chi[merge_nr]){
205 min_chi[merge_nr] = min_chi[
k];
206 best_proto_segment[merge_nr] = best_proto_segment[
k];
207 best_proto_segment[
k].clear();
231 for(
int j = 0;j < common_it+1; j++){
232 aState.proto_segment = best_proto_segment[j];
233 best_proto_segment[j].clear();
235 if(aState.proto_segment.size() == 0)
continue;
239 aState.sfit->localdir(), aState.sfit->covarianceMatrix(), aState.sfit->chi2());
241 segments.push_back(
temp);
243 if(aState.proto_segment.size() == 3){
249 aState.proto_segment.clear();
256 aState.doCollisions =
true;
258 aState.dPhiMax = aState.dPhiMax/2;
259 aState.dRIntMax = aState.dRIntMax/2;
260 aState.dPhiIntMax = aState.dPhiIntMax/2;
261 aState.chi2Norm_2D_ = aState.chi2Norm_2D_/5;
262 aState.chi2_str_ = 100;
263 aState.chi2Max = aState.chi2Max/2;
266 std::vector<CSCSegment>::iterator it =segments.begin();
267 bool good_segs =
false;
268 while(it != segments.end()) {
269 if ((*it).nRecHits() > 3){
275 if (good_segs && aState.doCollisions) {
281 if(!aState.doCollisions && !search_disp)
break;
286 std::vector<CSCSegment>::iterator it =segments.begin();
287 while(it != segments.end()) {
288 if((*it).nRecHits() == 3){
289 bool found_common =
false;
290 const std::vector<CSCRecHit2D>& theseRH = (*it).specificRecHits();
292 if(used[i1-ib] && used3p[i1-ib]){
295 int sh1layer =
id.
layer();
296 int RH_centerid = sh1->
nStrips()/2;
297 int RH_centerStrip = sh1->
channels(RH_centerid);
299 std::vector<CSCRecHit2D>::const_iterator sh;
300 for(sh = theseRH.begin(); sh != theseRH.end(); ++sh){
303 int shlayer = idRH.
layer();
304 int SegRH_centerid = sh->nStrips()/2;
305 int SegRH_centerStrip = sh->channels(SegRH_centerid);
306 int SegRH_wg = sh->hitWire();
307 if(sh1layer == shlayer && SegRH_centerStrip == RH_centerStrip && SegRH_wg == RH_wg){
309 segments.erase(it,(it+1));
315 if(found_common)
break;
317 if(!found_common)++it;
342 int layer = layerIndex[
i-
ib];
344 if (layerIndex[
i-ib] == layerIndex[i1-ib] || layerIndex[
i-ib] == layerIndex[i2-ib] || used[
i-ib])
continue;
361 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
366 if(iStn == 0 || iStn == 1){
368 maxWG_width[0] = 9.25;
369 maxWG_width[1] = 9.25;
371 if (wg_num > 1 && wg_num < 48){
372 maxWG_width[0] = 3.14;
373 maxWG_width[1] = 3.14;
376 maxWG_width[0] = 10.75;
377 maxWG_width[1] = 10.75;
392 if (gp2.
perp() > ((gp1.
perp() - aState.
dRMax*maxWG_width[iStn])*h2z)/h1z && gp2.
perp() < ((gp1.
perp() + aState.
dRMax*maxWG_width[iStn])*h2z)/h1z){
401 float strip_width[10] = {0.003878509, 0.002958185, 0.002327105, 0.00152552, 0.00465421, 0.002327105, 0.00465421, 0.002327105, 0.00465421, 0.002327105};
411 if(err_stpos_h1>0.25*strip_width[iStn] || err_stpos_h2>0.25*strip_width[iStn])dphi_incr = 0.5*strip_width[iStn];
413 return (fabs(dphi12) < (aState.
dPhiMax*aState.
strip_iadd+dphi_incr))?
true:
false;
421 float strip_width[10] = {0.003878509, 0.002958185, 0.002327105, 0.00152552, 0.00465421, 0.002327105, 0.00465421, 0.002327105, 0.00465421, 0.002327105};
426 float err_stpos_h1 = (*(aState.
proto_segment.begin()))->errorWithinStrip();
427 float err_stpos_h2 = (*(aState.
proto_segment.begin()+1))->errorWithinStrip();
431 float hphi = hp.
phi();
434 float sphi =
phiAtZ(aState, hp.
z());
435 float phidif = sphi-hphi;
446 float stpos = (*h).positionWithinStrip();
447 bool centr_str =
false;
448 if(iStn != 0 && iStn != 1){
449 if (stpos > -0.25 && stpos < 0.25) centr_str =
true;
451 if(err_stpos_h1<0.25*strip_width[iStn] || err_stpos_h2<0.25*strip_width[iStn] || err_stpos_h < 0.25*strip_width[iStn]){
452 dphi_incr = 0.5*strip_width[iStn];
454 if(centr_str) pos_str = 1.3;
460 float r_interpolated =
fit_r_phi(aState, r_glob,layer);
461 float dr = fabs(r_interpolated - R);
462 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
465 if(iStn == 0 || iStn == 1){
467 maxWG_width[0] = 9.25;
468 maxWG_width[1] = 9.25;
470 if (wg_num > 1 && wg_num < 48){
471 maxWG_width[0] = 3.14;
472 maxWG_width[1] = 3.14;
475 maxWG_width[0] = 10.75;
476 maxWG_width[1] = 10.75;
479 return (fabs(phidif) < aState.
dPhiIntMax*aState.
strip_iadd*pos_str+dphi_incr && fabs(dr) < aState.
dRIntMax*maxWG_width[iStn])?
true:
false;
483 if ( !aState.
sfit )
return 0.;
488 float x = gp.
x() + (gv.
x()/gv.
z())*(z - gp.
z());
489 float y = gp.
y() + (gv.
y()/gv.
z())*(z - gp.
z());
490 float phi = atan2(y, x);
491 if (phi < 0.
f ) phi += 2. *
M_PI;
500 unsigned int iadd = ( rechitsInChamber.size() > 20)? 1 : 0;
514 for(iu = ib; iu != rechitsInChamber.end(); ++iu) {
525 ChamberHitContainer::const_iterator it;
527 if (((*it)->cscDetId().layer() == layer) && (aHit != (*it)))
548 for (
int i=1;
i<7;
i++){
549 if (
points(
i-1)== 0.)
continue;
555 float delta = 2*Sxx - Sx*Sx;
556 float intercept = (Sxx*Sy - Sx*Sxy)/delta;
557 float slope = (2*Sxy - Sx*Sy)/delta;
558 return (intercept + slope*layer);
563 ChamberHitContainer::const_iterator iRH_worst;
570 buffer.reserve(init_size);
572 ChamberHitContainer::iterator
min;
578 if(kLayer < min_layer){
583 buffer.push_back(*min);
588 for (ChamberHitContainer::const_iterator
cand = buffer.begin();
cand != buffer.end();
cand++) {
595 int kRing = idRH.
ring();
599 int centerid = iRHp->
nStrips()/2;
600 int centerStrip = iRHp->
channels(centerid);
601 float stpos = (*iRHp).positionWithinStrip();
602 se(kLayer-1) = (*iRHp).errorWithinStrip();
604 if (kStation == 1 && (kRing == 1 || kRing == 4)) sp(kLayer-1) = stpos + centerStrip;
606 if (kLayer == 1 || kLayer == 3 || kLayer == 5) sp(kLayer-1) = stpos + centerStrip;
607 if (kLayer == 2 || kLayer == 4 || kLayer == 6) sp(kLayer-1) = stpos - 0.5 + centerStrip;
611 fitX(aState, sp, se, -1, -1, chi2_str);
621 ChamberHitContainer::const_iterator rh_to_be_deleted_1;
622 ChamberHitContainer::const_iterator rh_to_be_deleted_2;
628 int z1 = idRH1.
layer();
630 for (ChamberHitContainer::const_iterator i2 = i1+1; i2 != aState.
proto_segment.end(); ++i2) {
634 int z2 = idRH2.
layer();
638 if (ir == i1 || ir == i2)
continue;
643 int worst_layer = idRH.
layer();
647 if (
i == i1 ||
i == i2 ||
i == ir)
continue;
648 float slope = (sp(z2-1)-sp(z1-1))/(z2-z1);
649 float intersept = sp(z1-1) - slope*z1;
652 float di = fabs(sp(z-1) - intersept - slope*z);
657 bad_layer = worst_layer;
659 rh_to_be_deleted_1 = ir;
664 fitX(aState, sp, se, bad_layer, -1, chi2_str);
670 if (iworst > -1 && (nhits-1) > n_seg_min && (chi2_str) > aState.
chi2_str_*aState.
chi2D_iadd){
679 int z1 = idRH1.
layer();
681 for ( ChamberHitContainer::const_iterator i2 = i1+1; i2 != aState.
proto_segment.end(); ++i2) {
685 int z2 = idRH2.
layer();
690 if (ir == i1 || ir == i2 )
continue;
693 int worst_layer = idRH.
layer();
696 if (ir2 == i1 || ir2 == i2 || ir2 ==ir )
continue;
701 int worst_layer2 = idRH.
layer();
705 if (
i == i1 ||
i == i2 ||
i == ir||
i == ir2 )
continue;
706 float slope = (sp(z2-1)-sp(z1-1))/(z2-z1);
707 float intersept = sp(z1-1) - slope*z1;
710 float di = fabs(sp(z-1) - intersept - slope*z);
717 bad_layer = worst_layer;
718 bad_layer2 = worst_layer2;
719 rh_to_be_deleted_1 = ir;
720 rh_to_be_deleted_2 = ir2;
726 fitX(aState, sp, se, bad_layer ,bad_layer2, chi2_str);
732 if( iworst2-1 >= 0 && iworst2 <=
int(aState.
proto_segment.size()) ) {
735 if( iworst-1 >= 0 && iworst <=
int(aState.
proto_segment.size()) ){
747 for (
int i=1;
i<7;
i++){
748 if (
i == ir ||
i == ir2 ||
points(
i-1) == 0.)
continue;
752 Sy = Sy + (
points(
i-1)/sigma2);
753 Sx = Sx + ((i1)/sigma2);
754 Sxx = Sxx + (i1*i1)/sigma2;
755 Sxy = Sxy + (((i1)*
points(
i-1))/sigma2);
757 float delta = S*Sxx - Sx*Sx;
758 float intercept = (Sxx*Sy - Sx*Sxy)/delta;
759 float slope = (S*Sxy - Sx*Sy)/delta;
763 for (
int i=1;
i<7;
i++){
764 if (
i == ir ||
i == ir2 ||
points(
i-1) == 0.)
continue;
766 chi2_str = chi2_str + chi_str*chi_str;
768 return (intercept + slope*0);
775 if ((*it)->cscDetId().layer() == layer)
782 ChamberHitContainer::const_iterator it;
784 if ((*it)->cscDetId().layer() == layer)
789 return addHit(aState, h, layer);
794 std::unique_ptr<CSCSegFit> oldfit;
801 if ( (aState.
sfit->chi2() >= oldfit->chi2() ) || !ok ) {
810 std::unique_ptr<CSCSegFit> oldfit;
817 if ( !ok || ( (aState.
sfit->ndof() > 0) && (aState.
sfit->chi2()/aState.
sfit->ndof() >= aState.
chi2Max)) ) {
T getParameter(std::string const &) const
bool areHitsCloseInR(const AlgoState &aState, const CSCRecHit2D *h1, const CSCRecHit2D *h2) const
Utility functions.
CSCDetId cscDetId() const
ROOT::Math::SVector< double, 6 > SVector6
Typedefs.
std::vector< const CSCRecHit2D * >::const_iterator ChamberHitContainerCIt
bool areHitsCloseInGlobalPhi(const AlgoState &aState, const CSCRecHit2D *h1, const CSCRecHit2D *h2) const
float phiAtZ(const AlgoState &aState, float z) const
static const double slope[3]
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
bool replaceHit(AlgoState &aState, const CSCRecHit2D *h, int layer) const
Geom::Phi< T > phi() const
ChamberHitContainer proto_segment
std::unique_ptr< CSCSegFit > sfit
void tryAddingHitsToSegment(AlgoState &aState, const ChamberHitContainer &rechitsInChamber, const BoolContainer &used, const LayerIndex &layerIndex, const ChamberHitContainerCIt i1, const ChamberHitContainerCIt i2) const
const CSCChamber * aChamber
int channels(unsigned int i) const
Extracting strip channel numbers comprising the rechit - low.
const Surface::PositionType & position() const
The position (origin of the R.F.)
unsigned int nStrips() const
bool isSegmentGood(const AlgoState &aState, const ChamberHitContainer &rechitsInChamber) const
Abs< T >::type abs(const T &t)
void baseline(AlgoState &aState, int n_seg_min) const
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
bool isHitNearSegment(const AlgoState &aState, const CSCRecHit2D *h) const
static const std::string kLayer("layer")
void increaseProtoSegment(AlgoState &aState, const CSCRecHit2D *h, int layer, int chi2_factor) const
CSCSegAlgoRU(const edm::ParameterSet &ps)
Constructor.
std::vector< const CSCRecHit2D * > ChamberHitContainer
std::vector< bool > BoolContainer
std::vector< int > LayerIndex
void updateParameters(AlgoState &aState) const
void compareProtoSegment(AlgoState &aState, const CSCRecHit2D *h, int layer) const
unsigned short iChamberType()
bool addHit(AlgoState &aState, const CSCRecHit2D *hit, int layer) const
Utility functions.
double S(const TLorentzVector &, const TLorentzVector &)
float fit_r_phi(const AlgoState &aState, const SVector6 &points, int layer) const
short int hitWire() const
L1A.
std::vector< CSCSegment > buildSegments(const CSCChamber *aChamber, const ChamberHitContainer &rechits) const
float fitX(const AlgoState &aState, SVector6 points, SVector6 errors, int ir, int ir2, float &chi2_str) const
void flagHitsAsUsed(const AlgoState &aState, const ChamberHitContainer &rechitsInChamber, BoolContainer &used) const
bool hasHitOnLayer(const AlgoState &aState, int layer) const
float errorWithinStrip() const
The uncertainty of the estimated position within the strip.
LocalPoint localPosition() const