50 |
|
|
51 |
|
void PatternManager::run(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi) |
52 |
|
{ |
53 |
+ |
|
54 |
+ |
if (theConfig.exists("patternInpFile") && |
55 |
+ |
theConfig.exists("patternOutFile")) return; |
56 |
+ |
|
57 |
|
if (!hitSpec) return; |
58 |
|
if (hitSpec->rawId() == 0 ) return; |
59 |
< |
double phiref = hitSpec->position().phi(); |
60 |
< |
double ptref = simu->pt(); |
59 |
> |
|
60 |
> |
int stripRef = -1; |
61 |
> |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) { |
62 |
> |
if(is->first!=hitSpec->rawId()) continue; |
63 |
> |
RPCDigiSpec digi(is->first, is->second); |
64 |
> |
stripRef = digi.halfStrip(); |
65 |
> |
} |
66 |
> |
|
67 |
> |
///Use only events with a digi in reference station |
68 |
> |
if(stripRef<0) return; |
69 |
> |
|
70 |
> |
//float phiref = hitSpec->position().phi(); |
71 |
> |
float phiref = stripRef; |
72 |
> |
float ptref = simu->pt(); |
73 |
|
int chargeref = simu->charge(); |
74 |
|
unsigned int detref = hitSpec->rawId(); |
59 |
– |
/* |
60 |
– |
if (detref != 637602109 && detref != 637634877 && |
61 |
– |
detref != 637599914 && detref != 637632682 ) return; |
62 |
– |
|
63 |
– |
bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001); |
64 |
– |
if (!precisePos) return; |
65 |
– |
if ( simu->pt() < 16.) return; |
66 |
– |
*/ |
67 |
– |
|
75 |
|
|
76 |
|
GoldenPattern::Key key( detref, ptref, chargeref, phiref); |
77 |
+ |
//if(detref!=637602109 || chargeref<0 || phiref!=80) return; |
78 |
+ |
//std::cout<<key<<std::endl; |
79 |
|
|
80 |
|
Pattern pattern; |
81 |
|
theEvForPatCounter++; |
82 |
< |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) { |
82 |
> |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) { |
83 |
|
bool isOK = pattern.add(*is); |
84 |
|
if (!isOK) return; |
85 |
|
} |
94 |
|
L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi) |
95 |
|
{ |
96 |
|
L1Obj candidate; |
97 |
+ |
|
98 |
+ |
if (theConfig.exists("patternInpFile") && |
99 |
+ |
theConfig.exists("patternOutFile")) return candidate; |
100 |
+ |
|
101 |
|
if (!hitSpec) return candidate; |
102 |
|
if (hitSpec->rawId() == 0 ) return candidate; |
103 |
< |
double phiref = hitSpec->position().phi(); |
104 |
< |
double ptref = simu->pt(); |
103 |
> |
float phiref = hitSpec->position().phi(); |
104 |
> |
float ptref = simu->pt(); |
105 |
|
int chargeref = simu->charge(); |
106 |
|
unsigned int detref = hitSpec->rawId(); |
107 |
|
/* |
118 |
|
theEvForPatCounter++; |
119 |
|
static bool skipRpcData = theConfig.getUntrackedParameter<bool>("skipRpcData", false); |
120 |
|
static bool skipDtCscData = theConfig.getUntrackedParameter<bool>("skipDtCscData",false); |
121 |
< |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) { |
121 |
> |
for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) { |
122 |
|
DetId detId( is->first); |
123 |
|
if (skipRpcData && detId.subdetId()==MuonSubdetId::RPC) continue; |
124 |
|
if (skipDtCscData && (detId.subdetId()==MuonSubdetId::DT || detId.subdetId()==MuonSubdetId::CSC) ) continue; |
125 |
+ |
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; |
127 |
|
Pattern::add(vpattern,*is); |
128 |
|
// std::cout <<" after vpattern has size: "<<vpattern.size() << std::endl; |
129 |
|
if (vpattern.size() > 100) break; |
130 |
|
} |
131 |
|
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; |
132 |
> |
//std::cout <<" ------------------ END EVENT, NOW COMPARE, has #patterns: "<<vpattern.size()<<" vpattern[0].size="<<vpattern[0].size() << std::endl; |
133 |
|
|
134 |
|
GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref ); |
135 |
< |
// std::cout << thisKey << std::endl; |
135 |
> |
//std::cout << thisKey << std::endl; |
136 |
|
|
137 |
|
GoldenPattern::Result bestMatching; |
138 |
|
GoldenPattern::Key bestKey; |
139 |
< |
for (auto ip=vpattern.begin(); ip!= vpattern.end();++ip) { |
140 |
< |
const Pattern & pattern = *ip; |
141 |
< |
// std::cout << " HAS PATTERN "<<pattern << std::endl; |
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); |
146 |
< |
// if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue; |
147 |
< |
// if (!result.hasRpcDet(igps->first.theDet)) continue; |
148 |
< |
// if (result.nMatchedTot() < 5 )continue; |
149 |
< |
// if (!result) continue; |
150 |
< |
// std::cout <<"PATT KEY: "<<igps->first<<" "<<result ; //<<std::endl; |
151 |
< |
if (bestMatching < result) { |
152 |
< |
bestMatching = result; |
153 |
< |
bestKey = igps->first; |
154 |
< |
// std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl; |
141 |
< |
} |
142 |
< |
//else std::cout <<std::endl; |
143 |
< |
} |
139 |
> |
for (auto ip=vpattern.cbegin(); ip!= vpattern.cend();++ip) { |
140 |
> |
const Pattern & pattern = *ip; |
141 |
> |
// std::cout << " HAS PATTERN "<<pattern << std::endl; |
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); |
146 |
> |
|
147 |
> |
std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<std::endl; |
148 |
> |
if (bestMatching < result) { |
149 |
> |
bestMatching = result; |
150 |
> |
bestKey = igps->first; |
151 |
> |
// std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl; |
152 |
> |
} |
153 |
> |
//else std::cout <<std::endl; |
154 |
> |
} |
155 |
|
} |
156 |
|
|
157 |
|
// std::cout <<" ------------------ END COMPARE: " << std::endl; |
159 |
|
// abort(); |
160 |
|
if (bestMatching) { |
161 |
|
candidate.pt = bestKey.ptValue(); |
162 |
< |
candidate.eta = 1.; |
162 |
> |
candidate.eta = bestKey.etaValue(); |
163 |
|
candidate.phi = bestKey.phiValue(); |
164 |
|
candidate.q = bestMatching.nMatchedTot(); |
165 |
|
candidate.type = L1Obj::OTF; |
178 |
|
static ENTRY entry; |
179 |
|
tree->SetBranchAddress("entry",&entry); |
180 |
|
Int_t nentries = (Int_t) tree->GetEntries(); |
181 |
< |
for (Int_t i=0; i<nentries; i++) { |
181 |
> |
for (Int_t i=0; i<nentries; ++i) { |
182 |
|
tree->GetEntry(i); |
183 |
|
GoldenPattern::Key key; |
184 |
|
key.theDet = entry.key_det; |
185 |
|
key.thePtCode = entry.key_pt; |
186 |
|
key.thePhiCode = entry.key_phi; |
187 |
|
key.theCharge = entry.key_ch; |
188 |
+ |
|
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 |
+ |
|
196 |
|
GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case); |
197 |
|
if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key); |
198 |
|
theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq); |
201 |
|
patternInpFile.Close(); |
202 |
|
} |
203 |
|
|
204 |
< |
void PatternManager::endJob() |
186 |
< |
{ |
187 |
< |
for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) { |
188 |
< |
GoldenPattern & gp = igps->second; |
189 |
< |
gp.purge(); |
190 |
< |
} |
204 |
> |
void PatternManager::endJob(){ |
205 |
|
|
206 |
|
if ( !theConfig.exists("patternOutFile") ) return; |
207 |
|
std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile"); |
208 |
|
TFile patternOutFile( patternOutFileName.c_str(),"RECREATE"); |
209 |
< |
|
209 |
> |
|
210 |
> |
if (theConfig.exists("patternInpFile") && theConfig.exists("patternOutFile")){ |
211 |
> |
for (auto igps = theGPs.begin(); igps != theGPs.end();) { |
212 |
> |
GoldenPattern & gp = igps->second; |
213 |
> |
if(!gp.purge()) {theGPs.erase(igps++); } else { ++igps; } |
214 |
> |
} |
215 |
> |
} |
216 |
> |
|
217 |
|
static ENTRY entry; |
218 |
|
TTree *tree = new TTree("FlatPatterns","FlatPatterns"); |
219 |
|
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"); |
220 |
|
|
221 |
< |
for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) { |
221 |
> |
for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) { |
222 |
|
const GoldenPattern & gp = igps->second; |
223 |
|
entry.key_det = gp.theKey.theDet; |
224 |
|
entry.key_pt = gp.theKey.thePtCode; |
225 |
|
entry.key_phi = gp.theKey.thePhiCode; |
226 |
|
entry.key_ch = gp.theKey.theCharge; |
227 |
< |
for (unsigned int iCase =1; iCase <=5; ++iCase) { |
228 |
< |
entry.pat_Case = iCase; |
229 |
< |
const GoldenPattern::DetFreq * detFreq = 0; |
230 |
< |
if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc; |
210 |
< |
if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc; |
211 |
< |
if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc; |
212 |
< |
if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt; |
213 |
< |
if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt; |
214 |
< |
for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) { |
227 |
> |
|
228 |
> |
for (auto it=gp.PattCore.cbegin();it!=gp.PattCore.cend();++it){ |
229 |
> |
entry.pat_Case = it->first; |
230 |
> |
for (GoldenPattern::DetFreq::const_iterator idf = it->second.cbegin(); idf !=it->second.cend(); ++idf) { |
231 |
|
entry.patDet = idf->first; |
232 |
< |
for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) { |
232 |
> |
for (GoldenPattern::MFreq::const_iterator imf = idf->second.cbegin(); imf != idf->second.cend(); ++imf) { |
233 |
|
entry.posOrBend = imf->first; |
234 |
|
entry.freq = imf->second; |
235 |
|
tree->Fill(); |