1 |
konec |
1.1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
|
2 |
|
|
|
3 |
|
|
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
|
4 |
|
|
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
|
5 |
|
|
#include "DataFormats/MuonDetId/interface/CSCDetId.h"
|
6 |
|
|
#include "DataFormats/MuonDetId/interface/DTChamberId.h"
|
7 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDetIdUtil.h"
|
8 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/DTphDigiSpec.h"
|
9 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/CSCDigiSpec.h"
|
10 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
|
11 |
|
|
|
12 |
akalinow |
1.7 |
/////////////////////////////////////////////////
|
13 |
|
|
/////////////////////////////////////////////////
|
14 |
|
|
uint32_t Pattern::rotateDetId(uint32_t rawId, int step){
|
15 |
|
|
|
16 |
|
|
///Assume 60deg steps
|
17 |
|
|
while(step<0){step+=6;}
|
18 |
|
|
|
19 |
|
|
uint32_t rawIdRotated = rawId;
|
20 |
|
|
|
21 |
|
|
DetId detId(rawId);
|
22 |
|
|
switch (detId.subdetId()){
|
23 |
|
|
case MuonSubdetId::RPC: {
|
24 |
|
|
RPCDetId rpcDet(rawId);
|
25 |
|
|
///Barrel has 30deg sectors
|
26 |
|
|
if(rpcDet.region()==0) step*=2;
|
27 |
|
|
RPCDetId rpcDetRotated(rpcDet.region(),
|
28 |
|
|
rpcDet.ring(),
|
29 |
|
|
rpcDet.station(),
|
30 |
|
|
(rpcDet.sector()+step-1)%12+1,
|
31 |
|
|
rpcDet.layer(),
|
32 |
|
|
rpcDet.subsector(),
|
33 |
|
|
rpcDet.roll());
|
34 |
|
|
return rpcDetRotated.rawId();
|
35 |
|
|
}
|
36 |
|
|
case MuonSubdetId::DT: {
|
37 |
|
|
///Barrel has 30deg sectors
|
38 |
|
|
step*=2;
|
39 |
|
|
DTChamberId dtDet(rawId);
|
40 |
|
|
DTChamberId dtDetRotated(dtDet.wheel(),
|
41 |
|
|
dtDet.station(),
|
42 |
|
|
(dtDet.sector()+step)%12);
|
43 |
|
|
return dtDetRotated.rawId();
|
44 |
|
|
break;
|
45 |
|
|
}
|
46 |
|
|
case MuonSubdetId::CSC: {
|
47 |
|
|
CSCDetId cscDet(rawId);
|
48 |
|
|
//Most CSC chambers are 10deg wide
|
49 |
|
|
int cscFactor = 6;
|
50 |
|
|
int maxChamber = 36;
|
51 |
|
|
///Some are 20deg wide
|
52 |
|
|
if(cscDet.station()>1 && cscDet.ring()==1){
|
53 |
|
|
cscFactor = 3;
|
54 |
|
|
maxChamber = 18;
|
55 |
|
|
}
|
56 |
|
|
int cscStep = step*cscFactor;
|
57 |
|
|
CSCDetId cscDetRotated(cscDet.endcap(),
|
58 |
|
|
cscDet.station(),
|
59 |
|
|
cscDet.ring(),
|
60 |
|
|
(cscDet.chamber()+cscStep-1)%maxChamber+1,
|
61 |
|
|
cscDet.layer());
|
62 |
|
|
return cscDetRotated.rawId();
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
return rawIdRotated;
|
66 |
|
|
}
|
67 |
|
|
/////////////////////////////////////////////////
|
68 |
|
|
/////////////////////////////////////////////////
|
69 |
|
|
Pattern Pattern::getRotated(int step) const{
|
70 |
|
|
|
71 |
|
|
Pattern rotated;
|
72 |
|
|
|
73 |
|
|
for (auto it = theData.cbegin(); it != theData.cend(); ++it){
|
74 |
|
|
rotated.add(std::pair<uint32_t, unsigned int >(rotateDetId(it->first,step),it->second));
|
75 |
|
|
}
|
76 |
|
|
return rotated;
|
77 |
|
|
}
|
78 |
|
|
/////////////////////////////////////////////////
|
79 |
|
|
/////////////////////////////////////////////////
|
80 |
akalinow |
1.6 |
bool Pattern::operator==(const Pattern& o) const{
|
81 |
|
|
unsigned int thissize = theData.size();
|
82 |
|
|
if (thissize != o.size()) return false;
|
83 |
|
|
|
84 |
|
|
for (auto it = theData.cbegin(); it != theData.cend(); ++it){
|
85 |
|
|
auto itComp = o.theData.find(it->first);
|
86 |
|
|
if(itComp==o.theData.cend()) return false;
|
87 |
|
|
if(itComp->second!=it->second) return false;
|
88 |
|
|
}
|
89 |
akalinow |
1.5 |
|
90 |
konec |
1.4 |
return true;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
akalinow |
1.6 |
Pattern Pattern::addOrCopy( std::pair<uint32_t, unsigned int > aData){
|
94 |
akalinow |
1.5 |
|
95 |
akalinow |
1.6 |
auto it = theData.find(aData.first);
|
96 |
|
|
if(it!= theData.cend()){
|
97 |
|
|
Pattern modified = *this;
|
98 |
|
|
modified.theData[aData.first] = aData.second;
|
99 |
|
|
return modified;
|
100 |
konec |
1.1 |
}
|
101 |
akalinow |
1.6 |
theData[aData.first] = aData.second;
|
102 |
konec |
1.3 |
return Pattern();
|
103 |
konec |
1.1 |
}
|
104 |
|
|
|
105 |
akalinow |
1.7 |
void Pattern::add (std::vector<Pattern> & vpat, std::pair<uint32_t, unsigned int > aData)
|
106 |
konec |
1.2 |
{
|
107 |
akalinow |
1.6 |
//Use indexing to avoid problem with iterator invalidation afer adding new elements to vector
|
108 |
|
|
uint32_t vSize = vpat.size();
|
109 |
|
|
for(uint32_t index = 0;index<vSize;++index){
|
110 |
|
|
Pattern modified = vpat[index].addOrCopy(aData);
|
111 |
|
|
if (modified && (find(vpat.begin(), vpat.end(), modified) == vpat.end()) ) vpat.push_back(modified);
|
112 |
|
|
}
|
113 |
konec |
1.2 |
}
|
114 |
|
|
|
115 |
|
|
|
116 |
konec |
1.1 |
std::ostream & operator << (std::ostream &out, const Pattern &o)
|
117 |
|
|
{
|
118 |
|
|
out <<" Pattern: size: "<<o.size();
|
119 |
akalinow |
1.6 |
for (auto it = o.theData.cbegin(); it != o.theData.cend(); ++it){
|
120 |
konec |
1.1 |
DetId detId( it->first);
|
121 |
|
|
switch (detId.subdetId()) {
|
122 |
akalinow |
1.7 |
case MuonSubdetId::RPC: { out << std::endl <<RPCDetId(it->first)<<" "<<RPCDigiSpec(it->first, it->second); break; }
|
123 |
|
|
case MuonSubdetId::DT: { out << std::endl <<DTChamberId(it->first)<<" "<<DTphDigiSpec(it->first, it->second); break; }
|
124 |
|
|
case MuonSubdetId::CSC: { out << std::endl <<CSCDetId(it->first)<<" "<<CSCDigiSpec(it->first, it->second); break; }
|
125 |
konec |
1.1 |
};
|
126 |
|
|
}
|
127 |
|
|
return out;
|
128 |
|
|
}
|
129 |
|
|
|