CMS 3D CMS Logo

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