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/RPCSimAverageNoiseEff.h"
0004 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
0005 
0006 #include "SimMuon/RPCDigitizer/src/RPCSynchronizer.h"
0007 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
0008 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
0009 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
0010 
0011 #include <cmath>
0012 
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 
0018 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0019 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0020 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0022 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0023 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
0024 
0025 #include <cstring>
0026 #include <iostream>
0027 #include <fstream>
0028 #include <string>
0029 #include <vector>
0030 #include <cstdlib>
0031 #include <utility>
0032 #include <map>
0033 
0034 #include "CLHEP/Random/RandFlat.h"
0035 #include "CLHEP/Random/RandPoissonQ.h"
0036 
0037 using namespace std;
0038 
0039 RPCSimAverageNoiseEff::RPCSimAverageNoiseEff(const edm::ParameterSet& config) : RPCSim(config) {
0040   aveEff = config.getParameter<double>("averageEfficiency");
0041   aveCls = config.getParameter<double>("averageClusterSize");
0042   resRPC = config.getParameter<double>("timeResolution");
0043   timOff = config.getParameter<double>("timingRPCOffset");
0044   dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
0045   resEle = config.getParameter<double>("timeJitter");
0046   sspeed = config.getParameter<double>("signalPropagationSpeed");
0047   lbGate = config.getParameter<double>("linkGateWidth");
0048   rpcdigiprint = config.getParameter<bool>("printOutDigitizer");
0049 
0050   rate = config.getParameter<double>("Rate");
0051   nbxing = config.getParameter<int>("Nbxing");
0052   gate = config.getParameter<double>("Gate");
0053   frate = config.getParameter<double>("Frate");
0054 
0055   if (rpcdigiprint) {
0056     std::cout << "Average Efficiency        = " << aveEff << std::endl;
0057     std::cout << "Average Cluster Size      = " << aveCls << " strips" << std::endl;
0058     std::cout << "RPC Time Resolution       = " << resRPC << " ns" << std::endl;
0059     std::cout << "RPC Signal formation time = " << timOff << " ns" << std::endl;
0060     std::cout << "RPC adjacent strip delay  = " << dtimCs << " ns" << std::endl;
0061     std::cout << "Electronic Jitter         = " << resEle << " ns" << std::endl;
0062     std::cout << "Signal propagation time   = " << sspeed << " x c" << std::endl;
0063     std::cout << "Link Board Gate Width     = " << lbGate << " ns" << std::endl;
0064   }
0065 
0066   _rpcSync = new RPCSynchronizer(config);
0067 }
0068 
0069 RPCSimAverageNoiseEff::~RPCSimAverageNoiseEff() { delete _rpcSync; }
0070 
0071 int RPCSimAverageNoiseEff::getClSize(float posX, CLHEP::HepRandomEngine* engine) {
0072   std::map<int, std::vector<double> > clsMap = getRPCSimSetUp()->getClsMap();
0073 
0074   int cnt = 1;
0075   int min = 1;
0076   double func = 0.0;
0077   std::vector<double> sum_clsize;
0078 
0079   double rr_cl = CLHEP::RandFlat::shoot(engine);
0080   if (0.0 <= posX && posX < 0.2) {
0081     func = (clsMap[1])[(clsMap[1]).size() - 1] * (rr_cl);
0082     sum_clsize = clsMap[1];
0083   }
0084   if (0.2 <= posX && posX < 0.4) {
0085     func = (clsMap[2])[(clsMap[2]).size() - 1] * (rr_cl);
0086     sum_clsize = clsMap[2];
0087   }
0088   if (0.4 <= posX && posX < 0.6) {
0089     func = (clsMap[3])[(clsMap[3]).size() - 1] * (rr_cl);
0090     sum_clsize = clsMap[3];
0091   }
0092   if (0.6 <= posX && posX < 0.8) {
0093     func = (clsMap[4])[(clsMap[4]).size() - 1] * (rr_cl);
0094     sum_clsize = clsMap[4];
0095   }
0096   if (0.8 <= posX && posX < 1.0) {
0097     func = (clsMap[5])[(clsMap[5]).size() - 1] * (rr_cl);
0098     sum_clsize = clsMap[5];
0099   }
0100 
0101   for (vector<double>::iterator iter = sum_clsize.begin(); iter != sum_clsize.end(); ++iter) {
0102     cnt++;
0103     if (func > (*iter)) {
0104       min = cnt;
0105     } else if (func < (*iter)) {
0106       break;
0107     }
0108   }
0109   return min;
0110 }
0111 
0112 void RPCSimAverageNoiseEff::simulate(const RPCRoll* roll,
0113                                      const edm::PSimHitContainer& rpcHits,
0114                                      CLHEP::HepRandomEngine* engine) {
0115   _rpcSync->setRPCSimSetUp(getRPCSimSetUp());
0116   theRpcDigiSimLinks.clear();
0117   theDetectorHitMap.clear();
0118   theRpcDigiSimLinks = RPCDigiSimLinks(roll->id().rawId());
0119 
0120   RPCDetId rpcId = roll->id();
0121   RPCGeomServ RPCname(rpcId);
0122   std::string nameRoll = RPCname.name();
0123 
0124   const Topology& topology = roll->specs()->topology();
0125 
0126   for (edm::PSimHitContainer::const_iterator _hit = rpcHits.begin(); _hit != rpcHits.end(); ++_hit) {
0127     if (_hit->particleType() == 11)
0128       continue;
0129 
0130     // Here I hould check if the RPC are up side down;
0131     const LocalPoint& entr = _hit->entryPoint();
0132 
0133     int time_hit = _rpcSync->getSimHitBx(&(*_hit), engine);
0134     float posX = roll->strip(_hit->localPosition()) - static_cast<int>(roll->strip(_hit->localPosition()));
0135 
0136     std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
0137 
0138     // Effinciecy
0139     int centralStrip = topology.channel(entr) + 1;
0140     ;
0141     float fire = CLHEP::RandFlat::shoot(engine);
0142 
0143     if (fire < veff[centralStrip - 1]) {
0144       int fstrip = centralStrip;
0145       int lstrip = centralStrip;
0146 
0147       // Compute the cluster size
0148       //double w = CLHEP::RandFlat::shoot(engine);
0149       //if (w < 1.e-10) w=1.e-10;
0150       int clsize = this->getClSize(posX, engine);
0151 
0152       std::vector<int> cls;
0153       cls.push_back(centralStrip);
0154       if (clsize > 1) {
0155         for (int cl = 0; cl < (clsize - 1) / 2; cl++) {
0156           if (centralStrip - cl - 1 >= 1) {
0157             fstrip = centralStrip - cl - 1;
0158             cls.push_back(fstrip);
0159           }
0160           if (centralStrip + cl + 1 <= roll->nstrips()) {
0161             lstrip = centralStrip + cl + 1;
0162             cls.push_back(lstrip);
0163           }
0164         }
0165         if (clsize % 2 == 0) {
0166           // insert the last strip according to the
0167           // simhit position in the central strip
0168           double deltaw = roll->centreOfStrip(centralStrip).x() - entr.x();
0169           if (deltaw < 0.) {
0170             if (lstrip < roll->nstrips()) {
0171               lstrip++;
0172               cls.push_back(lstrip);
0173             }
0174           } else {
0175             if (fstrip > 1) {
0176               fstrip--;
0177               cls.push_back(fstrip);
0178             }
0179           }
0180         }
0181       }
0182 
0183       for (std::vector<int>::iterator i = cls.begin(); i != cls.end(); i++) {
0184         // Check the timing of the adjacent strip
0185         if (*i != centralStrip) {
0186           if (CLHEP::RandFlat::shoot(engine) < veff[*i - 1]) {
0187             std::pair<int, int> digi(*i, time_hit);
0188             strips.insert(digi);
0189 
0190             theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
0191           }
0192         } else {
0193           std::pair<int, int> digi(*i, time_hit);
0194           theDetectorHitMap.insert(DetectorHitMap::value_type(digi, &(*_hit)));
0195 
0196           strips.insert(digi);
0197         }
0198       }
0199     }
0200   }
0201 }
0202 
0203 void RPCSimAverageNoiseEff::simulateNoise(const RPCRoll* roll, CLHEP::HepRandomEngine* engine) {
0204   RPCDetId rpcId = roll->id();
0205 
0206   RPCGeomServ RPCname(rpcId);
0207   std::string nameRoll = RPCname.name();
0208 
0209   std::vector<float> vnoise = (getRPCSimSetUp())->getNoise(rpcId.rawId());
0210   std::vector<float> veff = (getRPCSimSetUp())->getEff(rpcId.rawId());
0211 
0212   unsigned int nstrips = roll->nstrips();
0213   double area = 0.0;
0214 
0215   if (rpcId.region() == 0) {
0216     const RectangularStripTopology* top_ = dynamic_cast<const RectangularStripTopology*>(&(roll->topology()));
0217     float xmin = (top_->localPosition(0.)).x();
0218     float xmax = (top_->localPosition((float)roll->nstrips())).x();
0219     float striplength = (top_->stripLength());
0220     area = striplength * (xmax - xmin);
0221   } else {
0222     const TrapezoidalStripTopology* top_ = dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology()));
0223     float xmin = (top_->localPosition(0.)).x();
0224     float xmax = (top_->localPosition((float)roll->nstrips())).x();
0225     float striplength = (top_->stripLength());
0226     area = striplength * (xmax - xmin);
0227   }
0228 
0229   for (unsigned int j = 0; j < vnoise.size(); ++j) {
0230     if (j >= nstrips)
0231       break;
0232 
0233     // The efficiency of 0% does not imply on the noise rate.
0234     // If the strip is masked the noise rate should be 0 Hz/cm^2
0235     //    if(veff[j] == 0) continue;
0236 
0237     //    double ave = vnoise[j]*nbxing*gate*area*1.0e-9*frate;
0238     // The vnoise is the noise rate per strip, so we shout multiply not
0239     // by the chamber area,
0240     // but the strip area which is area/((float)roll->nstrips()));
0241     double ave = vnoise[j] * nbxing * gate * area * 1.0e-9 * frate / ((float)roll->nstrips());
0242 
0243     CLHEP::RandPoissonQ randPoissonQ(*engine, ave);
0244     N_hits = randPoissonQ.fire();
0245 
0246     for (int i = 0; i < N_hits; i++) {
0247       int time_hit = (static_cast<int>(CLHEP::RandFlat::shoot(engine, (nbxing * gate) / gate))) - nbxing / 2;
0248       std::pair<int, int> digi(j + 1, time_hit);
0249       strips.insert(digi);
0250     }
0251   }
0252 }