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 edm::Service<edm::RandomNumberGenerator> rng;
00035 if ( ! rng.isAvailable()) {
00036 throw cms::Exception("Configuration")
00037 << "RPCDigitizer requires the RandomNumberGeneratorService\n"
00038 "which is not present in the configuration file. You must add the service\n"
00039 "in the configuration file or remove the modules that require it.";
00040 }
00041
00042 _rpcSync = new RPCSynchronizer(config);
00043
00044 rndEngine = &(rng->getEngine());
00045 flatDistribution = new CLHEP::RandFlat(rndEngine);
00046
00047 }
00048
00049 void
00050 RPCSimSimple::simulate(const RPCRoll* roll,
00051 const edm::PSimHitContainer& rpcHits)
00052 {
00053 _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
00054 theRpcDigiSimLinks.clear();
00055 theDetectorHitMap.clear();
00056 theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
00057
00058 const Topology& topology=roll->specs()->topology();
00059 for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin();
00060 _hit != rpcHits.end(); ++_hit){
00061
00062
00063
00064 const LocalPoint& entr=_hit->entryPoint();
00065 int time_hit = _rpcSync->getSimHitBx(&(*_hit));
00066
00067
00068 std::pair<int, int> digi(topology.channel(entr)+1,
00069 time_hit);
00070
00071 theDetectorHitMap.insert(DetectorHitMap::value_type(digi,&(*_hit)));
00072 strips.insert(digi);
00073 }
00074 }
00075
00076 RPCSimSimple::~RPCSimSimple(){}
00077
00078 void RPCSimSimple::simulateNoise(const RPCRoll* roll)
00079 {
00080
00081 RPCDetId rpcId = roll->id();
00082 int nstrips = roll->nstrips();
00083 double area = 0.0;
00084
00085 if ( rpcId.region() == 0 )
00086 {
00087 const RectangularStripTopology* top_ = dynamic_cast<const
00088 RectangularStripTopology*>(&(roll->topology()));
00089 float xmin = (top_->localPosition(0.)).x();
00090 float xmax = (top_->localPosition((float)roll->nstrips())).x();
00091 float striplength = (top_->stripLength());
00092 area = striplength*(xmax-xmin);
00093 }
00094 else
00095 {
00096 const TrapezoidalStripTopology* top_=dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
00097 float xmin = (top_->localPosition(0.)).x();
00098 float xmax = (top_->localPosition((float)roll->nstrips())).x();
00099 float striplength = (top_->stripLength());
00100 area = striplength*(xmax-xmin);
00101 }
00102
00103 double ave = rate*nbxing*gate*area*1.0e-9;
00104 poissonDistribution_ = new CLHEP::RandPoissonQ(rndEngine, ave);
00105 N_hits = poissonDistribution_->fire();
00106
00107 for (int i = 0; i < N_hits; i++ ){
00108
00109 flatDistribution = new CLHEP::RandFlat(rndEngine, 1, nstrips);
00110 int strip = static_cast<int>(flatDistribution->fire());
00111 int time_hit;
00112
00113 flatDistribution = new CLHEP::RandFlat(rndEngine, (nbxing*gate)/gate);
00114 time_hit = (static_cast<int>(flatDistribution->fire())) - nbxing/2;
00115
00116 std::pair<int, int> digi(strip,time_hit);
00117 strips.insert(digi);
00118 }
00119
00120 }