CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCLinkSynchroStat.cc
Go to the documentation of this file.
5 
6 #include <algorithm>
7 #include <sstream>
8 #include <iostream>
9 #include <iomanip>
10 
11 bool RPCLinkSynchroStat::LessLinkName::operator()(const BoardAndCounts& o1, const BoardAndCounts& o2) { return o1.first < o2.first; }
12 bool RPCLinkSynchroStat::LessCountSum::operator()(const BoardAndCounts& o1, const BoardAndCounts& o2) { return o1.second.sum()< o2.second.sum(); }
13 
14 void RPCLinkSynchroStat::add(const std::string & lbName, const unsigned int *hits)
15 {
16  LinkBoard lb(lbName);
17  SynchroCounts counts(hits);
18  for (std::vector<BoardAndCounts>::iterator it = theLinkStatMap.begin(); it != theLinkStatMap.end(); ++it) if (it->first == lb) it->second += counts;
19 }
20 
22 {
23  for (std::vector<ChamberAndPartition>::const_iterator it=theChamberAndPartitions.begin(); it != theChamberAndPartitions.end(); ++it) {
24  if( (*it)==part) return 1;
25  }
26  theChamberAndPartitions.push_back(part);
27  return 0;
28 }
29 
31 {
32  for (std::vector<LinkBoardElectronicIndex>::const_iterator it=theElePaths.begin(); it != theElePaths.end(); ++it) {
33  if ( it->dccId == ele.dccId
34  && it->dccInputChannelNum == ele.dccInputChannelNum
35  && it->tbLinkInputNum == ele.tbLinkInputNum
36  && it->lbNumInLink == ele.lbNumInLink) return 1;
37  }
38  theElePaths.push_back(ele);
39  return 0;
40 }
41 
43 {
44  for (unsigned int i=0; i <8 ; ++i) if(theCounts[i]) return i;
45  return 8;
46 }
47 
48 void RPCLinkSynchroStat::SynchroCounts::set(unsigned int bxDiff)
49 {
50  if (bxDiff < 8) theCounts[bxDiff]=1;
51 }
52 
54 {
55  if (bxDiff < 8) theCounts[bxDiff]++;
56 }
57 
59 {
60  for (unsigned int i=0; i<8; ++i) theCounts[i]+=rhs.theCounts[i];
61  return *this;
62 }
63 
65 { unsigned int result = 0; for (unsigned int i=0; i<8; ++i) result += theCounts[i]; return result; }
66 
68 { double result = 0.; for (unsigned int i=0; i<8; ++i) result += i*theCounts[i]; return result; }
69 
71 { unsigned int sum = mom0(); return sum==0 ? 0. : mom1()/sum; }
72 
74 {
75  double result = 0.;
76  int sum = mom0();
77  if (sum==0) return 0.;
78  double mean = mom1()/sum;
79  for (int i=0; i<8; ++i) result += theCounts[i]*(mean-i)*(mean-i);
80  result /= sum;
81  return sqrt(result);
82 }
83 
85 {
86  std::ostringstream str;
87  str<<" mean: "<<std::setw(8)<<mean();
88  str<<" rms: "<<std::setw(8)<<rms();
89  str<<" counts:"; for (int i=0; i<8; ++i) str<<" "<<std::setw(4)<<theCounts[i];
90  return str.str();
91 }
92 
94 {
95  for (unsigned int idx=0; idx <8; ++idx) if (theCounts[idx] != o.theCounts[idx]) return false;
96  return true;
97 }
98 
99 
100 
101 
102 
104  : theUseFirstHitOnly(useFirstFitOnly)
105 {
106  for (unsigned int i1=0; i1<=MAXDCCINDEX; ++i1) {
107  for (unsigned int i2=0; i2<=MAXRBCINDEX; i2++) {
108  for (unsigned int i3=0; i3 <=MAXLINKINDEX; ++i3) {
109  for (unsigned int i4=0; i4<=MAXLBINDEX; ++i4) {
110  theLinkStatNavi[i1][i2][i3][i4]=0;
111  }
112  }
113  }
114  }
115  theLinkStatMap.push_back( std::make_pair(LinkBoard("Dummy"), SynchroCounts()) );
116 }
117 
118 void RPCLinkSynchroStat::init(const RPCReadOutMapping* theCabling, bool addChamberInfo)
119 {
120  if (!theCabling) return;
121  std::vector<const DccSpec*> dccs = theCabling->dccList();
122  for (std::vector<const DccSpec*>::const_iterator it1= dccs.begin(); it1!= dccs.end(); ++it1) {
123  const std::vector<TriggerBoardSpec> & rmbs = (*it1)->triggerBoards();
124  for (std::vector<TriggerBoardSpec>::const_iterator it2 = rmbs.begin(); it2 != rmbs.end(); ++it2) {
125  const std::vector<LinkConnSpec> & links = it2->linkConns();
126  for (std::vector<LinkConnSpec>::const_iterator it3 = links.begin(); it3 != links.end(); ++it3) {
127  const std::vector<LinkBoardSpec> & lbs = it3->linkBoards();
128  for (std::vector<LinkBoardSpec>::const_iterator it4=lbs.begin(); it4 != lbs.end(); ++it4) {
129  LinkBoardElectronicIndex ele = { (*it1)->id(), it2->dccInputChannelNum(), it3->triggerBoardInputNumber(), it4->linkBoardNumInLink()};
130  LinkBoard linkBoard(it4->linkBoardName());
131  BoardAndCounts candid = std::make_pair(linkBoard,SynchroCounts());
132  std::vector<BoardAndCounts>::iterator candid_place = lower_bound(theLinkStatMap.begin(), theLinkStatMap.end(), candid, LessLinkName());
133  if (candid_place != theLinkStatMap.end() && candid.first == candid_place->first) {
134  candid_place->first.add(ele);
135  }
136  else {
137  candid_place = theLinkStatMap.insert(candid_place,candid);
138  candid_place->first.add(ele);
139  if (addChamberInfo) {
140  const std::vector<FebConnectorSpec> & febs = it4->febs();
141  for (std::vector<FebConnectorSpec>::const_iterator it5=febs.begin(); it5!= febs.end(); ++it5) {
142  std::string chamberName = it5->chamber().chamberLocationName();
143  std::string partitionName = it5->feb().localEtaPartitionName();
144  LinkBoard::ChamberAndPartition chamberAndPartition = std::make_pair(chamberName, partitionName);
145  candid_place->first.add(chamberAndPartition);
146  }
147  }
148  }
149  }
150  }
151  }
152  }
153  for (unsigned int idx=0; idx<theLinkStatMap.size(); ++idx) {
154  const std::vector<LinkBoardElectronicIndex> &paths= theLinkStatMap[idx].first.paths();
155  for (std::vector<LinkBoardElectronicIndex>::const_iterator it=paths.begin(); it!= paths.end();++it) {
156  theLinkStatNavi[it->dccId-DCCINDEXSHIFT][it->dccInputChannelNum][it->tbLinkInputNum][it->lbNumInLink]=idx;
157  }
158  }
159 // LogTrace("RPCLinkSynchroStat") <<" SIZE OF LINKS IS: " << theLinkStatMap.size() << endl;
160 }
161 
162 void RPCLinkSynchroStat::add(const RPCRawSynchro::ProdItem & vItem, std::vector<LinkBoardElectronicIndex> & problems)
163 {
164  std::vector< int > hits(theLinkStatMap.size(),0);
165  std::vector<ShortLinkInfo> slis;
166  for ( RPCRawSynchro::ProdItem::const_iterator it = vItem.begin(); it != vItem.end(); ++it) {
167  const LinkBoardElectronicIndex & path = it->first;
168  unsigned int bxDiff = it->second;
169  unsigned int eleCode = (path.dccId-DCCINDEXSHIFT)*100000 + path.dccInputChannelNum*1000 + path.tbLinkInputNum*10+path.lbNumInLink;
170  unsigned int idx = theLinkStatNavi[path.dccId-DCCINDEXSHIFT][path.dccInputChannelNum][path.tbLinkInputNum][path.lbNumInLink];
171  if (hits[idx]==0) {
172  ShortLinkInfo sli = { idx, std::vector<unsigned int>(1, eleCode), SynchroCounts() };
173  slis.push_back( sli );
174  hits[idx]=slis.size();
175  }
176  else {
177  std::vector<unsigned int> & v = slis[hits[idx]-1].hit_paths;
178  std::vector<unsigned int>::iterator iv = lower_bound (v.begin(), v.end(), eleCode);
179  if (iv == v.end() || (*iv) != eleCode) v.insert(iv,eleCode);
180  }
181  slis[hits[idx]-1].counts.set(bxDiff); // ensure one count per LB per BX
182  }
183 
184  for (std::vector<ShortLinkInfo>::const_iterator ic = slis.begin(); ic !=slis.end(); ++ic) {
185  if (theUseFirstHitOnly) {
186  theLinkStatMap[ic->idx].second.increment( ic->counts.firstHit() ); // first hit only
187  } else {
188  theLinkStatMap[ic->idx].second += ic->counts;
189  }
190  if (theLinkStatMap[ ic->idx].first.paths().size() != ic->hit_paths.size()) {
191  const std::vector<LinkBoardElectronicIndex> & paths = theLinkStatMap[ ic->idx].first.paths();
192  problems.insert(problems.end(),paths.begin(),paths.end());
193  }
194  }
195 
196 }
197 
199 {
200  std::ostringstream str;
201  std::vector<BoardAndCounts> sortedStat = theLinkStatMap;
202  stable_sort(sortedStat.begin(),sortedStat.end(),LessCountSum());
203  for (unsigned int idx=0; idx<sortedStat.size(); ++idx) {
204  const LinkBoard & board = sortedStat[idx].first;
205  const SynchroCounts & counts = sortedStat[idx].second;
206 
207  // DUMP LINKNAME
208  str << std::setw(20) << board.name();
209 
210  // DUMP COUNTS
211  str <<" "<<counts.print();
212 
213  //PATHS
214  str <<" paths: ";
215  const std::vector<LinkBoardElectronicIndex> & paths=board.paths();
216  for (std::vector<LinkBoardElectronicIndex>::const_iterator ip=paths.begin(); ip!=paths.end();++ip)
217  str<<"{"<<ip->dccId<<","<<std::setw(2)<<ip->dccInputChannelNum<<","<<std::setw(2)<<ip->tbLinkInputNum<<","<<ip->lbNumInLink<<"}";
218 
219  // DUMP CHAMBERS
220  std::map<std::string,std::vector<std::string> > chMap;
221  const std::vector<LinkBoard::ChamberAndPartition> & chamberAndPartitions = board.chamberAndPartitions();
222  for (std::vector<LinkBoard::ChamberAndPartition>::const_iterator it=chamberAndPartitions.begin(); it!=chamberAndPartitions.end();++it) {
223  std::vector<std::string> & partitions = chMap[it->first];
224  if (find(partitions.begin(), partitions.end(), it->second) == partitions.end()) partitions.push_back(it->second);
225  }
226  str << " chambers: ";
227  for (std::map<std::string,std::vector<std::string> >::const_iterator im=chMap.begin(); im != chMap.end(); ++im) {
228  str <<im->first<<"(";
229  for (std::vector<std::string>::const_iterator ip=im->second.begin(); ip != im->second.end(); ++ip) { str << *ip; if ((ip+1)!= (im->second.end()) ) str<<","; else str <<")"; }
230  }
231 
232 
233  str <<std::endl;
234  }
235  LogTrace("RPCLinkSynchroStat") <<"RPCLinkSynchroStat::dumpDelays, SIZE OF LINKS IS: " << theLinkStatMap.size() << std::endl;
236  return str.str();
237 }
bool operator()(const BoardAndCounts &o1, const BoardAndCounts &o2)
int i
Definition: DBlmapReader.cc:9
void init(const RPCReadOutMapping *theCabling, bool addChamberInfo)
bool operator()(const BoardAndCounts &o1, const BoardAndCounts &o2)
unsigned int theLinkStatNavi[MAXDCCINDEX+1][MAXRBCINDEX+1][MAXLINKINDEX+1][MAXLBINDEX+1]
std::vector< std::pair< LinkBoardElectronicIndex, int > > ProdItem
Definition: RPCRawSynchro.h:9
static const unsigned int MAXLINKINDEX
void increment(unsigned int bxDiff)
std::vector< const DccSpec * > dccList() const
all FEDs in map
static const unsigned int MAXLBINDEX
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
dictionary map
Definition: Association.py:205
const std::vector< ChamberAndPartition > & chamberAndPartitions() const
std::pair< LinkBoard, SynchroCounts > BoardAndCounts
RPCLinkSynchroStat(bool useFirstHitOnly)
SynchroCounts & operator+=(const SynchroCounts &rhs)
const std::vector< LinkBoardElectronicIndex > & paths() const
T sqrt(T t)
Definition: SSEVec.h:48
static const unsigned int MAXRBCINDEX
tuple result
Definition: query.py:137
std::pair< std::string, std::string > ChamberAndPartition
static const unsigned int DCCINDEXSHIFT
#define LogTrace(id)
void add(const RPCRawSynchro::ProdItem &counts, std::vector< LinkBoardElectronicIndex > &problems)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
part
Definition: HCALResponse.h:20
static const unsigned int MAXDCCINDEX
int add(const ChamberAndPartition &part)
if(dp >Float(M_PI)) dp-
bool operator==(const SynchroCounts &) const
const std::string & name() const
std::vector< unsigned int > theCounts
std::vector< BoardAndCounts > theLinkStatMap