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

Comparing UserCode/L1RpcTriggerAnalysis/src/GoldenPattern.cc (file contents):
Revision 1.6 by akalinow, Tue Jun 25 11:06:02 2013 UTC vs.
Revision 1.8 by akalinow, Thu Jul 11 11:25:22 2013 UTC

# Line 14 | Line 14
14   #include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
15  
16   void GoldenPattern::Result::runNoCheck() const {
17  double fract = 1;
17  
18 +  float fract = 1;
19    for(auto mType=myResults.cbegin();mType!=myResults.cend();++mType){    
20      for (auto it=mType->second.cbegin(); it!=mType->second.cend();++it) fract *= norm(mType->first,it->second);
21    }
22 +
23    unsigned int nTot = 0;
24    for(auto it=nMatchedPoints.cbegin();it!=nMatchedPoints.cend();++it) nTot+=it->second;    
25  
26    theValue*=(myResults[GoldenPattern::POSRPC].size()==nMatchedPoints[GoldenPattern::POSRPC]);
27    theValue*=(myResults[GoldenPattern::POSDT].size()==nMatchedPoints[GoldenPattern::POSDT]);
28    theValue*=(myResults[GoldenPattern::POSCSC].size()==nMatchedPoints[GoldenPattern::POSCSC]);
29 <  theValue = ( nTot > 4) ? pow(fract, 1./((double) nTot)) : 0.;
29 >  theValue = ( nTot > 4) ? pow(fract, 1./((float) nTot)) : 0.;
30 >  //AK theValue = ( nTot > 4) ? -log(fract) : 9999.0;
31   }
32  
33 < double GoldenPattern::Result::norm(GoldenPattern::PosBenCase where, double whereInDist) const {
34 <  double normValue = 2.*(0.5-fabs(whereInDist-0.5));  
35 <  static const double epsilon = 1.e-9;
33 > float GoldenPattern::Result::norm(GoldenPattern::PosBenCase where, float whereInDist) const {
34 >  float normValue = 2.*(0.5-fabs(whereInDist-0.5));  
35 >  //normValue = 0.95*whereInDist; //AK
36 >
37 >  static const float epsilon = 1.e-9;
38    if (normValue > epsilon) ++nMatchedPoints[where];
39 <  else normValue =1.;
39 >  else normValue = 0.05;
40    return normValue;
41   }
42  
# Line 54 | Line 58 | GoldenPattern::Result::operator bool() c
58    return (value() > 0.1); // && hasStation1 && hasStation2);
59   }
60  
61 < double GoldenPattern::Result::value() const {
61 > float GoldenPattern::Result::value() const {
62    run();
63    return theValue;
64   }
# Line 70 | Line 74 | unsigned int GoldenPattern::Result::nMat
74   std::ostream & operator << (std::ostream &out, const GoldenPattern::Result& o)
75   {
76    o.run();
77 <
74 <  /*
77 >  
78    out <<"Result: "
79        << " value: "<<o.theValue
80 <      <<" nPos+Ben: (";
81 <  for(auto mType=o.myResults.cbegin();
82 <      mType!=myResults.cend();++mType){
80 <    out<<o.nMatchedPoints[iType]<<"/"<<o.myResults[mType].size()<<", ";
80 >      <<" (POSRPC, POSCSC, BENCSC, POSDT, BENDT)(";
81 >  for(auto cit=o.myResults.cbegin();cit!=o.myResults.cend();++cit){
82 >    out<<o.nMatchedPoints[cit->first]<<"/"<<cit->second.size()<<", ";
83    }
84 <  out <<", tot:"<<o.nMatchedTot()<<")";
85 <  */
84 <  /*
85 <  <<o.nMatchedPosCsc<<"/"<<o.posCscResult.size()<<"+"<<o.nMatchedBenCsc<<"/"<<o.benCscResult.size()
86 <  <<", "<<o.nMatchedPosDt <<"/"<<o.posDtResult.size()<<"+"<<o.nMatchedBenDt<<"/"<<o.benDtResult.size()
87 <  <<", "<<o.nMatchedPosRpc<<"/"<<o.posRpcResult.size()
88 <  */
84 >  out <<"tot:"<<o.nMatchedTot()<<")";
85 >  
86    return out;
87   }
88 <
88 > //////////////////////////////////////////////////
89 > //////////////////////////////////////////////////
90   void GoldenPattern::add( GoldenPattern::PosBenCase aCase, uint32_t rawId, int posOrBen, unsigned int freq){
91    PattCore[aCase][rawId][posOrBen] += freq;
92   }
93 <
94 <
93 > //////////////////////////////////////////////////
94 > //////////////////////////////////////////////////
95   void GoldenPattern::add(const Pattern & p) {
96  
97    const Pattern::DataType & detdigi = p ;
# Line 110 | Line 108 | void GoldenPattern::add(const Pattern &
108        }
109        case MuonSubdetId::DT: {
110          DTphDigiSpec digi(rawId, is->second);
111 <        if (digi.bxNum() != 0 || digi.bxCnt() != 0 || digi.ts2() != 0) break;  
111 >        if (digi.bxNum() != 0 || digi.bxCnt() != 0 || digi.ts2() != 0 ||  digi.code()<4) break;
112          PattCore[GoldenPattern::POSDT][rawId][digi.phi()]++;
113          PattCore[GoldenPattern::BENDT][rawId][digi.phiB()]++;
114          break;
# Line 140 | Line 138 | GoldenPattern::Result GoldenPattern::com
138      }
139    }
140    if(nTot<5) return result;
141 <
141 >  /////////////////////////////////////////////////////////////////////
142  
143    SystFreq::const_iterator cit;
144    DetFreq::const_iterator idm;
# Line 149 | Line 147 | GoldenPattern::Result GoldenPattern::com
147      uint32_t rawId = is->first;
148      DetId detId(rawId);
149      if (detId.det() != DetId::Muon){
150 <      std::cout << "PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
150 >      std::cout << "GoldenPattern::compare PROBLEM: hit in unknown Det, detID: "<<detId.det()<<std::endl;
151        return result;
152      }
153      if (detId.subdetId() == MuonSubdetId::RPC) {
154        RPCDigiSpec digi(rawId, is->second);
155        mType = GoldenPattern::POSRPC;
156        cit = PattCore.find(mType);
157 <      if(cit==PattCore.cend()){
160 <        std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl;
161 <        return result;
162 <      }
157 >      if(cit==PattCore.cend())  return result; //AK: Ugly, FIX.
158        idm = cit->second.find(rawId);
159        if (idm != cit->second.cend() ) {
160 <        double f = whereInDistribution(digi.halfStrip(), idm->second);
160 >        float f = whereInDistribution(digi.halfStrip(), idm->second);
161          result.myResults[mType].push_back(std::make_pair(rawId, f));
162          RPCDetId rpc(rawId);
163          if(rpc.station()==1) result.hasStation1 = true;
# Line 173 | Line 168 | GoldenPattern::Result GoldenPattern::com
168        DTphDigiSpec digi(rawId, is->second);
169        mType = GoldenPattern::POSDT;
170        cit = PattCore.find(mType);
171 <      if(cit==PattCore.cend()){
177 <        std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl;
178 <        return result;
179 <      }
171 >      if(cit==PattCore.cend()) return result;
172        idm = cit->second.find(rawId);
173        if (idm != cit->second.cend() ) {
174 <        double f = whereInDistribution(digi.phi(), idm->second);
174 >        float f = whereInDistribution(digi.phi(), idm->second);
175          result.myResults[mType].push_back(std::make_pair(rawId, f));
176          DTChamberId dt(rawId);
177          if(dt.station()==1) result.hasStation1 = true;
# Line 187 | Line 179 | GoldenPattern::Result GoldenPattern::com
179        }
180        mType = GoldenPattern::BENDT;
181        cit = PattCore.find(mType);
182 <      if(cit==PattCore.cend()){
191 <        std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl;
192 <        return result;
193 <      }
182 >      if(cit==PattCore.cend()) return result;
183        idm = cit->second.find(rawId);
184        if (idm != cit->second.cend() ) {
185 <        double f = whereInDistribution(digi.phiB(), idm->second);
185 >        float f = whereInDistribution(digi.phiB(), idm->second);
186          result.myResults[mType].push_back(std::make_pair(rawId, f));
187        }
188      }
# Line 201 | Line 190 | GoldenPattern::Result GoldenPattern::com
190        CSCDigiSpec digi(rawId, is->second);
191        mType = GoldenPattern::POSCSC;
192        cit = PattCore.find(mType);
193 <      if(cit==PattCore.cend()){
205 <        std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl;
206 <        return result;
207 <      }
193 >      if(cit==PattCore.cend()) return result;
194        auto idm = cit->second.find(rawId);
195        if (idm != cit->second.cend() ) {
196 <        double f = whereInDistribution(digi.strip(), idm->second);
196 >        float f = whereInDistribution(digi.strip(), idm->second);
197          result.myResults[mType].push_back(std::make_pair(rawId, f));
198          CSCDetId csc(rawId);
199          if (csc.station()==1) result.hasStation1 = true;
# Line 215 | Line 201 | GoldenPattern::Result GoldenPattern::com
201        }
202        mType = GoldenPattern::BENCSC;
203        cit = PattCore.find(mType);
204 <      if(cit==PattCore.cend()){
219 <        std::cout << "PROBLEM: unknown measurement type: "<<mType<<std::endl;
220 <        return result;
221 <      }
204 >      if(cit==PattCore.cend()) return result;
205        idm = cit->second.find(rawId);
206        if (idm != cit->second.cend() ) {
207 <        double f = whereInDistribution(digi.pattern(), idm->second);
207 >        float f = whereInDistribution(digi.pattern(), idm->second);
208          result.myResults[mType].push_back(std::make_pair(rawId, f));
209        }
210      }
# Line 230 | Line 213 | GoldenPattern::Result GoldenPattern::com
213    return result;
214   }
215  
216 < double GoldenPattern::whereInDistribution( int obj, const GoldenPattern::MFreq & m) const
216 > float GoldenPattern::whereInDistribution( int obj, const GoldenPattern::MFreq & m) const
217   {
218  
219 <  double sum_before = 0;
220 <  double sum_after = 0;
221 <  double sum_obj = 0;
219 >  float sum_before = 0;
220 >  float sum_after = 0;
221 >  float sum_obj = 0;
222    for (MFreq::const_iterator im = m.begin(); im != m.end(); ++im) {
223      if (im->first  < obj) sum_before+= im->second;
224      if (im->first == obj) sum_obj = im->second;  
225      if (im->first  > obj) sum_after += im->second;
226    }
227 <  double sum = std::max(1.,sum_before+sum_after+sum_obj );
227 >  float sum = std::max((float)1.,sum_before+sum_after+sum_obj );
228    //return sum_obj/sum; //AK
229    return (sum_before+sum_obj/2.)/sum;
230   }
231  
232 < void GoldenPattern::purge(){
232 > bool GoldenPattern::purge(){
233  
234    bool remove = false;
235    int pos;
236    unsigned int bef2, bef1, aft1, aft2, aft3;
237 <  for (auto isf=PattCore.begin();isf!=PattCore.end();++isf){
237 >  for (auto isf=PattCore.begin();isf!=PattCore.end();){
238      for (auto idf = isf->second.begin(); idf !=isf->second.end();) {
239        for (auto imf = idf->second.begin(); imf != idf->second.end();) {
240          remove = false;
# Line 269 | Line 252 | void GoldenPattern::purge(){
252        }
253        if (idf->second.size()==0) isf->second.erase(idf++);  else  ++idf;
254      }
255 <    break;
255 >      if (isf->second.size()==0) PattCore.erase(isf++);  else  ++isf;
256    }
257 +  ///Usefull pattern has at least 4 measurements and has a RPC measurement
258 +  return PattCore.find(POSRPC)!=PattCore.end() && PattCore.size()>4;
259   }
260  
261   std::ostream & operator << (std::ostream &out, const GoldenPattern & o) {
# Line 281 | Line 266 | std::ostream & operator << (std::ostream
266  
267   for (auto isf=o.PattCore.cbegin();isf!=o.PattCore.cend();++isf){
268     for (auto idf = isf->second.cbegin(); idf!=isf->second.cend();++idf) {      
269 <     out <<typeInfos[isf->first]<<" Det: "<< idf->first<<" Value: ";
269 >     out <<typeInfos[isf->first]<<" Det: "<< idf->first;
270 >     if(typeInfos[isf->first].find("RPC")!=std::string::npos){
271 >       RPCDetId rpc(idf->first);
272 >       out<<" ("<<rpc<<") ";
273 >     }
274 >     if(typeInfos[isf->first].find("CSC")!=std::string::npos){
275 >       CSCDetId csc(idf->first);
276 >       out<<" ("<<csc<<") ";
277 >     }
278 >     if(typeInfos[isf->first].find("DT")!=std::string::npos){
279 >       DTChamberId dt(idf->first);
280 >       out<<" ("<<dt<<") ";
281 >     }
282 >     out <<" Value: ";
283       for (auto imf = idf->second.cbegin(); imf != idf->second.cend();++imf)
284         { out << imf->first<<":"<<imf->second<<", "; }
285       out << std::endl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines