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/RPCSynchronizer.h"
00004 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00005 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00006
00007 #include <FWCore/Framework/interface/Frameworkfwd.h>
00008 #include <FWCore/Framework/interface/EventSetup.h>
00009 #include <FWCore/Framework/interface/EDAnalyzer.h>
00010 #include <FWCore/Framework/interface/Event.h>
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include <FWCore/Framework/interface/ESHandle.h>
00013
00014 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00015 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00016 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00017 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00018 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00019 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
00020 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00021
00022 #include "FWCore/ServiceRegistry/interface/Service.h"
00023 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00024 #include "FWCore/Utilities/interface/Exception.h"
00025 #include "CLHEP/Random/RandomEngine.h"
00026 #include "CLHEP/Random/RandFlat.h"
00027 #include <CLHEP/Random/RandGaussQ.h>
00028 #include <CLHEP/Random/RandFlat.h>
00029
00030 #include<cstring>
00031 #include<iostream>
00032 #include<fstream>
00033 #include<string>
00034 #include<vector>
00035 #include<stdlib.h>
00036 #include <cmath>
00037
00038 using namespace std;
00039
00040 RPCSynchronizer::RPCSynchronizer(const edm::ParameterSet& config){
00041
00042 resRPC = config.getParameter<double>("timeResolution");
00043 timOff = config.getParameter<double>("timingRPCOffset");
00044 dtimCs = config.getParameter<double>("deltatimeAdjacentStrip");
00045 resEle = config.getParameter<double>("timeJitter");
00046 sspeed = config.getParameter<double>("signalPropagationSpeed");
00047 lbGate = config.getParameter<double>("linkGateWidth");
00048
00049 cosmics = config.getParameter<bool>("cosmics");
00050
00051
00052 cosmicPar=37.62;
00053
00054 double c=299792458;
00055
00056 cspeed=c*1e+2*1e-9;
00057
00058 sspeed=sspeed*cspeed;
00059
00060 }
00061
00062 void RPCSynchronizer::setRandomEngine(CLHEP::HepRandomEngine& eng){
00063 gauss1 = new CLHEP::RandGaussQ(eng);
00064 gauss2 = new CLHEP::RandGaussQ(eng);
00065 }
00066
00067
00068 RPCSynchronizer::~RPCSynchronizer(){
00069 delete gauss1;
00070 delete gauss2;
00071 }
00072
00073
00074 int RPCSynchronizer::getSimHitBx(const PSimHit* simhit)
00075 {
00076
00077 RPCSimSetUp* simsetup = this->getRPCSimSetUp();
00078 const RPCGeometry * geometry = simsetup->getGeometry();
00079 float timeref = simsetup->getTime(simhit->detUnitId());
00080
00081 int bx = -999;
00082 LocalPoint simHitPos = simhit->localPosition();
00083 float tof = simhit->timeOfFlight();
00084
00085
00086
00087 float rr_el = gauss1->fire(0.,resEle);
00088
00089 RPCDetId SimDetId(simhit->detUnitId());
00090
00091 const RPCRoll* SimRoll = 0;
00092
00093 for(TrackingGeometry::DetContainer::const_iterator it = geometry->dets().begin(); it != geometry->dets().end(); it++){
00094
00095 if( dynamic_cast< RPCChamber* >( *it ) != 0 ){
00096
00097 RPCChamber* ch = dynamic_cast< RPCChamber* >( *it );
00098
00099 std::vector< const RPCRoll*> rollsRaf = (ch->rolls());
00100 for(std::vector<const RPCRoll*>::iterator r = rollsRaf.begin();
00101 r != rollsRaf.end(); ++r){
00102
00103 if((*r)->id() == SimDetId) {
00104 SimRoll = &(*(*r));
00105 break;
00106 }
00107 }
00108 }
00109 }
00110
00111 if(SimRoll != 0){
00112
00113 float distanceFromEdge = 0;
00114 float half_stripL = 0.;
00115
00116 if(SimRoll->id().region() == 0){
00117 const RectangularStripTopology* top_= dynamic_cast<const RectangularStripTopology*> (&(SimRoll->topology()));
00118 half_stripL = top_->stripLength()/2;
00119 distanceFromEdge = half_stripL + simHitPos.y();
00120 }else{
00121 const TrapezoidalStripTopology* top_= dynamic_cast<const TrapezoidalStripTopology*> (&(SimRoll->topology()));
00122 half_stripL = top_->stripLength()/2;
00123 distanceFromEdge = half_stripL - simHitPos.y();
00124 }
00125
00126
00127 float prop_time = distanceFromEdge/sspeed;
00128
00129 double rr_tim1 = gauss2->fire(0.,resEle);
00130 double total_time = tof + prop_time + timOff + rr_tim1 + rr_el;
00131
00132
00133 double time_differ = 0.;
00134
00135 if(cosmics){
00136 time_differ = (total_time - (timeref + ((half_stripL/sspeed ) + timOff)))/cosmicPar;
00137 }
00138 else if(!cosmics){
00139 time_differ = total_time - (timeref + ( half_stripL/sspeed ) + timOff);
00140 }
00141
00142 double inf_time = 0;
00143 double sup_time = 0;
00144
00145
00146 for(int n = -5; n <= 5; ++n){
00147
00148 if(cosmics){
00149 inf_time = (-lbGate/2 + n*lbGate )/cosmicPar;
00150 sup_time = ( lbGate/2 + n*lbGate )/cosmicPar;
00151 }
00152 else if(!cosmics){
00153 inf_time = -lbGate/2 + n*lbGate;
00154 sup_time = lbGate/2 + n*lbGate;
00155 }
00156
00157 if(inf_time < time_differ && time_differ < sup_time) {
00158 bx = n;
00159 break;
00160 }
00161 }
00162 }
00163
00164
00165 return bx;
00166 }
00167