13 std::shared_ptr<GlobalCoordsObtainer> &globalcoordsobtainer)
15 debug_(
pset.getUntrackedParameter<
bool>(
"debug")),
16 chi2Th_(
pset.getParameter<double>(
"chi2Th")),
20 chiSquareThreshold_(50),
21 minHits4Fit_(
pset.getParameter<
int>(
"minHits4Fit")),
22 splitPathPerSL_(
pset.getParameter<
bool>(
"splitPathPerSL")) {
26 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: constructor";
38 while (ifin3.good()) {
49 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: destructor";
57 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzerInChamber::initialiase";
68 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzerInChamber: run";
71 int nMuonPath_counter = 0;
72 for (
auto muonpath = muonpaths.begin(); muonpath != muonpaths.end(); ++muonpath) {
74 LogDebug(
"MuonPathAnalyzerInChamber")
75 <<
"Full path: " << nMuonPath_counter <<
" , " << muonpath->get()->nprimitives() <<
" , " 76 << muonpath->get()->nprimitivesUp() <<
" , " << muonpath->get()->nprimitivesDown();
81 MuonPathPtr muonpathUp_ptr = std::make_shared<MuonPath>();
82 muonpathUp_ptr->setNPrimitives(8);
83 muonpathUp_ptr->setNPrimitivesUp(muonpath->get()->nprimitivesUp());
84 muonpathUp_ptr->setNPrimitivesDown(0);
86 MuonPathPtr muonpathDown_ptr = std::make_shared<MuonPath>();
87 muonpathDown_ptr->setNPrimitives(8);
88 muonpathDown_ptr->setNPrimitivesUp(0);
89 muonpathDown_ptr->setNPrimitivesDown(muonpath->get()->nprimitivesDown());
91 for (
int n = 0;
n < muonpath->get()->nprimitives(); ++
n) {
94 if (prim->superLayerId() == 3) {
95 muonpathUp_ptr->setPrimitive(prim,
n);
98 else if (prim->superLayerId() == 1) {
99 muonpathDown_ptr->setPrimitive(prim,
n);
106 analyze(*muonpath, outmuonpaths);
109 if (muonpathUp_ptr->nprimitivesUp() > 1 && muonpath->get()->nprimitivesDown() > 0)
110 analyze(muonpathUp_ptr, outmuonpaths);
112 if (muonpathDown_ptr->nprimitivesDown() > 1 && muonpath->get()->nprimitivesUp() > 0)
113 analyze(muonpathDown_ptr, outmuonpaths);
120 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MuonPathAnalyzer: finish";
128 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t starts";
132 LogDebug(
"MuonPathAnalyzerInChamber") << inMPath->nprimitives();
133 auto mPath = std::make_shared<MuonPath>(inMPath);
136 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2::analyze, looking at mPath: ";
137 for (
int i = 0;
i < mPath->nprimitives();
i++)
138 LogDebug(
"MuonPathAnalyzerInChamber")
139 << mPath->primitive(
i)->layerId() <<
" , " << mPath->primitive(
i)->superLayerId() <<
" , " 140 << mPath->primitive(
i)->channelId() <<
" , " << mPath->primitive(
i)->laterality();
144 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t is Analyzable? ";
145 if (!mPath->isAnalyzable())
148 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t yes it is analyzable " << mPath->isAnalyzable();
154 std::shared_ptr<MuonPath> mpAux;
156 float best_chi2 = 99999.;
162 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analyze \t\t\t\t\t Start with combination " <<
i;
167 for (
int ii = 0;
ii < 8;
ii++) {
168 xwire[
ii] = mPath->xWirePos(
ii);
169 if (xwire[
ii] == 0) {
170 present_layer[
ii] = 0;
173 present_layer[
ii] = 1;
178 mPath->setChiSquare(0);
180 if (mPath->chiSquare() != 0)
194 double jm_x = (mPath->horizPos());
196 for (
int i = 0;
i < mPath->nprimitives();
i++) {
197 if (mPath->primitive(
i)->isValidTime()) {
198 selected_Id = mPath->primitive(
i)->cameraId();
199 mPath->setRawId(selected_Id);
214 for (
int i = 0;
i < mPath->nprimitives();
i++) {
215 if (mPath->primitive(
i)->isValidTime()) {
226 if (hits_in_SL1 > 2 && hits_in_SL3 <= 2) {
228 jm_x += mPath->tanPhi() * (11.1 + 0.65);
231 }
else if (hits_in_SL1 <= 2 && hits_in_SL3 > 2) {
233 jm_x -= mPath->tanPhi() * (11.1 + 0.65);
236 }
else if (hits_in_SL1 > 2 && hits_in_SL3 > 2) {
249 mPath->setHorizPos(jm_x);
252 int thisec = MuonPathSLId.sector();
259 double phi_cmssw = jm_x_cmssw_global.
phi() -
PHI_CONV * (thisec - 1);
260 double psi = atan(mPath->tanPhi());
261 mPath->setPhiCMSSW(phi_cmssw);
262 mPath->setPhiBCMSSW(
hasPosRF(MuonPathSLId.wheel(), MuonPathSLId.sector()) ?
psi - phi_cmssw : -
psi - phi_cmssw);
267 double x_lut, slope_lut;
270 DTWireId wireId1(MuonPathSLId1, 2, 1);
271 DTWireId wireId3(MuonPathSLId3, 2, 1);
274 double shift_for_lut = 0.;
275 if (SL_for_LUT == 1) {
277 }
else if (SL_for_LUT == 3) {
282 if (shift_sl1 < shift_sl3) {
283 shift_for_lut = shift_sl1;
285 shift_for_lut = shift_sl3;
291 phi = global_coords[0];
292 phiB = global_coords[1];
294 mPath->setPhiB(phiB);
296 if (mPath->chiSquare() < best_chi2 && mPath->chiSquare() > 0) {
297 mpAux = std::make_shared<MuonPath>(mPath);
299 best_chi2 = mPath->chiSquare();
302 if (mpAux !=
nullptr) {
305 LogDebug(
"MuonPathAnalyzerInChamber")
306 <<
"DTp2:analize \t\t\t\t\t Laterality " << bestI <<
" is the one with smaller chi2";
309 LogDebug(
"MuonPathAnalyzerInChamber")
310 <<
"DTp2:analize \t\t\t\t\t No Laterality found with chi2 smaller than threshold";
313 LogDebug(
"MuonPathAnalyzerInChamber") <<
"DTp2:analize \t\t\t\t\t Ended working with this set of lateralities";
317 for (
int i = 0;
i <= mpath->nprimitives();
i++) {
318 if (mpath->primitive(
i)->isValidTime())
326 for (
int i = 0;
i <= mpath->nprimitives();
i++) {
339 LogDebug(
"MuonPathAnalyzerInChamber") <<
"MPAnalyzer::buildLateralities << setLateralitiesFromPrims ";
340 mpath->setLateralCombFromPrimitives();
353 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] Input[" << ilat <<
"]: " << lr;
358 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Adding it to " <<
lateralities_.size() <<
" lists...";
359 for (
unsigned int iall = 0; iall <
lateralities_.size(); iall++) {
370 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Duplicating " << ncurrentoptions <<
" lists...";
373 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[DEBUG_] - Now we have " <<
lateralities_.size() <<
" lists...";
376 for (
unsigned int iall = 0; iall < ncurrentoptions; iall++) {
386 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[WARNING]: TOO MANY LATERALITIES TO CHECK !!";
387 LogDebug(
"MuonPathAnalyzerInChamber") <<
"[WARNING]: skipping this muon";
395 for (
unsigned int iall = 0; iall <
lateralities_.size(); iall++) {
396 LogDebug(
"MuonPathAnalyzerInChamber") << iall <<
" -> [";
399 LogDebug(
"MuonPathAnalyzerInChamber") <<
",";
402 LogDebug(
"MuonPathAnalyzerInChamber") <<
"]";
408 for (
int i = 0;
i < 8;
i++)
409 mpath->primitive(
i)->setLaterality(
lat[
i]);
414 for (
int i = 0;
i < mpath->nprimitives();
i++) {
415 if (mpath->primitive(
i)->isValidTime()) {
416 selected_Id = mpath->primitive(
i)->cameraId();
417 mpath->setRawId(selected_Id);
424 LogDebug(
"MuonPathAnalyzerInChamber")
425 <<
"Id " << chId.rawId() <<
" Wh " << chId.wheel() <<
" St " << chId.station() <<
" Se " << chId.sector();
426 mpath->setRawId(chId.rawId());
430 DTWireId wireId1(MuonPathSLId1, 2, 1);
431 DTWireId wireId3(MuonPathSLId3, 2, 1);
434 LogDebug(
"MuonPathAnalyzerInChamber")
438 float zwire[
NUM_LAYERS_2SL] = {-13.7, -12.4, -11.1, -9.8002, 9.79999, 11.1, 12.4, 13.7};
439 for (
int i = 0;
i < mpath->nprimitives();
i++) {
440 if (mpath->primitive(
i)->isValidTime()) {
442 mpath->setXWirePos(10000 *
shiftinfo_[wireId1.rawId()] +
443 (mpath->primitive(
i)->channelId() + 0.5 * (double)((
i + 1) % 2)) *
delta,
447 (mpath->primitive(
i)->channelId() + 0.5 * (double)((
i + 1) % 2)) *
delta,
449 mpath->setZWirePos(zwire[
i] * 1000,
i);
450 mpath->setTWireTDC(mpath->primitive(
i)->tdcTimeStamp() *
DRIFT_SPEED,
i);
452 mpath->setXWirePos(0.,
i);
453 mpath->setZWirePos(0.,
i);
457 LogDebug(
"MuonPathAnalyzerInChamber") << mpath->primitive(
i)->tdcTimeStamp() <<
" ";
460 LogDebug(
"MuonPathAnalyzerInChamber");
464 TLateralities laterality,
469 for (
int l = 0;
l < 8; ++
l) {
470 if (present_layer[
l] == 1)
477 for (
int i = 0;
i < 8;
i++) {
478 xwire[
i] = mpath->xWirePos(
i);
479 zwire[
i] = mpath->zWirePos(
i);
480 tTDCvdrift[
i] = mpath->tWireTDC(
i);
488 for (
int lay = 0; lay < 8; lay++) {
490 LogDebug(
"MuonPathAnalyzerInChamber") <<
"In fitPerLat " << lay <<
" xwire " << xwire[lay] <<
" zwire " 491 << zwire[lay] <<
" tTDCvdrift " << tTDCvdrift[lay];
492 xhit[lay] = xwire[lay] + (-1 + 2 * laterality[lay]) * 1000 * tTDCvdrift[lay];
494 LogDebug(
"MuonPathAnalyzerInChamber") <<
"In fitPerLat " << lay <<
" xhit " << xhit[lay];
505 for (
int lay = 0; lay < 8; lay++) {
506 if (present_layer[lay] == 0)
509 LogDebug(
"MuonPathAnalyzerInChamber")
510 <<
" For layer " << lay + 1 <<
" xwire[lay] " << xwire[lay] <<
" zwire " << zwire[lay] <<
" b " <<
b[lay];
512 LogDebug(
"MuonPathAnalyzerInChamber") <<
" xhit[lat][lay] " << xhit[lay];
513 cbscal = (-1 + 2 * laterality[lay]) *
b[lay] + cbscal;
514 zbscal = zwire[lay] *
b[lay] + zbscal;
515 czscal = (-1 + 2 * laterality[lay]) * zwire[lay] + czscal;
517 bbscal =
b[lay] *
b[lay] + bbscal;
518 zzscal = zwire[lay] * zwire[lay] + zzscal;
519 ccscal = (-1 + 2 * laterality[lay]) * (-1 + 2 * laterality[lay]) + ccscal;
529 cz = (cbscal * zbscal - czscal * bbscal) / (zzscal * bbscal - zbscal * zbscal);
530 cb = (czscal * zbscal - cbscal * zzscal) / (zzscal * bbscal - zbscal * zbscal);
532 zb = (czscal * cbscal - zbscal * ccscal) / (bbscal * ccscal - cbscal * cbscal);
533 zc = (zbscal * cbscal - czscal * bbscal) / (bbscal * ccscal - cbscal * cbscal);
535 bc = (zbscal * czscal - cbscal * zzscal) / (ccscal * zzscal - czscal * czscal);
536 bz = (cbscal * czscal - zbscal * ccscal) / (ccscal * zzscal - czscal * czscal);
542 for (
int lay = 0; lay < 8; lay++) {
543 if (present_layer[lay] == 0)
546 LogDebug(
"MuonPathAnalyzerInChamber")
547 <<
" For layer " << lay + 1 <<
" xwire[lay] " << xwire[lay] <<
" zwire " << zwire[lay] <<
" b " <<
b[lay];
548 c_tilde[lay] = (-1 + 2 * laterality[lay]) + cz * zwire[lay] + cb *
b[lay];
549 z_tilde[lay] = zwire[lay] + zb *
b[lay] + zc * (-1 + 2 * laterality[lay]);
550 b_tilde[lay] =
b[lay] + bc * (-1 + 2 * laterality[lay]) + bz * zwire[lay];
554 double xctilde = 0.0;
555 double xztilde = 0.0;
556 double xbtilde = 0.0;
557 double ctildectilde = 0.0;
558 double ztildeztilde = 0.0;
559 double btildebtilde = 0.0;
561 double rect0vdrift = 0.0;
562 double recslope = 0.0;
565 for (
int lay = 0; lay < 8; lay++) {
566 if (present_layer[lay] == 0)
568 xctilde = xhit[lay] * c_tilde[lay] + xctilde;
569 ctildectilde = c_tilde[lay] * c_tilde[lay] + ctildectilde;
570 xztilde = xhit[lay] * z_tilde[lay] + xztilde;
571 ztildeztilde = z_tilde[lay] * z_tilde[lay] + ztildeztilde;
572 xbtilde = xhit[lay] * b_tilde[lay] + xbtilde;
573 btildebtilde = b_tilde[lay] * b_tilde[lay] + btildebtilde;
577 rect0vdrift = xctilde / ctildectilde;
578 recslope = xztilde / ztildeztilde;
579 recpos = xbtilde / btildebtilde;
581 LogDebug(
"MuonPathAnalyzerInChamber") <<
" In fitPerLat Reconstructed values per lat " 582 <<
" rect0vdrift " << rect0vdrift;
583 LogDebug(
"MuonPathAnalyzerInChamber")
585 << recslope <<
" recpos " << recpos;
591 double recchi2 = 0.0;
592 int sign_tdriftvdrift = {0};
593 int incell_tdriftvdrift = {0};
594 int physical_slope = {0};
601 int swap_laterality[8] = {0};
603 for (
int lay = 0; lay < 8; lay++) {
604 if (present_layer[lay] == 0)
606 rectdriftvdrift[lay] = tTDCvdrift[lay] - rect0vdrift / 1000;
608 LogDebug(
"MuonPathAnalyzerInChamber") << rectdriftvdrift[lay];
609 recres[lay] = xhit[lay] - zwire[lay] * recslope -
b[lay] * recpos - (-1 + 2 * laterality[lay]) * rect0vdrift;
612 if (
abs(rectdriftvdrift[lay]) < 3) {
613 swap_laterality[lay] = 1;
616 if ((present_layer[lay] == 1) && (rectdriftvdrift[lay] < -0.1)) {
617 sign_tdriftvdrift = -1;
618 if (-0.1 - rectdriftvdrift[lay] > maxDif) {
619 maxDif = -0.1 - rectdriftvdrift[lay];
623 if ((present_layer[lay] == 1) && (
abs(rectdriftvdrift[lay]) > 21.1)) {
624 incell_tdriftvdrift = -1;
625 if (rectdriftvdrift[lay] - 21.1 > maxDif) {
626 maxDif = rectdriftvdrift[lay] - 21.1;
634 if (lat_added == 0) {
635 std::vector<TLateralities> additional_lateralities;
636 additional_lateralities.clear();
637 additional_lateralities.push_back(laterality);
641 if (swap_laterality[
swap] == 1) {
642 int add_lat_size =
int(additional_lateralities.size());
643 for (
int ll = 0; ll < add_lat_size; ++ll) {
644 TLateralities tmp_lat = additional_lateralities[ll];
651 additional_lateralities.push_back(tmp_lat);
657 int already_there = 0;
658 for (
int k = 0;
k <
int(additional_lateralities.size()); ++
k) {
664 if (already_there == 0) {
668 additional_lateralities.clear();
672 if (fabs(recslope / 10) > 1.3)
675 if (physical_slope == -1 &&
debug_)
676 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with UNPHYSICAL slope ";
677 if (sign_tdriftvdrift == -1 &&
debug_)
678 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with negative tdrift-vdrift ";
679 if (incell_tdriftvdrift == -1 &&
debug_)
680 LogDebug(
"MuonPathAnalyzerInChamber") <<
"Combination with tdrift-vdrift larger than half cell ";
682 for (
int lay = 0; lay < 8; lay++) {
683 if (present_layer[lay] == 0)
685 recchi2 = recres[lay] * recres[lay] + recchi2;
689 recchi2 = recchi2 / (n_hits - 3);
692 LogDebug(
"MuonPathAnalyzerInChamber")
693 <<
"In fitPerLat Chi2 " << recchi2 <<
" with sign " << sign_tdriftvdrift <<
" within cell " 694 << incell_tdriftvdrift <<
" physical_slope " << physical_slope;
697 if (
true && maxInt != -1) {
698 present_layer[maxInt] = 0;
700 LogDebug(
"MuonPathAnalyzerInChamber") <<
"We get rid of hit in layer " << maxInt;
704 if (!(sign_tdriftvdrift == -1) && !(incell_tdriftvdrift == -1) && !(physical_slope == -1)) {
705 mpath->setBxTimeValue((rect0vdrift /
DRIFT_SPEED) / 1000);
706 mpath->setTanPhi(-1 * recslope / 10);
707 mpath->setHorizPos(recpos / 10000);
708 mpath->setChiSquare(recchi2 / 100000000);
711 LogDebug(
"MuonPathAnalyzerInChamber")
713 <<
"t0 " << mpath->bxTimeValue() <<
" slope " << mpath->tanPhi() <<
" pos " << mpath->horizPos() <<
" chi2 " 714 << mpath->chiSquare() <<
" rawId " << mpath->rawId();
718 mPath->setQuality(
NOPATH);
720 int nPrimsUp(0), nPrimsDown(0);
722 if (mPath->primitive(
i)->isValidTime()) {
730 mPath->setNPrimitivesUp(nPrimsUp);
731 mPath->setNPrimitivesDown(nPrimsDown);
733 if (mPath->nprimitivesUp() >= 4 && mPath->nprimitivesDown() >= 4) {
735 }
else if ((mPath->nprimitivesUp() == 4 && mPath->nprimitivesDown() == 3) ||
736 (mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() == 4)) {
738 }
else if ((mPath->nprimitivesUp() == 4 && mPath->nprimitivesDown() <= 2 && mPath->nprimitivesDown() > 0) ||
739 (mPath->nprimitivesUp() <= 2 && mPath->nprimitivesUp() > 0 && mPath->nprimitivesDown() == 4)) {
740 mPath->setQuality(
CHIGHQ);
741 }
else if ((mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() == 3)) {
743 }
else if ((mPath->nprimitivesUp() == 3 && mPath->nprimitivesDown() <= 2 && mPath->nprimitivesDown() > 0) ||
744 (mPath->nprimitivesUp() <= 2 && mPath->nprimitivesUp() > 0 && mPath->nprimitivesDown() == 3) ||
745 (mPath->nprimitivesUp() == 2 && mPath->nprimitivesDown() == 2)) {
746 mPath->setQuality(
CLOWQ);
747 }
else if (mPath->nprimitivesUp() >= 4 || mPath->nprimitivesDown() >= 4) {
748 mPath->setQuality(
HIGHQ);
749 }
else if (mPath->nprimitivesUp() == 3 || mPath->nprimitivesDown() == 3) {
750 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
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]