Skip to content

Commit 57ac712

Browse files
committed
First version of Theta-Phi matching
1 parent eb45085 commit 57ac712

File tree

2 files changed

+236
-0
lines changed

2 files changed

+236
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifndef Phase2L1Trigger_DTTrigger_MPThetaMatching_h
2+
#define Phase2L1Trigger_DTTrigger_MPThetaMatching_h
3+
4+
#include "L1Trigger/DTTriggerPhase2/interface/MPFilter.h"
5+
6+
#include <iostream>
7+
#include <fstream>
8+
9+
// ===============================================================================
10+
// Previous definitions and declarations
11+
// ===============================================================================
12+
13+
// ===============================================================================
14+
// Class declarations
15+
// ===============================================================================
16+
17+
18+
class MPThetaMatching : public MPFilter {
19+
public:
20+
// Constructors and destructor
21+
MPThetaMatching(const edm::ParameterSet &pset);
22+
~MPThetaMatching() override = default;
23+
24+
// Main methods
25+
void initialise(const edm::EventSetup &iEventSetup) override;
26+
void run(edm::Event &iEvent,
27+
const edm::EventSetup &iEventSetup,
28+
std::vector<cmsdt::metaPrimitive> &inMPaths,
29+
std::vector<cmsdt::metaPrimitive> &outMPaths) override;
30+
void run(edm::Event &iEvent,
31+
const edm::EventSetup &iEventSetup,
32+
MuonPathPtrs &inMPath,
33+
MuonPathPtrs &outMPath) override{};
34+
35+
void finish() override;
36+
37+
// Other public methods
38+
39+
// Public attributes
40+
41+
float vwire = 24.4 ; // cm/ns
42+
// float zFE[5] = {-654., -389., 123., 389., 654.}; //cm
43+
// float xFE[3] = {199/2., 245/2., 303/2.};//cm
44+
float zFE[5] = {-658.9, -393.3, 126.4, 393.3, 658.9}; //cm
45+
float xFE[3] = {218/2., 266.8/2., 315/2.};//cm
46+
float ZRES_CONV = 65536. / 1500;
47+
48+
private:
49+
// Private methods
50+
std::vector<cmsdt::metaPrimitive> filter(std::vector<cmsdt::metaPrimitive> inMPs,
51+
int th_option,
52+
int th_quality,
53+
double shift_back);
54+
55+
bool isThereThetaMPInChamber(int sector,int wheel,int station,std::vector<cmsdt::metaPrimitive> thetaMPs);
56+
// Lambda function to compare pairs based on the float value, ascending order
57+
static bool compare(const std::pair<cmsdt::metaPrimitive, float>& a, const std::pair<cmsdt::metaPrimitive, float>& b) {
58+
return a.second < b.second;
59+
};
60+
61+
// Private attributes
62+
const bool debug_;
63+
int th_option_;
64+
int th_quality_;
65+
int scenario_;
66+
67+
68+
};
69+
70+
#endif
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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

Comments
 (0)