ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc
Revision: 1.4
Committed: Mon May 20 15:58:52 2013 UTC (11 years, 11 months ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

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