ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc
(Generate patch)

Comparing UserCode/L1RpcTriggerAnalysis/src/PatternManager.cc (file contents):
Revision 1.6 by konec, Thu May 23 18:24:04 2013 UTC vs.
Revision 1.13 by akalinow, Thu Jul 11 11:25:22 2013 UTC

# Line 8 | Line 8
8   #include "UserCode/L1RpcTriggerAnalysis/interface/DTphDigiSpec.h"
9   #include "UserCode/L1RpcTriggerAnalysis/interface/CSCDigiSpec.h"
10   #include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
11 + #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
12  
13   #include "UserCode/L1RpcTriggerAnalysis/interface/Pattern.h"
14   #include "UserCode/L1RpcTriggerAnalysis/interface/GoldenPattern.h"
# Line 49 | Line 50 | PatternManager::~PatternManager()
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();
58 /*
59  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 */
66
75  
76    GoldenPattern::Key key( detref, ptref, chargeref, phiref);
77  
78    Pattern pattern;
79    theEvForPatCounter++;
80 <  for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
80 >  for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) {
81 >    DetId detId( is->first);    
82      bool isOK = pattern.add(*is);
83      if (!isOK) return;
84    }
85    if (pattern.size() == 0) return;
86    theEvUsePatCounter++;
87  
88 +
89    if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
90    theGPs[key].add(pattern);
81
91   }
92  
93   L1Obj PatternManager::check(const EventObj* ev, const TrackObj * simu, const HitSpecObj * hitSpec,  const VDigiSpec & vDigi)
94   {
95    L1Obj candidate;
96 +  if (theConfig.exists("patternInpFile") &&
97 +      theConfig.exists("patternOutFile")) return candidate;
98 +
99    if (!hitSpec) return candidate;
100    if (hitSpec->rawId() == 0 ) return candidate;
101 <  double phiref = hitSpec->position().phi();
102 <  double ptref  = simu->pt();
101 >  //float phiref = hitSpec->position().phi();
102 >  float ptref  = simu->pt();
103    int    chargeref = simu->charge();
104    unsigned int detref =  hitSpec->rawId();
93 /*
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;
105  
106 < */
107 < //  std::cout <<" ------------------ EVENT: " << std::endl;
106 >  VDigiSpec::const_iterator is=vDigi.end();
107 >  for (is = vDigi.begin(); is!=vDigi.end(); ++is) {  
108 >    if(is->first==hitSpec->rawId()) break;
109 >  }
110 >  if(is==vDigi.end()){return candidate;} //Require a digi in reference station. Creates inefficiency!
111 >  RPCDigiSpec digiRef(is->first, is->second);
112 >  int stripRef = digiRef.halfStrip();
113 >  
114    std::vector<Pattern> vpattern(1);
115    theEvForPatCounter++;
116 <  for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); is++) {
117 <    bool isOK = Pattern::add(vpattern,*is);
116 >  static bool skipRpcData   = theConfig.getUntrackedParameter<bool>("skipRpcData",  false);
117 >  static bool skipDtCscData = theConfig.getUntrackedParameter<bool>("skipDtCscData",false);
118 >  for (VDigiSpec::const_iterator is= vDigi.begin(); is!=vDigi.end(); ++is) {
119 >    DetId detId( is->first);
120 >    if (skipRpcData   && detId.subdetId()==MuonSubdetId::RPC) continue;
121 >    if (skipDtCscData && (detId.subdetId()==MuonSubdetId::DT || detId.subdetId()==MuonSubdetId::CSC) ) continue;
122 >    if(detId.subdetId()==MuonSubdetId::DT && DTphDigiSpec(is->first, is->second).bxNum()!=0) continue;
123 >    Pattern::add(vpattern,*is);
124 >    if (vpattern.size() > 100) break;
125    }
126    if (vpattern[0].size() == 0) return candidate;
109 //  std::cout <<" ------------------ END EVENT, COMPARE" << std::endl;
110
111  GoldenPattern::Key thisKey(detref, ptref, chargeref, phiref );
112 //  std::cout << thisKey <<" PATTENR_SIZE: "<<pattern.size()<< std::endl;
127  
128 +  GoldenPattern::Key thisKey(detref, ptref, chargeref,stripRef);
129 +  //std::cout << thisKey << std::endl;
130 +  /*
131 +  RPCDetId aId(637599786);
132 +  std::cout<<aId<<std::endl;
133 +  RPCDetId bId(637599914);
134 +  std::cout<<bId<<std::endl;
135 +  */
136    GoldenPattern::Result bestMatching;
137    GoldenPattern::Key    bestKey;
138 <  for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
139 <  for (auto ip=vpattern.begin(); ip!= vpattern.end();++ip) {
140 <    const Pattern & pattern = *ip;
141 < //    if (!(thisKey==igps->first)) continue;
142 < //    std::cout << " HAS PATTERN "<<pattern << std::endl;
143 <    GoldenPattern & gp = igps->second;
144 <    GoldenPattern::Result result = gp.compare(pattern);
145 < //    if (!result.hasRpcDet(637602109) && !result.hasRpcDet(637634877) && !result.hasRpcDet(637599914) && !result.hasRpcDet(637632682)) continue;
146 < //   if (!result.hasRpcDet(igps->first.theDet)) continue;
147 < //   if (result.nMatchedTot() < 5 )continue;
148 < //   if (!result) continue;
149 < //    std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<" is Less: "<<(result<bestMatching)<<" isBetter: "<<(result>bestMatching)<<" isBerres: "<<(bestMatching<result)  ; //<<std::endl;
150 <    if (bestMatching < result) {
151 <      bestMatching = result;
152 <      bestKey =  igps->first;
153 < //      std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl;
154 <    }
155 < //else std::cout <<std::endl;
156 <  }
157 <  }
158 <
159 < //  std::cout <<" ------------------ END COMPARE: " << std::endl;
160 < //  std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::cout <<" ######"<<" pt: "<< bestKey.ptValue()<<std::endl;
138 >  for (auto ip=vpattern.cbegin(); ip!= vpattern.cend();++ip) {
139 >    Pattern pattern;
140 >    int phiRotation = -1;
141 >    ///Find rotation degree to match the base set of patterns. This still can be optimised.
142 >    for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) {
143 >      ///Rotate the hit pattern to math the golden pattern      
144 >      for(int iStep=0;iStep<5;++iStep){
145 >        uint32_t rawIdRotated = Pattern::rotateDetId(digiRef.rawId(),iStep);
146 >        if(rawIdRotated==igps->first.theDet && igps->first.thePhiCode==digiRef.halfStrip()){
147 >          pattern = ip->getRotated(iStep);
148 >          phiRotation = iStep;
149 >          break;
150 >        }
151 >      }
152 >      GoldenPattern::Key thisRotatedKey(Pattern::rotateDetId(digiRef.rawId(),phiRotation), ptref, chargeref,stripRef);
153 >      if(!pattern.size()) continue;
154 >      //if(pattern.size()<7) return candidate;
155 >      //if(!(thisRotatedKey==igps->first)) continue;
156 >      
157 >      GoldenPattern & gp = igps->second;
158 >      GoldenPattern::Result result = gp.compare(pattern);  
159 >      /*
160 >      std::cout<<"Step: "<<phiRotation<<std::endl;
161 >      std::cout<<*ip<<std::endl;
162 >      std::cout<<pattern<<std::endl;
163 >      std::cout<<gp<<std::endl;
164 >      std::cout <<"PATT KEY: "<<igps->first<<" "<<result<<std::endl;
165 >      */
166 >      if (bestMatching < result) {
167 >        bestMatching = result;
168 >        bestKey =  igps->first;
169 >        //      std::cout <<" ----"<<" pt: "<< bestKey.ptValue()<<std::endl;
170 >      }
171 >      //else std::cout <<std::endl;
172 >    }
173 >  }
174 >
175 >  //std::cout <<" ------------------ END COMPARE: " << std::endl;
176 >  //std::cout <<"THIS KEY: "<<thisKey << std::endl;
177 >  //std::cout <<"BEST KEY: "<<bestKey<<" "<< bestMatching<<std::endl;
178 >  //abort();
179    if (bestMatching) {
180      candidate.pt = bestKey.ptValue();
181 <    candidate.eta = 1.;
181 >    candidate.eta = bestKey.etaValue();
182      candidate.phi = bestKey.phiValue();
183 +    candidate.charge = bestKey.chargeValue();
184      candidate.q   = bestMatching.nMatchedTot();
185      candidate.type = L1Obj::OTF;
186    }
# Line 157 | Line 198 | void PatternManager::beginJob()
198    static ENTRY entry;
199    tree->SetBranchAddress("entry",&entry);
200    Int_t nentries = (Int_t) tree->GetEntries();
201 <  for (Int_t i=0; i<nentries; i++) {
201 >  for (Int_t i=0; i<nentries; ++i) {
202      tree->GetEntry(i);
203      GoldenPattern::Key key;
204      key.theDet =     entry.key_det;
205      key.thePtCode =  entry.key_pt;
206      key.thePhiCode = entry.key_phi;
207      key.theCharge =  entry.key_ch;
208 +
209      GoldenPattern::PosBenCase pat_Case = static_cast<GoldenPattern::PosBenCase>(entry.pat_Case);
210      if (theGPs.find(key)==theGPs.end()) theGPs[key]=GoldenPattern(key);
211      theGPs[key].add(pat_Case, entry.patDet, entry.posOrBend, entry.freq);
# Line 172 | Line 214 | void PatternManager::beginJob()
214    patternInpFile.Close();
215   }
216  
217 < void PatternManager::endJob()
176 < {
177 <  for (std::map< GoldenPattern::Key, GoldenPattern>::iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
178 <    GoldenPattern & gp = igps->second;
179 <    gp.purge();
180 <  }
217 > void PatternManager::endJob(){
218  
219    if ( !theConfig.exists("patternOutFile") ) return;
220    std::string patternOutFileName = theConfig.getParameter<std::string>("patternOutFile");
221    TFile patternOutFile( patternOutFileName.c_str(),"RECREATE");
222 <
222 >  
223 >  if (theConfig.exists("patternInpFile") && theConfig.exists("patternOutFile")){
224 >    for (auto igps = theGPs.begin(); igps != theGPs.end();) {
225 >      GoldenPattern & gp = igps->second;      
226 >      if(!gp.purge()) {theGPs.erase(igps++); } else { ++igps; }
227 >    }
228 >  }
229 >  
230    static ENTRY entry;
231    TTree *tree = new TTree("FlatPatterns","FlatPatterns");
232    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");
233  
234 <  for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); igps++) {
234 >  for (std::map< GoldenPattern::Key, GoldenPattern>::const_iterator igps = theGPs.begin(); igps != theGPs.end(); ++igps) {
235      const GoldenPattern & gp = igps->second;
236      entry.key_det =  gp.theKey.theDet;
237      entry.key_pt =  gp.theKey.thePtCode;
238      entry.key_phi =  gp.theKey.thePhiCode;
239      entry.key_ch =  gp.theKey.theCharge;
240 <    for (unsigned int iCase =1; iCase <=5; ++iCase) {
241 <      entry.pat_Case = iCase;
242 <      const GoldenPattern::DetFreq * detFreq = 0;
243 <      if (iCase==GoldenPattern::POSRPC) detFreq = &gp.posRpc;
200 <      if (iCase==GoldenPattern::POSCSC) detFreq = &gp.posCsc;
201 <      if (iCase==GoldenPattern::BENCSC) detFreq = &gp.bendingCsc;
202 <      if (iCase==GoldenPattern::POSDT ) detFreq = &gp.posDt;
203 <      if (iCase==GoldenPattern::BENDT ) detFreq = &gp.bendingDt;
204 <      for (GoldenPattern::DetFreq::const_iterator idf = detFreq->begin(); idf != detFreq->end(); idf++) {
240 >    
241 >    for (auto it=gp.PattCore.cbegin();it!=gp.PattCore.cend();++it){
242 >      entry.pat_Case = it->first;
243 >      for (GoldenPattern::DetFreq::const_iterator idf = it->second.cbegin(); idf !=it->second.cend(); ++idf) {
244          entry.patDet = idf->first;
245 <        for (GoldenPattern::MFreq::const_iterator imf = idf->second.begin(); imf != idf->second.end(); imf++) {
245 >        for (GoldenPattern::MFreq::const_iterator imf = idf->second.cbegin(); imf != idf->second.cend(); ++imf) {
246            entry.posOrBend = imf->first;
247            entry.freq = imf->second;
248            tree->Fill();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines