CMS 3D CMS Logo

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