1 |
konec |
1.1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/PatternManager.h"
|
2 |
|
|
|
3 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/EventObj.h"
|
4 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/TrackObj.h"
|
5 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/HitSpecObj.h"
|
6 |
|
|
|
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 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
|
13 |
|
|
#include "UserCode/L1RpcTriggerAnalysis/interface/GoldenPattern.h"
|
14 |
|
|
|
15 |
|
|
#include "TFile.h"
|
16 |
|
|
#include "TTree.h"
|
17 |
|
|
|
18 |
|
|
namespace {
|
19 |
|
|
typedef struct {
|
20 |
|
|
UInt_t key_det;
|
21 |
|
|
unsigned int key_pt;
|
22 |
|
|
unsigned int key_phi;
|
23 |
|
|
int key_ch;
|
24 |
|
|
unsigned int pat_Case;
|
25 |
|
|
UInt_t patDet;
|
26 |
|
|
int posOrBend;
|
27 |
|
|
unsigned int freq;
|
28 |
|
|
} ENTRY;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
PatternManager::PatternManager(const edm::ParameterSet &cfg)
|
32 |
|
|
: theConfig(cfg), theEvForPatCounter(0), theEvUsePatCounter(0)
|
33 |
|
|
|
34 |
|
|
{}
|
35 |
|
|
|
36 |
|
|
PatternManager::~PatternManager()
|
37 |
|
|
{
|
38 |
|
|
std::cout <<" Events checked for pattenrs: " << theEvForPatCounter << std::endl;
|
39 |
konec |
1.5 |
std::cout <<" Events used for pattenrs: " << theEvUsePatCounter << std::endl;
|
40 |
konec |
1.1 |
std::cout <<" Size of GoldenPatterns: " << theGPs.size() << std::endl;
|
41 |
|
|
if (theConfig.getUntrackedParameter<bool>("dump",false)) {
|
42 |
|
|
for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator
|
43 |
|
|
im = theGPs.begin(); im!= theGPs.end(); ++im) {
|
44 |
|
|
std::cout <<" GP: "<< (*im).second << std::endl;
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
void PatternManager::run(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi)
|
51 |
|
|
{
|
52 |
|
|
if (!hitSpec) return;
|
53 |
|
|
if (hitSpec->rawId() == 0 ) return;
|
54 |
|
|
double phiref = hitSpec->position().phi();
|
55 |
|
|
double ptref = simu->pt();
|
56 |
|
|
int chargeref = simu->charge();
|
57 |
|
|
unsigned int detref = hitSpec->rawId();
|
58 |
konec |
1.2 |
/*
|
59 |
konec |
1.1 |
if (detref != 637602109 && detref != 637634877 &&
|
60 |
|
|
detref != 637599914 && detref != 637632682 ) return;
|
61 |
|
|
|
62 |
|
|
bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001);
|
63 |
|
|
if (!precisePos) return;
|
64 |
|
|
if ( simu->pt() < 16.) return;
|
65 |
konec |
1.2 |
*/
|
66 |
konec |
1.1 |
|
67 |
|
|
|
68 |
|
|
GoldenPattern::Key key( detref, ptref, chargeref, phiref);
|
69 |
|
|
|
70 |
|
|
Pattern pattern;
|
71 |
|
|
theEvForPatCounter++;
|
72 |
|
|
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
|
73 |
|
|
bool isOK = pattern.add(*is);
|
74 |
|
|
if (!isOK) return;
|
75 |
|
|
}
|
76 |
|
|
if (pattern.size() == 0) return;
|
77 |
|
|
theEvUsePatCounter++;
|
78 |
|
|
|
79 |
|
|
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
|
80 |
|
|
theGPs[key].add(pattern);
|
81 |
|
|
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi)
|
85 |
|
|
{
|
86 |
|
|
L1Obj candidate;
|
87 |
|
|
if (!hitSpec) return candidate;
|
88 |
|
|
if (hitSpec->rawId() == 0 ) return candidate;
|
89 |
|
|
double phiref = hitSpec->position().phi();
|
90 |
|
|
double ptref = simu->pt();
|
91 |
|
|
int chargeref = simu->charge();
|
92 |
|
|
unsigned int detref = hitSpec->rawId();
|
93 |
konec |
1.5 |
/*
|
94 |
konec |
1.1 |
if (detref != 637602109 && detref != 637634877 &&
|
95 |
|
|
detref != 637599914 && detref != 637632682 ) return candidate;
|
96 |
|
|
|
97 |
|
|
bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001);
|
98 |
|
|
if (!precisePos) return candidate;
|
99 |
|
|
if ( simu->pt() < 26. || simu->pt() > 27. ) return candidate;
|
100 |
|
|
|
101 |
konec |
1.2 |
*/
|
102 |
konec |
1.5 |
// std::cout <<" ------------------ EVENT: " << std::endl;
|
103 |
konec |
1.6 |
std::vector<Pattern> vpattern(1);
|
104 |
konec |
1.1 |
theEvForPatCounter++;
|
105 |
|
|
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
|
106 |
konec |
1.6 |
bool isOK = Pattern::add(vpattern,*is);
|
107 |
konec |
1.1 |
}
|
108 |
konec |
1.6 |
if (vpattern[0].size() == 0) return candidate;
|
109 |
konec |
1.2 |
// std::cout <<" ------------------ END EVENT, COMPARE" << std::endl;
|
110 |
konec |
1.1 |
|
111 |
konec |
1.5 |
GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref );
|
112 |
|
|
// std::cout << thisKey <<" PATTENR_SIZE: "<<pattern.size()<< std::endl;
|
113 |
konec |
1.1 |
|
114 |
|
|
GoldenPattern::Result bestMatching;
|
115 |
|
|
GoldenPattern::Key bestKey;
|
116 |
|
|
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
117 |
konec |
1.6 |
for (auto ip=vpattern.begin(); ip!= vpattern.end();++ip) {
|
118 |
|
|
const Pattern & pattern = *ip;
|
119 |
konec |
1.1 |
// if (!(thisKey==igps->first)) continue;
|
120 |
|
|
// std::cout << " HAS PATTERN "<<pattern << std::endl;
|
121 |
|
|
GoldenPattern & gp = igps->second;
|
122 |
|
|
GoldenPattern::Result result = gp.compare(pattern);
|
123 |
konec |
1.4 |
// if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue;
|
124 |
konec |
1.6 |
// if (!result.hasRpcDet(igps->first.theDet)) continue;
|
125 |
|
|
// if (result.nMatchedTot() < 5 )continue;
|
126 |
|
|
// if (!result) continue;
|
127 |
konec |
1.5 |
// std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<" is Less: "<<(result<bestMatching)<<" isBetter: "<<(result>bestMatching)<<" isBerres: "<<(bestMatching<result) ; //<<std::endl;
|
128 |
|
|
if (bestMatching < result) {
|
129 |
konec |
1.1 |
bestMatching = result;
|
130 |
|
|
bestKey = igps->first;
|
131 |
konec |
1.5 |
// std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl;
|
132 |
|
|
}
|
133 |
|
|
//else std::cout <<std::endl;
|
134 |
konec |
1.1 |
}
|
135 |
konec |
1.6 |
}
|
136 |
konec |
1.5 |
|
137 |
konec |
1.2 |
// std::cout <<" ------------------ END COMPARE: " << std::endl;
|
138 |
konec |
1.5 |
// std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::cout <<" ######"<<" pt: "<< bestKey.ptValue()<<std::endl;
|
139 |
konec |
1.1 |
if (bestMatching) {
|
140 |
|
|
candidate.pt = bestKey.ptValue();
|
141 |
|
|
candidate.eta = 1.;
|
142 |
|
|
candidate.phi = bestKey.phiValue();
|
143 |
|
|
candidate.q = bestMatching.nMatchedTot();
|
144 |
|
|
candidate.type = L1Obj::OTF;
|
145 |
|
|
}
|
146 |
|
|
return candidate;
|
147 |
|
|
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
void PatternManager::beginJob()
|
152 |
|
|
{
|
153 |
|
|
if ( !theConfig.exists("patternInpFile") ) return;
|
154 |
|
|
std::string patternInpFileName = theConfig.getParameter<std::string>("patternInpFile");
|
155 |
|
|
TFile patternInpFile( patternInpFileName.c_str());
|
156 |
|
|
TTree * tree = (TTree*) patternInpFile.Get("FlatPatterns");
|
157 |
|
|
static ENTRY entry;
|
158 |
|
|
tree->SetBranchAddress("entry",&entry);
|
159 |
|
|
Int_t nentries = (Int_t) tree->GetEntries();
|
160 |
|
|
for (Int_t i=0; i<nentries; i++) {
|
161 |
|
|
tree->GetEntry(i);
|
162 |
|
|
GoldenPattern::Key key;
|
163 |
|
|
key.theDet = entry.key_det;
|
164 |
|
|
key.thePtCode = entry.key_pt;
|
165 |
|
|
key.thePhiCode = entry.key_phi;
|
166 |
|
|
key.theCharge = entry.key_ch;
|
167 |
|
|
GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
|
168 |
|
|
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
|
169 |
|
|
theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
|
170 |
|
|
}
|
171 |
|
|
delete tree;
|
172 |
|
|
patternInpFile.Close();
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
void PatternManager::endJob()
|
176 |
|
|
{
|
177 |
|
|
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
178 |
|
|
GoldenPattern & gp = igps->second;
|
179 |
|
|
gp.purge();
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
if ( !theConfig.exists("patternOutFile") ) return;
|
183 |
|
|
std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
|
184 |
|
|
TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
|
185 |
|
|
|
186 |
|
|
static ENTRY entry;
|
187 |
|
|
TTree *tree = new TTree("FlatPatterns","FlatPatterns");
|
188 |
|
|
tree->Branch("entry",&entry,"key_det/i:key_pt/i:key_phi/i:key_ch/I:pat_Case/i:patDet/i:posOrBend/I:freq/i");
|
189 |
|
|
|
190 |
|
|
for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
191 |
|
|
const GoldenPattern & gp = igps->second;
|
192 |
|
|
entry.key_det = gp.theKey.theDet;
|
193 |
|
|
entry.key_pt = gp.theKey.thePtCode;
|
194 |
|
|
entry.key_phi = gp.theKey.thePhiCode;
|
195 |
|
|
entry.key_ch = gp.theKey.theCharge;
|
196 |
|
|
for (unsigned int iCase =1; iCase <=5; ++iCase) {
|
197 |
|
|
entry.pat_Case = iCase;
|
198 |
|
|
const GoldenPattern::DetFreq * detFreq = 0;
|
199 |
|
|
if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc;
|
200 |
|
|
if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc;
|
201 |
|
|
if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc;
|
202 |
|
|
if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt;
|
203 |
|
|
if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt;
|
204 |
|
|
for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) {
|
205 |
|
|
entry.patDet = idf->first;
|
206 |
|
|
for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) {
|
207 |
|
|
entry.posOrBend = imf->first;
|
208 |
|
|
entry.freq = imf->second;
|
209 |
|
|
tree->Fill();
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
|
|
patternOutFile.Write();
|
215 |
|
|
patternOutFile.Close();
|
216 |
|
|
// delete tree;
|
217 |
|
|
}
|
218 |
|
|
|