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 |
std::cout <<" Events used for pattenrs: " << theEvUsePatCounter << std::endl;
|
40 |
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 |
/*
|
59 |
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 |
*/
|
66 |
|
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 |
/*
|
94 |
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 |
*/
|
102 |
// std::cout <<" ------------------ EVENT: " << std::endl;
|
103 |
std::vector<Pattern> vpattern(1);
|
104 |
theEvForPatCounter++;
|
105 |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) Pattern::add(vpattern,*is);
|
106 |
if (vpattern[0].size() == 0) return candidate;
|
107 |
// std::cout <<" ------------------ END EVENT, COMPARE" << std::endl;
|
108 |
|
109 |
GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref );
|
110 |
// std::cout << thisKey <<" PATTENR_SIZE: "<<pattern.size()<< std::endl;
|
111 |
|
112 |
GoldenPattern::Result bestMatching;
|
113 |
GoldenPattern::Key bestKey;
|
114 |
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
115 |
for (auto ip=vpattern.begin(); ip!= vpattern.end();++ip) {
|
116 |
const Pattern & pattern = *ip;
|
117 |
// if (!(thisKey==igps->first)) continue;
|
118 |
// std::cout << " HAS PATTERN "<<pattern << std::endl;
|
119 |
GoldenPattern & gp = igps->second;
|
120 |
GoldenPattern::Result result = gp.compare(pattern);
|
121 |
// if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue;
|
122 |
// if (!result.hasRpcDet(igps->first.theDet)) continue;
|
123 |
// if (result.nMatchedTot() < 5 )continue;
|
124 |
// if (!result) continue;
|
125 |
// std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<" is Less: "<<(result<bestMatching)<<" isBetter: "<<(result>bestMatching)<<" isBerres: "<<(bestMatching<result) ; //<<std::endl;
|
126 |
if (bestMatching < result) {
|
127 |
bestMatching = result;
|
128 |
bestKey = igps->first;
|
129 |
// std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl;
|
130 |
}
|
131 |
//else std::cout <<std::endl;
|
132 |
}
|
133 |
}
|
134 |
|
135 |
// std::cout <<" ------------------ END COMPARE: " << std::endl;
|
136 |
// std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::cout <<" ######"<<" pt: "<< bestKey.ptValue()<<std::endl;
|
137 |
if (bestMatching) {
|
138 |
candidate.pt = bestKey.ptValue();
|
139 |
candidate.eta = 1.;
|
140 |
candidate.phi = bestKey.phiValue();
|
141 |
candidate.q = bestMatching.nMatchedTot();
|
142 |
candidate.type = L1Obj::OTF;
|
143 |
}
|
144 |
return candidate;
|
145 |
|
146 |
}
|
147 |
|
148 |
|
149 |
void PatternManager::beginJob()
|
150 |
{
|
151 |
if ( !theConfig.exists("patternInpFile") ) return;
|
152 |
std::string patternInpFileName = theConfig.getParameter<std::string>("patternInpFile");
|
153 |
TFile patternInpFile( patternInpFileName.c_str());
|
154 |
TTree * tree = (TTree*) patternInpFile.Get("FlatPatterns");
|
155 |
static ENTRY entry;
|
156 |
tree->SetBranchAddress("entry",&entry);
|
157 |
Int_t nentries = (Int_t) tree->GetEntries();
|
158 |
for (Int_t i=0; i<nentries; i++) {
|
159 |
tree->GetEntry(i);
|
160 |
GoldenPattern::Key key;
|
161 |
key.theDet = entry.key_det;
|
162 |
key.thePtCode = entry.key_pt;
|
163 |
key.thePhiCode = entry.key_phi;
|
164 |
key.theCharge = entry.key_ch;
|
165 |
GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
|
166 |
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
|
167 |
theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
|
168 |
}
|
169 |
delete tree;
|
170 |
patternInpFile.Close();
|
171 |
}
|
172 |
|
173 |
void PatternManager::endJob()
|
174 |
{
|
175 |
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
176 |
GoldenPattern & gp = igps->second;
|
177 |
gp.purge();
|
178 |
}
|
179 |
|
180 |
if ( !theConfig.exists("patternOutFile") ) return;
|
181 |
std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
|
182 |
TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
|
183 |
|
184 |
static ENTRY entry;
|
185 |
TTree *tree = new TTree("FlatPatterns","FlatPatterns");
|
186 |
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");
|
187 |
|
188 |
for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
|
189 |
const GoldenPattern & gp = igps->second;
|
190 |
entry.key_det = gp.theKey.theDet;
|
191 |
entry.key_pt = gp.theKey.thePtCode;
|
192 |
entry.key_phi = gp.theKey.thePhiCode;
|
193 |
entry.key_ch = gp.theKey.theCharge;
|
194 |
for (unsigned int iCase =1; iCase <=5; ++iCase) {
|
195 |
entry.pat_Case = iCase;
|
196 |
const GoldenPattern::DetFreq * detFreq = 0;
|
197 |
if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc;
|
198 |
if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc;
|
199 |
if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc;
|
200 |
if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt;
|
201 |
if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt;
|
202 |
for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) {
|
203 |
entry.patDet = idf->first;
|
204 |
for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) {
|
205 |
entry.posOrBend = imf->first;
|
206 |
entry.freq = imf->second;
|
207 |
tree->Fill();
|
208 |
}
|
209 |
}
|
210 |
}
|
211 |
}
|
212 |
patternOutFile.Write();
|
213 |
patternOutFile.Close();
|
214 |
// delete tree;
|
215 |
}
|
216 |
|