CMS 3D CMS Logo

ETLDeviceSim.cc
Go to the documentation of this file.
1 #include "CLHEP/Units/GlobalPhysicalConstants.h"
6 
9 
11  : geom_(nullptr),
12  MIPPerMeV_(1.0 / pset.getParameter<double>("meVPerMIP")),
13  bxTime_(pset.getParameter<double>("bxTime")),
14  tofDelay_(pset.getParameter<double>("tofDelay")) {}
15 
18  evs.get<MTDDigiGeometryRecord>().get(geom);
19  geom_ = geom.product();
20 }
21 
22 void ETLDeviceSim::getHitsResponse(const std::vector<std::tuple<int, uint32_t, float> >& hitRefs,
24  mtd_digitizer::MTDSimHitDataAccumulator* simHitAccumulator,
25  CLHEP::HepRandomEngine* hre) {
26  //loop over sorted hits
27  const int nchits = hitRefs.size();
28  for (int i = 0; i < nchits; ++i) {
29  const int hitidx = std::get<0>(hitRefs[i]);
30  const uint32_t id = std::get<1>(hitRefs[i]);
31  const MTDDetId detId(id);
32 
33  // Safety check (this should never happen, it should be an exception
34  if (detId.det() != DetId::Forward || detId.mtdSubDetector() != 2) {
35  throw cms::Exception("ETLDeviceSim")
36  << "got a DetId that was not ETL: Det = " << detId.det() << " subDet = " << detId.mtdSubDetector();
37  }
38 
39  if (id == 0)
40  continue; // to be ignored at RECO level
41 
42  ETLDetId etlid(detId);
43  DetId geoId = ETLDetId(etlid.mtdSide(), etlid.mtdRR(), etlid.module(), 0);
44  const MTDGeomDet* thedet = geom_->idToDet(geoId);
45  if (thedet == nullptr) {
46  throw cms::Exception("ETLDeviceSim") << "GeographicalID: " << std::hex << geoId.rawId() << " (" << detId.rawId()
47  << ") is invalid!" << std::dec << std::endl;
48  }
49  const PixelTopology& topo = static_cast<const PixelTopology&>(thedet->topology());
50 
51  const float toa = std::get<2>(hitRefs[i]) + tofDelay_;
52  const PSimHit& hit = hits->at(hitidx);
53  const float charge = 1000.f * hit.energyLoss() * MIPPerMeV_;
54 
55  // calculate the simhit row and column
56  const auto& pentry = hit.entryPoint();
57  // ETL is already in module-local coordinates so just scale to cm from mm
58  Local3DPoint simscaled(0.1 * pentry.x(), 0.1 * pentry.y(), 0.1 * pentry.z());
59  const auto& thepixel = topo.pixel(simscaled); // mm -> cm here is the switch
60  const uint8_t row(thepixel.first), col(thepixel.second);
61 
62  auto simHitIt =
63  simHitAccumulator->emplace(mtd_digitizer::MTDCellId(id, row, col), mtd_digitizer::MTDCellInfo()).first;
64 
65  // Accumulate in 15 buckets of 25ns (9 pre-samples, 1 in-time, 5 post-samples)
66  const int itime = std::floor(toa / bxTime_) + 9;
67  if (itime < 0 || itime > 14)
68  continue;
69 
70  // Check if time index is ok and store energy
71  if (itime >= (int)simHitIt->second.hit_info[0].size())
72  continue;
73 
74  (simHitIt->second).hit_info[0][itime] += charge;
75 
76  // Store the time of the first SimHit in the right DataFrame bucket
77  const float tof = toa - (itime - 9) * bxTime_;
78 
79  if ((simHitIt->second).hit_info[1][itime] == 0. || tof < (simHitIt->second).hit_info[1][itime]) {
80  (simHitIt->second).hit_info[1][itime] = tof;
81  }
82  }
83 }
const MTDGeometry * geom_
Definition: ETLDeviceSim.h:35
virtual std::pair< float, float > pixel(const LocalPoint &p) const =0
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
void getEventSetup(const edm::EventSetup &evt)
Definition: ETLDeviceSim.cc:16
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:160
int mtdRR() const
Definition: MTDDetId.h:64
int mtdSide() const
Definition: MTDDetId.h:59
Definition: DetId.h:17
void getHitsResponse(const std::vector< std::tuple< int, uint32_t, float > > &hitRefs, const edm::Handle< edm::PSimHitContainer > &hits, mtd_digitizer::MTDSimHitDataAccumulator *simHitAccumulator, CLHEP::HepRandomEngine *hre)
Definition: ETLDeviceSim.cc:22
float tofDelay_
Definition: ETLDeviceSim.h:39
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
int module() const
Definition: ETLDetId.h:46
T get() const
Definition: EventSetup.h:73
col
Definition: cuy.py:1010
float MIPPerMeV_
Definition: ETLDeviceSim.h:37
T const * product() const
Definition: ESHandle.h:86
ETLDeviceSim(const edm::ParameterSet &pset)
Definition: ETLDeviceSim.cc:10