CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoLocalMuon/CSCRecHitD/src/CSCRecHitDBuilder.cc

Go to the documentation of this file.
00001 // This is CSCRecHitDBuilder.cc
00002 
00003 #include <RecoLocalMuon/CSCRecHitD/src/CSCRecHitDBuilder.h>
00004 #include <RecoLocalMuon/CSCRecHitD/src/CSCHitFromStripOnly.h>
00005 #include <RecoLocalMuon/CSCRecHitD/src/CSCHitFromWireOnly.h>
00006 #include <RecoLocalMuon/CSCRecHitD/src/CSCMake2DRecHit.h>
00007 #include <RecoLocalMuon/CSCRecHitD/src/CSCWireHitCollection.h>
00008 #include <RecoLocalMuon/CSCRecHitD/src/CSCStripHitCollection.h>
00009 #include <RecoLocalMuon/CSCRecHitD/src/CSCRangeMapForRecHit.h>
00010  
00011 #include <Geometry/CSCGeometry/interface/CSCChamberSpecs.h>
00012 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
00013 #include <Geometry/CSCGeometry/interface/CSCGeometry.h>
00014 
00015 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00016 
00017 #include <CondFormats/CSCObjects/interface/CSCDBGains.h>
00018 #include <CondFormats/DataRecord/interface/CSCDBGainsRcd.h>
00019 #include <CondFormats/CSCObjects/interface/CSCDBCrosstalk.h>
00020 #include <CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h>
00021 #include <CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h>
00022 #include <CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h>
00023 
00024 #include <FWCore/Utilities/interface/Exception.h>
00025 #include <FWCore/MessageLogger/interface/MessageLogger.h> 
00026 
00027 #include <iostream>
00028 
00029 
00030 CSCRecHitDBuilder::CSCRecHitDBuilder( const edm::ParameterSet& ps ) : geom_(0) {
00031   
00032   // Receives ParameterSet percolated down from EDProducer      
00033 
00034   useCalib               = ps.getParameter<bool>("CSCUseCalibrations");  
00035   stripWireDeltaT        = ps.getParameter<int>("CSCstripWireDeltaTime");
00036   
00037   hitsFromStripOnly_     = new CSCHitFromStripOnly( ps ); 
00038   hitsFromWireOnly_      = new CSCHitFromWireOnly( ps );  
00039   make2DHits_            = new CSCMake2DRecHit( ps );
00040 }
00041 
00042 
00043 CSCRecHitDBuilder::~CSCRecHitDBuilder() {
00044   delete hitsFromStripOnly_;
00045   delete hitsFromWireOnly_;
00046   delete make2DHits_;   
00047 }
00048 
00049 
00050 void CSCRecHitDBuilder::build( const CSCStripDigiCollection* stripdc, const CSCWireDigiCollection* wiredc,
00051                                CSCRecHit2DCollection& oc ) {
00052   LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] build entered";
00053   // Clean hit collections sorted by layer    
00054   std::vector<CSCDetId> stripLayer;
00055   std::vector<CSCDetId>::const_iterator sIt;
00056   std::vector<CSCDetId> wireLayer;
00057   std::vector<CSCDetId>::const_iterator wIt;
00058 
00059   
00060   // Make collection of wire only hits !  
00061   CSCWireHitCollection clean_woc;
00062   
00063   for ( CSCWireDigiCollection::DigiRangeIterator it = wiredc->begin(); it != wiredc->end(); ++it ){
00064     const CSCDetId& id = (*it).first;
00065     const CSCLayer* layer = getLayer( id );
00066     const CSCWireDigiCollection::Range rwired = wiredc->get( id );
00067     // Skip if no wire digis in this layer
00068     if ( rwired.second == rwired.first ) {
00069             continue; 
00070     }
00071           
00072     std::vector<CSCWireHit> rhv = hitsFromWireOnly_->runWire( id, layer, rwired);
00073 
00074     if ( rhv.size() > 0 ) wireLayer.push_back( id );
00075     
00076     // Add the wire hits to master collection
00077     clean_woc.put( id, rhv.begin(), rhv.end() );
00078   }
00079 
00080   LogTrace("CSCRecHitBuilder") << "[CSCRecHitDBuilder] wire hits created";
00081 
00082   // Make collection of strip only hits
00083   
00084   CSCStripHitCollection clean_soc;  
00085   for ( CSCStripDigiCollection::DigiRangeIterator it = stripdc->begin(); it != stripdc->end(); ++it ){
00086     const CSCDetId& id = (*it).first;
00087     const CSCLayer* layer = getLayer( id );
00088     const CSCStripDigiCollection::Range& rstripd = (*it).second;
00089     
00090     // Skip if no strip digis in this layer
00091     if ( rstripd.second == rstripd.first ) continue;
00092     
00093     std::vector<CSCStripHit> rhv = hitsFromStripOnly_->runStrip( id, layer, rstripd);
00094 
00095     if ( rhv.size() > 0 ) stripLayer.push_back( id );
00096     
00097     // Add the strip hits to master collection
00098     clean_soc.put( id, rhv.begin(), rhv.end() );
00099   }
00100 
00101   LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] strip hits created";
00102 
00103 
00104   // Now create 2-D hits by looking at superposition of strip and wire hit in a layer
00105   //
00106   // N.B.  I've sorted the hits from layer 1-6 always, so can test if there are "holes", 
00107   // that is layers without hits for a given chamber.
00108 
00109   // Vector to store rechit within layer
00110   std::vector<CSCRecHit2D> hitsInLayer;
00111 
00112   int layer_idx     = 0;
00113   int hits_in_layer = 0;
00114   CSCDetId old_id; 
00115 
00116   // Now loop over each layer containing strip hits
00117   for ( sIt=stripLayer.begin(); sIt != stripLayer.end(); ++sIt ) {
00118 
00119     hitsInLayer.clear();
00120     hits_in_layer = 0;
00121    
00122     std::vector<CSCStripHit> cscStripHit;
00123     
00124     CSCRangeMapForRecHit acc;
00125     CSCStripHitCollection::range range = clean_soc.get(acc.cscDetLayer(*sIt));
00126 
00127     // Create vector of strip hits for this layer    
00128     for ( CSCStripHitCollection::const_iterator clean_soc = range.first; clean_soc != range.second; ++clean_soc)
00129       cscStripHit.push_back(*clean_soc);
00130 
00131     const CSCDetId& sDetId = (*sIt);
00132     const CSCLayer* layer  = getLayer( sDetId );
00133 
00134     // This is used to test for gaps in layers and needs to be initialized here 
00135     if ( layer_idx == 0 ) {
00136       old_id = sDetId;
00137     }
00138 
00139     CSCDetId compId = sDetId;
00140     CSCWireDigiCollection::Range rwired = wiredc->get( sDetId );
00141     // Skip if no wire digis in this layer
00142     // But for ME11, real wire digis are labelled as belonging to ME1b, so that's where ME1a must look
00143     // (We try ME1a - above - anyway, because simulated wire digis are labelled as ME1a.)
00144     if ( rwired.second == rwired.first ) {
00145       if ( sDetId.station()!=1 || sDetId.ring()!=4 ){
00146         continue; // not ME1a, skip to next layer
00147       }
00148       // So if ME1a has no wire digis (always the case for data) make the
00149       // wire digi ID point to ME1b. This is what is compared to the
00150       // strip digi ID below (and not used anywhere else). 
00151       // Later, rechits use the strip digi ID for construction.
00152    
00153       // It is ME1a but no wire digis there, so try ME1b...
00154       int endcap  = sDetId.endcap();
00155       int chamber = sDetId.chamber();
00156       int layer   = sDetId.layer();
00157       CSCDetId idw( endcap, 1, 1, chamber, layer ); // Set idw to same layer in ME1b
00158       compId = idw;
00159     }
00160     
00161     // Now loop over wire hits
00162     for ( wIt=wireLayer.begin(); wIt != wireLayer.end(); ++wIt ) {
00163         
00164       const CSCDetId& wDetId  = (*wIt);
00165         
00166       // Because of ME1a, use the compId to make a comparison between strip and wire hit CSCDetId
00167       if ((wDetId.endcap()  == compId.endcap() ) &&
00168           (wDetId.station() == compId.station()) &&
00169           (wDetId.ring()    == compId.ring()   ) &&
00170           (wDetId.chamber() == compId.chamber()) &&
00171           (wDetId.layer()   == compId.layer()  )) {
00172           
00173         // Create vector of wire hits for this layer
00174         std::vector<CSCWireHit> cscWireHit;
00175        
00176         CSCRangeMapForRecHit acc2;
00177         CSCWireHitCollection::range range = clean_woc.get(acc2.cscDetLayer(*wIt));
00178       
00179         for ( CSCWireHitCollection::const_iterator clean_woc = range.first; clean_woc != range.second; ++clean_woc)
00180           cscWireHit.push_back(*clean_woc);
00181 
00182         // Build 2D hit for all possible strip-wire pairs 
00183         // overlapping within this layer
00184 
00185         LogTrace("CSCRecHitBuilder")<< "[CSCRecHitDBuilder] found " << cscStripHit.size() << " strip and " 
00186                              << cscWireHit.size()  << " wire hits in layer " << sDetId;
00187 
00188         for (unsigned i = 0; i != cscStripHit.size(); ++i ) {
00189           const CSCStripHit s_hit = cscStripHit[i];
00190           for (unsigned j = 0; j != cscWireHit.size(); ++j ) {
00191             const CSCWireHit w_hit = cscWireHit[j];
00192             CSCRecHit2D rechit = make2DHits_->hitFromStripAndWire(sDetId, layer, w_hit, s_hit);
00193 
00194             bool isInFiducial = make2DHits_->isHitInFiducial( layer, rechit );
00195             if ( isInFiducial ) {
00196               hitsInLayer.push_back( rechit );
00197               hits_in_layer++;
00198             }
00199           }
00200         }
00201       }
00202     }
00203 
00204     LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] " << hits_in_layer << " rechits found in layer " << sDetId;
00205 
00206     // output vector of 2D rechits to collection
00207     if (hits_in_layer > 0) {
00208       oc.put( sDetId, hitsInLayer.begin(), hitsInLayer.end() );
00209       hitsInLayer.clear();
00210     }
00211     hits_in_layer = 0;
00212     layer_idx++;
00213     old_id = sDetId;
00214   }
00215 
00216   LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] " << oc.size() << " 2d rechits created in this event.";
00217 
00218 }
00219 
00220 
00221 const CSCLayer* CSCRecHitDBuilder::getLayer( const CSCDetId& detId )  {
00222   if ( !geom_ ) throw cms::Exception("MissingGeometry") << "[CSCRecHitDBuilder::getLayer] Missing geometry" << std::endl;
00223   return geom_->layer(detId);
00224 }
00225 
00226 
00227 void CSCRecHitDBuilder::setConditions( const CSCRecoConditions* reco ) {
00228   hitsFromStripOnly_->setConditions( reco );
00229   hitsFromWireOnly_->setConditions( reco );
00230   make2DHits_->setConditions( reco );  
00231 }