CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/SimMuon/RPCDigitizer/src/RPCDigitizer.cc

Go to the documentation of this file.
00001 #include "SimMuon/RPCDigitizer/src/RPCDigitizer.h"
00002 #include "SimMuon/RPCDigitizer/src/RPCSimFactory.h"
00003 #include "SimMuon/RPCDigitizer/src/RPCSim.h"
00004 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00005 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
00009 
00010 // default constructor allocates default wire and strip digitizers
00011 
00012 RPCDigitizer::RPCDigitizer(const edm::ParameterSet& config, CLHEP::HepRandomEngine& eng) {
00013   theName = config.getParameter<std::string>("digiModel");
00014   theRPCSim = RPCSimFactory::get()->create(theName,config.getParameter<edm::ParameterSet>("digiModelConfig"));
00015   theRPCSim->setRandomEngine(eng);
00016 }
00017 
00018 RPCDigitizer::~RPCDigitizer() {
00019   if( theRPCSim )
00020     delete theRPCSim;
00021   theRPCSim = 0;
00022 }
00023 
00024 void RPCDigitizer::doAction(MixCollection<PSimHit> & simHits, 
00025                             RPCDigiCollection & rpcDigis,
00026                             RPCDigiSimLinks & rpcDigiSimLink)
00027 {
00028 
00029   theRPCSim->setRPCSimSetUp(theSimSetUp);
00030 
00031   // arrange the hits by roll
00032   std::map<int, edm::PSimHitContainer> hitMap;
00033   for(MixCollection<PSimHit>::MixItr hitItr = simHits.begin();
00034       hitItr != simHits.end(); ++hitItr) 
00035   {
00036     hitMap[hitItr->detUnitId()].push_back(*hitItr);
00037   }
00038 
00039    if ( ! theGeometry) {
00040    throw cms::Exception("Configuration")
00041      << "RPCDigitizer requires the RPCGeometry \n which is not present in the configuration file.  You must add the service\n in the configuration file or remove the modules that require it.";
00042   }
00043 
00044 
00045   std::vector<RPCRoll*>  rpcRolls = theGeometry->rolls() ;
00046   for(std::vector<RPCRoll*>::iterator r = rpcRolls.begin();
00047       r != rpcRolls.end(); r++){
00048 
00049     const edm::PSimHitContainer & rollSimHits = hitMap[(*r)->id()];
00050     
00051 //    LogDebug("RPCDigitizer") << "RPCDigitizer: found " << rollSimHits.size() 
00052 //                           <<" hit(s) in the rpc roll";  
00053     
00054     theRPCSim->simulate(*r,rollSimHits);
00055     theRPCSim->simulateNoise(*r);
00056     theRPCSim->fillDigis((*r)->id(),rpcDigis);
00057     rpcDigiSimLink.insert(theRPCSim->rpcDigiSimLinks());
00058   }
00059 }
00060 
00061 const RPCRoll * RPCDigitizer::findDet(int detId) const {
00062   assert(theGeometry != 0);
00063   const GeomDetUnit* detUnit = theGeometry->idToDetUnit(RPCDetId(detId));
00064   return dynamic_cast<const RPCRoll *>(detUnit);
00065 }
00066