14 |
|
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h" |
15 |
|
|
16 |
|
void GoldenPattern::Result::runNoCheck() const { |
17 |
< |
double fract = 1; |
17 |
> |
float fract = 1; |
18 |
|
|
19 |
|
for(auto mType=myResults.cbegin();mType!=myResults.cend();++mType){ |
20 |
|
for (auto it=mType->second.cbegin(); it!=mType->second.cend();++it) fract *= norm(mType->first,it->second); |
25 |
|
theValue*=(myResults[GoldenPattern::POSRPC].size()==nMatchedPoints[GoldenPattern::POSRPC]); |
26 |
|
theValue*=(myResults[GoldenPattern::POSDT].size()==nMatchedPoints[GoldenPattern::POSDT]); |
27 |
|
theValue*=(myResults[GoldenPattern::POSCSC].size()==nMatchedPoints[GoldenPattern::POSCSC]); |
28 |
< |
theValue = ( nTot > 4) ? pow(fract, 1./((double) nTot)) : 0.; |
28 |
> |
theValue = ( nTot > 4) ? pow(fract, 1./((float) nTot)) : 0.; |
29 |
|
} |
30 |
|
|
31 |
< |
double GoldenPattern::Result::norm(GoldenPattern::PosBenCase where, double whereInDist) const { |
32 |
< |
double normValue = 2.*(0.5-fabs(whereInDist-0.5)); |
33 |
< |
static const double epsilon = 1.e-9; |
31 |
> |
float GoldenPattern::Result::norm(GoldenPattern::PosBenCase where, float whereInDist) const { |
32 |
> |
float normValue = 2.*(0.5-fabs(whereInDist-0.5)); |
33 |
> |
//normValue = whereInDist; //AK |
34 |
> |
static const float epsilon = 1.e-9; |
35 |
|
if (normValue > epsilon) ++nMatchedPoints[where]; |
36 |
< |
else normValue =1.; |
36 |
> |
else normValue = 0.05; |
37 |
|
return normValue; |
38 |
|
} |
39 |
|
|
55 |
|
return (value() > 0.1); // && hasStation1 && hasStation2); |
56 |
|
} |
57 |
|
|
58 |
< |
double GoldenPattern::Result::value() const { |
58 |
> |
float GoldenPattern::Result::value() const { |
59 |
|
run(); |
60 |
|
return theValue; |
61 |
|
} |
71 |
|
std::ostream & operator << (std::ostream &out, const GoldenPattern::Result& o) |
72 |
|
{ |
73 |
|
o.run(); |
74 |
< |
|
74 |
< |
/* |
74 |
> |
|
75 |
|
out <<"Result: " |
76 |
|
<< " value: "<<o.theValue |
77 |
|
<<" nPos+Ben: ("; |
78 |
< |
for(auto mType=o.myResults.cbegin(); |
79 |
< |
mType!=myResults.cend();++mType){ |
80 |
< |
out<<o.nMatchedPoints[iType]<<"/"<<o.myResults[mType].size()<<", "; |
78 |
> |
for(auto cit=o.myResults.cbegin();cit!=o.myResults.cend();++cit){ |
79 |
> |
out<<o.nMatchedPoints[cit->first]<<"/"<<cit->second.size()<<", "; |
80 |
|
} |
81 |
|
out <<", tot:"<<o.nMatchedTot()<<")"; |
82 |
< |
*/ |
84 |
< |
/* |
85 |
< |
<<o.nMatchedPosCsc<<"/"<<o.posCscResult.size()<<"+"<<o.nMatchedBenCsc<<"/"<<o.benCscResult.size() |
86 |
< |
<<", "<<o.nMatchedPosDt <<"/"<<o.posDtResult.size()<<"+"<<o.nMatchedBenDt<<"/"<<o.benDtResult.size() |
87 |
< |
<<", "<<o.nMatchedPosRpc<<"/"<<o.posRpcResult.size() |
88 |
< |
*/ |
82 |
> |
|
83 |
|
return out; |
84 |
|
} |
85 |
|
|
143 |
|
uint32_t rawId = is->first; |
144 |
|
DetId detId(rawId); |
145 |
|
if (detId.det() != DetId::Muon){ |
146 |
< |
std::cout << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl; |
146 |
> |
std::cout << "GoldenPattern::compare PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl; |
147 |
|
return result; |
148 |
|
} |
149 |
|
if (detId.subdetId() == MuonSubdetId::RPC) { |
150 |
|
RPCDigiSpec digi(rawId, is->second); |
151 |
|
mType = GoldenPattern::POSRPC; |
152 |
|
cit = PattCore.find(mType); |
153 |
< |
if(cit==PattCore.cend()){ |
160 |
< |
std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl; |
161 |
< |
return result; |
162 |
< |
} |
153 |
> |
if(cit==PattCore.cend()) return result; //AK: Ugly, FIX. |
154 |
|
idm = cit->second.find(rawId); |
155 |
|
if (idm != cit->second.cend() ) { |
156 |
< |
double f = whereInDistribution(digi.halfStrip(), idm->second); |
156 |
> |
float f = whereInDistribution(digi.halfStrip(), idm->second); |
157 |
|
result.myResults[mType].push_back(std::make_pair(rawId, f)); |
158 |
|
RPCDetId rpc(rawId); |
159 |
|
if(rpc.station()==1) result.hasStation1 = true; |
164 |
|
DTphDigiSpec digi(rawId, is->second); |
165 |
|
mType = GoldenPattern::POSDT; |
166 |
|
cit = PattCore.find(mType); |
167 |
< |
if(cit==PattCore.cend()){ |
177 |
< |
std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl; |
178 |
< |
return result; |
179 |
< |
} |
167 |
> |
if(cit==PattCore.cend()) return result; |
168 |
|
idm = cit->second.find(rawId); |
169 |
|
if (idm != cit->second.cend() ) { |
170 |
< |
double f = whereInDistribution(digi.phi(), idm->second); |
170 |
> |
float f = whereInDistribution(digi.phi(), idm->second); |
171 |
|
result.myResults[mType].push_back(std::make_pair(rawId, f)); |
172 |
|
DTChamberId dt(rawId); |
173 |
|
if(dt.station()==1) result.hasStation1 = true; |
175 |
|
} |
176 |
|
mType = GoldenPattern::BENDT; |
177 |
|
cit = PattCore.find(mType); |
178 |
< |
if(cit==PattCore.cend()){ |
191 |
< |
std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl; |
192 |
< |
return result; |
193 |
< |
} |
178 |
> |
if(cit==PattCore.cend()) return result; |
179 |
|
idm = cit->second.find(rawId); |
180 |
|
if (idm != cit->second.cend() ) { |
181 |
< |
double f = whereInDistribution(digi.phiB(), idm->second); |
181 |
> |
float f = whereInDistribution(digi.phiB(), idm->second); |
182 |
|
result.myResults[mType].push_back(std::make_pair(rawId, f)); |
183 |
|
} |
184 |
|
} |
186 |
|
CSCDigiSpec digi(rawId, is->second); |
187 |
|
mType = GoldenPattern::POSCSC; |
188 |
|
cit = PattCore.find(mType); |
189 |
< |
if(cit==PattCore.cend()){ |
205 |
< |
std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl; |
206 |
< |
return result; |
207 |
< |
} |
189 |
> |
if(cit==PattCore.cend()) return result; |
190 |
|
auto idm = cit->second.find(rawId); |
191 |
|
if (idm != cit->second.cend() ) { |
192 |
< |
double f = whereInDistribution(digi.strip(), idm->second); |
192 |
> |
float f = whereInDistribution(digi.strip(), idm->second); |
193 |
|
result.myResults[mType].push_back(std::make_pair(rawId, f)); |
194 |
|
CSCDetId csc(rawId); |
195 |
|
if (csc.station()==1) result.hasStation1 = true; |
197 |
|
} |
198 |
|
mType = GoldenPattern::BENCSC; |
199 |
|
cit = PattCore.find(mType); |
200 |
< |
if(cit==PattCore.cend()){ |
219 |
< |
std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl; |
220 |
< |
return result; |
221 |
< |
} |
200 |
> |
if(cit==PattCore.cend()) return result; |
201 |
|
idm = cit->second.find(rawId); |
202 |
|
if (idm != cit->second.cend() ) { |
203 |
< |
double f = whereInDistribution(digi.pattern(), idm->second); |
203 |
> |
float f = whereInDistribution(digi.pattern(), idm->second); |
204 |
|
result.myResults[mType].push_back(std::make_pair(rawId, f)); |
205 |
|
} |
206 |
|
} |
209 |
|
return result; |
210 |
|
} |
211 |
|
|
212 |
< |
double GoldenPattern::whereInDistribution( int obj, const GoldenPattern::MFreq & m) const |
212 |
> |
float GoldenPattern::whereInDistribution( int obj, const GoldenPattern::MFreq & m) const |
213 |
|
{ |
214 |
|
|
215 |
< |
double sum_before = 0; |
216 |
< |
double sum_after = 0; |
217 |
< |
double sum_obj = 0; |
215 |
> |
float sum_before = 0; |
216 |
> |
float sum_after = 0; |
217 |
> |
float sum_obj = 0; |
218 |
|
for (MFreq::const_iterator im = m.begin(); im != m.end(); ++im) { |
219 |
|
if (im->first < obj) sum_before+= im->second; |
220 |
|
if (im->first == obj) sum_obj = im->second; |
221 |
|
if (im->first > obj) sum_after += im->second; |
222 |
|
} |
223 |
< |
double sum = std::max(1.,sum_before+sum_after+sum_obj ); |
223 |
> |
float sum = std::max((float)1.,sum_before+sum_after+sum_obj ); |
224 |
|
//return sum_obj/sum; //AK |
225 |
|
return (sum_before+sum_obj/2.)/sum; |
226 |
|
} |
227 |
|
|
228 |
< |
void GoldenPattern::purge(){ |
228 |
> |
bool GoldenPattern::purge(){ |
229 |
|
|
230 |
|
bool remove = false; |
231 |
|
int pos; |
232 |
|
unsigned int bef2, bef1, aft1, aft2, aft3; |
233 |
< |
for (auto isf=PattCore.begin();isf!=PattCore.end();++isf){ |
233 |
> |
for (auto isf=PattCore.begin();isf!=PattCore.end();){ |
234 |
|
for (auto idf = isf->second.begin(); idf !=isf->second.end();) { |
235 |
|
for (auto imf = idf->second.begin(); imf != idf->second.end();) { |
236 |
|
remove = false; |
248 |
|
} |
249 |
|
if (idf->second.size()==0) isf->second.erase(idf++); else ++idf; |
250 |
|
} |
251 |
< |
break; |
251 |
> |
if (isf->second.size()==0) PattCore.erase(isf++); else ++isf; |
252 |
|
} |
253 |
+ |
///Usefull pattern has at least 4 measurements and has a RPC measurement |
254 |
+ |
return PattCore.find(POSRPC)!=PattCore.end() && PattCore.size()>4; |
255 |
|
} |
256 |
|
|
257 |
|
std::ostream & operator << (std::ostream &out, const GoldenPattern & o) { |
262 |
|
|
263 |
|
for (auto isf=o.PattCore.cbegin();isf!=o.PattCore.cend();++isf){ |
264 |
|
for (auto idf = isf->second.cbegin(); idf!=isf->second.cend();++idf) { |
265 |
< |
out <<typeInfos[isf->first]<<" Det: "<< idf->first<<" Value: "; |
265 |
> |
out <<typeInfos[isf->first]<<" Det: "<< idf->first; |
266 |
> |
if(typeInfos[isf->first].find("RPC")!=std::string::npos){ |
267 |
> |
RPCDetId rpc(idf->first); |
268 |
> |
out<<" ("<<rpc<<") "; |
269 |
> |
} |
270 |
> |
if(typeInfos[isf->first].find("CSC")!=std::string::npos){ |
271 |
> |
CSCDetId csc(idf->first); |
272 |
> |
out<<" ("<<csc<<") "; |
273 |
> |
} |
274 |
> |
if(typeInfos[isf->first].find("DT")!=std::string::npos){ |
275 |
> |
DTChamberId dt(idf->first); |
276 |
> |
out<<" ("<<dt<<") "; |
277 |
> |
} |
278 |
> |
out <<" Value: "; |
279 |
|
for (auto imf = idf->second.cbegin(); imf != idf->second.cend();++imf) |
280 |
|
{ out << imf->first<<":"<<imf->second<<", "; } |
281 |
|
out << std::endl; |