|
| 1 | +#include "L1Trigger/DTTriggerPhase2/interface/MPThetaMatching.h" |
| 2 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 3 | +#include "L1Trigger/DTTriggerPhase2/interface/constants.h" |
| 4 | + |
| 5 | +using namespace edm; |
| 6 | +using namespace std; |
| 7 | +using namespace cmsdt; |
| 8 | + |
| 9 | +// ============================================================================ |
| 10 | +// Constructors and destructor |
| 11 | +// ============================================================================ |
| 12 | +MPThetaMatching::MPThetaMatching(const ParameterSet &pset) |
| 13 | + : MPFilter(pset), debug_(pset.getUntrackedParameter<bool>("debug")), |
| 14 | + th_option_(pset.getParameter<int>("th_option")), |
| 15 | + th_quality_(pset.getParameter<int>("th_quality")), |
| 16 | + scenario_(pset.getParameter<int>("scenario")) {} |
| 17 | + |
| 18 | +// ============================================================================ |
| 19 | +// Main methods (initialise, run, finish) |
| 20 | +// ============================================================================ |
| 21 | +void MPThetaMatching::initialise(const edm::EventSetup &iEventSetup) {} |
| 22 | + |
| 23 | +void MPThetaMatching::run(edm::Event &iEvent, |
| 24 | + const edm::EventSetup &iEventSetup, |
| 25 | + std::vector<metaPrimitive> &inMPaths, |
| 26 | + std::vector<metaPrimitive> &outMPaths) { |
| 27 | + |
| 28 | + if (debug_) |
| 29 | + LogDebug("MPThetaMatching") << "MPThetaMatching: run"; |
| 30 | + |
| 31 | + double shift_back = 0; // Needed for t0 (TDC) calculation, taken from main algo |
| 32 | + if (scenario_ == MC) shift_back = 400; |
| 33 | + else if (scenario_ == DATA) shift_back = 0; |
| 34 | + else if (scenario_ == SLICE_TEST) shift_back = 400; |
| 35 | + |
| 36 | + auto filteredMPs = filter(inMPaths, th_option_, th_quality_, shift_back); |
| 37 | + for (auto &mp : filteredMPs) |
| 38 | + outMPaths.push_back(mp); |
| 39 | + |
| 40 | +} |
| 41 | + |
| 42 | +void MPThetaMatching::finish(){}; |
| 43 | + |
| 44 | +/////////////////////////// |
| 45 | +/// OTHER METHODS |
| 46 | + |
| 47 | +std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> inMPs, |
| 48 | + int th_option, int th_quality, double shift_back) { |
| 49 | + std::vector<metaPrimitive> outMPs; |
| 50 | + std::vector<metaPrimitive> thetaMPs; |
| 51 | + std::vector<metaPrimitive> phiMPs; |
| 52 | + |
| 53 | + //survey theta and phi MPs |
| 54 | + for (auto & mp: inMPs) { |
| 55 | + |
| 56 | + DTChamberId chId(mp.rawId); |
| 57 | + DTSuperLayerId slId(mp.rawId); |
| 58 | + |
| 59 | + if(slId.superLayer() == 2) thetaMPs.push_back(mp); |
| 60 | + else phiMPs.push_back(mp); |
| 61 | + } |
| 62 | + |
| 63 | + // Loop on phi, save those at station without Theta MPs |
| 64 | + for (auto & mp: phiMPs) { |
| 65 | + |
| 66 | + DTChamberId chId(mp.rawId); |
| 67 | + DTSuperLayerId slId(mp.rawId); |
| 68 | + |
| 69 | + int sector = chId.sector(); |
| 70 | + int wheel = chId.wheel(); |
| 71 | + int station = chId.station(); |
| 72 | + |
| 73 | + if (station == 4) {outMPs.push_back(mp); //No theta matching for MB4, save MP |
| 74 | + continue;} |
| 75 | + |
| 76 | + if(!isThereThetaMPInChamber(sector,wheel,station,thetaMPs) ) {outMPs.push_back(mp); // No theta MPs in chamber to match, save MP |
| 77 | + continue;} |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + // Loop on theta |
| 82 | + for (auto & mp1: thetaMPs) { |
| 83 | + std::vector<std::pair<metaPrimitive,float>> deltaTimePosPhiCands; |
| 84 | + |
| 85 | + DTChamberId chId(mp1.rawId); |
| 86 | + DTSuperLayerId slId(mp1.rawId); |
| 87 | + |
| 88 | + int sector = chId.sector(); |
| 89 | + int wheel = chId.wheel(); |
| 90 | + int station = chId.station(); |
| 91 | + |
| 92 | + if (station == 4) { LogDebug("MPThetaMatching") << "MPThetaMatching: station 4 does NOT have Theta SL 2"; |
| 93 | + continue;} |
| 94 | + |
| 95 | +// float t0 = (mp1.t0 - shift_back * LHC_CLK_FREQ) * ((float) TIME_TO_TDC_COUNTS / (float) LHC_CLK_FREQ); |
| 96 | + float t0 = ((int)round(mp1.t0 / (float)LHC_CLK_FREQ)) - shift_back; |
| 97 | + float posRefZ = zFE[wheel+2]; |
| 98 | + if(wheel==0 && (sector ==1 || sector==4 || sector==5 || sector==8 || sector==9 ||sector==12)) posRefZ = -posRefZ; |
| 99 | + float posZ = abs(mp1.phi); //??? |
| 100 | + |
| 101 | + for (auto & mp2: phiMPs) { |
| 102 | + |
| 103 | + DTChamberId chId2(mp2.rawId); |
| 104 | + DTSuperLayerId slId2(mp2.rawId); |
| 105 | + |
| 106 | + //if (co_option==1 && PhiMP2==0) continue; // Phi Only |
| 107 | + //else if (co_option==2 && PhiMP2==1) continue; // Theta Only |
| 108 | + |
| 109 | + int sector2 = chId2.sector(); |
| 110 | + int wheel2 = chId2.wheel(); |
| 111 | + int station2 = chId2.station(); |
| 112 | + if (station2 == 4) continue; |
| 113 | + |
| 114 | + if(station2 != station || sector2 != sector || wheel2 != wheel) continue; |
| 115 | + |
| 116 | + if ((mp2.quality > th_quality)) {outMPs.push_back(mp2); //don't do theta matching for q > X, save |
| 117 | + continue; |
| 118 | + } |
| 119 | + |
| 120 | +// float t02 = (mp2.t0 - shift_back * LHC_CLK_FREQ) * ((float) TIME_TO_TDC_COUNTS / (float) LHC_CLK_FREQ); |
| 121 | + float t02 = ((int)round(mp2.t0 / (float)LHC_CLK_FREQ)) - shift_back; |
| 122 | + |
| 123 | + //cout<<"posRefZ: "<<posRefZ<<" Z: "<<posZ/ZRES_CONV<<endl; |
| 124 | + float tphi = t02-abs(posZ/ZRES_CONV -posRefZ)/vwire; |
| 125 | + //cout<<"tphi: "<<tphi<<endl; |
| 126 | + |
| 127 | + int LR = -1; |
| 128 | + if(wheel==0 && (sector==3 || sector==4 || sector==7 || sector==8 || sector==11 || sector==12)) LR = +1; |
| 129 | + else if (wheel>0) LR = pow(-1,wheel+sector+1); |
| 130 | + else if (wheel<0) LR = pow(-1,-wheel+sector); |
| 131 | + //cout<<"wh st se: "<< wheel <<" "<< station <<" "<< sector <<" LR: "<< LR<<endl; |
| 132 | + float posRefX = LR*xFE[station-1]; |
| 133 | + float ttheta =t0-(mp2.x *1000 -posRefX)/vwire; |
| 134 | + |
| 135 | + deltaTimePosPhiCands.push_back({mp2,abs(tphi-ttheta)}); |
| 136 | + |
| 137 | + |
| 138 | + } //loop in phis |
| 139 | + |
| 140 | + //reorder deltaTimePosPhiCands according to tphi-ttheta distance |
| 141 | + std::sort(deltaTimePosPhiCands.begin(), deltaTimePosPhiCands.end(), compare); |
| 142 | + int count = 0; |
| 143 | + for (const std::pair<metaPrimitive, float>& p : deltaTimePosPhiCands){ //save up to nth nearest Phi candidate |
| 144 | + if(count<th_option) |
| 145 | + outMPs.push_back(p.first); |
| 146 | + else break; |
| 147 | + count++; |
| 148 | + } |
| 149 | + }// loop in thetas |
| 150 | + |
| 151 | + return outMPs; |
| 152 | +} |
| 153 | + |
| 154 | +bool MPThetaMatching::isThereThetaMPInChamber(int sector2,int wheel2,int station2, std::vector<metaPrimitive> thetaMPs){ |
| 155 | + for (auto & mp1: thetaMPs) { |
| 156 | + DTChamberId chId(mp1.rawId); |
| 157 | + DTSuperLayerId slId(mp1.rawId); |
| 158 | + |
| 159 | + int sector = chId.sector(); |
| 160 | + int wheel = chId.wheel(); |
| 161 | + int station = chId.station(); |
| 162 | + if (sector==sector2 && wheel == wheel2 && station==station2) return true; |
| 163 | +} |
| 164 | + return false; |
| 165 | +}; |
| 166 | + |
0 commit comments