Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:50

0001 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
0002 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
0003 #include "SimMuon/RPCDigitizer/src/RPCSimSimple.h"
0004 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
0005 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
0006 
0007 #include <cmath>
0008 
0009 #include "CLHEP/Random/RandFlat.h"
0010 #include "CLHEP/Random/RandPoissonQ.h"
0011 
0012 #include <cstring>
0013 #include <iostream>
0014 #include <string>
0015 #include <vector>
0016 #include <cstdlib>
0017 #include <utility>
0018 #include <map>
0019 
0020 RPCSimSimple::RPCSimSimple(const edm::ParameterSet& config) : RPCSim(config) {
0021   rate = config.getParameter<double>("Rate");
0022   nbxing = config.getParameter<int>("Nbxing");
0023   gate = config.getParameter<double>("Gate");
0024 
0025   _rpcSync = new RPCSynchronizer(config);
0026 }
0027 
0028 RPCSimSimple::~RPCSimSimple() { delete _rpcSync; }
0029 
0030 void RPCSimSimple::simulate(const RPCRoll* roll, const edm::PSimHitContainer& rpcHits, CLHEP::HepRandomEngine* engine) {
0031   _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
0032   theRpcDigiSimLinks.clear();
0033   theDetectorHitMap.clear();
0034   theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
0035 
0036   const Topology& topology = roll->specs()->topology();
0037   for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
0038     // Here I hould check if the RPC are up side down;
0039     const LocalPoint& entr = _hit->entryPoint();
0040     int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
0041     //    const LocalPoint& exit=_hit->exitPoint();
0042 
0043     std::pair<int, int> digi(topology.channel(entr) + 1, time_hit);
0044 
0045     theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
0046     strips.insert(digi);
0047   }
0048 }
0049 
0050 void RPCSimSimple::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
0051   RPCDetId rpcId = roll->id();
0052   int nstrips = roll->nstrips();
0053   double area = 0.0;
0054 
0055   if (rpcId.region() == 0) {
0056     const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
0057     float xmin = (top_->localPosition(0.)).x();
0058     float xmax = (top_->localPosition((float)roll->nstrips())).x();
0059     float striplength = (top_->stripLength());
0060     area = striplength * (xmax - xmin);
0061   } else {
0062     const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
0063     float xmin = (top_->localPosition(0.)).x();
0064     float xmax = (top_->localPosition((float)roll->nstrips())).x();
0065     float striplength = (top_->stripLength());
0066     area = striplength * (xmax - xmin);
0067   }
0068 
0069   double ave = rate * nbxing * gate * area * 1.0e-9;
0070 
0071   CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
0072   N_hits = randPoissonQ.fire();
0073 
0074   for (int i = 0; i < N_hits; i++) {
0075     int strip = static_cast<int>(CLHEP::RandFlat::shoot(engine, 1, nstrips));
0076     int time_hit;
0077     time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
0078     std::pair<int, int> digi(strip, time_hit);
0079     strips.insert(digi);
0080   }
0081 }