1 |
#ifndef UserCode_L1RpcTriggerAnalysis_GoldenPattern_H
|
2 |
#define UserCode_L1RpcTriggerAnalysis_GoldenPattern_H
|
3 |
|
4 |
#include "UserCode/L1RpcTriggerAnalysis/interface/L1RpcTriggerAnalysisEfficiencyUtilities.h"
|
5 |
#include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
|
6 |
#include <map>
|
7 |
#include <vector>
|
8 |
#include <cmath>
|
9 |
#include <ostream>
|
10 |
#include <iostream>
|
11 |
|
12 |
class GoldenPattern {
|
13 |
public:
|
14 |
|
15 |
//
|
16 |
// where
|
17 |
//
|
18 |
enum PosBenCase { POSRPC=1, POSCSC=2, BENCSC=3, POSDT=4, BENDT=5 };
|
19 |
|
20 |
//
|
21 |
// Key
|
22 |
//
|
23 |
struct Key {
|
24 |
Key(uint32_t det=0, double pt=0, int charge= 0, double phi=0) : theDet(det), theCharge(charge) {
|
25 |
thePtCode = L1RpcTriggerAnalysisEfficiencyUtilities::PtScale().ptCode(pt);
|
26 |
while (phi < 0) { phi+=2*M_PI; }
|
27 |
thePhiCode = int( phi * 3000.);
|
28 |
}
|
29 |
bool operator< (const Key & o) const {
|
30 |
if (theCharge*thePtCode < o.theCharge*o.thePtCode) return true;
|
31 |
else if (theCharge*thePtCode==o.theCharge*o.thePtCode && thePhiCode < o.thePhiCode) return true;
|
32 |
else if (theCharge*thePtCode==o.theCharge*o.thePtCode && thePhiCode==o.thePhiCode && theDet<o.theDet) return true;
|
33 |
else return false;
|
34 |
}
|
35 |
bool operator==(const Key& o) const {
|
36 |
return !(theDet!=o.theDet || thePtCode!=o.thePtCode || thePhiCode!=o.thePhiCode || theCharge!=o.theCharge);
|
37 |
}
|
38 |
double ptValue() const { return L1RpcTriggerAnalysisEfficiencyUtilities::PtScale().ptValue( thePtCode); }
|
39 |
double phiValue() const { return (double)thePhiCode/3000.; }
|
40 |
uint32_t theDet;
|
41 |
unsigned int thePtCode;
|
42 |
unsigned int thePhiCode;
|
43 |
int theCharge;
|
44 |
friend std::ostream & operator << (std::ostream &out, const Key & o) {
|
45 |
out << "Key_det:"<<o.theDet<<"_pt:"<<o.thePtCode<<"_charge"<<o.theCharge<<"_phi:"<<o.thePhiCode;
|
46 |
return out;
|
47 |
}
|
48 |
};
|
49 |
|
50 |
//
|
51 |
// Result
|
52 |
//
|
53 |
class Result {
|
54 |
public:
|
55 |
Result() : checkMe(true), theValue(0.),
|
56 |
nMatchedPosRpc(0), nMatchedPosCsc(0), nMatchedPosDt(0), nMatchedBenCsc(0), nMatchedBenDt(0),
|
57 |
hasStation1(false), hasStation2(false) {}
|
58 |
bool operator<( const Result & o) const;
|
59 |
operator bool() const;
|
60 |
double value() const;
|
61 |
unsigned int nMatchedTot() const;
|
62 |
bool hasRpcDet(uint32_t rawId) {
|
63 |
for (auto it=posRpcResult.begin(); it != posRpcResult.end(); it++) {
|
64 |
if (it->first == rawId && it->second > 0. && it->second < 1.) return true;
|
65 |
}
|
66 |
return false;
|
67 |
}
|
68 |
private:
|
69 |
void run() const { if (checkMe) {checkMe=false; runNoCheck(); } }
|
70 |
void runNoCheck() const;
|
71 |
double norm(PosBenCase where, double whereInDist) const;
|
72 |
private:
|
73 |
mutable bool checkMe;
|
74 |
mutable double theValue;
|
75 |
mutable unsigned int nMatchedPosRpc, nMatchedPosCsc, nMatchedPosDt, nMatchedBenCsc, nMatchedBenDt;
|
76 |
bool hasStation1, hasStation2;
|
77 |
std::vector< std::pair<uint32_t, double > > posRpcResult;
|
78 |
std::vector< std::pair<uint32_t, double > > posCscResult;
|
79 |
std::vector< std::pair<uint32_t, double > > benCscResult;
|
80 |
std::vector< std::pair<uint32_t, double > > posDtResult;
|
81 |
std::vector< std::pair<uint32_t, double > > benDtResult;
|
82 |
friend std::ostream & operator << (std::ostream &out, const Result& o);
|
83 |
friend class GoldenPattern;
|
84 |
};
|
85 |
|
86 |
|
87 |
//
|
88 |
// GoldenPatterns methods
|
89 |
//
|
90 |
GoldenPattern() {}
|
91 |
GoldenPattern(const GoldenPattern::Key & key) : theKey(key) {}
|
92 |
void add( const Pattern & p);
|
93 |
void add( GoldenPattern::PosBenCase aCase, uint32_t rawId, int pos, unsigned int freq);
|
94 |
Result compare( const Pattern & p) const;
|
95 |
|
96 |
private:
|
97 |
|
98 |
Key theKey;
|
99 |
typedef std::map<int, unsigned int> MFreq;
|
100 |
typedef std::map<uint32_t, MFreq > DetFreq;
|
101 |
|
102 |
DetFreq posRpc;
|
103 |
|
104 |
DetFreq posCsc;
|
105 |
DetFreq bendingCsc;
|
106 |
|
107 |
DetFreq posDt;
|
108 |
DetFreq bendingDt;
|
109 |
|
110 |
private:
|
111 |
|
112 |
void purge();
|
113 |
double whereInDistribution(int obj, const MFreq & m) const;
|
114 |
friend std::ostream & operator << (std::ostream &out, const GoldenPattern & o);
|
115 |
friend class PatternManager;
|
116 |
};
|
117 |
#endif
|