Skip to content

Commit 6e5643a

Browse files
committed
Add ME0 Trigger Object (Stub) and Producer
1 parent 365705a commit 6e5643a

22 files changed

+1597
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef DataFormats_ME0Stub_H
2+
#define DataFormats_ME0Stub_H
3+
4+
#include <vector>
5+
#include <cstdint>
6+
#include <string>
7+
#include <iostream>
8+
#include <iomanip>
9+
10+
#include "DataFormats/MuonDetId/interface/GEMDetId.h"
11+
#include "DataFormats/GEMDigi/interface/ME0StubPrimitive.h"
12+
13+
class ME0Stub final {
14+
public:
15+
ME0Stub() : detId(), etaPartition(0), padStrip(0), bending_angle(0),
16+
layercount(0), quality(0), patternId(0), bx(0) {}
17+
ME0Stub(const GEMDetId& id,
18+
const ME0StubPrimitive& stub)
19+
: detId(id), etaPartition(stub.EtaPartition()), padStrip(stub.Strip()+stub.SubStrip()),
20+
bending_angle(stub.BendingAngle()), layercount(stub.LayerCount()),
21+
quality(stub.Quality()), patternId(stub.PatternId()), bx(stub.BX()) {}
22+
ME0Stub(const GEMDetId& id,
23+
int etaPartition_,
24+
double padStrip_,
25+
double bending_angle_,
26+
int layercount_,
27+
int quality_,
28+
int patternId_,
29+
double bx_)
30+
: detId(id), etaPartition(etaPartition_), padStrip(padStrip_), bending_angle(bending_angle_),
31+
layercount(layercount_), quality(quality_), patternId(patternId_), bx(bx_) {}
32+
33+
// clone
34+
ME0Stub* clone() const { return new ME0Stub(*this); }
35+
36+
// Get private variable
37+
GEMDetId DetId() const {return detId;}
38+
int EtaPartition() const {return etaPartition;}
39+
double Strip() const {return padStrip;}
40+
double BendingAngle() const {return bending_angle;}
41+
int LayerCount() const {return layercount;}
42+
int Quality() const {return quality;}
43+
int PatternId() const {return patternId;}
44+
double BX() const {return bx;}
45+
46+
// operators
47+
bool operator==(const ME0Stub& other) {
48+
if (layercount == 0 && other.layercount == 0) {return true;}
49+
return (quality == other.quality);
50+
}
51+
bool operator>(const ME0Stub& other) {return (quality > other.quality);}
52+
bool operator<(const ME0Stub& other) {return (quality < other.quality);}
53+
bool operator>=(const ME0Stub& other) {return (quality >= other.quality);}
54+
bool operator<=(const ME0Stub& other) {return (quality <= other.quality);}
55+
// ostream
56+
friend std::ostream& operator<<(std::ostream& os, const ME0Stub& stub) {
57+
os << "id=" << stub.PatternId() << ", lc=" << stub.LayerCount()
58+
<< ", strip=" << std::fixed << std::setprecision(3) << stub.Strip() << ", prt=" << stub.EtaPartition()
59+
<< ", quality=" << stub.Quality();
60+
return os;
61+
}
62+
private:
63+
GEMDetId detId;
64+
int etaPartition;
65+
double padStrip;
66+
double bending_angle;
67+
int layercount;
68+
int quality;
69+
int patternId;
70+
double bx;
71+
};
72+
73+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef DataFormats_ME0StubCollection_H
2+
#define DataFormats_ME0StubCollection_H
3+
4+
/** \class ME0StubCollection
5+
*
6+
* The collection of ME0Stub's. See \ref CSCSegmentCollection.h for details from which is derived.
7+
*
8+
* \author Woohyeon Heo
9+
*/
10+
11+
#include "DataFormats/MuonDetId/interface/GEMDetId.h"
12+
#include "DataFormats/GEMDigi/interface/ME0Stub.h"
13+
14+
#include "DataFormats/Common/interface/RangeMap.h"
15+
#include "DataFormats/Common/interface/ClonePolicy.h"
16+
#include "DataFormats/Common/interface/OwnVector.h"
17+
18+
typedef edm::RangeMap<GEMDetId, edm::OwnVector<ME0Stub> > ME0StubCollection;
19+
20+
#include "DataFormats/Common/interface/Ref.h"
21+
typedef edm::Ref<ME0StubCollection> ME0StubRef;
22+
23+
#endif
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#ifndef DataFormats_ME0StubPrimitive_H
2+
#define DataFormats_ME0StubPrimitive_H
3+
4+
#include <vector>
5+
#include <cstdint>
6+
#include <string>
7+
#include <iostream>
8+
9+
#include "DataFormats/MuonDetId/interface/GEMDetId.h"
10+
11+
class ME0StubPrimitive final {
12+
public:
13+
// Constructors
14+
ME0StubPrimitive();
15+
ME0StubPrimitive(int lc_,
16+
int hc_,
17+
int id_,
18+
int strip_,
19+
int partition_);
20+
ME0StubPrimitive(int lc_,
21+
int hc_,
22+
int id_,
23+
int strip_,
24+
int partition_,
25+
double bx_);
26+
ME0StubPrimitive(int lc_,
27+
int hc_,
28+
int id_,
29+
int strip_,
30+
int partition_,
31+
double bx_,
32+
std::vector<double>& centroid_);
33+
34+
// clone
35+
ME0StubPrimitive* clone() const { return new ME0StubPrimitive(*this); }
36+
37+
// Get private variable
38+
int LayerCount() const {return lc;}
39+
int HitCount() const {return hc;}
40+
int PatternId() const {return id;}
41+
int Strip() const {return strip;}
42+
int EtaPartition() const {return partition;}
43+
int BX() const {return bx;}
44+
double SubStrip() const {return substrip;}
45+
double BendingAngle() const {return bend_ang;}
46+
double MSE() const {return mse;}
47+
std::vector<double> Centroids() const {return centroid;}
48+
int Quality() const {return quality;}
49+
int MaxClusterSize() const {return max_cluster_size;}
50+
int MaxNoise() const {return max_noise;}
51+
52+
// Set private variable
53+
void SetLayerCount(int lc_) {lc=lc_;}
54+
void SetHitCount(int hc_) {hc=hc_;}
55+
void SetPatternId(int id_) {id=id_;}
56+
void SetStrip(int strip_) {strip=strip_;}
57+
void SetEtaPartition(int partition_) {partition=partition_;}
58+
void SetBX(double bx_) {bx=bx_;}
59+
void SetCentroids(std::vector<double> centroid_) {centroid=centroid_;}
60+
void SetMaxClusterSize(int max_cluster_size_) {max_cluster_size=max_cluster_size_;}
61+
void SetMaxNoise(int max_noise_) {max_noise=max_noise_;}
62+
63+
void reset();
64+
void update_quality();
65+
void fit(int max_span=37);
66+
67+
// operators
68+
bool operator==(const ME0StubPrimitive& other) {
69+
if (lc == 0 && other.lc == 0) {return true;}
70+
return (quality == other.quality);
71+
}
72+
bool operator>(const ME0StubPrimitive& other) {return (quality > other.quality);}
73+
bool operator<(const ME0StubPrimitive& other) {return (quality < other.quality);}
74+
bool operator>=(const ME0StubPrimitive& other) {return (quality >= other.quality);}
75+
bool operator<=(const ME0StubPrimitive& other) {return (quality <= other.quality);}
76+
// ostream
77+
friend std::ostream& operator<<(std::ostream& os, const ME0StubPrimitive& stub) {
78+
os << "id=" << stub.PatternId() << ", lc=" << stub.LayerCount()
79+
<< ", strip=" << stub.Strip() << ", prt=" << stub.EtaPartition()
80+
<< ", quality=" << stub.Quality();
81+
return os;
82+
}
83+
private:
84+
int lc, hc, id, strip, partition;
85+
double bx = -9999;
86+
std::vector<double> centroid;
87+
double substrip = 0.0;
88+
double bend_ang = 0.0;
89+
double mse = 9999;
90+
int quality = 0;
91+
int max_cluster_size=0;
92+
int max_noise=0;
93+
bool ignore_bend = false;
94+
std::vector<double> llse_fit(const std::vector<double>& x, const std::vector<double>& y);
95+
};
96+
97+
#endif
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "DataFormats/GEMDigi/interface/ME0StubPrimitive.h"
2+
3+
//define class ME0StubPrimitive
4+
ME0StubPrimitive::ME0StubPrimitive() : lc{0}, hc{0}, id{0}, strip{0}, partition{0} {
5+
update_quality();
6+
}
7+
ME0StubPrimitive::ME0StubPrimitive(int lc_,
8+
int hc_,
9+
int id_,
10+
int strip_,
11+
int partition_) :
12+
lc{lc_}, hc{hc_}, id{id_}, strip{strip_}, partition{partition_} {
13+
update_quality();
14+
}
15+
ME0StubPrimitive::ME0StubPrimitive(int lc_,
16+
int hc_,
17+
int id_,
18+
int strip_,
19+
int partition_,
20+
double bx_) :
21+
lc{lc_}, hc{hc_}, id{id_}, strip{strip_}, partition{partition_}, bx{bx_} {
22+
update_quality();
23+
}
24+
ME0StubPrimitive::ME0StubPrimitive(int lc_,
25+
int hc_,
26+
int id_,
27+
int strip_,
28+
int partition_,
29+
double bx_,
30+
std::vector<double>& centroid_) :
31+
lc{lc_}, hc{hc_}, id{id_}, strip{strip_}, partition{partition_}, bx{bx_}, centroid{centroid_} {
32+
update_quality();
33+
}
34+
void ME0StubPrimitive::reset() {
35+
lc = 0; hc = 0; id = 0;
36+
update_quality();
37+
}
38+
void ME0StubPrimitive::update_quality() {
39+
int idmask;
40+
if (lc) {
41+
if (ignore_bend) {idmask = 0xfe;}
42+
else {idmask = 0xff;}
43+
quality = (lc << 23) | (hc << 17) | ((id & idmask) << 12) | (strip << 4) | partition;
44+
} else {quality = 0;}
45+
}
46+
void ME0StubPrimitive::fit(int max_span) {
47+
if (id!=0) {
48+
std::vector<double> tmp;
49+
for (double cent : centroid) {
50+
tmp.push_back(cent-(max_span/2+1));
51+
}
52+
std::vector<double> x;
53+
std::vector<double> centroids;
54+
for (uint32_t i=0; i < tmp.size(); ++i) {
55+
if (tmp[i] != -1*(max_span/2+1)) {
56+
x.push_back(i-2.5);
57+
centroids.push_back(tmp[i]);
58+
}
59+
}
60+
std::vector<double> fit = llse_fit(x, centroids);
61+
bend_ang = fit[0];
62+
substrip = fit[1];
63+
mse = fit[2];
64+
}
65+
}
66+
std::vector<double> ME0StubPrimitive::llse_fit(const std::vector<double>& x, const std::vector<double>& y) {
67+
double x_sum = 0;
68+
double y_sum = 0;
69+
for (double val : x) {x_sum += val;}
70+
for (double val : y) {y_sum += val;}
71+
int n = x.size();
72+
// linear regression
73+
double product = 0;
74+
double squares = 0;
75+
for (int i=0; i<n; ++i) {
76+
product += (n*x[i] - x_sum)*(n*y[i] - y_sum);
77+
squares += (n*x[i] - x_sum)*(n*x[i] - x_sum);
78+
}
79+
80+
double m = product/squares;
81+
double b = (y_sum - m*x_sum)/n;
82+
double sse = 0.0;
83+
for (int i=0; i<n; ++i) {
84+
sse += (y[i] - m*x[i] - b)*(y[i] - m*x[i] - b);
85+
}
86+
87+
std::vector<double> fit = {m, b, sse/n};
88+
return fit;
89+
}

