CMS 3D CMS Logo

ETLDeviceSim.cc
Go to the documentation of this file.
1 #include "CLHEP/Units/GlobalPhysicalConstants.h"
4 
9 
14 
16  : geomToken_(iC.esConsumes()),
17  geom_(nullptr),
18  MIPPerMeV_(1.0 / pset.getParameter<double>("meVPerMIP")),
19  bxTime_(pset.getParameter<double>("bxTime")),
20  tofDelay_(pset.getParameter<double>("tofDelay")) {}
21 
23 
24 void ETLDeviceSim::getHitsResponse(const std::vector<std::tuple<int, uint32_t, float> >& hitRefs,
26  mtd_digitizer::MTDSimHitDataAccumulator* simHitAccumulator,
27  CLHEP::HepRandomEngine* hre) {
28  using namespace geant_units::operators;
29 
30  //loop over sorted hits
31  const int nchits = hitRefs.size();
32  for (int i = 0; i < nchits; ++i) {
33  const int hitidx = std::get<0>(hitRefs[i]);
34  const uint32_t id = std::get<1>(hitRefs[i]);
35  const MTDDetId detId(id);
36 
37  // Safety check (this should never happen, it should be an exception
38  if (detId.det() != DetId::Forward || detId.mtdSubDetector() != 2) {
39  throw cms::Exception("ETLDeviceSim")
40  << "got a DetId that was not ETL: Det = " << detId.det() << " subDet = " << detId.mtdSubDetector();
41  }
42 
43  if (id == 0)
44  continue; // to be ignored at RECO level
45 
46  ETLDetId etlid(detId);
47  DetId geoId = ETLDetId(etlid.mtdSide(), etlid.mtdRR(), etlid.module(), etlid.modType());
48  const MTDGeomDet* thedet = geom_->idToDet(geoId);
49  if (thedet == nullptr) {
50  throw cms::Exception("ETLDeviceSim") << "GeographicalID: " << std::hex << geoId.rawId() << " (" << detId.rawId()
51  << ") is invalid!" << std::dec << std::endl;
52  }
53  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
54  const RectangularMTDTopology& topo = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
55 
56  const float toa = std::get<2>(hitRefs[i]) + tofDelay_;
57  const PSimHit& hit = hits->at(hitidx);
58  const float charge = convertGeVToMeV(hit.energyLoss()) * MIPPerMeV_;
59 
60  // calculate the simhit row and column
61  const auto& pentry = hit.entryPoint();
62  // ETL is already in module-local coordinates so just scale to cm from mm
63  Local3DPoint simscaled(convertMmToCm(pentry.x()), convertMmToCm(pentry.y()), convertMmToCm(pentry.z()));
64  //The following lines check whether the pixel point is actually out of the active area.
65  //If that is the case it simply ignores the point but in the future some more sophisticated function could be applied.
66  if (!topo.isInPixel(simscaled)) {
67  continue;
68  }
69  const auto& thepixel = topo.pixel(simscaled);
70  const uint8_t row(thepixel.first), col(thepixel.second);
71 
72  auto simHitIt =
73  simHitAccumulator->emplace(mtd_digitizer::MTDCellId(id, row, col), mtd_digitizer::MTDCellInfo()).first;
74 
75  // Accumulate in 15 buckets of 25ns (9 pre-samples, 1 in-time, 5 post-samples)
76  const int itime = std::floor(toa / bxTime_) + 9;
77  if (itime < 0 || itime > 14)
78  continue;
79 
80  // Check if time index is ok and store energy
81  if (itime >= (int)simHitIt->second.hit_info[0].size())
82  continue;
83 
84  (simHitIt->second).hit_info[0][itime] += charge;
85 
86  // Store the time of the first SimHit in the right DataFrame bucket
87  const float tof = toa - (itime - 9) * bxTime_;
88 
89  if ((simHitIt->second).hit_info[1][itime] == 0. || tof < (simHitIt->second).hit_info[1][itime]) {
90  (simHitIt->second).hit_info[1][itime] = tof;
91  }
92  }
93 }
const MTDGeometry * geom_
Definition: ETLDeviceSim.h:36
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool isInPixel(const LocalPoint &p) const
const edm::ESGetToken< MTDGeometry, MTDDigiGeometryRecord > geomToken_
Definition: ETLDeviceSim.h:35
virtual const PixelTopology & specificTopology() const
int mtdSide() const
Definition: MTDDetId.h:59
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
int modType() const
Definition: ETLDetId.h:106
ETLDeviceSim(const edm::ParameterSet &pset, edm::ConsumesCollector iC)
Definition: ETLDeviceSim.cc:15
void getEventSetup(const edm::EventSetup &evt)
Definition: ETLDeviceSim.cc:22
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
std::pair< float, float > pixel(const LocalPoint &p) const override
constexpr NumType convertGeVToMeV(NumType gev)
Definition: angle_units.h:74
int module() const
Definition: ETLDetId.h:103
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
int mtdRR() const
Definition: MTDDetId.h:64
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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:24
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
float tofDelay_
Definition: ETLDeviceSim.h:40
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
col
Definition: cuy.py:1009
float MIPPerMeV_
Definition: ETLDeviceSim.h:38