36 <<
"--------------------------------------------------------------------\n"
37 <<
"dRMax = " <<
dRMax <<
'\n'
38 <<
"dPhiMax = " <<
dPhiMax <<
'\n'
41 <<
"chi2Max = " <<
chi2Max <<
'\n'
42 <<
"wideSeg = " <<
wideSeg <<
'\n'
61 int recHits_per_layer[6] = {0, 0, 0, 0, 0, 0};
64 return std::vector<CSCSegment>();
67 for (
unsigned int i = 0;
i <
rechits.size();
i++) {
68 recHits_per_layer[
rechits[
i]->cscDetId().layer() - 1]++;
69 layerIndex[
i] =
rechits[
i]->cscDetId().layer();
74 reverse(layerIndex.begin(), layerIndex.end());
78 return std::vector<CSCSegment>();
100 aState.dRMax =
dRMax;
108 int scale_factor = 1;
113 std::vector<CSCSegment> segments;
117 aState.windowScale = 1.;
118 bool search_disp =
false;
119 aState.strip_iadd = 1;
120 aState.chi2D_iadd = 1;
121 int npass = (
wideSeg > 1.) ? 3 : 2;
122 for (
int ipass = 0; ipass < npass; ++ipass) {
123 if (aState.windowScale > 1.) {
125 aState.strip_iadd = 2 * scale_factor;
126 aState.chi2D_iadd = 2 * scale_factor;
127 if (aState.enlarge) {
141 if (aState.doCollisions && search_disp &&
142 int(
rechits.size() - used_rh) >
144 aState.doCollisions =
false;
145 aState.windowScale = 1.;
146 aState.dRMax = scale_factor * 2.0;
147 aState.dPhiMax = scale_factor * 2 * aState.dPhiMax;
148 aState.dRIntMax = scale_factor * 2 * aState.dRIntMax;
149 aState.dPhiIntMax = scale_factor * 2 * aState.dPhiIntMax;
150 aState.chi2Norm_2D_ = scale_factor * 5 * aState.chi2Norm_2D_;
151 aState.chi2_str_ = scale_factor * 100;
152 aState.chi2Max = scale_factor * 2 * aState.chi2Max;
157 for (
unsigned int n_seg_min = 6u; n_seg_min > 2u + iadd; --n_seg_min) {
159 std::array<BoolContainer, 120> common_used_it = {};
160 for (
unsigned int i = 0;
i < common_used_it.size();
i++) {
161 common_used_it[
i] = common_used;
164 float min_chi[120] = {9999};
166 bool first_proto_segment =
true;
170 if (used[
i1 -
ib] || recHits_per_layer[
int(layerIndex[
i1 -
ib]) - 1] > 25 ||
171 (n_seg_min == 3 && used3p[
i1 -
ib]))
173 int layer1 = layerIndex[
i1 -
ib];
176 if (used[
i2 -
ib] || recHits_per_layer[
int(layerIndex[
i2 -
ib]) - 1] > 25 ||
177 (n_seg_min == 3 && used3p[
i2 -
ib]))
179 int layer2 = layerIndex[
i2 -
ib];
180 if ((
abs(layer2 - layer1) + 1) <
int(n_seg_min))
184 aState.proto_segment.clear();
185 if (!
addHit(aState, h1, layer1))
187 if (!
addHit(aState, h2, layer2))
194 if (aState.proto_segment.size() > n_seg_min) {
198 if (aState.sfit->chi2() > aState.chi2Norm_2D_ * aState.chi2D_iadd ||
199 aState.proto_segment.size() < n_seg_min)
200 aState.proto_segment.clear();
201 if (!aState.proto_segment.empty()) {
204 if (first_proto_segment) {
206 min_chi[0] = aState.sfit->chi2();
207 best_proto_segment[0] = aState.proto_segment;
208 first_proto_segment =
false;
212 min_chi[common_it] = aState.sfit->chi2();
213 best_proto_segment[common_it] = aState.proto_segment;
215 int iter = common_it;
216 for (iu =
ib; iu != ie; ++iu) {
217 for (
hi = aState.proto_segment.begin();
hi != aState.proto_segment.end(); ++
hi) {
220 for (
int k = 0;
k < iter + 1;
k++) {
221 if (common_used_it[
k][iu -
ib] ==
true) {
222 if (merge_nr != -1) {
224 for (ik =
ib; ik != ie; ++ik) {
225 if (common_used_it[
k][ik -
ib] ==
true) {
226 common_used_it[merge_nr][ik -
ib] =
true;
227 common_used_it[
k][ik -
ib] =
false;
231 if (min_chi[
k] < min_chi[merge_nr]) {
232 min_chi[merge_nr] = min_chi[
k];
233 best_proto_segment[merge_nr] = best_proto_segment[
k];
234 best_proto_segment[
k].clear();
256 for (
int j = 0;
j < common_it + 1;
j++) {
257 aState.proto_segment = best_proto_segment[
j];
258 best_proto_segment[
j].clear();
260 if (aState.proto_segment.empty())
265 aState.sfit->intercept(),
266 aState.sfit->localdir(),
267 aState.sfit->covarianceMatrix(),
268 aState.sfit->chi2());
269 aState.sfit =
nullptr;
270 segments.push_back(
temp);
272 if (aState.proto_segment.size() == 3) {
277 aState.proto_segment.clear();
284 aState.doCollisions =
true;
286 aState.chi2_str_ = 100;
287 aState.dPhiMax = 0.5 * aState.dPhiMax / scale_factor;
288 aState.dRIntMax = 0.5 * aState.dRIntMax / scale_factor;
289 aState.dPhiIntMax = 0.5 * aState.dPhiIntMax / scale_factor;
290 aState.chi2Norm_2D_ = 0.2 * aState.chi2Norm_2D_ / scale_factor;
291 aState.chi2Max = 0.5 * aState.chi2Max / scale_factor;
294 std::vector<CSCSegment>::iterator it = segments.begin();
295 bool good_segs =
false;
296 while (it != segments.end()) {
297 if ((*it).nRecHits() > 3) {
304 aState.doCollisions) {
310 if (!aState.doCollisions && !search_disp)
316 std::vector<CSCSegment>::iterator it = segments.begin();
317 while (it != segments.end()) {
318 if ((*it).nRecHits() == 3) {
319 bool found_common =
false;
320 const std::vector<CSCRecHit2D>& theseRH = (*it).specificRecHits();
322 if (used[
i1 -
ib] && used3p[
i1 -
ib]) {
325 int sh1layer =
id.
layer();
326 int RH_centerid = sh1->
nStrips() / 2;
327 int RH_centerStrip = sh1->
channels(RH_centerid);
329 std::vector<CSCRecHit2D>::const_iterator sh;
330 for (sh = theseRH.begin(); sh != theseRH.end(); ++sh) {
333 int shlayer = idRH.
layer();
334 int SegRH_centerid = sh->nStrips() / 2;
335 int SegRH_centerStrip = sh->channels(SegRH_centerid);
336 int SegRH_wg = sh->hitWire();
337 if (sh1layer == shlayer && SegRH_centerStrip == RH_centerStrip && SegRH_wg == RH_wg) {
339 segments.erase(it, (it + 1));
377 int layer = layerIndex[
i -
ib];
380 if (layerIndex[
i -
ib] == layerIndex[
i1 -
ib] || layerIndex[
i -
ib] == layerIndex[
i2 -
ib] || used[
i -
ib])
398 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
403 if (iStn == 0 || iStn == 1) {
405 maxWG_width[0] = 9.25;
406 maxWG_width[1] = 9.25;
408 if (wg_num > 1 && wg_num < 48) {
409 maxWG_width[0] = 3.14;
410 maxWG_width[1] = 3.14;
413 maxWG_width[0] = 10.75;
414 maxWG_width[1] = 10.75;
437 return (gp2.
perp() > ((gp1.
perp() - aState.
dRMax * maxWG_width[iStn]) * h2z) / h1z &&
438 gp2.
perp() < ((gp1.
perp() + aState.
dRMax * maxWG_width[iStn]) * h2z) / h1z)
447 float strip_width[10] = {0.003878509,
466 if (err_stpos_h1 > 0.25 * strip_width[iStn] || err_stpos_h2 > 0.25 * strip_width[iStn])
467 dphi_incr = 0.5 * strip_width[iStn];
477 float strip_width[10] = {0.003878509,
491 float err_stpos_h1 = (*(aState.
proto_segment.begin()))->errorWithinStrip();
492 float err_stpos_h2 = (*(aState.
proto_segment.begin() + 1))->errorWithinStrip();
495 float err_stpos_h =
h->errorWithinStrip();
496 float hphi =
hp.phi();
499 float sphi =
phiAtZ(aState,
hp.z());
500 float phidif = sphi - hphi;
507 int iStn =
id.iChamberType() - 1;
511 float stpos = (*h).positionWithinStrip();
512 bool centr_str =
false;
513 if (iStn != 0 && iStn != 1) {
514 if (stpos > -0.25 && stpos < 0.25)
517 if (err_stpos_h1 < 0.25 * strip_width[iStn] || err_stpos_h2 < 0.25 * strip_width[iStn] ||
518 err_stpos_h < 0.25 * strip_width[iStn]) {
519 dphi_incr = 0.5 * strip_width[iStn];
525 r_glob((*(aState.
proto_segment.begin() + 1))->cscDetId().layer() - 1) = gp2.
perp();
527 int layer =
h->cscDetId().layer();
528 float r_interpolated =
fit_r_phi(aState, r_glob, layer);
529 float dr = fabs(r_interpolated -
R);
530 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
532 int wg_num =
h->hitWire();
533 if (iStn == 0 || iStn == 1) {
535 maxWG_width[0] = 9.25;
536 maxWG_width[1] = 9.25;
538 if (wg_num > 1 && wg_num < 48) {
539 maxWG_width[0] = 3.14;
540 maxWG_width[1] = 3.14;
543 maxWG_width[0] = 10.75;
544 maxWG_width[1] = 10.75;
556 fabs(
dr) < aState.
dRIntMax * maxWG_width[iStn])
569 float x =
gp.x() + (gv.
x() / gv.
z()) * (
z -
gp.z());
570 float y =
gp.y() + (gv.
y() / gv.
z()) * (
z -
gp.z());
571 float phi = atan2(
y,
x);
583 unsigned int iadd = (rechitsInChamber.size() > 20) ? 1 : 0;
586 if (rechitsInChamber.size() <= 12 && aState.
enlarge)
601 for (iu =
ib; iu != rechitsInChamber.end(); ++iu) {
603 used[iu -
ib] =
true;
612 ChamberHitContainer::const_iterator it;
614 if (((*it)->cscDetId().layer() == layer) && (aHit != (*it)))
635 for (
int i = 1;
i < 7;
i++) {
643 float delta = 2 * Sxx - Sx * Sx;
644 float intercept = (Sxx * Sy - Sx * Sxy) /
delta;
646 return (intercept +
slope * layer);
657 buffer.reserve(init_size);
658 while (
buffer.size() < init_size) {
659 ChamberHitContainer::iterator
min;
683 int kRing = idRH.
ring();
687 int centerid = iRHp->
nStrips() / 2;
688 int centerStrip = iRHp->
channels(centerid);
689 float stpos = (*iRHp).positionWithinStrip();
690 se(
kLayer - 1) = (*iRHp).errorWithinStrip();
692 if (kStation == 1 && (kRing == 1 || kRing == 4))
693 sp(
kLayer - 1) = stpos + centerStrip;
696 sp(
kLayer - 1) = stpos + centerStrip;
698 sp(
kLayer - 1) = stpos - 0.5 + centerStrip;
712 ChamberHitContainer::const_iterator rh_to_be_deleted_1;
713 ChamberHitContainer::const_iterator rh_to_be_deleted_2;
720 int z1 = idRH1.
layer();
731 if (ir ==
i1 || ir ==
i2)
737 int worst_layer = idRH.
layer();
742 if (
i ==
i1 ||
i ==
i2 ||
i == ir)
744 float slope = (sp(
z2 - 1) - sp(z1 - 1)) / (
z2 - z1);
745 float intersept = sp(z1 - 1) -
slope * z1;
748 float di = fabs(sp(
z - 1) - intersept -
slope *
z);
753 bad_layer = worst_layer;
755 rh_to_be_deleted_1 = ir;
776 int z1 = idRH1.
layer();
788 if (ir ==
i1 || ir ==
i2)
792 int worst_layer = idRH.
layer();
793 for (ChamberHitContainer::const_iterator ir2 = aState.
proto_segment.begin();
797 if (ir2 ==
i1 || ir2 ==
i2 || ir2 == ir)
803 int worst_layer2 = idRH.
layer();
808 if (
i ==
i1 ||
i ==
i2 ||
i == ir ||
i == ir2)
810 float slope = (sp(
z2 - 1) - sp(z1 - 1)) / (
z2 - z1);
811 float intersept = sp(z1 - 1) -
slope * z1;
814 float di = fabs(sp(
z - 1) - intersept -
slope *
z);
821 bad_layer = worst_layer;
822 bad_layer2 = worst_layer2;
823 rh_to_be_deleted_1 = ir;
824 rh_to_be_deleted_2 = ir2;
836 if (iworst2 - 1 >= 0 && iworst2 <=
int(aState.
proto_segment.size())) {
839 if (iworst - 1 >= 0 && iworst <=
int(aState.
proto_segment.size())) {
852 for (
int i = 1;
i < 7;
i++) {
853 if (
i == ir ||
i == ir2 ||
points(
i - 1) == 0.)
857 S =
S + (1 / sigma2);
858 Sy = Sy + (
points(
i - 1) / sigma2);
859 Sx = Sx + ((
i1) / sigma2);
860 Sxx = Sxx + (
i1 *
i1) / sigma2;
861 Sxy = Sxy + (((
i1)*
points(
i - 1)) / sigma2);
863 float delta =
S * Sxx - Sx * Sx;
864 float intercept = (Sxx * Sy - Sx * Sxy) /
delta;
869 for (
int i = 1;
i < 7;
i++) {
870 if (
i == ir ||
i == ir2 ||
points(
i - 1) == 0.)
875 return (intercept +
slope * 0);
882 if ((*it)->cscDetId().layer() == layer)
889 ChamberHitContainer::const_iterator it;
891 if ((*it)->cscDetId().layer() == layer)
896 return addHit(aState,
h, layer);
901 std::unique_ptr<CSCSegFit> oldfit;
908 if ((aState.
sfit->chi2() >= oldfit->chi2()) || !
ok) {
917 std::unique_ptr<CSCSegFit> oldfit;
924 if (!
ok || ((aState.
sfit->ndof() > 0) && (aState.
sfit->chi2() / aState.
sfit->ndof() >= aState.
chi2Max))) {