DataFormats/GEMDigi/src/classes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
#include "DataFormats/GEMDigi/interface/ME0TriggerDigi.h"
3838
#include "DataFormats/GEMDigi/interface/ME0TriggerDigiCollection.h"
3939

40+
#include "DataFormats/GEMDigi/interface/ME0Stub.h"
41+
#include "DataFormats/GEMDigi/interface/ME0StubCollection.h"
42+
4043
#include "DataFormats/Common/interface/Wrapper.h"
4144
#include <vector>

DataFormats/GEMDigi/src/classes_def.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,21 @@
137137
<class name="MuonDigiCollection<ME0DetId,ME0TriggerDigi>"/>
138138
<class name="edm::Wrapper<MuonDigiCollection<ME0DetId,ME0TriggerDigi> >" splitLevel="0"/>
139139

140+
<class name="ME0Stub" ClassVersion="0">
141+
<version ClassVersion="0" checksum="896321440"/>
142+
</class>
143+
<class name="std::vector<ME0Stub*>" splitLevel="0"/>
144+
<class name="edm::OwnVector<ME0Stub,edm::ClonePolicy<ME0Stub> >" splitLevel="0" rntupleSplit="false" />
145+
<class name="edm::RangeMap<GEMDetId,edm::OwnVector<ME0Stub,edm::ClonePolicy<ME0Stub> >,edm::ClonePolicy<ME0Stub> >" splitLevel="0"/>
146+
<class name="edm::Wrapper<edm::RangeMap<GEMDetId,edm::OwnVector<ME0Stub,edm::ClonePolicy<ME0Stub> >,edm::ClonePolicy<ME0Stub> > >" splitLevel="0"/>
147+
<class name="ME0StubRef" splitLevel="0"/>
148+
140149
<class name="std::map<GEMDetId,std::vector<ME0TriggerDigi> >"/>
141150
<class name="std::pair<GEMDetId,std::vector<ME0TriggerDigi> >"/>
142151
<class name="MuonDigiCollection<GEMDetId,ME0TriggerDigi>"/>
143152
<class name="edm::Wrapper<MuonDigiCollection<GEMDetId,ME0TriggerDigi> >" splitLevel="0"/>
153+
<class name="edm::OwnVector<ME0Stub, edm::ClonePolicy<ME0Stub> >">
154+
<method name="sort" splitLevel="0"/>
155+
</class>
144156

