Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:11

0001 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
0002 #include <iostream>
0003 
0004 CSCRecHit2D::CSCRecHit2D()
0005     : theTpeak(-999.),
0006       thePositionWithinStrip(-999.),
0007       theErrorWithinStrip(-999.),
0008       theEnergyDeposit(-994.),
0009       theQuality(0),
0010       theScaledWireTime(0),
0011       theBadStrip(0),
0012       theBadWireGroup(0),
0013       nStrips_(0),
0014       nWireGroups_(0),
0015       nTimeBins_(0),
0016       theLocalPosition(0., 0.),
0017       theLocalError(0., 0., 0.) {
0018   for (unsigned int i = 0; i < MAXSTRIPS; i++)
0019     theStrips_[i] = 0;
0020   for (unsigned int i = 0; i < MAXSTRIPS; i++)
0021     for (unsigned int j = 0; j < MAXTIMEBINS; j++)
0022       theADCs_[i * MAXTIMEBINS + j] = 0;
0023 }
0024 
0025 CSCRecHit2D::CSCRecHit2D(const CSCDetId& id,
0026                          const LocalPoint& pos,
0027                          const LocalError& err,
0028                          const ChannelContainer& channels,
0029                          const ADCContainer& adcs,
0030                          const ChannelContainer& wgroups,
0031                          float tpeak,
0032                          float posInStrip,
0033                          float errInStrip,
0034                          int quality,
0035                          short int badStrip,
0036                          short int badWireGroup,
0037                          int scaledWireTime,
0038                          float energyDeposit)
0039     : RecHit2DLocalPos(id),
0040       theTpeak(tpeak),
0041       thePositionWithinStrip(posInStrip),
0042       theErrorWithinStrip(errInStrip),
0043       theEnergyDeposit(energyDeposit),
0044       theQuality(quality),
0045       theScaledWireTime(scaledWireTime),
0046       theBadStrip(badStrip),
0047       theBadWireGroup(badWireGroup),
0048       theLocalPosition(pos),
0049       theLocalError(err) {
0050   nStrips_ = channels.size();
0051   nWireGroups_ = wgroups.size();
0052 
0053   if (nStrips_ > MAXSTRIPS) {
0054     std::cout << "CSCRecHit2D: not enough strips in DataFormat! " << unsigned(nStrips_) << std::endl;
0055     nStrips_ = MAXSTRIPS;
0056   }
0057 
0058   for (unsigned int i = 0; i < MAXSTRIPS; i++)
0059     theStrips_[i] = 0;
0060   for (unsigned int i = 0; i < MAXSTRIPS; i++)
0061     theL1APhaseBits_[i] = 0;
0062   for (unsigned int i = 0; i < MAXSTRIPS; i++)
0063     for (unsigned int j = 0; j < MAXTIMEBINS; j++)
0064       theADCs_[i * MAXTIMEBINS + j] = 0;
0065 
0066   for (unsigned int i = 0; i < nStrips_; i++) {
0067     theStrips_[i] = channels[i] & 0x000000FF;
0068     theL1APhaseBits_[i] = channels[i] & 0x0000FF00;
0069   }
0070   if (nWireGroups_ > 0) {
0071     //take only the low bits
0072     hitWire_ = wgroups[nWireGroups_ / 2] & 0x0000FFFF;
0073     theWGroupsBX_ = (wgroups[nWireGroups_ / 2] >> 16) & 0x0000FFFF;
0074   } else {
0075     hitWire_ = 0;
0076     theWGroupsBX_ = 0;
0077   }
0078   ADCContainer tmp(adcs);  //must be a bug in RangeMap!!!???
0079   nTimeBins_ = tmp.size() / nStrips_;
0080   unsigned int k = 0;
0081   for (unsigned int i = 0; i < nStrips_; i++)
0082     for (unsigned int j = 0; j < nTimeBins_; j++) {
0083       theADCs_[i * MAXTIMEBINS + j] = tmp[k];
0084       k++;
0085     }
0086 }
0087 
0088 CSCRecHit2D::~CSCRecHit2D() {}
0089 
0090 bool CSCRecHit2D::sharesInput(const TrackingRecHit* other, TrackingRecHit::SharedInputType what) const {
0091   // This is to satisfy the base class virtual function
0092 
0093   // @@ Cast the enum (!) But what if the TRH::SIT changes?!
0094   CSCRecHit2D::SharedInputType cscWhat = static_cast<CSCRecHit2D::SharedInputType>(what);
0095   return sharesInput(other, cscWhat);
0096 }
0097 
0098 bool CSCRecHit2D::sharesInput(const TrackingRecHit* other, CSCRecHit2D::SharedInputType what) const {
0099   // Check to see if the TrackingRecHit is actually a CSCRecHit2D.
0100   if (other->geographicalId().subdetId() != MuonSubdetId::CSC)
0101     return false;
0102 
0103   // Now I can static cast, because the previous guarantees that this is a CSCRecHit2D
0104   const CSCRecHit2D* otherRecHit = static_cast<const CSCRecHit2D*>(other);
0105 
0106   return sharesInput(otherRecHit, what);
0107 }
0108 
0109 bool CSCRecHit2D::sharesInput(const CSCRecHit2D* otherRecHit, CSCRecHit2D::SharedInputType what) const {
0110   // Check to see if the geographical ID of the two are the same
0111   if (geographicalId() != otherRecHit->geographicalId())
0112     return false;
0113 
0114   // Trivial cases
0115   if (nStrips() == 0 && otherRecHit->nStrips() == 0 && nWireGroups() == 0 && otherRecHit->nWireGroups() == 0)
0116     return true;
0117   if ((what == allWires || what == someWires) && nWireGroups() == 0 && otherRecHit->nWireGroups() == 0)
0118     return true;
0119   if ((what == allStrips || what == someStrips) && nStrips() == 0 && otherRecHit->nStrips() == 0)
0120     return true;
0121 
0122   // Check to see if the wire containers are the same length
0123   if ((what == all || what == allWires) && nWireGroups() != otherRecHit->nWireGroups())
0124     return false;
0125 
0126   // Check to see if the strip containers are the same length
0127   if ((what == all || what == allStrips) && nStrips() != otherRecHit->nStrips())
0128     return false;
0129 
0130   bool foundWire = false;
0131   // Check to see if the wires are the same
0132   if (what != allStrips && what != someStrips) {
0133     //can we do better here?
0134     if (hitWire() != otherRecHit->hitWire())
0135       return false;
0136   }
0137 
0138   // Check to see if the wires are the same
0139   bool foundStrip = false;
0140   if (what != allWires && what != someWires) {
0141     for (unsigned int i = 0; i < nStrips(); i++) {
0142       bool found = false;
0143       for (unsigned int j = 0; j < nStrips(); j++) {
0144         //a strip is a channel for all but ME1/1a chambers (where 3 ganged strips are a channel)
0145         if (cscDetId().channel(channels(i)) == otherRecHit->cscDetId().channel(otherRecHit->channels(j))) {
0146           if (what == some || what == someStrips)
0147             return true;
0148           else {
0149             found = true;
0150             foundStrip = true;
0151             break;
0152           }
0153         }
0154       }
0155       if ((what == all || what == allStrips) && !found)
0156         return false;
0157     }
0158     if (what == someStrips && !foundStrip)
0159       return false;
0160   }
0161 
0162   // In case we were looking for "some" and found absolutely nothing.
0163   if (!foundWire && !foundStrip)
0164     return false;
0165 
0166   // If we made it this far, then:
0167   //  1) the detector IDs are the same
0168   //  2) the channel containers have the same number of entries
0169   //  3) for each entry in my channel container, I can find the same value in the other RecHit's corresponding channel container
0170   // I think that means we are the same.
0171   return true;
0172 }
0173 
0174 void CSCRecHit2D::print() const {
0175   std::cout << "CSCRecHit in CSC Detector: " << cscDetId() << std::endl;
0176   std::cout << "  local x = " << localPosition().x() << " +/- " << sqrt(localPositionError().xx())
0177             << " y = " << localPosition().y() << " +/- " << sqrt(localPositionError().yy()) << std::endl;
0178 
0179   std::cout << " tpeak " << theTpeak << " psoInStrip " << thePositionWithinStrip << " errorinstrip "
0180             << theErrorWithinStrip << " "
0181             << " qual " << theQuality << " wiretime " << theScaledWireTime << " tbs " << theBadStrip << " bwg "
0182             << theBadWireGroup << std::endl;
0183 
0184   std::cout << "  Channels: ";
0185   for (unsigned int i = 0; i < nStrips(); i++) {
0186     std::cout << std::dec << channels(i) << " "
0187               << " ("
0188               << "HEX: " << std::hex << channels(i) << ")"
0189               << " ";
0190   }
0191   std::cout << std::endl;
0192 
0193   /// L1A
0194   std::cout << "  L1APhase: ";
0195   for (int i = 0; i < (int)nStrips(); i++) {
0196     std::cout << "|";
0197     for (int k = 0; k < 8; k++) {
0198       std::cout << ((channelsl1a(i) >> (15 - k)) & 0x1) << " ";
0199     }
0200     std::cout << "| ";
0201   }
0202   std::cout << std::endl;
0203 
0204   std::cout << "nWireGroups " << (int)nWireGroups() << " central wire " << hitWire_ << std::endl;
0205 }
0206 
0207 std::ostream& operator<<(std::ostream& os, const CSCRecHit2D& rh) {
0208   os << "CSCRecHit2D: "
0209      << "local x: " << rh.localPosition().x() << " +/- " << sqrt(rh.localPositionError().xx())
0210      << " y: " << rh.localPosition().y() << " +/- " << sqrt(rh.localPositionError().yy())
0211      << " in strip X: " << rh.positionWithinStrip() << " +/- " << rh.errorWithinStrip() << " quality: " << rh.quality()
0212      << " tpeak: " << rh.tpeak() << " wireTime: " << rh.wireTime() << std::endl;
0213   os << "strips: ";
0214   for (size_t iS = 0; iS < rh.nStrips(); ++iS) {
0215     os << rh.channels(iS) << "  ";
0216   }
0217   int nwgs = rh.nWireGroups();
0218   if (nwgs == 1) {
0219     os << "central wire: " << rh.hitWire() << " of " << nwgs << " wiregroup" << std::endl;
0220   } else {
0221     os << "central wire: " << rh.hitWire() << " of " << nwgs << " wiregroups" << std::endl;
0222   }
0223   return os;
0224 }