Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:19:05

0001 /* This is CSCHitFromWireOnly
0002  *
0003  * Finds wiregroup with hits, and fill in CSCWireHitCollection
0004  * which includes only DetId and wiregroup #
0005  *
0006  */
0007 
0008 #include <RecoLocalMuon/CSCRecHitD/src/CSCHitFromWireOnly.h>
0009 #include <RecoLocalMuon/CSCRecHitD/src/CSCWireHit.h>
0010 
0011 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
0012 #include <Geometry/CSCGeometry/interface/CSCLayerGeometry.h>
0013 
0014 #include <DataFormats/CSCDigi/interface/CSCWireDigi.h>
0015 
0016 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0017 
0018 #include <iostream>
0019 
0020 CSCHitFromWireOnly::CSCHitFromWireOnly(const edm::ParameterSet& ps) : recoConditions_(nullptr) {
0021   deltaT = ps.getParameter<int>("CSCWireClusterDeltaT");
0022   useReducedWireTime = ps.getParameter<bool>("CSCUseReducedWireTimeWindow");
0023   wireTimeWindow_low = ps.getParameter<int>("CSCWireTimeWindowLow");
0024   wireTimeWindow_high = ps.getParameter<int>("CSCWireTimeWindowHigh");
0025 
0026   //clusterSize            = ps.getParameter<int>("CSCWireClusterMaxSize");
0027 }
0028 
0029 CSCHitFromWireOnly::~CSCHitFromWireOnly() {}
0030 
0031 std::vector<CSCWireHit> CSCHitFromWireOnly::runWire(const CSCDetId& id,
0032                                                     const CSCLayer* layer,
0033                                                     const CSCWireDigiCollection::Range& rwired) {
0034   std::vector<CSCWireHit> hitsInLayer;
0035 
0036   id_ = id;
0037   layer_ = layer;
0038   layergeom_ = layer->geometry();
0039   bool any_digis = true;
0040   int n_wgroup = 0;
0041 
0042   // Loop over wire digi collection
0043   for (CSCWireDigiCollection::const_iterator it = rwired.first; it != rwired.second; ++it) {
0044     const CSCWireDigi wdigi = *it;
0045 
0046     if (isDeadWG(id, wdigi.getWireGroup())) {
0047       continue;
0048     }
0049     if (any_digis) {
0050       any_digis = false;
0051       makeWireCluster(wdigi);
0052       n_wgroup = 1;
0053     } else {
0054       if (!addToCluster(wdigi)) {
0055         // Make Wire Hit from cluster, delete old cluster and start new one
0056         float whit_pos = findWireHitPosition();
0057         bool deadWG_left = isDeadWG(id, wire_in_cluster.at(0) - 1);
0058         bool deadWG_right = isDeadWG(id, wire_in_cluster.at(wire_in_cluster.size() - 1) + 1);
0059         short int aDeadWG = 0;
0060         if (!deadWG_left && !deadWG_right) {
0061           aDeadWG = 0;
0062         } else if (deadWG_left && deadWG_right) {
0063           aDeadWG = 255;
0064         } else {
0065           if (deadWG_left) {
0066             aDeadWG = wire_in_cluster.at(0) - 1;
0067           } else {
0068             aDeadWG = wire_in_cluster.at(wire_in_cluster.size() - 1) + 1;
0069           }
0070         }
0071         // Set time bins for wire hit as the time bins of the central wire digi, lower of central two if an even number of digis.
0072         std::vector<int> timeBinsOn = wire_cluster[n_wgroup / 2].getTimeBinsOn();
0073         //CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, isDeadWGAround, timeBinsOn );
0074         CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, aDeadWG, timeBinsOn);
0075 
0076         if (!useReducedWireTime) {
0077           hitsInLayer.push_back(whit);
0078         } else if (theTime >= wireTimeWindow_low && theTime <= wireTimeWindow_high) {
0079           hitsInLayer.push_back(whit);
0080         }
0081 
0082         makeWireCluster(wdigi);
0083         n_wgroup = 1;
0084       } else {
0085         n_wgroup++;
0086       }
0087     }
0088     // Don't forget to fill last wire hit !!!
0089     if (rwired.second - it == 1) {
0090       float whit_pos = findWireHitPosition();
0091       bool deadWG_left = isDeadWG(id, wire_in_cluster.at(0) - 1);
0092       bool deadWG_right = isDeadWG(id, wire_in_cluster.at(wire_in_cluster.size() - 1) + 1);
0093       short int aDeadWG = 0;
0094       if (!deadWG_left && !deadWG_right) {
0095         aDeadWG = 0;
0096       } else if (deadWG_left && deadWG_right) {
0097         aDeadWG = 255;
0098       } else {
0099         if (deadWG_left) {
0100           aDeadWG = wire_in_cluster.at(0) - 1;
0101         } else {
0102           aDeadWG = wire_in_cluster.at(wire_in_cluster.size() - 1) + 1;
0103         }
0104       }
0105       std::vector<int> timeBinsOn = wire_cluster[n_wgroup / 2].getTimeBinsOn();
0106       /// BX
0107       //CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, isDeadWGAround, timeBinsOn );
0108       CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, aDeadWG, timeBinsOn);
0109 
0110       if (!useReducedWireTime) {
0111         hitsInLayer.push_back(whit);
0112       } else if (theTime >= wireTimeWindow_low && theTime <= wireTimeWindow_high) {
0113         hitsInLayer.push_back(whit);
0114       }
0115 
0116       n_wgroup++;
0117     }
0118   }
0119 
0120   /// Print statement (!!!to control WireHit content!!!) BX
0121   /*
0122       for(std::vector<CSCWireHit>::const_iterator itWHit=hitsInLayer.begin(); itWHit!=hitsInLayer.end(); ++itWHit){
0123          (*itWHit).print(); 
0124          }  
0125   */
0126 
0127   return hitsInLayer;
0128 }
0129 
0130 void CSCHitFromWireOnly::makeWireCluster(const CSCWireDigi& digi) {
0131   wire_cluster.clear();
0132   wire_in_cluster.clear();
0133   wire_in_clusterAndBX.clear();  /// BX to wire
0134   theLastChannel = digi.getWireGroup();
0135   theTime = digi.getTimeBin();
0136   wire_cluster.push_back(digi);
0137 }
0138 
0139 bool CSCHitFromWireOnly::addToCluster(const CSCWireDigi& digi) {
0140   int iwg = digi.getWireGroup();
0141 
0142   if (iwg == theLastChannel) {
0143     return true;  // Same wire group but different tbin -> ignore
0144   } else {
0145     if ((iwg == theLastChannel + 1) && (abs(digi.getTimeBin() - theTime) <= deltaT)) {
0146       theLastChannel = iwg;
0147       wire_cluster.push_back(digi);
0148       return true;
0149     }
0150   }
0151 
0152   return false;
0153 }
0154 
0155 /* findWireHitPosition
0156  *
0157  * This position is expressed in terms of wire #... is a float since it may be a fraction.
0158  */
0159 float CSCHitFromWireOnly::findWireHitPosition() {
0160   // Again use center of mass to determine position of wire hit
0161   // To do so, need to know wire spacing and # of wires
0162 
0163   float y = 0.0;
0164 
0165   for (unsigned i = 0; i < wire_cluster.size(); ++i) {
0166     CSCWireDigi wdigi = wire_cluster[i];
0167     int wgroup = wdigi.getWireGroup();
0168     wire_in_cluster.push_back(wgroup);
0169     int wgroupAndBX = wdigi.getBXandWireGroup();  /// BX to WireHit
0170     //std::cout << " wgroupAndBX: " << std::hex << wgroupAndBX << std::dec << std::endl;
0171     wire_in_clusterAndBX.push_back(wgroupAndBX);  /// BX to WireHit
0172     y += float(wgroup);
0173   }
0174 
0175   float wiregpos = y / wire_cluster.size();
0176 
0177   return wiregpos;
0178 }
0179 
0180 bool CSCHitFromWireOnly::isDeadWG(const CSCDetId& id, int WG) {
0181   const std::bitset<112>& deadWG = recoConditions_->badWireWord(id);
0182   bool isDead = false;
0183   if (WG > -1 && WG < 112) {
0184     isDead = deadWG.test(WG);
0185   }
0186   return isDead;
0187 }