145157
</lcgdict>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef L1Trigger_L1TGEM_ME0StubAlgoChamber_H
2+
#define L1Trigger_L1TGEM_ME0StubAlgoChamber_H
3+
4+
#include "L1Trigger/L1TGEM/interface/ME0StubAlgoSubfunction.h"
5+
#include "L1Trigger/L1TGEM/interface/ME0StubAlgoPartition.h"
6+
#include "L1Trigger/L1TGEM/interface/ME0StubAlgoMask.h"
7+
#include <vector>
8+
#include <cstdint>
9+
#include <algorithm>
10+
11+
namespace l1t {
12+
namespace me0 {
13+
// map<int, vector<vector<uint64_t>>> cross_partition_cancellation(vector<vector<uint64_t>> segments);
14+
std::vector<std::vector<ME0StubPrimitive>> cross_partition_cancellation(std::vector<std::vector<ME0StubPrimitive>>& segments, int cross_part_seg_width);
15+
std::vector<ME0StubPrimitive> process_chamber(const std::vector<std::vector<UInt192>>& chamber_data,
16+
const std::vector<std::vector<std::vector<int>>>& chamber_bx_data,
17+
Config& config);
18+
}
19+
}
20+
21+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef L1Trigger_L1TGEM_ME0StubAlgoMask_H
2+
#define L1Trigger_L1TGEM_ME0StubAlgoMask_H
3+
4+
#include "L1Trigger/L1TGEM/interface/ME0StubAlgoSubfunction.h"
5+
6+
namespace l1t {
7+
namespace me0 {
8+
std::vector<int> shift_center(const hi_lo_t& ly, int max_span);
9+
uint64_t set_high_bits(const std::vector<int>& lo_hi_pair);
10+
Mask get_ly_mask(const patdef_t& ly_pat, int max_span);
11+
12+
const patdef_t pat_straight = patdef_t(17, create_pat_ly(-0.4, 0.4));
13+
const patdef_t pat_l = patdef_t(16, create_pat_ly(0.2, 0.9));
14+
const patdef_t pat_r = mirror_patdef(pat_l, pat_l.id - 1);
15+
const patdef_t pat_l2 = patdef_t(14, create_pat_ly(0.9, 1.7));
16+
const patdef_t pat_r2 = mirror_patdef(pat_l2, pat_l2.id - 1);
17+
const patdef_t pat_l3 = patdef_t(12, create_pat_ly(1.4, 2.3));
18+
const patdef_t pat_r3 = mirror_patdef(pat_l3, pat_l3.id - 1);
19+
const patdef_t pat_l4 = patdef_t(10, create_pat_ly(2.0, 3.0));
20+
const patdef_t pat_r4 = mirror_patdef(pat_l4, pat_l4.id - 1);
21+
const patdef_t pat_l5 = patdef_t(8, create_pat_ly(2.7, 3.8));
22+
const patdef_t pat_r5 = mirror_patdef(pat_l5, pat_l5.id - 1);
23+
const patdef_t pat_l6 = patdef_t(6, create_pat_ly(3.5, 4.7));
24+
const patdef_t pat_r6 = mirror_patdef(pat_l6, pat_l6.id - 1);
25+
const patdef_t pat_l7 = patdef_t(4, create_pat_ly(4.3, 5.5));
26+
const patdef_t pat_r7 = mirror_patdef(pat_l7, pat_l7.id-1);
27+
const patdef_t pat_l8 = patdef_t(2, create_pat_ly(5.4, 7.0));
28+
const patdef_t pat_r8 = mirror_patdef(pat_l8, pat_l8.id-1);
29+
30+
const std::vector<Mask> LAYER_MASK
31+
{get_ly_mask(pat_straight,37),
32+
get_ly_mask(pat_l,37),
33+
get_ly_mask(pat_r,37),
34+
get_ly_mask(pat_l2,37),
35+
get_ly_mask(pat_r2,37),
36+
get_ly_mask(pat_l3,37),
37+
get_ly_mask(pat_r3,37),
38+
get_ly_mask(pat_l4,37),
39+
get_ly_mask(pat_r4,37),
40+
get_ly_mask(pat_l5,37),
41+
get_ly_mask(pat_r5,37),
42+
get_ly_mask(pat_l6,37),
43+
get_ly_mask(pat_r6,37),
44+
get_ly_mask(pat_l7,37),
45+
get_ly_mask(pat_r7,37),
46+
get_ly_mask(pat_l8,37),
47+
get_ly_mask(pat_r8,37)};
48+
}
49+
}
50+
#endif

0 commit comments

Comments
 (0)