CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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("CSCRecHit") << "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("CSCRecHit") << "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("CSCRecHit") << "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     bool foundMatch = false;
00120     hitsInLayer.clear();
00121     hits_in_layer = 0;
00122    
00123     std::vector<CSCStripHit> cscStripHit;
00124     
00125     CSCRangeMapForRecHit acc;
00126     CSCStripHitCollection::range range = clean_soc.get(acc.cscDetLayer(*sIt));
00127 
00128     // Create vector of strip hits for this layer    
00129     for ( CSCStripHitCollection::const_iterator clean_soc = range.first; clean_soc != range.second; ++clean_soc)
00130       cscStripHit.push_back(*clean_soc);
00131 
00132     const CSCDetId& sDetId = (*sIt);
00133     const CSCLayer* layer  = getLayer( sDetId );
00134 
00135     // This is used to test for gaps in layers and needs to be initialized here 
00136     if ( layer_idx == 0 ) {
00137       old_id = sDetId;
00138     }
00139 
00140     CSCDetId compId = sDetId;
00141     CSCWireDigiCollection::Range rwired = wiredc->get( sDetId );
00142     // Skip if no wire digis in this layer
00143     // But for ME11, real wire digis are labelled as belonging to
00144     //ME1b, so that's where ME1a must look
00145     // (We try ME1a - above - anyway, because simulated wire digis are labelled as ME1a.)
00146     if ( rwired.second == rwired.first ) {
00147       if ( sDetId.station()!=1 || sDetId.ring()!=4 ){
00148         continue; // not ME1a, skip to next layer
00149       }
00150       // So if ME1a has no wire digis (always the case for data) make the
00151       // wire digi ID pointing to ME1b. This is what is compared to the
00152       // strip digi ID below (and not used anywhere else). Later, rechits use 
00153       // the strip digi ID for construction,  
00154    
00155       // It is ME1a but no wire digis there, so try ME1b...
00156       int endcap  = sDetId.endcap();
00157       int chamber = sDetId.chamber();
00158       int layer   = sDetId.layer();
00159       CSCDetId idw( endcap, 1, 1, chamber, layer ); // Set idw to same layer in ME1b
00160       compId = idw;
00161     }
00162     
00163     // Now loop over wire hits
00164     for ( wIt=wireLayer.begin(); wIt != wireLayer.end(); ++wIt ) {
00165         
00166       const CSCDetId& wDetId  = (*wIt);
00167         
00168       // Because of ME1a, use the compId to make a comparison between strip and wire hit CSCDetId
00169       if ((wDetId.endcap()  == compId.endcap() ) &&
00170           (wDetId.station() == compId.station()) &&
00171           (wDetId.ring()    == compId.ring()   ) &&
00172           (wDetId.chamber() == compId.chamber()) &&
00173           (wDetId.layer()   == compId.layer()  )) {
00174           
00175         // Create vector of wire hits for this layer
00176         std::vector<CSCWireHit> cscWireHit;
00177        
00178         CSCRangeMapForRecHit acc2;
00179         CSCWireHitCollection::range range = clean_woc.get(acc2.cscDetLayer(*wIt));
00180       
00181         for ( CSCWireHitCollection::const_iterator clean_woc = range.first; clean_woc != range.second; ++clean_woc)
00182           cscWireHit.push_back(*clean_woc);
00183 
00184         // Build 2D hit for all possible strip-wire pairs 
00185         // overlapping within this layer
00186 
00187         LogTrace("CSCRecHit")<< "CSCRecHitDBuilder: found " << cscStripHit.size() << " strip and " 
00188                              << cscWireHit.size()  << " wire hits in layer " << sDetId;
00189 
00190         for (unsigned i = 0; i != cscStripHit.size(); ++i ) {
00191           const CSCStripHit s_hit = cscStripHit[i];
00192           for (unsigned j = 0; j != cscWireHit.size(); ++j ) {
00193             const CSCWireHit w_hit = cscWireHit[j];
00194             CSCRecHit2D rechit = make2DHits_->hitFromStripAndWire(sDetId, layer, w_hit, s_hit);
00195             bool isInFiducial = make2DHits_->isHitInFiducial( layer, rechit );
00196             if ( isInFiducial ) {
00197               foundMatch = true;  
00198               hitsInLayer.push_back( rechit );
00199               hits_in_layer++;
00200             }
00201           }
00202         }
00203       }
00204     }
00205 
00206     LogTrace("CSCRecHit") << "CSCRecHitDBuilder: " << hits_in_layer << " rechits found in layer " << sDetId;
00207 
00208     // output vector of 2D rechits to collection
00209     if (hits_in_layer > 0) {
00210       oc.put( sDetId, hitsInLayer.begin(), hitsInLayer.end() );
00211       hitsInLayer.clear();
00212     }
00213     hits_in_layer = 0;
00214     layer_idx++;
00215     old_id = sDetId;
00216   }
00217 
00218   LogTrace("CSCRecHit|CSCOutput") << "CSCRecHitDBuilder: " << oc.size() << " 2d rechits created in this event.";
00219 
00220 }
00221 
00222 
00223 const CSCLayer* CSCRecHitDBuilder::getLayer( const CSCDetId& detId )  {
00224   if ( !geom_ ) throw cms::Exception("MissingGeometry") << "[CSCRecHitDBuilder::getLayer] Missing geometry" << std::endl;
00225   return geom_->layer(detId);
00226 }
00227 
00228 
00229 void CSCRecHitDBuilder::setConditions( const CSCRecoConditions* reco ) {
00230   hitsFromStripOnly_->setConditions( reco );
00231   hitsFromWireOnly_->setConditions( reco );
00232   make2DHits_->setConditions( reco );  
00233 }