CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Geometry/CSCGeometry/src/CSCGangedWireGrouping.cc

Go to the documentation of this file.
00001 #include <Geometry/CSCGeometry/src/CSCGangedWireGrouping.h>
00002 
00003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00004 
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <algorithm>
00008 
00009 CSCGangedWireGrouping::CSCGangedWireGrouping( 
00010   const Container& consecutiveGroups, 
00011   const Container& wiresInConsecutiveGroups, 
00012   int numberOfGroups ) : 
00013      theNumberOfGroups(numberOfGroups) {
00014 
00015   int countGroups = 0;       // counter for no. of wire groups
00016   int firstWire = 1;         // (virtual) wire number which is 1st in a group
00017   int countConsecutive = 0;  // counter for the sections in DDD
00018 
00019   for ( CIterator it = consecutiveGroups.begin();
00020         it != consecutiveGroups.end(); ++it ) {
00021     int igs = *it;
00022     if ( igs != 0 ) {
00023       // igs is number of consecutive groups each containing
00024       // an identical number of wires
00025       countGroups += igs;
00026       for ( int ic = 0; ic != igs; ++ic ) {
00027         theFirstWireOfEachWireGroup.push_back( firstWire );
00028         int wiresInGroup= wiresInConsecutiveGroups[countConsecutive];
00029         theNumberOfWiresPerWireGroup.push_back( wiresInGroup );
00030         firstWire += wiresInGroup; // ready for next group
00031       }
00032     }
00033     else {
00034       // zero means a gap - just add in the no. of virtual wires in gap
00035       firstWire += wiresInConsecutiveGroups[countConsecutive];
00036     }
00037     ++countConsecutive; // ready for next set of consecutive groups
00038   }
00039 
00040   theNumberOfWires = firstWire - 1; // at end of loop we're on 1st for next
00041 
00042   if ( countGroups != numberOfGroups ) {
00043     edm::LogError("CSC") << "CSCGangedWireGrouping: ERROR in parsing wire info from DDD..." << "\n";
00044     edm::LogError("CSC") << "groups expected = " << numberOfGroups << 
00045       " groups seen = " << countGroups << "\n";
00046     edm::LogError("CSC") << "Please report this error to Tim.Cox@cern.ch" << "\n";
00047   }
00048 
00049   LogTrace("CSCWireGeometry|CSC") << "CSCGangedWireGrouping constructor complete," <<
00050     " wire group list follows... ";
00051   LogTrace("CSCWireGeometry|CSC") << "Size of group buffers = " << theFirstWireOfEachWireGroup.size() <<
00052     " and " << theNumberOfWiresPerWireGroup.size();
00053   LogTrace("CSCWireGeometry|CSC") << " wg#    1st wire  #wires";
00054   for ( size_t i = 0; i != theFirstWireOfEachWireGroup.size(); ++i ) {
00055     LogTrace("CSCWireGeometry|CSC") << std::setw(4) << i+1 << std::setw(12) << theFirstWireOfEachWireGroup[i] <<
00056       std::setw(8) << theNumberOfWiresPerWireGroup[i];
00057   }
00058   LogTrace("CSCWireGeometry|CSC") << "Total no. of wires = " << theNumberOfWires;
00059 
00060 }
00061 
00062 int CSCGangedWireGrouping::numberOfWiresPerGroup( int wireGroup ) const { 
00063   if ( wireGroup > 0 && wireGroup <= theNumberOfGroups )
00064     return theNumberOfWiresPerWireGroup[ wireGroup-1 ];
00065   else return 0;
00066 }
00067 
00068 int CSCGangedWireGrouping::wireGroup(int wire) const {
00069   // Return wire group number (start at 1) containing (virtual) 'wire'
00070   // Return 0 if 'wire' is not in a wire group; this includes
00071   // wires out outside the chamber, and lying in 'dead' regions
00072 
00073   int wireG = 0;
00074 
00075   // upper_bound works on a sorted range and points to first element 
00076   // _succeeding_ supplied value.
00077 
00078   CIterator it = upper_bound( theFirstWireOfEachWireGroup.begin(),
00079                               theFirstWireOfEachWireGroup.end(), wire );
00080 
00081   // We are now pointing to the wire group _after_ the required one
00082   // (unless we are at begin() or end() when we just return wireG=0)
00083   ptrdiff_t pd = it - theFirstWireOfEachWireGroup.begin(); 
00084 
00085   if ( pd > 0 ) {
00086     size_t id = --pd; //@@ Need to step back one. IS THIS SANE CODE?
00087     int wiresInGroup = theNumberOfWiresPerWireGroup[id];
00088     int firstWire    = theFirstWireOfEachWireGroup[id];
00089   
00090   // Require wire not past end of group (may be in a dead region, or
00091   // bigger than total wires in chamber)
00092     if ( wire < (firstWire + wiresInGroup) ) wireG = ++id;
00093   }
00094   return wireG;
00095 }
00096 
00097 float CSCGangedWireGrouping::middleWireOfGroup( int wireGroup ) const {
00098   // Return exact wire number for group with odd number of wires
00099   // Return half-integer wire number for group with even number of wires
00100   // i.e. first + 0.5 * float(#) - 0.5
00101   // Return 0 if out of range
00102 
00103   float middleWire = 0.;
00104   if ( wireGroup > 0 && wireGroup <= theNumberOfGroups ) {
00105     middleWire = theFirstWireOfEachWireGroup[ wireGroup-1 ] +
00106       0.5 * theNumberOfWiresPerWireGroup[ wireGroup-1 ] -
00107          0.5 ;
00108   }
00109   return middleWire;
00110 }
00111