CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DataFormats/CSCRecHit/src/CSCRecHit2D.cc

Go to the documentation of this file.
00001 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
00002 #include <iostream>
00003 
00004 CSCRecHit2D::CSCRecHit2D() :
00005   theLocalPosition(0.,0.), 
00006   theLocalError(0.,0.,0.),
00007   theStrips( ChannelContainer() ),
00008   theADCs( ADCContainer() ),
00009   theWireGroups( ChannelContainer() ),
00010   theTpeak( -999. ),  
00011   thePositionWithinStrip(-999.),
00012   theErrorWithinStrip(-999.),
00013   theQuality( 0 ), theBadStrip( 0 ), theBadWireGroup( 0 ),
00014   theScaledWireTime( 0 )
00015 {
00016 
00018 theStripsLowBits.clear();
00019 for(int i=0; i<(int)theStrips.size(); i++){
00020         theStripsLowBits.push_back(theStrips[i] & 0x000000FF);
00021         }
00023 theStripsHighBits.clear();
00024 for(int i=0; i<(int)theStrips.size(); i++){
00025         theStripsHighBits.push_back(theStrips[i] & 0x0000FF00);
00026         }
00027 
00029 theWgroupsHighBits.clear();
00030 for(int i=0; i<(int)theWireGroups.size(); i++)
00031    theWgroupsHighBits.push_back((theWireGroups[i] >> 16) & 0x0000FFFF);
00032 theWgroupsLowBits.clear();
00033 for(int i=0; i<(int)theWireGroups.size(); i++)
00034    theWgroupsLowBits.push_back(theWireGroups[i] & 0x0000FFFF);
00035 
00036 }
00037 
00038 CSCRecHit2D::CSCRecHit2D( const CSCDetId& id, 
00039                           const LocalPoint& pos, 
00040                           const LocalError& err, 
00041                           const ChannelContainer& channels, 
00042                           const ADCContainer& adcs,
00043                           const ChannelContainer& wgroups,
00044                           float tpeak, 
00045                           float posInStrip, 
00046                           float errInStrip,
00047                           int quality, short int badStrip, short int badWireGroup,
00048                           int scaledWireTime ):
00049   RecHit2DLocalPos( id ), 
00050   theLocalPosition( pos ), 
00051   theLocalError( err ),
00052   theStrips( channels ),
00053   theADCs( adcs ),
00054   theWireGroups( wgroups ),
00055   theTpeak( tpeak ),
00056   thePositionWithinStrip( posInStrip ),
00057   theErrorWithinStrip( errInStrip ),
00058   theQuality( quality ), theBadStrip( badStrip ), theBadWireGroup( badWireGroup ),
00059   theScaledWireTime ( scaledWireTime )
00060 {
00061 
00063 theStripsLowBits.clear();
00064 for(int i=0; i<(int)theStrips.size(); i++){
00065         theStripsLowBits.push_back(theStrips[i] & 0x000000FF);
00066         }
00068 theStripsHighBits.clear();
00069 for(int i=0; i<(int)theStrips.size(); i++){
00070         theStripsHighBits.push_back(theStrips[i] & 0x0000FF00);
00071         }
00072 
00074 theWgroupsHighBits.clear();
00075 for(int i=0; i<(int)theWireGroups.size(); i++)
00076    theWgroupsHighBits.push_back((theWireGroups[i] >> 16) & 0x0000FFFF);
00077 theWgroupsLowBits.clear();
00078 for(int i=0; i<(int)theWireGroups.size(); i++)
00079    theWgroupsLowBits.push_back(theWireGroups[i] & 0x0000FFFF);
00080 
00081 }
00082 
00083 CSCRecHit2D::~CSCRecHit2D() {}
00084 
00085 bool CSCRecHit2D::sharesInput(const TrackingRecHit *other, TrackingRecHit::SharedInputType what) const {
00086   
00087   // This is to satisfy the base class virtual function
00088   
00089   // @@ Cast the enum (!) But what if the TRH::SIT changes?!
00090   CSCRecHit2D::SharedInputType cscWhat = static_cast<CSCRecHit2D::SharedInputType>(what);
00091   return sharesInput(other, cscWhat);
00092 }
00093 
00094 bool CSCRecHit2D::sharesInput(const TrackingRecHit *other, CSCRecHit2D::SharedInputType what) const {
00095   
00096   // Check to see if the TrackingRecHit is actually a CSCRecHit2D.
00097   if (other->geographicalId().subdetId() != MuonSubdetId::CSC) return false;
00098   
00099   // Now I can static cast, because the previous guarantees that this is a CSCRecHit2D
00100   const CSCRecHit2D *otherRecHit = static_cast<const CSCRecHit2D *>(other);
00101   
00102   return sharesInput(otherRecHit, what);
00103 }
00104 
00105 bool CSCRecHit2D::sharesInput(const  CSCRecHit2D *otherRecHit, CSCRecHit2D::SharedInputType what) const {
00106   
00107   // Check to see if the geographical ID of the two are the same
00108   if (geographicalId() != otherRecHit->geographicalId()) return false;
00109   
00110   // Trivial cases
00111   const ChannelContainer otherStrips = otherRecHit->channels();
00112   const ChannelContainer otherWireGroups = otherRecHit->wgroups();
00113   if (theStrips.size() == 0 && otherStrips.size() == 0 && theWireGroups.size() == 0 && otherWireGroups.size() == 0) return true;
00114   if ((what == allWires || what == someWires) && theWireGroups.size() == 0 && otherWireGroups.size() == 0) return true;
00115   if ((what == allStrips || what == someStrips) && theStrips.size() == 0 && otherStrips.size() == 0) return true;
00116   
00117   // Check to see if the wire containers are the same length
00118   if ((what == all || what == allWires) && theWireGroups.size() != otherWireGroups.size()) return false;
00119   
00120   // Check to see if the strip containers are the same length
00121   if ((what == all || what == allStrips) && theStrips.size() != otherStrips.size()) return false;
00122   
00123   bool foundWire = false;
00124   // Check to see if the wires are the same
00125   if (what != allStrips && what != someStrips) {
00126     for (ChannelContainer::const_iterator iWire = theWireGroups.begin(); iWire != theWireGroups.end(); ++iWire) {
00127       bool found = false;
00128       for (ChannelContainer::const_iterator jWire = otherWireGroups.begin(); jWire != otherWireGroups.end(); ++jWire) {
00129         if (*iWire == *jWire) {
00130           if (what == some || what == someWires) return true;
00131           else {
00132             found = true;
00133             foundWire = true;
00134             break;
00135           }
00136         }
00137       }
00138       if ((what == all || what == allWires) && !found) return false;
00139     }
00140     if (what == someWires && !foundWire) return false;
00141   }
00142   
00143   // Check to see if the wires are the same
00144   bool foundStrip = false;
00145   if (what != allWires && what != someWires) {
00146     for (ChannelContainer::const_iterator iStrip = theStrips.begin(); iStrip != theStrips.end(); ++iStrip) {
00147       bool found = false;
00148       for (ChannelContainer::const_iterator jStrip = otherStrips.begin(); jStrip != otherStrips.end(); ++jStrip) {
00149         //a strip is a channel for all but ME1/1a chambers (where 3 ganged strips are a channel)
00150         if(cscDetId().channel(*iStrip)==otherRecHit->cscDetId().channel(*jStrip)){
00151           if (what == some || what == someStrips) return true;
00152           else {
00153             found = true;
00154             foundStrip = true;
00155             break;
00156           }
00157         }
00158       }
00159       if ((what == all || what == allStrips) && !found) return false;
00160     }
00161     if (what == someStrips && !foundStrip) return false;
00162   }
00163   
00164   // In case we were looking for "some" and found absolutely nothing.
00165   if (!foundWire && !foundStrip) return false;
00166   
00167   // If we made it this far, then:
00168   //  1) the detector IDs are the same
00169   //  2) the channel containers have the same number of entries
00170   //  3) for each entry in my channel container, I can find the same value in the other RecHit's corresponding channel container
00171   // I think that means we are the same.
00172   return true;
00173 }
00174 
00177 /*
00178 void CSCRecHit2D::print() const {
00179 std::cout << "CSCRecHit in CSC Detector: " << cscDetId() << std::endl;
00180 std::cout << "  local x = " << localPosition().x() << " +/- " << sqrt( localPositionError().xx() ) <<  " y = " << localPosition().y() << " +/- " << sqrt( localPositionError().yy() ) << std::endl;
00181 
00183 std::cout << "  L1A+Channels: ";
00184 for (int i=0; i<(int)channelsTotal().size(); i++) {std::cout 
00185        << std::hex << channelsTotal()[i] << " ";}
00186 std::cout << std::endl;
00187 
00188 std::cout << "  Channels: ";
00189 for (int i=0; i<(int)channels().size(); i++) {std::cout << std::dec << channels()[i] << " "
00190      << " (" << "HEX: " << std::hex << channels()[i] << ")" << " ";
00191       }
00192   std::cout << std::endl;
00193 
00194 
00196 std::cout << "  L1APhase: ";
00197   for (int i=0; i<(int)channelsl1a().size(); i++) {
00198        std::cout << "|";
00199        for (int k=0; k<8 ; k++){ 
00200        std::cout << ((channelsl1a()[i] >> (15-k)) & 0x1) << " ";}
00201        std::cout << "| ";       
00202        }           
00203   std::cout << std::endl;
00204 
00205  
00206 std::cout << "  WireGroups: ";
00207 for (int i=0; i<(int)wgroups().size(); i++) {std::cout << std::dec << wgroups()[i]  
00208        << " ";}
00209   std::cout << std::endl;
00210 }
00211 */
00212 
00213 
00214 void CSCRecHit2D::print() const {
00215 std::cout << "CSCRecHit in CSC Detector: " << cscDetId() << std::endl;
00216 std::cout << "  local x = " << localPosition().x() << " +/- " << sqrt( localPositionError().xx() ) <<  " y = " << localPosition().y() << " +/- " << sqrt( localPositionError().yy() ) << std::endl;
00217 
00219 std::cout << "  L1A+Channels: ";
00220 for (int i=0; i<(int)channelsTotal().size(); i++) {std::cout 
00221        << std::hex << channelsTotal()[i] << " ";}
00222 std::cout << std::endl;
00223 
00224 std::cout << "  Channels: ";
00225 for (int i=0; i<(int)channels().size(); i++) {std::cout << std::dec << channels()[i] << " "
00226      << " (" << "HEX: " << std::hex << channels()[i] << ")" << " ";
00227       }
00228   std::cout << std::endl;
00229 
00230 
00232 std::cout << "  L1APhase: ";
00233   for (int i=0; i<(int)channelsl1a().size(); i++) {
00234        std::cout << "|";
00235        for (int k=0; k<8 ; k++){ 
00236        std::cout << ((channelsl1a()[i] >> (15-k)) & 0x1) << " ";}
00237        std::cout << "| ";       
00238        }           
00239   std::cout << std::endl;
00240 
00241 std::cout << "  BX + WireGroups combined: ";
00242    for (int i=0; i<(int)wgroupsBXandWire().size(); i++) {std::cout //std::dec << wgroups()[i] 
00243         << "HEX: " << std::hex << wgroupsBXandWire()[i] << std::hex << " | ";
00244    }
00245  
00246 std::cout << "  WireGroups: ";
00247 for (int i=0; i<(int)wgroups().size(); i++) {std::cout << std::dec << wgroups()[i]  
00248        << " | ";}
00249 std::cout << " BX#: ";
00250    for (int i=0; i<(int)wgroupsBX().size(); i++) {std::cout << std::dec << wgroupsBX()[i] 
00251        << " (" << "HEX: " << std::hex << wgroupsBX()[i] << ")" << " | ";
00252    }
00253 
00254   std::cout << std::endl;
00255 }
00256 
00257 
00258 /*
00259 void CSCRecHit2D::print() const {
00260   std::cout << *this << std::endl;
00261 }
00262 */
00263 
00264 std::ostream& operator<<(std::ostream& os, const CSCRecHit2D& rh) {
00265   os << "CSCRecHit2D: local x = " << rh.localPosition().x() << " +/- " << sqrt( rh.localPositionError().xx() ) <<
00266     " y = " << rh.localPosition().y() << " +/- " << sqrt( rh.localPositionError().yy() ) <<
00267     " in strip X = " << rh.positionWithinStrip() << " +/-  = " << rh.errorWithinStrip()<<" quality = "<<rh.quality()<<"\n";
00268   os << "             strip # : ";
00269   for(size_t iS =0;iS< rh.channels().size();++iS){
00270     os <<rh.channels().at(iS)<<"  ";
00271   }
00272 os << "\n             wire # : ";
00273   for(size_t iW =0;iW< rh.wgroups().size();++iW){
00274     os <<rh.wgroups().at(iW)<<"  ";
00275   }
00276   return os;
00277 }
00278 
00279