ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc
Revision: 1.1
Committed: Fri May 17 13:04:54 2013 UTC (11 years, 11 months ago) by konec
Content type: text/plain
Branch: MAIN
Log Message:
extenstion for OTF

File Contents

# Content
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: " << theEvForPatCounter << 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 if (detref != 637602109 && detref != 637634877 &&
59 detref != 637599914 && detref != 637632682 ) return;
60
61 bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001);
62 if (!precisePos) return;
63 if ( simu->pt() < 16.) return;
64
65
66 GoldenPattern::Key key( detref, ptref, chargeref, phiref);
67
68 Pattern pattern;
69 theEvForPatCounter++;
70 for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
71 bool isOK = pattern.add(*is);
72 if (!isOK) return;
73 }
74 if (pattern.size() == 0) return;
75 theEvUsePatCounter++;
76
77 if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
78 theGPs[key].add(pattern);
79
80 }
81
82 L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi)
83 {
84 L1Obj candidate;
85 if (!hitSpec) return candidate;
86 if (hitSpec->rawId() == 0 ) return candidate;
87 double phiref = hitSpec->position().phi();
88 double ptref = simu->pt();
89 int chargeref = simu->charge();
90 unsigned int detref = hitSpec->rawId();
91 if (detref != 637602109 && detref != 637634877 &&
92 detref != 637599914 && detref != 637632682 ) return candidate;
93
94 bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001);
95 if (!precisePos) return candidate;
96 if ( simu->pt() < 26. || simu->pt() > 27. ) return candidate;
97
98 std::cout <<" ------------------ EVENT: " << std::endl;
99 Pattern pattern;
100 theEvForPatCounter++;
101 for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
102 bool isOK = pattern.add(*is);
103 if (!isOK) { return candidate; }
104 }
105 if (pattern.size() == 0) return candidate;
106 std::cout <<" ------------------ END EVENT, COMPARE" << std::endl;
107
108 // GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref );
109 // std::cout << thisKey << std::endl;
110
111 GoldenPattern::Result bestMatching;
112 GoldenPattern::Key bestKey;
113 for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
114 // if (!(thisKey==igps->first)) continue;
115 // std::cout << " HAS PATTERN "<<pattern << std::endl;
116 GoldenPattern & gp = igps->second;
117 GoldenPattern::Result result = gp.compare(pattern);
118 if (result > bestMatching) {
119 bestMatching = result;
120 bestKey = igps->first;
121 }
122 // std::cout <<result << std::endl;
123 }
124 std::cout <<" ------------------ END COMPARE: " << std::endl;
125 std::cout <<"BEST: "<< bestMatching<<" pt: "<<bestKey.ptValue()<<std::endl;
126 if (bestMatching) {
127 candidate.pt = bestKey.ptValue();
128 candidate.eta = 1.;
129 candidate.phi = bestKey.phiValue();
130 candidate.q = bestMatching.nMatchedTot();
131 candidate.type = L1Obj::OTF;
132 }
133 return candidate;
134
135 }
136
137
138 void PatternManager::beginJob()
139 {
140 if ( !theConfig.exists("patternInpFile") ) return;
141 std::string patternInpFileName = theConfig.getParameter<std::string>("patternInpFile");
142 TFile patternInpFile( patternInpFileName.c_str());
143 TTree * tree = (TTree*) patternInpFile.Get("FlatPatterns");
144 static ENTRY entry;
145 tree->SetBranchAddress("entry",&entry);
146 Int_t nentries = (Int_t) tree->GetEntries();
147 for (Int_t i=0; i<nentries; i++) {
148 tree->GetEntry(i);
149 GoldenPattern::Key key;
150 key.theDet = entry.key_det;
151 key.thePtCode = entry.key_pt;
152 key.thePhiCode = entry.key_phi;
153 key.theCharge = entry.key_ch;
154 GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
155 if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
156 theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
157 }
158 delete tree;
159 patternInpFile.Close();
160 }
161
162 void PatternManager::endJob()
163 {
164 for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
165 GoldenPattern & gp = igps->second;
166 gp.purge();
167 }
168
169 if ( !theConfig.exists("patternOutFile") ) return;
170 std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
171 TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
172
173 static ENTRY entry;
174 TTree *tree = new TTree("FlatPatterns","FlatPatterns");
175 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");
176
177 for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
178 const GoldenPattern & gp = igps->second;
179 entry.key_det = gp.theKey.theDet;
180 entry.key_pt = gp.theKey.thePtCode;
181 entry.key_phi = gp.theKey.thePhiCode;
182 entry.key_ch = gp.theKey.theCharge;
183 for (unsigned int iCase =1; iCase <=5; ++iCase) {
184 entry.pat_Case = iCase;
185 const GoldenPattern::DetFreq * detFreq = 0;
186 if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc;
187 if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc;
188 if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc;
189 if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt;
190 if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt;
191 for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) {
192 entry.patDet = idf->first;
193 for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) {
194 entry.posOrBend = imf->first;
195 entry.freq = imf->second;
196 tree->Fill();
197 }
198 }
199 }
200 }
201 patternOutFile.Write();
202 patternOutFile.Close();
203 // delete tree;
204 }
205