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

Comparing UserCode/L1RpcTriggerAnalysis/src/Pattern.cc (file contents):
Revision 1.5 by akalinow, Tue Jun 25 10:49:35 2013 UTC vs.
Revision 1.7 by akalinow, Thu Jul 11 11:25:22 2013 UTC

# Line 9 | Line 9
9   #include "UserCode/L1RpcTriggerAnalysis/interface/CSCDigiSpec.h"
10   #include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
11  
12 < bool Pattern::operator==(const Pattern& o) const
13 < {
14 <  unsigned int thissize = theData.size();
15 < if (thissize != o.size()) return false;
12 > /////////////////////////////////////////////////
13 > /////////////////////////////////////////////////
14 > uint32_t Pattern::rotateDetId(uint32_t rawId, int step){
15 >
16 >  ///Assume 60deg steps
17 >  while(step<0){step+=6;}
18 >
19 >  uint32_t rawIdRotated = rawId;
20 >
21 >  DetId detId(rawId);
22 >  switch (detId.subdetId()){    
23 >  case MuonSubdetId::RPC: {
24 >    RPCDetId rpcDet(rawId);
25 >    ///Barrel has 30deg sectors
26 >    if(rpcDet.region()==0) step*=2;
27 >    RPCDetId rpcDetRotated(rpcDet.region(),
28 >                           rpcDet.ring(),
29 >                           rpcDet.station(),
30 >                           (rpcDet.sector()+step-1)%12+1,
31 >                           rpcDet.layer(),
32 >                           rpcDet.subsector(),
33 >                           rpcDet.roll());
34 >    return rpcDetRotated.rawId();      
35 >  }
36 >  case MuonSubdetId::DT: {
37 >    ///Barrel has 30deg sectors
38 >    step*=2;
39 >    DTChamberId dtDet(rawId);
40 >    DTChamberId dtDetRotated(dtDet.wheel(),
41 >                             dtDet.station(),
42 >                             (dtDet.sector()+step)%12);
43 >    return dtDetRotated.rawId();      
44 >    break;
45 >  }
46 >  case MuonSubdetId::CSC: {
47 >    CSCDetId cscDet(rawId);
48 >    //Most CSC chambers are 10deg wide
49 >    int cscFactor = 6;
50 >    int maxChamber = 36;
51 >    ///Some are 20deg wide
52 >    if(cscDet.station()>1 && cscDet.ring()==1){
53 >        cscFactor = 3;
54 >        maxChamber = 18;
55 >      }
56 >    int cscStep = step*cscFactor;
57 >    CSCDetId cscDetRotated(cscDet.endcap(),
58 >                           cscDet.station(),
59 >                           cscDet.ring(),
60 >                           (cscDet.chamber()+cscStep-1)%maxChamber+1,
61 >                           cscDet.layer());
62 >    return cscDetRotated.rawId();      
63 >  }
64 >  }  
65 >  return rawIdRotated;
66 > }
67 > /////////////////////////////////////////////////
68 > /////////////////////////////////////////////////
69 > Pattern Pattern::getRotated(int step) const{
70 >
71 >  Pattern rotated;
72 >  
73 >  for (auto it = theData.cbegin(); it != theData.cend(); ++it){
74 >    rotated.add(std::pair<uint32_t,  unsigned int >(rotateDetId(it->first,step),it->second));
75 >  }
76 >  return rotated;
77 > }
78 > /////////////////////////////////////////////////
79 > /////////////////////////////////////////////////
80 > bool Pattern::operator==(const Pattern& o) const{
81 >  unsigned int thissize = theData.size();
82 >  if (thissize != o.size()) return false;
83 >
84 >  for (auto it = theData.cbegin(); it != theData.cend(); ++it){
85 >    auto itComp = o.theData.find(it->first);    
86 >    if(itComp==o.theData.cend()) return false;
87 >    if(itComp->second!=it->second) return false;    
88 >  }
89  
17  for (unsigned int idx=0; idx<thissize; idx++) {
18     if (theData[idx].first != o.theData[idx].first) return false;
19     if (theData[idx].second != o.theData[idx].second) return false;
20  }
21
90    return true;
91   }
92  
93 < Pattern Pattern::addOrCopy( std::pair<uint32_t,  unsigned int > aData)
26 < {
93 > Pattern Pattern::addOrCopy( std::pair<uint32_t,  unsigned int > aData){
94  
95 <  for (unsigned int idx=0; idx < theData.size(); ++idx) {
96 <    if (theData[idx].first == aData.first) {
97 <      Pattern modified =  *this;
98 <      modified.theData[idx].second = aData.second;
99 <      return modified;
33 < //      if (*this == modified) return Pattern(); // nothing to do
34 < //      else  return modified;                   // really duplicate
35 <    }
95 >  auto it = theData.find(aData.first);    
96 >  if(it!= theData.cend()){
97 >    Pattern modified =  *this;
98 >    modified.theData[aData.first] = aData.second;
99 >    return modified;
100    }
101 <  theData.push_back(aData);
101 >  theData[aData.first] = aData.second;
102    return Pattern();
103   }
104  
105 < void Pattern::add (  std::vector<Pattern> & vpat, std::pair<uint32_t,  unsigned int > aData)
105 > void Pattern::add (std::vector<Pattern> & vpat, std::pair<uint32_t,  unsigned int > aData)
106   {
107 <  std::vector<Pattern> copied;
108 <  for (std::vector<Pattern>::iterator ip = vpat.begin(); ip != vpat.end(); ++ip) {
109 <    Pattern modified =  ip->addOrCopy(aData);
110 <    if (modified && (find(copied.begin(), copied.end(), modified) == copied.end()) ) copied.push_back(modified);
107 >  //Use indexing to avoid problem with iterator invalidation afer adding new elements to vector
108 >  uint32_t vSize = vpat.size();
109 >  for(uint32_t index = 0;index<vSize;++index){
110 >    Pattern modified =  vpat[index].addOrCopy(aData);
111 >    if (modified && (find(vpat.begin(), vpat.end(), modified) == vpat.end()) ) vpat.push_back(modified);
112    }
48  if (copied.size() != 0) vpat.insert(vpat.end(), copied.begin(), copied.end());
113   }
114  
115  
52
116   std::ostream & operator << (std::ostream &out, const Pattern &o)
117   {
118    out <<" Pattern:  size: "<<o.size();
119 <  for (Pattern::DataType::const_iterator it=o.theData.begin(); it!= o.theData.end(); it++) {
119 >  for (auto it = o.theData.cbegin(); it != o.theData.cend(); ++it){
120      DetId detId( it->first);
121      switch (detId.subdetId()) {
122 <      case MuonSubdetId::RPC: { out << std::endl <<" RPC: "<<RPCDigiSpec(it->first, it->second);  break; }
123 <      case MuonSubdetId::DT:  { out << std::endl <<" DT:  "<<DTphDigiSpec(it->first, it->second); break; }
124 <      case MuonSubdetId::CSC: { out << std::endl <<" CSC: "<<CSCDigiSpec(it->first, it->second);  break; }
122 >    case MuonSubdetId::RPC: { out << std::endl <<RPCDetId(it->first)<<" "<<RPCDigiSpec(it->first, it->second);  break; }
123 >    case MuonSubdetId::DT:  { out << std::endl <<DTChamberId(it->first)<<" "<<DTphDigiSpec(it->first, it->second); break; }
124 >    case MuonSubdetId::CSC: { out << std::endl <<CSCDetId(it->first)<<" "<<CSCDigiSpec(it->first, it->second);  break; }
125      };
126    }
127    return out;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines