ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc
Revision: 1.11
Committed: Tue Jun 25 11:06:03 2013 UTC (11 years, 10 months ago) by akalinow
Content type: text/plain
Branch: MAIN
Changes since 1.10: +42 -50 lines
Log Message:
*some further interface modifications by AK

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 konec 1.8 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
12 konec 1.1
13     #include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
14     #include "UserCode/L1RpcTriggerAnalysis/interface/GoldenPattern.h"
15    
16     #include "TFile.h"
17     #include "TTree.h"
18    
19     namespace {
20     typedef struct {
21     UInt_t key_det;
22     unsigned int key_pt;
23     unsigned int key_phi;
24     int key_ch;
25     unsigned int pat_Case;
26     UInt_t patDet;
27     int posOrBend;
28     unsigned int freq;
29     } ENTRY;
30     }
31    
32     PatternManager::PatternManager(const edm::ParameterSet &cfg)
33     : theConfig(cfg), theEvForPatCounter(0), theEvUsePatCounter(0)
34    
35     {}
36    
37     PatternManager::~PatternManager()
38     {
39     std::cout <<" Events checked for pattenrs: " << theEvForPatCounter << std::endl;
40 konec 1.5 std::cout <<" Events used for pattenrs: " << theEvUsePatCounter << std::endl;
41 konec 1.1 std::cout <<" Size of GoldenPatterns: " << theGPs.size() << std::endl;
42     if (theConfig.getUntrackedParameter<bool>("dump",false)) {
43     for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator
44     im = theGPs.begin(); im!= theGPs.end(); ++im) {
45     std::cout <<" GP: "<< (*im).second << std::endl;
46     }
47     }
48    
49     }
50    
51     void PatternManager::run(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi)
52     {
53     if (!hitSpec) return;
54     if (hitSpec->rawId() == 0 ) return;
55     double phiref = hitSpec->position().phi();
56     double ptref = simu->pt();
57     int chargeref = simu->charge();
58     unsigned int detref = hitSpec->rawId();
59 konec 1.2 /*
60 konec 1.1 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 konec 1.2 */
67 konec 1.1
68    
69     GoldenPattern::Key key( detref, ptref, chargeref, phiref);
70    
71     Pattern pattern;
72     theEvForPatCounter++;
73 akalinow 1.11 for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) {
74 konec 1.1 bool isOK = pattern.add(*is);
75     if (!isOK) return;
76     }
77     if (pattern.size() == 0) return;
78     theEvUsePatCounter++;
79    
80     if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
81     theGPs[key].add(pattern);
82    
83     }
84    
85     L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec, const VDigiSpec & vDigi)
86     {
87     L1Obj candidate;
88     if (!hitSpec) return candidate;
89     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 konec 1.5 /*
95 akalinow 1.11 if (detref != 637602109 && detref != 637634877 &&
96 konec 1.1 detref != 637599914 && detref != 637632682 ) return candidate;
97    
98     bool precisePos = ( fabs(hitSpec->position().phi()-1.025) < 0.001);
99     if (!precisePos) return candidate;
100     if ( simu->pt() < 26. || simu->pt() > 27. ) return candidate;
101    
102 konec 1.2 */
103 konec 1.9 // std::cout <<" ------------------ EVENT: "<<*ev <<" number of digis: "<<vDigi.size()<< std::endl;
104 konec 1.6 std::vector<Pattern> vpattern(1);
105 konec 1.1 theEvForPatCounter++;
106 konec 1.8 static bool skipRpcData = theConfig.getUntrackedParameter<bool>("skipRpcData", false);
107     static bool skipDtCscData = theConfig.getUntrackedParameter<bool>("skipDtCscData",false);
108 akalinow 1.11 for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) {
109 konec 1.8 DetId detId( is->first);
110     if (skipRpcData && detId.subdetId()==MuonSubdetId::RPC) continue;
111     if (skipDtCscData && (detId.subdetId()==MuonSubdetId::DT || detId.subdetId()==MuonSubdetId::CSC) ) continue;
112 akalinow 1.11 if(detId.subdetId()==MuonSubdetId::DT && DTphDigiSpec(is->first, is->second).bxNum()!=0) continue; //AK. Correct?
113     // std::cout << "adding------- "<< is-vDigi.begin()+1 <<" digi det: "<<is->first<<"(rpc:"<<(detId.subdetId()==MuonSubdetId::RPC)<<") data: "<<is->second<< std::endl;
114 konec 1.8 Pattern::add(vpattern,*is);
115 akalinow 1.11 // std::cout <<" after vpattern has size: "<<vpattern.size() << std::endl;
116 konec 1.9 if (vpattern.size() > 100) break;
117 konec 1.8 }
118 konec 1.6 if (vpattern[0].size() == 0) return candidate;
119 akalinow 1.10 //std::cout <<" ------------------ END EVENT, NOW COMPARE, has #patterns: "<<vpattern.size()<<" vpattern[0].size="<<vpattern[0].size() << std::endl;
120 konec 1.1
121 konec 1.5 GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref );
122 akalinow 1.11 // std::cout << thisKey << std::endl;
123 konec 1.1
124     GoldenPattern::Result bestMatching;
125     GoldenPattern::Key bestKey;
126 akalinow 1.11 for (auto ip=vpattern.cbegin(); ip!= vpattern.cend();++ip) {
127     const Pattern & pattern = *ip;
128     // std::cout << " HAS PATTERN "<<pattern << std::endl;
129     for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) {
130     // if (!(thisKey==igps->first)) continue;
131     GoldenPattern & gp = igps->second;
132     GoldenPattern::Result result = gp.compare(pattern);
133     // if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue;
134     // if (!result.hasRpcDet(igps->first.theDet)) continue;
135     // if (result.nMatchedTot() < 5 )continue;
136     // if (!result) continue;
137     // std::cout <<"PATT KEY: "<<igps->first<<" "<<result ; //<<std::endl;
138     if (bestMatching < result) {
139     bestMatching = result;
140     bestKey = igps->first;
141     // std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl;
142     }
143     //else std::cout <<std::endl;
144     }
145 konec 1.6 }
146 konec 1.5
147 akalinow 1.11 // std::cout <<" ------------------ END COMPARE: " << std::endl;
148     // std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::cout <<" ######"<<" pt: "<< bestKey.ptValue()<<std::endl;
149 konec 1.8 // abort();
150 konec 1.1 if (bestMatching) {
151     candidate.pt = bestKey.ptValue();
152 akalinow 1.11 candidate.eta = bestKey.etaValue();
153 konec 1.1 candidate.phi = bestKey.phiValue();
154     candidate.q = bestMatching.nMatchedTot();
155     candidate.type = L1Obj::OTF;
156     }
157     return candidate;
158    
159     }
160    
161    
162     void PatternManager::beginJob()
163     {
164     if ( !theConfig.exists("patternInpFile") ) return;
165     std::string patternInpFileName = theConfig.getParameter<std::string>("patternInpFile");
166     TFile patternInpFile( patternInpFileName.c_str());
167     TTree * tree = (TTree*) patternInpFile.Get("FlatPatterns");
168     static ENTRY entry;
169     tree->SetBranchAddress("entry",&entry);
170     Int_t nentries = (Int_t) tree->GetEntries();
171 akalinow 1.11 for (Int_t i=0; i<nentries; ++i) {
172 konec 1.1 tree->GetEntry(i);
173     GoldenPattern::Key key;
174     key.theDet = entry.key_det;
175     key.thePtCode = entry.key_pt;
176     key.thePhiCode = entry.key_phi;
177     key.theCharge = entry.key_ch;
178     GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
179     if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
180     theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
181     }
182     delete tree;
183     patternInpFile.Close();
184     }
185    
186 akalinow 1.11 void PatternManager::endJob(){
187 konec 1.1
188     if ( !theConfig.exists("patternOutFile") ) return;
189     std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
190     TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
191    
192 akalinow 1.11 for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) {
193     GoldenPattern & gp = igps->second;
194     gp.purge();
195     }
196    
197 konec 1.1 static ENTRY entry;
198     TTree *tree = new TTree("FlatPatterns","FlatPatterns");
199     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");
200    
201 akalinow 1.11 for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) {
202 konec 1.1 const GoldenPattern & gp = igps->second;
203     entry.key_det = gp.theKey.theDet;
204     entry.key_pt = gp.theKey.thePtCode;
205     entry.key_phi = gp.theKey.thePhiCode;
206     entry.key_ch = gp.theKey.theCharge;
207 akalinow 1.11
208     for (auto it=gp.PattCore.cbegin();it!=gp.PattCore.cend();++it){
209     entry.pat_Case = it->first;
210     for (GoldenPattern::DetFreq::const_iterator idf = it->second.cbegin(); idf !=it->second.cend(); ++idf) {
211 konec 1.1 entry.patDet = idf->first;
212 akalinow 1.11 for (GoldenPattern::MFreq::const_iterator imf = idf->second.cbegin(); imf != idf->second.cend(); ++imf) {
213 konec 1.1 entry.posOrBend = imf->first;
214     entry.freq = imf->second;
215     tree->Fill();
216     }
217     }
218     }
219     }
220     patternOutFile.Write();
221     patternOutFile.Close();
222     // delete tree;
223     }
224