ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc
Revision: 1.3
Committed: Mon May 20 15:47:23 2013 UTC (11 years, 11 months ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -0 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.3 if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue;
123 konec 1.1 if (result > bestMatching) {
124     bestMatching = result;
125     bestKey = igps->first;
126     }
127     // std::cout <<result << std::endl;
128     }
129 konec 1.2 // std::cout <<" ------------------ END COMPARE: " << std::endl;
130     // std::cout <<"BEST: "<< bestMatching<<" pt: "<<bestKey.ptValue()<<std::endl;
131 konec 1.1 if (bestMatching) {
132     candidate.pt = bestKey.ptValue();
133     candidate.eta = 1.;
134     candidate.phi = bestKey.phiValue();
135     candidate.q = bestMatching.nMatchedTot();
136     candidate.type = L1Obj::OTF;
137     }
138     return candidate;
139    
140     }
141    
142    
143     void PatternManager::beginJob()
144     {
145     if ( !theConfig.exists("patternInpFile") ) return;
146     std::string patternInpFileName = theConfig.getParameter<std::string>("patternInpFile");
147     TFile patternInpFile( patternInpFileName.c_str());
148     TTree * tree = (TTree*) patternInpFile.Get("FlatPatterns");
149     static ENTRY entry;
150     tree->SetBranchAddress("entry",&entry);
151     Int_t nentries = (Int_t) tree->GetEntries();
152     for (Int_t i=0; i<nentries; i++) {
153     tree->GetEntry(i);
154     GoldenPattern::Key key;
155     key.theDet = entry.key_det;
156     key.thePtCode = entry.key_pt;
157     key.thePhiCode = entry.key_phi;
158     key.theCharge = entry.key_ch;
159     GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
160     if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
161     theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
162     }
163     delete tree;
164     patternInpFile.Close();
165     }
166    
167     void PatternManager::endJob()
168     {
169     for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
170     GoldenPattern & gp = igps->second;
171     gp.purge();
172     }
173    
174     if ( !theConfig.exists("patternOutFile") ) return;
175     std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
176     TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
177    
178     static ENTRY entry;
179     TTree *tree = new TTree("FlatPatterns","FlatPatterns");
180     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");
181    
182     for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
183     const GoldenPattern & gp = igps->second;
184     entry.key_det = gp.theKey.theDet;
185     entry.key_pt = gp.theKey.thePtCode;
186     entry.key_phi = gp.theKey.thePhiCode;
187     entry.key_ch = gp.theKey.theCharge;
188     for (unsigned int iCase =1; iCase <=5; ++iCase) {
189     entry.pat_Case = iCase;
190     const GoldenPattern::DetFreq * detFreq = 0;
191     if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc;
192     if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc;
193     if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc;
194     if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt;
195     if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt;
196     for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) {
197     entry.patDet = idf->first;
198     for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) {
199     entry.posOrBend = imf->first;
200     entry.freq = imf->second;
201     tree->Fill();
202     }
203     }
204     }
205     }
206     patternOutFile.Write();
207     patternOutFile.Close();
208     // delete tree;
209     }
210