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;
59 int recHits_per_layer[6] = {0,0,0,0,0,0};
61 if (rechits.size()>150){
62 return std::vector<CSCSegment>();
65 for(
unsigned int i = 0;
i < rechits.size();
i++) {
66 recHits_per_layer[rechits[
i]->cscDetId().layer()-1]++;
67 layerIndex[
i] = rechits[
i]->cscDetId().layer();
72 reverse(layerIndex.begin(), layerIndex.end());
73 reverse(rechits.begin(), rechits.end());
75 if (rechits.size() < 2) {
76 return std::vector<CSCSegment>();
106 int scale_factor = 1;
107 if(aState.enlarge) scale_factor = 2;
110 std::vector<CSCSegment> segments;
114 aState.windowScale = 1.;
115 bool search_disp =
false;
116 aState.strip_iadd = 1;
117 aState.chi2D_iadd = 1;
118 int npass = (
wideSeg > 1.)? 3 : 2;
119 for (
int ipass = 0; ipass < npass; ++ipass) {
120 if(aState.windowScale >1.){
122 aState.strip_iadd = 2*scale_factor;
123 aState.chi2D_iadd = 2*scale_factor;
126 if( rechits.size() <= 12 )iadd = 0;
132 if(used[i1-ib])used_rh++;
136 if(aState.doCollisions && search_disp &&
int(rechits.size()-used_rh)>2){
137 aState.doCollisions =
false;
138 aState.windowScale = 1.;
139 aState.dRMax = scale_factor*2.0;
140 aState.dPhiMax = scale_factor*2*aState.dPhiMax;
141 aState.dRIntMax = scale_factor*2*aState.dRIntMax;
142 aState.dPhiIntMax = scale_factor*2*aState.dPhiIntMax;
143 aState.chi2Norm_2D_ = scale_factor*5*aState.chi2Norm_2D_;
144 aState.chi2_str_ = scale_factor*100;
145 aState.chi2Max = scale_factor*2*aState.chi2Max;
150 for(
unsigned int n_seg_min = 6u; n_seg_min > 2u + iadd; --n_seg_min){
152 std::array<BoolContainer, 120> common_used_it = {};
153 for (
unsigned int i = 0;
i < common_used_it.size();
i++) {
154 common_used_it[
i] = common_used;
157 float min_chi[120] = {9999};
159 bool first_proto_segment =
true;
163 if(used[i1-ib] || recHits_per_layer[
int(layerIndex[i1-ib])-1]>25 || (n_seg_min == 3 && used3p[i1-
ib]))
continue;
164 int layer1 = layerIndex[i1-
ib];
167 if(used[i2-ib] || recHits_per_layer[
int(layerIndex[i2-ib])-1]>25 || (n_seg_min == 3 && used3p[i2-
ib]))
continue;
168 int layer2 = layerIndex[i2-
ib];
169 if((
abs(layer2 - layer1) + 1) <
int(n_seg_min))
break;
172 aState.proto_segment.clear();
173 if (!
addHit(aState, h1, layer1))
continue;
174 if (!
addHit(aState, h2, layer2))
continue;
179 if(aState.proto_segment.size() > n_seg_min){
183 if(aState.sfit->chi2() > aState.chi2Norm_2D_*aState.chi2D_iadd || aState.proto_segment.size() < n_seg_min) aState.proto_segment.clear();
184 if (!aState.proto_segment.empty()) {
187 if(first_proto_segment){
189 min_chi[0] = aState.sfit->chi2();
190 best_proto_segment[0] = aState.proto_segment;
191 first_proto_segment =
false;
195 min_chi[common_it] = aState.sfit->chi2();
196 best_proto_segment[common_it] = aState.proto_segment;
198 int iter = common_it;
199 for(iu = ib; iu != ie; ++iu) {
200 for(hi = aState.proto_segment.begin(); hi != aState.proto_segment.end(); ++hi) {
203 for(
int k = 0;
k < iter+1;
k++){
204 if(common_used_it[
k][iu-ib] ==
true){
207 for(ik = ib; ik != ie; ++ik) {
208 if(common_used_it[
k][ik-ib] ==
true){
209 common_used_it[merge_nr][ik-
ib] =
true;
210 common_used_it[
k][ik-
ib] =
false;
214 if(min_chi[
k] < min_chi[merge_nr]){
215 min_chi[merge_nr] = min_chi[
k];
216 best_proto_segment[merge_nr] = best_proto_segment[
k];
217 best_proto_segment[
k].clear();
241 for(
int j = 0;j < common_it+1; j++){
242 aState.proto_segment = best_proto_segment[j];
243 best_proto_segment[j].clear();
245 if(aState.proto_segment.empty())
continue;
249 aState.sfit->localdir(), aState.sfit->covarianceMatrix(), aState.sfit->chi2());
250 aState.sfit =
nullptr;
251 segments.push_back(
temp);
253 if(aState.proto_segment.size() == 3){
259 aState.proto_segment.clear();
266 aState.doCollisions =
true;
268 aState.chi2_str_ = 100;
269 aState.dPhiMax = 0.5*aState.dPhiMax/scale_factor;
270 aState.dRIntMax = 0.5*aState.dRIntMax/scale_factor;
271 aState.dPhiIntMax = 0.5*aState.dPhiIntMax/scale_factor;
272 aState.chi2Norm_2D_ = 0.2*aState.chi2Norm_2D_/scale_factor;
273 aState.chi2Max = 0.5*aState.chi2Max/scale_factor;
276 std::vector<CSCSegment>::iterator it =segments.begin();
277 bool good_segs =
false;
278 while(it != segments.end()) {
279 if ((*it).nRecHits() > 3){
285 if (good_segs && aState.doCollisions) {
291 if(!aState.doCollisions && !search_disp)
break;
296 std::vector<CSCSegment>::iterator it =segments.begin();
297 while(it != segments.end()) {
298 if((*it).nRecHits() == 3){
299 bool found_common =
false;
300 const std::vector<CSCRecHit2D>& theseRH = (*it).specificRecHits();
302 if(used[i1-ib] && used3p[i1-ib]){
305 int sh1layer =
id.
layer();
306 int RH_centerid = sh1->
nStrips()/2;
307 int RH_centerStrip = sh1->
channels(RH_centerid);
309 std::vector<CSCRecHit2D>::const_iterator sh;
310 for(sh = theseRH.begin(); sh != theseRH.end(); ++sh){
313 int shlayer = idRH.
layer();
314 int SegRH_centerid = sh->nStrips()/2;
315 int SegRH_centerStrip = sh->channels(SegRH_centerid);
316 int SegRH_wg = sh->hitWire();
317 if(sh1layer == shlayer && SegRH_centerStrip == RH_centerStrip && SegRH_wg == RH_wg){
319 segments.erase(it,(it+1));
325 if(found_common)
break;
327 if(!found_common)++it;
352 int layer = layerIndex[
i-
ib];
354 if (layerIndex[
i-ib] == layerIndex[i1-ib] || layerIndex[
i-ib] == layerIndex[i2-ib] || used[
i-ib])
continue;
371 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
376 if(iStn == 0 || iStn == 1){
378 maxWG_width[0] = 9.25;
379 maxWG_width[1] = 9.25;
381 if (wg_num > 1 && wg_num < 48){
382 maxWG_width[0] = 3.14;
383 maxWG_width[1] = 3.14;
386 maxWG_width[0] = 10.75;
387 maxWG_width[1] = 10.75;
409 return (gp2.
perp() > ((gp1.
perp() - aState.
dRMax*maxWG_width[iStn])*h2z)/h1z && gp2.
perp() < ((gp1.
perp() + aState.
dRMax*maxWG_width[iStn])*h2z)/h1z)?
true:
false;
415 float strip_width[10] = {0.003878509, 0.002958185, 0.002327105, 0.00152552, 0.00465421, 0.002327105, 0.00465421, 0.002327105, 0.00465421, 0.002327105};
425 if(err_stpos_h1>0.25*strip_width[iStn] || err_stpos_h2>0.25*strip_width[iStn])dphi_incr = 0.5*strip_width[iStn];
427 return (fabs(dphi12) < (aState.
dPhiMax*aState.
strip_iadd+dphi_incr))?
true:
false;
435 float strip_width[10] = {0.003878509, 0.002958185, 0.002327105, 0.00152552, 0.00465421, 0.002327105, 0.00465421, 0.002327105, 0.00465421, 0.002327105};
440 float err_stpos_h1 = (*(aState.
proto_segment.begin()))->errorWithinStrip();
441 float err_stpos_h2 = (*(aState.
proto_segment.begin()+1))->errorWithinStrip();
445 float hphi = hp.
phi();
448 float sphi =
phiAtZ(aState, hp.
z());
449 float phidif = sphi-hphi;
460 float stpos = (*h).positionWithinStrip();
461 bool centr_str =
false;
462 if(iStn != 0 && iStn != 1){
463 if (stpos > -0.25 && stpos < 0.25) centr_str =
true;
465 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]){
466 dphi_incr = 0.5*strip_width[iStn];
468 if(centr_str) pos_str = 1.3;
474 float r_interpolated =
fit_r_phi(aState, r_glob,layer);
475 float dr = fabs(r_interpolated - R);
476 float maxWG_width[10] = {0, 0, 4.1, 5.69, 2.49, 5.06, 2.49, 5.06, 1.87, 5.06};
479 if(iStn == 0 || iStn == 1){
481 maxWG_width[0] = 9.25;
482 maxWG_width[1] = 9.25;
484 if (wg_num > 1 && wg_num < 48){
485 maxWG_width[0] = 3.14;
486 maxWG_width[1] = 3.14;
489 maxWG_width[0] = 10.75;
490 maxWG_width[1] = 10.75;
500 return (fabs(phidif) < aState.
dPhiIntMax*aState.
strip_iadd*pos_str+dphi_incr && fabs(dr) < aState.
dRIntMax*maxWG_width[iStn])?
true:
false;
506 if ( !aState.
sfit )
return 0.;
511 float x = gp.
x() + (gv.
x()/gv.
z())*(z - gp.
z());
512 float y = gp.
y() + (gv.
y()/gv.
z())*(z - gp.
z());
513 float phi = atan2(y, x);
514 if (phi < 0.
f ) phi += 2. *
M_PI;
524 unsigned int iadd = ( rechitsInChamber.size() > 20)? 1 : 0;
527 if( rechitsInChamber.size() <= 12 && aState.
enlarge) iadd = 0;
540 for(iu = ib; iu != rechitsInChamber.end(); ++iu) {
551 ChamberHitContainer::const_iterator it;
553 if (((*it)->cscDetId().layer() == layer) && (aHit != (*it)))
574 for (
int i=1;
i<7;
i++){
575 if (
points(
i-1)== 0.)
continue;
581 float delta = 2*Sxx - Sx*Sx;
582 float intercept = (Sxx*Sy - Sx*Sxy)/delta;
583 float slope = (2*Sxy - Sx*Sy)/delta;
584 return (intercept + slope*layer);
595 buffer.reserve(init_size);
597 ChamberHitContainer::iterator
min;
603 if(kLayer < min_layer){
608 buffer.push_back(*min);
613 for (ChamberHitContainer::const_iterator
cand = buffer.begin();
cand != buffer.end();
cand++) {
620 int kRing = idRH.
ring();
624 int centerid = iRHp->
nStrips()/2;
625 int centerStrip = iRHp->
channels(centerid);
626 float stpos = (*iRHp).positionWithinStrip();
627 se(kLayer-1) = (*iRHp).errorWithinStrip();
629 if (kStation == 1 && (kRing == 1 || kRing == 4)) sp(kLayer-1) = stpos + centerStrip;
631 if (kLayer == 1 || kLayer == 3 || kLayer == 5) sp(kLayer-1) = stpos + centerStrip;
632 if (kLayer == 2 || kLayer == 4 || kLayer == 6) sp(kLayer-1) = stpos - 0.5 + centerStrip;
636 fitX(aState, sp, se, -1, -1, chi2_str);
646 ChamberHitContainer::const_iterator rh_to_be_deleted_1;
647 ChamberHitContainer::const_iterator rh_to_be_deleted_2;
653 int z1 = idRH1.
layer();
655 for (ChamberHitContainer::const_iterator i2 = i1+1; i2 != aState.
proto_segment.end(); ++i2) {
659 int z2 = idRH2.
layer();
663 if (ir == i1 || ir == i2)
continue;
668 int worst_layer = idRH.
layer();
672 if (
i == i1 ||
i == i2 ||
i == ir)
continue;
673 float slope = (sp(z2-1)-sp(z1-1))/(z2-z1);
674 float intersept = sp(z1-1) - slope*z1;
677 float di = fabs(sp(z-1) - intersept - slope*z);
682 bad_layer = worst_layer;
684 rh_to_be_deleted_1 = ir;
689 fitX(aState, sp, se, bad_layer, -1, chi2_str);
695 if (iworst > -1 && (nhits-1) > n_seg_min && (chi2_str) > aState.
chi2_str_*aState.
chi2D_iadd){
704 int z1 = idRH1.
layer();
706 for ( ChamberHitContainer::const_iterator i2 = i1+1; i2 != aState.
proto_segment.end(); ++i2) {
710 int z2 = idRH2.
layer();
715 if (ir == i1 || ir == i2 )
continue;
718 int worst_layer = idRH.
layer();
721 if (ir2 == i1 || ir2 == i2 || ir2 ==ir )
continue;
726 int worst_layer2 = idRH.
layer();
730 if (
i == i1 ||
i == i2 ||
i == ir||
i == ir2 )
continue;
731 float slope = (sp(z2-1)-sp(z1-1))/(z2-z1);
732 float intersept = sp(z1-1) - slope*z1;
735 float di = fabs(sp(z-1) - intersept - slope*z);
742 bad_layer = worst_layer;
743 bad_layer2 = worst_layer2;
744 rh_to_be_deleted_1 = ir;
745 rh_to_be_deleted_2 = ir2;
751 fitX(aState, sp, se, bad_layer ,bad_layer2, chi2_str);
757 if( iworst2-1 >= 0 && iworst2 <=
int(aState.
proto_segment.size()) ) {
760 if( iworst-1 >= 0 && iworst <=
int(aState.
proto_segment.size()) ){
772 for (
int i=1;
i<7;
i++){
773 if (
i == ir ||
i == ir2 ||
points(
i-1) == 0.)
continue;
777 Sy = Sy + (
points(
i-1)/sigma2);
778 Sx = Sx + ((i1)/sigma2);
779 Sxx = Sxx + (i1*i1)/sigma2;
780 Sxy = Sxy + (((i1)*
points(
i-1))/sigma2);
782 float delta = S*Sxx - Sx*Sx;
783 float intercept = (Sxx*Sy - Sx*Sxy)/delta;
784 float slope = (S*Sxy - Sx*Sy)/delta;
788 for (
int i=1;
i<7;
i++){
789 if (
i == ir ||
i == ir2 ||
points(
i-1) == 0.)
continue;
791 chi2_str = chi2_str + chi_str*chi_str;
793 return (intercept + slope*0);
800 if ((*it)->cscDetId().layer() == layer)
807 ChamberHitContainer::const_iterator it;
809 if ((*it)->cscDetId().layer() == layer)
814 return addHit(aState, h, layer);
819 std::unique_ptr<CSCSegFit> oldfit;
826 if ( (aState.
sfit->chi2() >= oldfit->chi2() ) || !ok ) {
835 std::unique_ptr<CSCSegFit> oldfit;
842 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.
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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
LocalPoint localPosition() const override
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
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
bool addHit(AlgoState &aState, const CSCRecHit2D *hit, int layer) const
Utility functions.
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.