35 <<
"--------------------------------------------------------------------\n"
36 <<
"dRMax = " << dRMax <<
'\n'
37 <<
"dPhiMax = " << dPhiMax <<
'\n'
38 <<
"dRIntMax = " << dRIntMax <<
'\n'
39 <<
"dPhiIntMax = " << dPhiIntMax <<
'\n'
40 <<
"chi2Max = " << chi2Max <<
'\n'
41 <<
"wideSeg = " << wideSeg <<
'\n'
42 <<
"minLayersApart = " << minLayersApart << std::endl;
60 int recHits_per_layer[6] = {0, 0, 0, 0, 0, 0};
62 if (rechits.size() > 150) {
63 return std::vector<CSCSegment>();
66 for (
unsigned int i = 0;
i < rechits.size();
i++) {
67 recHits_per_layer[rechits[
i]->cscDetId().layer() - 1]++;
68 layerIndex[
i] = rechits[
i]->cscDetId().layer();
73 reverse(layerIndex.begin(), layerIndex.end());
74 reverse(rechits.begin(), rechits.end());
76 if (rechits.size() < 2) {
77 return std::vector<CSCSegment>();
107 std::vector<CSCSegment> segments;
111 aState.windowScale = 1.;
112 bool search_disp =
false;
113 aState.strip_iadd = 1;
114 aState.chi2D_iadd = 1;
115 int npass = (
wideSeg > 1.) ? 3 : 2;
116 for (
int ipass = 0; ipass < npass; ++ipass) {
117 if (aState.windowScale > 1.) {
119 aState.strip_iadd = 4;
120 aState.chi2D_iadd = 4;
122 if (rechits.size() <= 12)
133 if (aState.doCollisions && search_disp &&
134 int(rechits.size() - used_rh) >
136 aState.doCollisions =
false;
137 aState.windowScale = 1.;
139 aState.dPhiMax = 4 * aState.dPhiMax;
140 aState.dRIntMax = 4 * aState.dRIntMax;
141 aState.dPhiIntMax = 4 * aState.dPhiIntMax;
142 aState.chi2Norm_2D_ = 10 * aState.chi2Norm_2D_;
143 aState.chi2_str_ = 200;
144 aState.chi2Max = 4 * aState.chi2Max;
149 for (
unsigned int n_seg_min = 6u; n_seg_min > 2u + iadd; --n_seg_min) {
151 std::array<BoolContainer, 120> common_used_it = {};
152 for (
unsigned int i = 0;
i < common_used_it.size();
i++) {
153 common_used_it[
i] = common_used;
156 float min_chi[120] = {9999};
158 bool first_proto_segment =
true;
162 if (used[i1 - ib] || recHits_per_layer[
int(layerIndex[i1 - ib]) - 1] > 25 ||
163 (n_seg_min == 3 && used3p[i1 -
ib]))
165 int layer1 = layerIndex[i1 -
ib];
168 if (used[i2 - ib] || recHits_per_layer[
int(layerIndex[i2 - ib]) - 1] > 25 ||
169 (n_seg_min == 3 && used3p[i2 -
ib]))
171 int layer2 = layerIndex[i2 -
ib];
172 if ((
abs(layer2 - layer1) + 1) <
int(n_seg_min))
176 aState.proto_segment.clear();
177 if (!
addHit(aState, h1, layer1))
179 if (!
addHit(aState, h2, layer2))
186 if (aState.proto_segment.size() > n_seg_min) {
190 if (aState.sfit->chi2() > aState.chi2Norm_2D_ * aState.chi2D_iadd ||
191 aState.proto_segment.size() < n_seg_min)
192 aState.proto_segment.clear();
193 if (!aState.proto_segment.empty()) {
196 if (first_proto_segment) {
198 min_chi[0] = aState.sfit->chi2();
199 best_proto_segment[0] = aState.proto_segment;
200 first_proto_segment =
false;
204 min_chi[common_it] = aState.sfit->chi2();
205 best_proto_segment[common_it] = aState.proto_segment;
207 int iter = common_it;
208 for (iu = ib; iu != ie; ++iu) {
209 for (hi = aState.proto_segment.begin(); hi != aState.proto_segment.end(); ++hi) {
212 for (
int k = 0;
k < iter + 1;
k++) {
213 if (common_used_it[
k][iu - ib] ==
true) {
214 if (merge_nr != -1) {
216 for (ik = ib; ik != ie; ++ik) {
217 if (common_used_it[
k][ik - ib] ==
true) {
218 common_used_it[merge_nr][ik -
ib] =
true;
219 common_used_it[
k][ik -
ib] =
false;
223 if (min_chi[
k] < min_chi[merge_nr]) {
224 min_chi[merge_nr] = min_chi[
k];
225 best_proto_segment[merge_nr] = best_proto_segment[
k];
226 best_proto_segment[
k].clear();
248 for (
int j = 0;
j < common_it + 1;
j++) {
249 aState.proto_segment = best_proto_segment[
j];
250 best_proto_segment[
j].clear();
252 if (aState.proto_segment.empty())
257 aState.sfit->intercept(),
258 aState.sfit->localdir(),
259 aState.sfit->covarianceMatrix(),
260 aState.sfit->chi2());
261 aState.sfit =
nullptr;
262 segments.push_back(
temp);
264 if (aState.proto_segment.size() == 3) {
269 aState.proto_segment.clear();
276 aState.doCollisions =
true;
278 aState.chi2_str_ = 100;
279 aState.dPhiMax = 0.25 * aState.dPhiMax;
280 aState.dRIntMax = 0.25 * aState.dRIntMax;
281 aState.dPhiIntMax = 0.25 * aState.dPhiIntMax;
282 aState.chi2Norm_2D_ = 0.1 * aState.chi2Norm_2D_;
283 aState.chi2Max = 0.25 * aState.chi2Max;
286 std::vector<CSCSegment>::iterator it = segments.begin();
287 bool good_segs =
false;
288 while (it != segments.end()) {
289 if ((*it).nRecHits() > 3) {
296 aState.doCollisions) {
302 if (!aState.doCollisions && !search_disp)
308 std::vector<CSCSegment>::iterator it = segments.begin();
309 while (it != segments.end()) {
310 if ((*it).nRecHits() == 3) {
311 bool found_common =
false;
312 const std::vector<CSCRecHit2D>& theseRH = (*it).specificRecHits();
314 if (used[i1 - ib] && used3p[i1 - ib]) {
317 int sh1layer =
id.
layer();
318 int RH_centerid = sh1->
nStrips() / 2;
319 int RH_centerStrip = sh1->
channels(RH_centerid);
321 std::vector<CSCRecHit2D>::const_iterator sh;
322 for (sh = theseRH.begin(); sh != theseRH.end(); ++sh) {
325 int shlayer = idRH.
layer();
326 int SegRH_centerid = sh->nStrips() / 2;
327 int SegRH_centerStrip = sh->channels(SegRH_centerid);
328 int SegRH_wg = sh->hitWire();
329 if (sh1layer == shlayer && SegRH_centerStrip == RH_centerStrip && SegRH_wg == RH_wg) {
331 segments.erase(it, (it + 1));
372 if (layerIndex[
i - ib] == layerIndex[i1 - ib] || layerIndex[
i - ib] == layerIndex[i2 - ib] || used[
i - ib])
390 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
395 if (iStn == 0 || iStn == 1) {
397 maxWG_width[0] = 9.25;
398 maxWG_width[1] = 9.25;
400 if (wg_num > 1 && wg_num < 48) {
401 maxWG_width[0] = 3.14;
402 maxWG_width[1] = 3.14;
405 maxWG_width[0] = 10.75;
406 maxWG_width[1] = 10.75;
430 float strip_width[10] = {0.003878509,
449 if (err_stpos_h1 > 0.25 * strip_width[iStn] || err_stpos_h2 > 0.25 * strip_width[iStn])
450 dphi_incr = 0.5 * strip_width[iStn];
452 return (fabs(dphi12) < (aState.
dPhiMax * aState.
strip_iadd + dphi_incr)) ?
true :
false;
460 float strip_width[10] = {0.003878509,
474 float err_stpos_h1 = (*(aState.
proto_segment.begin()))->errorWithinStrip();
475 float err_stpos_h2 = (*(aState.
proto_segment.begin() + 1))->errorWithinStrip();
479 float hphi = hp.
phi();
482 float sphi =
phiAtZ(aState, hp.
z());
483 float phidif = sphi - hphi;
494 float stpos = (*h).positionWithinStrip();
495 bool centr_str =
false;
496 if (iStn != 0 && iStn != 1) {
497 if (stpos > -0.25 && stpos < 0.25)
500 if (err_stpos_h1 < 0.25 * strip_width[iStn] || err_stpos_h2 < 0.25 * strip_width[iStn] ||
501 err_stpos_h < 0.25 * strip_width[iStn]) {
502 dphi_incr = 0.5 * strip_width[iStn];
508 r_glob((*(aState.
proto_segment.begin() + 1))->cscDetId().layer() - 1) = gp2.
perp();
511 float r_interpolated =
fit_r_phi(aState, r_glob, layer);
512 float dr = fabs(r_interpolated - R);
513 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
516 if (iStn == 0 || iStn == 1) {
518 maxWG_width[0] = 9.25;
519 maxWG_width[1] = 9.25;
521 if (wg_num > 1 && wg_num < 48) {
522 maxWG_width[0] = 3.14;
523 maxWG_width[1] = 3.14;
526 maxWG_width[0] = 10.75;
527 maxWG_width[1] = 10.75;
543 float x = gp.
x() + (gv.
x() / gv.
z()) * (z - gp.
z());
544 float y = gp.
y() + (gv.
y() / gv.
z()) * (z - gp.
z());
545 float phi = atan2(y, x);
557 unsigned int iadd = (rechitsInChamber.size() > 20) ? 1 : 0;
560 if (rechitsInChamber.size() <= 12)
575 for (iu = ib; iu != rechitsInChamber.end(); ++iu) {
577 used[iu -
ib] =
true;
586 ChamberHitContainer::const_iterator it;
588 if (((*it)->cscDetId().layer() ==
layer) && (aHit != (*it)))
609 for (
int i = 1;
i < 7;
i++) {
610 if (points(
i - 1) == 0.)
612 Sy = Sy + (points(
i - 1));
615 Sxy = Sxy + ((
i)*points(i - 1));
617 float delta = 2 * Sxx - Sx * Sx;
618 float intercept = (Sxx * Sy - Sx * Sxy) / delta;
619 float slope = (2 * Sxy - Sx * Sy) / delta;
620 return (intercept + slope * layer);
631 buffer.reserve(init_size);
632 while (buffer.size() < init_size) {
633 ChamberHitContainer::iterator
min;
639 if (kLayer < min_layer) {
644 buffer.push_back(*min);
649 for (ChamberHitContainer::const_iterator cand = buffer.begin(); cand != buffer.end(); cand++) {
657 int kRing = idRH.
ring();
661 int centerid = iRHp->
nStrips() / 2;
662 int centerStrip = iRHp->
channels(centerid);
663 float stpos = (*iRHp).positionWithinStrip();
664 se(kLayer - 1) = (*iRHp).errorWithinStrip();
666 if (kStation == 1 && (kRing == 1 || kRing == 4))
667 sp(kLayer - 1) = stpos + centerStrip;
669 if (kLayer == 1 || kLayer == 3 || kLayer == 5)
670 sp(kLayer - 1) = stpos + centerStrip;
671 if (kLayer == 2 || kLayer == 4 || kLayer == 6)
672 sp(kLayer - 1) = stpos - 0.5 + centerStrip;
676 fitX(aState, sp, se, -1, -1, chi2_str);
686 ChamberHitContainer::const_iterator rh_to_be_deleted_1;
687 ChamberHitContainer::const_iterator rh_to_be_deleted_2;
694 int z1 = idRH1.
layer();
696 for (ChamberHitContainer::const_iterator i2 = i1 + 1; i2 != aState.
proto_segment.end(); ++i2) {
700 int z2 = idRH2.
layer();
705 if (ir == i1 || ir == i2)
711 int worst_layer = idRH.
layer();
716 if (
i == i1 ||
i == i2 ||
i == ir)
718 float slope = (sp(z2 - 1) - sp(z1 - 1)) / (z2 - z1);
719 float intersept = sp(z1 - 1) - slope * z1;
722 float di = fabs(sp(z - 1) - intersept - slope * z);
727 bad_layer = worst_layer;
729 rh_to_be_deleted_1 = ir;
734 fitX(aState, sp, se, bad_layer, -1, chi2_str);
740 if (iworst > -1 && (nhits - 1) > n_seg_min && (chi2_str) > aState.
chi2_str_ * aState.
chi2D_iadd) {
750 int z1 = idRH1.
layer();
752 for (ChamberHitContainer::const_iterator i2 = i1 + 1; i2 != aState.
proto_segment.end(); ++i2) {
756 int z2 = idRH2.
layer();
762 if (ir == i1 || ir == i2)
766 int worst_layer = idRH.
layer();
767 for (ChamberHitContainer::const_iterator ir2 = aState.
proto_segment.begin();
771 if (ir2 == i1 || ir2 == i2 || ir2 == ir)
777 int worst_layer2 = idRH.
layer();
782 if (
i == i1 ||
i == i2 ||
i == ir ||
i == ir2)
784 float slope = (sp(z2 - 1) - sp(z1 - 1)) / (z2 - z1);
785 float intersept = sp(z1 - 1) - slope * z1;
788 float di = fabs(sp(z - 1) - intersept - slope * z);
795 bad_layer = worst_layer;
796 bad_layer2 = worst_layer2;
797 rh_to_be_deleted_1 = ir;
798 rh_to_be_deleted_2 = ir2;
804 fitX(aState, sp, se, bad_layer, bad_layer2, chi2_str);
810 if (iworst2 - 1 >= 0 && iworst2 <=
int(aState.
proto_segment.size())) {
813 if (iworst - 1 >= 0 && iworst <=
int(aState.
proto_segment.size())) {
826 for (
int i = 1;
i < 7;
i++) {
827 if (
i == ir ||
i == ir2 || points(
i - 1) == 0.)
829 sigma2 = errors(
i - 1) * errors(
i - 1);
831 S = S + (1 / sigma2);
832 Sy = Sy + (points(
i - 1) / sigma2);
833 Sx = Sx + ((i1) / sigma2);
834 Sxx = Sxx + (i1 * i1) / sigma2;
835 Sxy = Sxy + (((i1)*points(
i - 1)) / sigma2);
837 float delta = S * Sxx - Sx * Sx;
838 float intercept = (Sxx * Sy - Sx * Sxy) / delta;
839 float slope = (S * Sxy - Sx * Sy) / delta;
843 for (
int i = 1;
i < 7;
i++) {
844 if (
i == ir ||
i == ir2 || points(
i - 1) == 0.)
846 chi_str = (points(
i - 1) - intercept - slope * (
i - 3.5)) / (errors(
i - 1));
847 chi2_str = chi2_str + chi_str * chi_str;
849 return (intercept + slope * 0);
856 if ((*it)->cscDetId().layer() ==
layer)
863 ChamberHitContainer::const_iterator it;
865 if ((*it)->cscDetId().layer() ==
layer)
870 return addHit(aState, h, layer);
875 std::unique_ptr<CSCSegFit> oldfit;
882 if ((aState.
sfit->chi2() >= oldfit->chi2()) || !ok) {
891 std::unique_ptr<CSCSegFit> oldfit;
898 if (!ok || ((aState.
sfit->ndof() > 0) && (aState.
sfit->chi2() / aState.
sfit->ndof() >= aState.
chi2Max))) {
bool areHitsCloseInR(const AlgoState &aState, const CSCRecHit2D *h1, const CSCRecHit2D *h2) const
Utility functions.
CSCDetId cscDetId() const
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
constexpr std::array< uint8_t, layerIndexSize > layer
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
unsigned short iChamberType() 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
ROOT::Math::SVector< double, 6 > SVector6
Typedefs.
LocalPoint localPosition() const override
bool addHit(AlgoState &aState, const CSCRecHit2D *hit, int layer) const
Utility functions.
T getParameter(std::string const &) const
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.
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.