Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:24

0001 #include <Geometry/CSCGeometry/src/CSCGangedWireGrouping.h>
0002 
0003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0004 
0005 #include <iostream>
0006 #include <iomanip>
0007 #include <algorithm>
0008 #include <cstddef>
0009 
0010 CSCGangedWireGrouping::CSCGangedWireGrouping(const Container& consecutiveGroups,
0011                                              const Container& wiresInConsecutiveGroups,
0012                                              int numberOfGroups)
0013     : theNumberOfGroups(numberOfGroups) {
0014   int countGroups = 0;       // counter for no. of wire groups
0015   int firstWire = 1;         // (virtual) wire number which is 1st in a group
0016   int countConsecutive = 0;  // counter for the sections in DDD
0017 
0018   for (int igs : consecutiveGroups) {
0019     if (igs != 0) {
0020       // igs is number of consecutive groups each containing
0021       // an identical number of wires
0022       countGroups += igs;
0023       for (int ic = 0; ic != igs; ++ic) {
0024         theFirstWireOfEachWireGroup.emplace_back(firstWire);
0025         int wiresInGroup = wiresInConsecutiveGroups[countConsecutive];
0026         theNumberOfWiresPerWireGroup.emplace_back(wiresInGroup);
0027         firstWire += wiresInGroup;  // ready for next group
0028       }
0029     } else {
0030       // zero means a gap - just add in the no. of virtual wires in gap
0031       firstWire += wiresInConsecutiveGroups[countConsecutive];
0032     }
0033     ++countConsecutive;  // ready for next set of consecutive groups
0034   }
0035 
0036   theNumberOfWires = firstWire - 1;  // at end of loop we're on 1st for next
0037 
0038   if (countGroups != numberOfGroups) {
0039     edm::LogError("CSC") << "CSCGangedWireGrouping: ERROR in parsing wire info from DDD..."
0040                          << "\n";
0041     edm::LogError("CSC") << "groups expected = " << numberOfGroups << " groups seen = " << countGroups << "\n";
0042     edm::LogError("CSC") << "Please report this error to Tim.Cox@cern.ch"
0043                          << "\n";
0044   }
0045 
0046   LogTrace("CSCWireGeometry|CSC") << "CSCGangedWireGrouping constructor complete,"
0047                                   << " wire group list follows... ";
0048   LogTrace("CSCWireGeometry|CSC") << "Size of group buffers = " << theFirstWireOfEachWireGroup.size() << " and "
0049                                   << theNumberOfWiresPerWireGroup.size();
0050   LogTrace("CSCWireGeometry|CSC") << " wg#    1st wire  #wires";
0051   for (size_t i = 0; i != theFirstWireOfEachWireGroup.size(); ++i) {
0052     LogTrace("CSCWireGeometry|CSC") << std::setw(4) << i + 1 << std::setw(12) << theFirstWireOfEachWireGroup[i]
0053                                     << std::setw(8) << theNumberOfWiresPerWireGroup[i];
0054   }
0055   LogTrace("CSCWireGeometry|CSC") << "Total no. of wires = " << theNumberOfWires;
0056 }
0057 
0058 int CSCGangedWireGrouping::numberOfWiresPerGroup(int wireGroup) const {
0059   if (wireGroup > 0 && wireGroup <= theNumberOfGroups)
0060     return theNumberOfWiresPerWireGroup[wireGroup - 1];
0061   else
0062     return 0;
0063 }
0064 
0065 int CSCGangedWireGrouping::wireGroup(int wire) const {
0066   // Return wire group number (start at 1) containing (virtual) 'wire'
0067   // Return 0 if 'wire' is not in a wire group; this includes
0068   // wires out outside the chamber, and lying in 'dead' regions
0069 
0070   int wireG = 0;
0071 
0072   // upper_bound works on a sorted range and points to first element
0073   // _succeeding_ supplied value.
0074 
0075   CIterator it = upper_bound(theFirstWireOfEachWireGroup.begin(), theFirstWireOfEachWireGroup.end(), wire);
0076 
0077   // We are now pointing to the wire group _after_ the required one
0078   // (unless we are at begin() or end() when we just return wireG=0)
0079   ptrdiff_t pd = it - theFirstWireOfEachWireGroup.begin();
0080 
0081   if (pd > 0) {
0082     size_t id = --pd;  //@@ Need to step back one. IS THIS SANE CODE?
0083     int wiresInGroup = theNumberOfWiresPerWireGroup[id];
0084     int firstWire = theFirstWireOfEachWireGroup[id];
0085 
0086     // Require wire not past end of group (may be in a dead region, or
0087     // bigger than total wires in chamber)
0088     if (wire < (firstWire + wiresInGroup))
0089       wireG = ++id;
0090   }
0091   return wireG;
0092 }
0093 
0094 float CSCGangedWireGrouping::middleWireOfGroup(int wireGroup) const {
0095   // Return exact wire number for group with odd number of wires
0096   // Return half-integer wire number for group with even number of wires
0097   // i.e. first + 0.5 * float(#) - 0.5
0098   // Return 0 if out of range
0099 
0100   float middleWire = 0.;
0101   if (wireGroup > 0 && wireGroup <= theNumberOfGroups) {
0102     middleWire = theFirstWireOfEachWireGroup[wireGroup - 1] + 0.5 * theNumberOfWiresPerWireGroup[wireGroup - 1] - 0.5;
0103   }
0104   return middleWire;
0105 }