CMS 3D CMS Logo

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