14 std::shared_ptr<GlobalCoordsObtainer> &globalcoordsobtainer)
16 debug_(
pset.getUntrackedParameter<
bool>(
"debug")),
17 chi2Th_(
pset.getParameter<double>(
"chi2Th")),
21 chiSquareThreshold_(50),
22 minHits4Fit_(
pset.getParameter<
int>(
"minHits4Fit")),
23 splitPathPerSL_(
pset.getParameter<
bool>(
"splitPathPerSL")) {
27 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: constructor";
39 while (ifin3.good()) {
50 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: destructor";
58 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzerInChamber::initialiase";
69 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzerInChamber: run";
72 int nMuonPath_counter = 0;
73 for (
auto muonpath = muonpaths.begin(); muonpath != muonpaths.end(); ++muonpath) {
75 LogDebug(
"MuonPathAnalyzerInChamber")
76 <<
"Full path: " << nMuonPath_counter <<
" , " << muonpath->get()->nprimitives() <<
" , " 77 << muonpath->get()->nprimitivesUp() <<
" , " << muonpath->get()->nprimitivesDown();
82 MuonPathPtr muonpathUp_ptr = std::make_shared<MuonPath>();
83 muonpathUp_ptr->setNPrimitives(8);
84 muonpathUp_ptr->setNPrimitivesUp(muonpath->get()->nprimitivesUp());
85 muonpathUp_ptr->setNPrimitivesDown(0);
87 MuonPathPtr muonpathDown_ptr = std::make_shared<MuonPath>();
88 muonpathDown_ptr->setNPrimitives(8);
89 muonpathDown_ptr->setNPrimitivesUp(0);
90 muonpathDown_ptr->setNPrimitivesDown(muonpath->get()->nprimitivesDown());
92 for (
int n = 0;
n < muonpath->get()->nprimitives(); ++
n) {
95 if (prim->superLayerId() == 3) {
96 muonpathUp_ptr->setPrimitive(prim,
n);
99 else if (prim->superLayerId() == 1) {
100 muonpathDown_ptr->setPrimitive(prim,
n);
107 analyze(*muonpath, outmuonpaths);
110 if (muonpathUp_ptr->nprimitivesUp() > 1 && muonpath->get()->nprimitivesDown() > 0)
111 analyze(muonpathUp_ptr, outmuonpaths);
113 if (muonpathDown_ptr->nprimitivesDown() > 1 && muonpath->get()->nprimitivesUp() > 0)
114 analyze(muonpathDown_ptr, outmuonpaths);
121 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: finish";
129 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t starts";
133 LogDebug(
"MuonPathAnalyzerInChamber") << inMPath->nprimitives();
134 auto mPath = std::make_shared<MuonPath>(inMPath);
137 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2::analyze, looking at mPath: ";
138 for (
int i = 0;
i < mPath->nprimitives();
i++)
139 LogDebug(
"MuonPathAnalyzerInChamber")
140 << mPath->primitive(
i)->layerId() <<
" , " << mPath->primitive(
i)->superLayerId() <<
" , " 141 << mPath->primitive(
i)->channelId() <<
" , " << mPath->primitive(
i)->laterality();
145 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t is Analyzable? ";
146 if (!mPath->isAnalyzable())
149 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t yes it is analyzable " << mPath->isAnalyzable();
155 std::shared_ptr<MuonPath> mpAux;
157 float best_chi2 = 99999.;
163 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t Start with combination " <<
i;
168 for (
int ii = 0;
ii < 8;
ii++) {
169 xwire[
ii] = mPath->xWirePos(
ii);
170 if (xwire[
ii] == 0) {
171 present_layer[
ii] = 0;
174 present_layer[
ii] = 1;
179 mPath->setChiSquare(0);
181 if (mPath->chiSquare() != 0)
195 double jm_x = (mPath->horizPos());
197 for (
int i = 0;
i < mPath->nprimitives();
i++) {
198 if (mPath->primitive(
i)->isValidTime()) {
199 selected_Id = mPath->primitive(
i)->cameraId();
200 mPath->setRawId(selected_Id);
215 for (
int i = 0;
i < mPath->nprimitives();
i++) {
216 if (mPath->primitive(
i)->isValidTime()) {
227 if (hits_in_SL1 > 2 && hits_in_SL3 <= 2) {
229 jm_x += mPath->tanPhi() * (11.1 + 0.65);
232 }
else if (hits_in_SL1 <= 2 && hits_in_SL3 > 2) {
234 jm_x -= mPath->tanPhi() * (11.1 + 0.65);
237 }
else if (hits_in_SL1 > 2 && hits_in_SL3 > 2) {
250 mPath->setHorizPos(jm_x);
253 int thisec = MuonPathSLId.sector();
260 double phi_cmssw = jm_x_cmssw_global.
phi() -
PHI_CONV * (thisec - 1);
261 double psi = atan(mPath->tanPhi());
262 mPath->setPhiCMSSW(phi_cmssw);
263 mPath->setPhiBCMSSW(
hasPosRF(MuonPathSLId.wheel(), MuonPathSLId.sector()) ?
psi - phi_cmssw : -
psi - phi_cmssw);
268 double x_lut, slope_lut;
271 DTWireId wireId1(MuonPathSLId1, 2, 1);
272 DTWireId wireId3(MuonPathSLId3, 2, 1);
275 double shift_for_lut = 0.;
276 if (SL_for_LUT == 1) {
278 }
else if (SL_for_LUT == 3) {
283 if (shift_sl1 < shift_sl3) {
284 shift_for_lut = shift_sl1;
286 shift_for_lut = shift_sl3;
292 phi = global_coords[0];
293 phiB = global_coords[1];
295 mPath->setPhiB(phiB);
297 if (mPath->chiSquare() < best_chi2 && mPath->chiSquare() > 0) {
298 mpAux = std::make_shared<MuonPath>(mPath);
300 best_chi2 = mPath->chiSquare();
303 if (mpAux !=
nullptr) {
306 LogDebug(
"MuonPathAnalyzerInChamber")
307 <<
"DTp2:analize \t\t\t\t\t Laterality " << bestI <<
" is the one with smaller chi2";
310 LogDebug(
"MuonPathAnalyzerInChamber")
311 <<
"DTp2:analize \t\t\t\t\t No Laterality found with chi2 smaller than threshold";
314 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analize \t\t\t\t\t Ended working with this set of lateralities";
318 for (
int i = 0;
i <= mpath->nprimitives();
i++) {
319 if (mpath->primitive(
i)->isValidTime())
327 for (
int i = 0;
i <= mpath->nprimitives();
i++) {
340 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MPAnalyzer::buildLateralities << setLateralitiesFromPrims ";
341 mpath->setLateralCombFromPrimitives();
354 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] Input[" << ilat <<
"]: " << lr;
359 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Adding it to " <<
lateralities_.size() <<
" lists...";
360 for (
unsigned int iall = 0; iall <
lateralities_.size(); iall++) {
371 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Duplicating " << ncurrentoptions <<
" lists...";
374 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Now we have " <<
lateralities_.size() <<
" lists...";
377 for (
unsigned int iall = 0; iall < ncurrentoptions; iall++) {
387 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[WARNING]: TOO MANY LATERALITIES TO CHECK !!";
388 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[WARNING]: skipping this muon";
396 for (
unsigned int iall = 0; iall <
lateralities_.size(); iall++) {
397 LogDebug(
"MuonPathAnalyzerInChamber") << iall <<
" -> [";
400 LogDebug(
"MuonPathAnalyzerInChamber") <<
",";
403 LogDebug(
"MuonPathAnalyzerInChamber") <<
"]";
409 for (
int i = 0;
i < 8;
i++)
410 mpath->primitive(
i)->setLaterality(
lat[
i]);
415 for (
int i = 0;
i < mpath->nprimitives();
i++) {
416 if (mpath->primitive(
i)->isValidTime()) {
417 selected_Id = mpath->primitive(
i)->cameraId();
418 mpath->setRawId(selected_Id);
425 LogDebug(
"MuonPathAnalyzerInChamber")
426 <<
"Id " << chId.rawId() <<
" Wh " << chId.wheel() <<
" St " << chId.station() <<
" Se " << chId.sector();
427 mpath->setRawId(chId.rawId());
431 DTWireId wireId1(MuonPathSLId1, 2, 1);
432 DTWireId wireId3(MuonPathSLId3, 2, 1);
435 LogDebug(
"MuonPathAnalyzerInChamber")
439 float zwire[
NUM_LAYERS_2SL] = {-13.7, -12.4, -11.1, -9.8002, 9.79999, 11.1, 12.4, 13.7};
440 for (
int i = 0;
i < mpath->nprimitives();
i++) {
441 if (mpath->primitive(
i)->isValidTime()) {
443 mpath->setXWirePos(10000 *
shiftinfo_[wireId1.rawId()] +
444 (mpath->primitive(
i)->channelId() + 0.5 * (double)((
i + 1) % 2)) *
delta,
448 (mpath->primitive(
i)->channelId() + 0.5 * (double)((
i + 1) % 2)) *
delta,
450 mpath->setZWirePos(zwire[
i] * 1000,
i);
451 mpath->setTWireTDC(mpath->primitive(
i)->tdcTimeStamp() *
DRIFT_SPEED,
i);
453 mpath->setXWirePos(0.,
i);
454 mpath->setZWirePos(0.,
i);
458 LogDebug(
"MuonPathAnalyzerInChamber") << mpath->primitive(
i)->tdcTimeStamp() <<
" ";
461 LogDebug(
"MuonPathAnalyzerInChamber");
465 TLateralities laterality,
470 for (
int l = 0;
l < 8; ++
l) {
471 if (present_layer[
l] == 1)
478 for (
int i = 0;
i < 8;
i++) {
479 xwire[
i] = mpath->xWirePos(
i);
480 zwire[
i] = mpath->zWirePos(
i);
481 tTDCvdrift[
i] = mpath->tWireTDC(
i);
489 for (
int lay = 0; lay < 8; lay++) {
491 LogDebug(
"MuonPathAnalyzerInChamber") <<
"In fitPerLat " << lay <<
" xwire " << xwire[lay] <<
" zwire " 492 << zwire[lay] <<
" tTDCvdrift " << tTDCvdrift[lay];
493 xhit[lay] = xwire[lay] + (-1 + 2 * laterality[lay]) * 1000 * tTDCvdrift[lay];
495 LogDebug(
"MuonPathAnalyzerInChamber") <<
"In fitPerLat " << lay <<
" xhit " << xhit[lay];
506 for (
int lay = 0; lay < 8; lay++) {
507 if (present_layer[lay] == 0)
510 LogDebug(
"MuonPathAnalyzerInChamber")
511 <<
" For layer " << lay + 1 <<
" xwire[lay] " << xwire[lay] <<
" zwire " << zwire[lay] <<
" b " <<
b[lay];
513 LogDebug(
"MuonPathAnalyzerInChamber") <<
" xhit[lat][lay] " << xhit[lay];
514 cbscal = (-1 + 2 * laterality[lay]) *
b[lay] + cbscal;
515 zbscal = zwire[lay] *
b[lay] + zbscal;
516 czscal = (-1 + 2 * laterality[lay]) * zwire[lay] + czscal;
518 bbscal =
b[lay] *
b[lay] + bbscal;
519 zzscal = zwire[lay] * zwire[lay] + zzscal;
520 ccscal = (-1 + 2 * laterality[lay]) * (-1 + 2 * laterality[lay]) + ccscal;
530 cz = (cbscal * zbscal - czscal * bbscal) / (zzscal * bbscal - zbscal * zbscal);
531 cb = (czscal * zbscal - cbscal * zzscal) / (zzscal * bbscal - zbscal * zbscal);
533 zb = (czscal * cbscal - zbscal * ccscal) / (bbscal * ccscal - cbscal * cbscal);
534 zc = (zbscal * cbscal - czscal * bbscal) / (bbscal * ccscal - cbscal * cbscal);
536 bc = (zbscal * czscal - cbscal * zzscal) / (ccscal * zzscal - czscal * czscal);
537 bz = (cbscal * czscal - zbscal * ccscal) / (ccscal * zzscal - czscal * czscal);
543 for (
int lay = 0; lay < 8; lay++) {
544 if (present_layer[lay] == 0)
547 LogDebug(
"MuonPathAnalyzerInChamber")
548 <<
" For layer " << lay + 1 <<
" xwire[lay] " << xwire[lay] <<
" zwire " << zwire[lay] <<
" b " <<
b[lay];
549 c_tilde[lay] = (-1 + 2 * laterality[lay]) + cz * zwire[lay] + cb *
b[lay];
550 z_tilde[lay] = zwire[lay] + zb *
b[lay] + zc * (-1 + 2 * laterality[lay]);
551 b_tilde[lay] =
b[lay] + bc * (-1 + 2 * laterality[lay]) + bz * zwire[lay];
555 double xctilde = 0.0;
556 double xztilde = 0.0;
557 double xbtilde = 0.0;
558 double ctildectilde = 0.0;
559 double ztildeztilde = 0.0;
560 double btildebtilde = 0.0;
562 double rect0vdrift = 0.0;
563 double recslope = 0.0;
566 for (
int lay = 0; lay < 8; lay++) {
567 if (present_layer[lay] == 0)
569 xctilde = xhit[lay] * c_tilde[lay] + xctilde;
570 ctildectilde = c_tilde[lay] * c_tilde[lay] + ctildectilde;
571 xztilde = xhit[lay] * z_tilde[lay] + xztilde;
572 ztildeztilde = z_tilde[lay] * z_tilde[lay] + ztildeztilde;
573 xbtilde = xhit[lay] * b_tilde[lay] + xbtilde;
574 btildebtilde = b_tilde[lay] * b_tilde[lay] + btildebtilde;
578 rect0vdrift = xctilde / ctildectilde;
579 recslope = xztilde / ztildeztilde;
580 recpos = xbtilde / btildebtilde;
582 LogDebug(
"MuonPathAnalyzerInChamber") <<
" In fitPerLat Reconstructed values per lat " 583 <<
" rect0vdrift " << rect0vdrift;
584 LogDebug(
"MuonPathAnalyzerInChamber")
586 << recslope <<
" recpos " << recpos;
592 double recchi2 = 0.0;
593 int sign_tdriftvdrift = {0};
594 int incell_tdriftvdrift = {0};
595 int physical_slope = {0};
602 int swap_laterality[8] = {0};
604 for (
int lay = 0; lay < 8; lay++) {
605 if (present_layer[lay] == 0)
607 rectdriftvdrift[lay] = tTDCvdrift[lay] - rect0vdrift / 1000;
609 LogDebug(
"MuonPathAnalyzerInChamber") << rectdriftvdrift[lay];
610 recres[lay] = xhit[lay] - zwire[lay] * recslope -
b[lay] * recpos - (-1 + 2 * laterality[lay]) * rect0vdrift;
613 if (
abs(rectdriftvdrift[lay]) < 3) {
614 swap_laterality[lay] = 1;
617 if ((present_layer[lay] == 1) && (rectdriftvdrift[lay] < -0.1)) {
618 sign_tdriftvdrift = -1;
619 if (-0.1 - rectdriftvdrift[lay] > maxDif) {
620 maxDif = -0.1 - rectdriftvdrift[lay];
624 if ((present_layer[lay] == 1) && (
abs(rectdriftvdrift[lay]) > 21.1)) {
625 incell_tdriftvdrift = -1;
626 if (rectdriftvdrift[lay] - 21.1 > maxDif) {
627 maxDif = rectdriftvdrift[lay] - 21.1;
635 if (lat_added == 0) {
636 std::vector<TLateralities> additional_lateralities;
637 additional_lateralities.clear();
638 additional_lateralities.push_back(laterality);
642 if (swap_laterality[
swap] == 1) {
643 int add_lat_size =
int(additional_lateralities.size());
644 for (
int ll = 0; ll < add_lat_size; ++ll) {
645 TLateralities tmp_lat = additional_lateralities[ll];
652 additional_lateralities.push_back(tmp_lat);
658 int already_there = 0;
659 for (
int k = 0;
k <
int(additional_lateralities.size()); ++
k) {
665 if (already_there == 0) {
669 additional_lateralities.clear();
673 if (fabs(recslope / 10) > 1.3)
676 if (physical_slope == -1 &&
debug_)
677 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with UNPHYSICAL slope ";
678 if (sign_tdriftvdrift == -1 &&
debug_)
679 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with negative tdrift-vdrift ";
680 if (incell_tdriftvdrift == -1 &&
debug_)
681 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with tdrift-vdrift larger than half cell ";
683 for (
int lay = 0; lay < 8; lay++) {
684 if (present_layer[lay] == 0)
686 recchi2 = recres[lay] * recres[lay] + recchi2;
690 recchi2 = recchi2 / (n_hits - 3);
693 LogDebug(
"MuonPathAnalyzerInChamber")
694 <<
"In fitPerLat Chi2 " << recchi2 <<
" with sign " << sign_tdriftvdrift <<
" within cell " 695 << incell_tdriftvdrift <<
" physical_slope " << physical_slope;
698 if (
true && maxInt != -1) {
699 present_layer[maxInt] = 0;
701 LogDebug(
"MuonPathAnalyzerInChamber") <<
"We get rid of hit in layer " << maxInt;
705 if (!(sign_tdriftvdrift == -1) && !(incell_tdriftvdrift == -1) && !(physical_slope == -1)) {
706 mpath->setBxTimeValue((rect0vdrift /
DRIFT_SPEED) / 1000);
707 mpath->setTanPhi(-1 * recslope / 10);
708 mpath->setHorizPos(recpos / 10000);
709 mpath->setChiSquare(recchi2 / 100000000);
712 LogDebug(
"MuonPathAnalyzerInChamber")
714 <<
"t0 " << mpath->bxTimeValue() <<
" slope " << mpath->tanPhi() <<
" pos " << mpath->horizPos() <<
" chi2 " 715 << mpath->chiSquare() <<
" rawId " << mpath->rawId();
719 mPath->setQuality(
NOPATH);
721 int nPrimsUp(0), nPrimsDown(0);
723 if (mPath->primitive(
i)->isValidTime()) {
731 mPath->setNPrimitivesUp(nPrimsUp);
732 mPath->setNPrimitivesDown(nPrimsDown);
734 if (mPath->nprimitivesUp() >= 4 && mPath->nprimitivesDown() >= 4) {
736 }
else if ((mPath->nprimitivesUp() == 4 && mPath->nprimitivesDown() == 3) ||
737 (mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() == 4)) {
739 }
else if ((mPath->nprimitivesUp() == 4 && mPath->nprimitivesDown() <= 2 && mPath->nprimitivesDown() > 0) ||
740 (mPath->nprimitivesUp() <= 2 && mPath->nprimitivesUp() > 0 && mPath->nprimitivesDown() == 4)) {
741 mPath->setQuality(
CHIGHQ);
742 }
else if ((mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() == 3)) {
744 }
else if ((mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() <= 2 && mPath->nprimitivesDown() > 0) ||
745 (mPath->nprimitivesUp() <= 2 && mPath->nprimitivesUp() > 0 && mPath->nprimitivesDown() == 3) ||
746 (mPath->nprimitivesUp() == 2 && mPath->nprimitivesDown() == 2)) {
747 mPath->setQuality(
CLOWQ);
748 }
else if (mPath->nprimitivesUp() >= 4 || mPath->nprimitivesDown() >= 4) {
749 mPath->setQuality(
HIGHQ);
750 }
else if (mPath->nprimitivesUp() == 3 || mPath->nprimitivesDown() == 3) {
751 mPath->setQuality(
LOWQ);
int station() const
Return the station number.
DTGeometry const * dtGeo_
void setChiSquareThreshold(float ch2Thr)
Point3DBase< Scalar, LocalTag > LocalPoint
MuonPathAnalyzerInChamber(const edm::ParameterSet &pset, edm::ConsumesCollector &iC, std::shared_ptr< GlobalCoordsObtainer > &globalcoordsobtainer)
int superLayer() const
Return the superlayer number.
void setCellLayout(MuonPathPtr &mpath)
std::string fullPath() const
constexpr bool isNotFinite(T x)
Geom::Phi< T > phi() const
std::vector< MuonPathPtr > MuonPathPtrs
void setWirePosAndTimeInMP(MuonPathPtr &mpath)
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomH
cmsdt::MP_QUALITY minQuality_
std::map< std::string, int, std::less< std::string > > psi
void swap(Association< C > &lhs, Association< C > &rhs)
float chiSquareThreshold_
void evaluateQuality(MuonPathPtr &mPath)
~MuonPathAnalyzerInChamber() override
int totalNumValLateralities_
constexpr int INCREASED_RES_SLOPE_POW
bool hasPosRF(int wh, int sec)
void buildLateralities(MuonPathPtr &mpath)
constexpr float Z_SHIFT_MB4
void setLateralitiesInMP(MuonPathPtr &mpath, TLateralities lat)
std::map< int, float > shiftinfo_
Abs< T >::type abs(const T &t)
void initialise(const edm::EventSetup &iEventSetup) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
std::vector< TLateralities > lateralities_
constexpr double PHI_CONV
constexpr uint32_t rawId() const
get the raw id
void calculateFitParameters(MuonPathPtr &mpath, TLateralities lat, int present_layer[cmsdt::NUM_LAYERS_2SL], int &lat_added)
constexpr int NUM_LAYERS_2SL
std::vector< cmsdt::LATQ_TYPE > latQuality_
void analyze(MuonPathPtr &inMPath, MuonPathPtrs &outMPaths)
int wheel() const
Return the wheel number.
std::shared_ptr< MuonPath > MuonPathPtr
static unsigned int const shift
std::shared_ptr< GlobalCoordsObtainer > globalcoordsobtainer_
constexpr int INCREASED_RES_POS_POW
edm::FileInPath shift_filename_
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
void run(edm::Event &iEvent, const edm::EventSetup &iEventSetup, MuonPathPtrs &inMpath, std::vector< cmsdt::metaPrimitive > &metaPrimitives) override
std::shared_ptr< DTPrimitive > DTPrimitivePtr
constexpr float DRIFT_SPEED
int cellLayout_[cmsdt::NUM_LAYERS_2SL]