74 |
|
unsigned int detref = hitSpec->rawId(); |
75 |
|
|
76 |
|
GoldenPattern::Key key( detref, ptref, chargeref, phiref); |
77 |
– |
//if(detref!=637602109 || chargeref<0 || phiref!=80) return; |
78 |
– |
//std::cout<<key<<std::endl; |
77 |
|
|
78 |
|
Pattern pattern; |
79 |
|
theEvForPatCounter++; |
80 |
|
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) { |
81 |
+ |
DetId detId( is->first); |
82 |
|
bool isOK = pattern.add(*is); |
83 |
|
if (!isOK) return; |
84 |
|
} |
85 |
|
if (pattern.size() == 0) return; |
86 |
|
theEvUsePatCounter++; |
87 |
|
|
88 |
+ |
|
89 |
|
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key); |
90 |
|
theGPs[key].add(pattern); |
91 |
– |
|
91 |
|
} |
92 |
|
|
93 |
|
L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi) |
94 |
|
{ |
95 |
|
L1Obj candidate; |
97 |
– |
|
96 |
|
if (theConfig.exists("patternInpFile") && |
97 |
|
theConfig.exists("patternOutFile")) return candidate; |
98 |
|
|
99 |
|
if (!hitSpec) return candidate; |
100 |
|
if (hitSpec->rawId() == 0 ) return candidate; |
101 |
< |
float phiref = hitSpec->position().phi(); |
101 |
> |
//float phiref = hitSpec->position().phi(); |
102 |
|
float ptref = simu->pt(); |
103 |
|
int chargeref = simu->charge(); |
104 |
|
unsigned int detref = hitSpec->rawId(); |
107 |
– |
/* |
108 |
– |
if (detref != 637602109 && detref != 637634877 && |
109 |
– |
detref != 637599914 && detref != 637632682 ) return candidate; |
110 |
– |
|
111 |
– |
bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001); |
112 |
– |
if (!precisePos) return candidate; |
113 |
– |
if ( simu->pt() < 26. || simu->pt() > 27. ) return candidate; |
105 |
|
|
106 |
< |
*/ |
107 |
< |
// std::cout <<" ------------------ EVENT: "<<*ev <<" number of digis: "<<vDigi.size()<< std::endl; |
106 |
> |
VDigiSpec::const_iterator is=vDigi.end(); |
107 |
> |
for (is = vDigi.begin(); is!=vDigi.end(); ++is) { |
108 |
> |
if(is->first==hitSpec->rawId()) break; |
109 |
> |
} |
110 |
> |
if(is==vDigi.end()){return candidate;} //Require a digi in reference station. Creates inefficiency! |
111 |
> |
RPCDigiSpec digiRef(is->first, is->second); |
112 |
> |
int stripRef = digiRef.halfStrip(); |
113 |
> |
|
114 |
|
std::vector<Pattern> vpattern(1); |
115 |
|
theEvForPatCounter++; |
116 |
|
static bool skipRpcData = theConfig.getUntrackedParameter<bool>("skipRpcData", false); |
119 |
|
DetId detId( is->first); |
120 |
|
if (skipRpcData && detId.subdetId()==MuonSubdetId::RPC) continue; |
121 |
|
if (skipDtCscData && (detId.subdetId()==MuonSubdetId::DT || detId.subdetId()==MuonSubdetId::CSC) ) continue; |
122 |
< |
if(detId.subdetId()==MuonSubdetId::DT && DTphDigiSpec(is->first, is->second).bxNum()!=0) continue; //AK. Correct? |
126 |
< |
// std::cout << "adding------- "<< is-vDigi.begin()+1 <<" digi det: "<<is->first<<"(rpc:"<<(detId.subdetId()==MuonSubdetId::RPC)<<") data: "<<is->second<< std::endl; |
122 |
> |
if(detId.subdetId()==MuonSubdetId::DT && DTphDigiSpec(is->first, is->second).bxNum()!=0) continue; |
123 |
|
Pattern::add(vpattern,*is); |
128 |
– |
// std::cout <<" after vpattern has size: "<<vpattern.size() << std::endl; |
124 |
|
if (vpattern.size() > 100) break; |
125 |
|
} |
126 |
|
if (vpattern[0].size() == 0) return candidate; |
132 |
– |
//std::cout <<" ------------------ END EVENT, NOW COMPARE, has #patterns: "<<vpattern.size()<<" vpattern[0].size="<<vpattern[0].size() << std::endl; |
127 |
|
|
128 |
< |
GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref ); |
128 |
> |
GoldenPattern::Key thisKey(detref, ptref, chargeref,stripRef); |
129 |
|
//std::cout << thisKey << std::endl; |
130 |
< |
|
130 |
> |
/* |
131 |
> |
RPCDetId aId(637599786); |
132 |
> |
std::cout<<aId<<std::endl; |
133 |
> |
RPCDetId bId(637599914); |
134 |
> |
std::cout<<bId<<std::endl; |
135 |
> |
*/ |
136 |
|
GoldenPattern::Result bestMatching; |
137 |
|
GoldenPattern::Key bestKey; |
138 |
|
for (auto ip=vpattern.cbegin(); ip!= vpattern.cend();++ip) { |
139 |
< |
const Pattern & pattern = *ip; |
140 |
< |
// std::cout << " HAS PATTERN "<<pattern << std::endl; |
139 |
> |
Pattern pattern; |
140 |
> |
int phiRotation = -1; |
141 |
> |
///Find rotation degree to match the base set of patterns. This still can be optimised. |
142 |
|
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) { |
143 |
< |
//if (!(thisKey==igps->first)) continue; |
144 |
< |
GoldenPattern & gp = igps->second; |
145 |
< |
GoldenPattern::Result result = gp.compare(pattern); |
143 |
> |
///Rotate the hit pattern to math the golden pattern |
144 |
> |
for(int iStep=0;iStep<5;++iStep){ |
145 |
> |
uint32_t rawIdRotated = Pattern::rotateDetId(digiRef.rawId(),iStep); |
146 |
> |
if(rawIdRotated==igps->first.theDet && igps->first.thePhiCode==digiRef.halfStrip()){ |
147 |
> |
pattern = ip->getRotated(iStep); |
148 |
> |
phiRotation = iStep; |
149 |
> |
break; |
150 |
> |
} |
151 |
> |
} |
152 |
> |
GoldenPattern::Key thisRotatedKey(Pattern::rotateDetId(digiRef.rawId(),phiRotation), ptref, chargeref,stripRef); |
153 |
> |
if(!pattern.size()) continue; |
154 |
> |
//if(pattern.size()<7) return candidate; |
155 |
> |
//if(!(thisRotatedKey==igps->first)) continue; |
156 |
|
|
157 |
+ |
GoldenPattern & gp = igps->second; |
158 |
+ |
GoldenPattern::Result result = gp.compare(pattern); |
159 |
+ |
/* |
160 |
+ |
std::cout<<"Step: "<<phiRotation<<std::endl; |
161 |
+ |
std::cout<<*ip<<std::endl; |
162 |
+ |
std::cout<<pattern<<std::endl; |
163 |
+ |
std::cout<<gp<<std::endl; |
164 |
|
std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<std::endl; |
165 |
+ |
*/ |
166 |
|
if (bestMatching < result) { |
167 |
|
bestMatching = result; |
168 |
|
bestKey = igps->first; |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
< |
// std::cout <<" ------------------ END COMPARE: " << std::endl; |
176 |
< |
// std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::cout <<" ######"<<" pt: "<< bestKey.ptValue()<<std::endl; |
177 |
< |
// abort(); |
175 |
> |
//std::cout <<" ------------------ END COMPARE: " << std::endl; |
176 |
> |
//std::cout <<"THIS KEY: "<<thisKey << std::endl; |
177 |
> |
//std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::endl; |
178 |
> |
//abort(); |
179 |
|
if (bestMatching) { |
180 |
|
candidate.pt = bestKey.ptValue(); |
181 |
|
candidate.eta = bestKey.etaValue(); |
182 |
|
candidate.phi = bestKey.phiValue(); |
183 |
+ |
candidate.charge = bestKey.chargeValue(); |
184 |
|
candidate.q = bestMatching.nMatchedTot(); |
185 |
|
candidate.type = L1Obj::OTF; |
186 |
|
} |
206 |
|
key.thePhiCode = entry.key_phi; |
207 |
|
key.theCharge = entry.key_ch; |
208 |
|
|
189 |
– |
/* |
190 |
– |
if(entry.key_det!=637602109 || |
191 |
– |
entry.key_pt!=7 || |
192 |
– |
entry.key_phi!=166 || |
193 |
– |
entry.key_ch!=-1) continue; |
194 |
– |
*/ |
195 |
– |
|
209 |
|
GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case); |
210 |
|
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key); |
211 |
|
theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq); |