CMS 3D CMS Logo

CSCGangedWireGrouping.cc
Go to the documentation of this file.
2 
4 
5 #include <iostream>
6 #include <iomanip>
7 #include <algorithm>
8 #include <cstddef>
9 
11  const Container& consecutiveGroups,
12  const Container& wiresInConsecutiveGroups,
13  int numberOfGroups ) :
14  theNumberOfGroups(numberOfGroups) {
15 
16  int countGroups = 0; // counter for no. of wire groups
17  int firstWire = 1; // (virtual) wire number which is 1st in a group
18  int countConsecutive = 0; // counter for the sections in DDD
19 
20  for (int igs : consecutiveGroups) {
21  if ( igs != 0 ) {
22  // igs is number of consecutive groups each containing
23  // an identical number of wires
24  countGroups += igs;
25  for ( int ic = 0; ic != igs; ++ic ) {
26  theFirstWireOfEachWireGroup.emplace_back( firstWire );
27  int wiresInGroup= wiresInConsecutiveGroups[countConsecutive];
28  theNumberOfWiresPerWireGroup.emplace_back( wiresInGroup );
29  firstWire += wiresInGroup; // ready for next group
30  }
31  }
32  else {
33  // zero means a gap - just add in the no. of virtual wires in gap
34  firstWire += wiresInConsecutiveGroups[countConsecutive];
35  }
36  ++countConsecutive; // ready for next set of consecutive groups
37  }
38 
39  theNumberOfWires = firstWire - 1; // at end of loop we're on 1st for next
40 
41  if ( countGroups != numberOfGroups ) {
42  edm::LogError("CSC") << "CSCGangedWireGrouping: ERROR in parsing wire info from DDD..." << "\n";
43  edm::LogError("CSC") << "groups expected = " << numberOfGroups <<
44  " groups seen = " << countGroups << "\n";
45  edm::LogError("CSC") << "Please report this error to Tim.Cox@cern.ch" << "\n";
46  }
47 
48  LogTrace("CSCWireGeometry|CSC") << "CSCGangedWireGrouping constructor complete," <<
49  " wire group list follows... ";
50  LogTrace("CSCWireGeometry|CSC") << "Size of group buffers = " << theFirstWireOfEachWireGroup.size() <<
51  " and " << theNumberOfWiresPerWireGroup.size();
52  LogTrace("CSCWireGeometry|CSC") << " wg# 1st wire #wires";
53  for ( size_t i = 0; i != theFirstWireOfEachWireGroup.size(); ++i ) {
54  LogTrace("CSCWireGeometry|CSC") << std::setw(4) << i+1 << std::setw(12) << theFirstWireOfEachWireGroup[i] <<
55  std::setw(8) << theNumberOfWiresPerWireGroup[i];
56  }
57  LogTrace("CSCWireGeometry|CSC") << "Total no. of wires = " << theNumberOfWires;
58 
59 }
60 
62  if ( wireGroup > 0 && wireGroup <= theNumberOfGroups )
63  return theNumberOfWiresPerWireGroup[ wireGroup-1 ];
64  else return 0;
65 }
66 
67 int CSCGangedWireGrouping::wireGroup(int wire) const {
68  // Return wire group number (start at 1) containing (virtual) 'wire'
69  // Return 0 if 'wire' is not in a wire group; this includes
70  // wires out outside the chamber, and lying in 'dead' regions
71 
72  int wireG = 0;
73 
74  // upper_bound works on a sorted range and points to first element
75  // _succeeding_ supplied value.
76 
77  CIterator it = upper_bound( theFirstWireOfEachWireGroup.begin(),
78  theFirstWireOfEachWireGroup.end(), wire );
79 
80  // We are now pointing to the wire group _after_ the required one
81  // (unless we are at begin() or end() when we just return wireG=0)
82  ptrdiff_t pd = it - theFirstWireOfEachWireGroup.begin();
83 
84  if ( pd > 0 ) {
85  size_t id = --pd; //@@ Need to step back one. IS THIS SANE CODE?
86  int wiresInGroup = theNumberOfWiresPerWireGroup[id];
87  int firstWire = theFirstWireOfEachWireGroup[id];
88 
89  // Require wire not past end of group (may be in a dead region, or
90  // bigger than total wires in chamber)
91  if ( wire < (firstWire + wiresInGroup) ) wireG = ++id;
92  }
93  return wireG;
94 }
95 
97  // Return exact wire number for group with odd number of wires
98  // Return half-integer wire number for group with even number of wires
99  // i.e. first + 0.5 * float(#) - 0.5
100  // Return 0 if out of range
101 
102  float middleWire = 0.;
103  if ( wireGroup > 0 && wireGroup <= theNumberOfGroups ) {
104  middleWire = theFirstWireOfEachWireGroup[ wireGroup-1 ] +
105  0.5 * theNumberOfWiresPerWireGroup[ wireGroup-1 ] -
106  0.5 ;
107  }
108  return middleWire;
109 }
110 
CSCGangedWireGrouping(const Container &consecutiveGroups, const Container &wiresInConsecutiveGroups, int numberOfGroups)
std::vector< int > Container
#define LogTrace(id)
int numberOfWiresPerGroup(int wireGroup) const override
Container::const_iterator CIterator
int wireGroup(int wire) const override
float middleWireOfGroup(int wireGroup) const override