CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/SimMuon/RPCDigitizer/src/RPCSimTriv.cc

Go to the documentation of this file.
00001 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00002 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
00003 #include "SimMuon/RPCDigitizer/src/RPCSimTriv.h"
00004 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00005 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00006 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00007 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
00008 
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "CLHEP/Random/RandomEngine.h"
00013 #include "CLHEP/Random/RandFlat.h"
00014 #include <cmath>
00015 #include <utility>
00016 #include <map>
00017 
00018 //#include "CLHEP/config/CLHEP.h"
00019 #include "CLHEP/Random/Random.h"
00020 #include "CLHEP/Random/RandFlat.h"
00021 #include "CLHEP/Random/RandPoissonQ.h"
00022 
00023 
00024 RPCSimTriv::RPCSimTriv(const edm::ParameterSet& config) : RPCSim(config){
00025 
00026   rate=config.getParameter<double>("Rate");
00027   nbxing=config.getParameter<int>("Nbxing");
00028   gate=config.getParameter<double>("Gate");
00029 
00030   _rpcSync = new RPCSynchronizer(config);
00031 }
00032 
00033 void RPCSimTriv::setRandomEngine(CLHEP::HepRandomEngine& eng){
00034   flatDistribution1 = new CLHEP::RandFlat(eng);
00035   flatDistribution2 = new CLHEP::RandFlat(eng);
00036   poissonDistribution = new CLHEP::RandPoissonQ(eng);
00037   _rpcSync->setRandomEngine(eng);
00038 }
00039 
00040 RPCSimTriv::~RPCSimTriv(){
00041   delete flatDistribution1;
00042   delete flatDistribution2;
00043   delete poissonDistribution;
00044   delete _rpcSync;
00045 }
00046 
00047 void
00048 RPCSimTriv::simulate(const RPCRoll* roll,
00049                        const edm::PSimHitContainer& rpcHits)
00050 {
00051 
00052   _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
00053   theRpcDigiSimLinks.clear();
00054   theDetectorHitMap.clear();
00055   theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
00056 
00057   const Topology& topology=roll->specs()->topology();
00058   for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
00059        _hit != rpcHits.end(); ++_hit){
00060 
00061     int type = _hit->particleType();
00062     if (type == 13 || type == -13){
00063       // Here I hould check if the RPC are up side down;
00064       const LocalPoint& entr=_hit->entryPoint();
00065       int time_hit = _rpcSync->getSimHitBx(&(*_hit));
00066       std::pair<int, int> digi(topology.channel(entr)+1,
00067                                time_hit);
00068 
00069       theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00070       strips.insert(digi);
00071     }
00072   }
00073 }
00074 
00075 
00076 void RPCSimTriv::simulateNoise(const RPCRoll* roll)
00077 {
00078 
00079   RPCDetId rpcId = roll->id();
00080   int nstrips = roll->nstrips();
00081   double area = 0.0;
00082   
00083   if ( rpcId.region() == 0 )
00084     {
00085       const RectangularStripTopology* top_ = dynamic_cast<const
00086         RectangularStripTopology*>(&(roll->topology()));
00087       float xmin = (top_->localPosition(0.)).x();
00088       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00089       float striplength = (top_->stripLength());
00090       area = striplength*(xmax-xmin);
00091     }
00092   else
00093     {
00094       const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
00095       float xmin = (top_->localPosition(0.)).x();
00096       float xmax = (top_->localPosition((float)roll->nstrips())).x();
00097       float striplength = (top_->stripLength());
00098       area = striplength*(xmax-xmin);
00099     }
00100   
00101 
00102   double ave = rate*nbxing*gate*area*1.0e-9;
00103 
00104   N_hits = poissonDistribution->fire(ave);
00105   
00106   for (int i = 0; i < N_hits; i++ ){
00107     int strip = static_cast<int>(flatDistribution1->fire(1,nstrips));
00108     int time_hit;
00109     time_hit = (static_cast<int>(flatDistribution2->fire((nbxing*gate)/gate))) - nbxing/2;
00110     std::pair<int, int> digi(strip,time_hit);
00111     strips.insert(digi);
00112   }
00113 }