CMS 3D CMS Logo

BTLDeviceSim.cc
Go to the documentation of this file.
7 
12 
13 #include "CLHEP/Random/RandGaussQ.h"
14 
16  : geomToken_(iC.esConsumes()),
17  topoToken_(iC.esConsumes()),
18  geom_(nullptr),
19  topo_(nullptr),
20  bxTime_(pset.getParameter<double>("bxTime")),
21  LightYield_(pset.getParameter<double>("LightYield")),
22  LightCollEff_(pset.getParameter<double>("LightCollectionEff")),
23  LightCollSlopeR_(pset.getParameter<double>("LightCollectionSlopeR")),
24  LightCollSlopeL_(pset.getParameter<double>("LightCollectionSlopeL")),
25  PDE_(pset.getParameter<double>("PhotonDetectionEff")),
26  LCEpositionSlope_(pset.getParameter<double>("LCEpositionSlope")) {}
27 
29  geom_ = &evs.getData(geomToken_);
30  topo_ = &evs.getData(topoToken_);
31 }
32 
33 void BTLDeviceSim::getHitsResponse(const std::vector<std::tuple<int, uint32_t, float> >& hitRefs,
35  mtd_digitizer::MTDSimHitDataAccumulator* simHitAccumulator,
36  CLHEP::HepRandomEngine* hre) {
37  using namespace geant_units::operators;
38 
39  //loop over sorted simHits
40  for (auto const& hitRef : hitRefs) {
41  const int hitidx = std::get<0>(hitRef);
42  const uint32_t id = std::get<1>(hitRef);
43  const MTDDetId detId(id);
44  const PSimHit& hit = hits->at(hitidx);
45 
46  // --- Safety check on the detector ID
47  if (detId.det() != DetId::Forward || detId.mtdSubDetector() != 1)
48  continue;
49 
50  if (id == 0)
51  continue; // to be ignored at RECO level
52 
53  BTLDetId btlid(detId);
55  const MTDGeomDet* thedet = geom_->idToDet(geoId);
56 
57  if (thedet == nullptr) {
58  throw cms::Exception("BTLDeviceSim") << "GeographicalID: " << std::hex << geoId.rawId() << " (" << detId.rawId()
59  << ") is invalid!" << std::dec << std::endl;
60  }
61  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
62  const RectangularMTDTopology& topo = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
63  // calculate the simhit row and column
64  const auto& position = hit.localPosition();
66  // translate from crystal-local coordinates to module-local coordinates to get the row and column
67  simscaled = topo.pixelToModuleLocalPoint(simscaled, btlid.row(topo.nrows()), btlid.column(topo.nrows()));
68  const auto& thepixel = topo.pixel(simscaled);
69  uint8_t row(thepixel.first), col(thepixel.second);
70 
71  if (btlid.row(topo.nrows()) != row || btlid.column(topo.nrows()) != col) {
72  edm::LogWarning("BTLDeviceSim") << "BTLDetId (row,column): (" << btlid.row(topo.nrows()) << ','
73  << btlid.column(topo.nrows()) << ") is not equal to "
74  << "topology (row,column): (" << uint32_t(row) << ',' << uint32_t(col)
75  << "), overriding to detid";
76  row = btlid.row(topo.nrows());
77  col = btlid.column(topo.nrows());
78  }
79 
80  // --- Store the detector element ID as a key of the MTDSimHitDataAccumulator map
81  auto simHitIt =
82  simHitAccumulator->emplace(mtd_digitizer::MTDCellId(id, row, col), mtd_digitizer::MTDCellInfo()).first;
83 
84  // --- Get the simHit energy and convert it from MeV to photo-electrons
85  float Npe = convertGeVToMeV(hit.energyLoss()) * LightYield_ * LightCollEff_ * PDE_;
86 
87  // --- Calculate the light propagation time to the crystal bases (labeled L and R)
88  double distR = 0.5 * topo.pitch().first - convertMmToCm(hit.localPosition().x());
89  double distL = 0.5 * topo.pitch().first + convertMmToCm(hit.localPosition().x());
90 
91  double tR = std::get<2>(hitRef) + LightCollSlopeR_ * distR;
92  double tL = std::get<2>(hitRef) + LightCollSlopeL_ * distL;
93 
94  // --- Accumulate in 15 buckets of 25ns (9 pre-samples, 1 in-time, 5 post-samples)
95  const int iBXR = std::floor(tR / bxTime_) + mtd_digitizer::kInTimeBX;
96  const int iBXL = std::floor(tL / bxTime_) + mtd_digitizer::kInTimeBX;
97 
98  // --- Right side
99  if (iBXR > 0 && iBXR < mtd_digitizer::kNumberOfBX) {
100  // Accumulate the energy of simHits in the same crystal
101  (simHitIt->second).hit_info[0][iBXR] += Npe * (1. + LCEpositionSlope_ * convertMmToCm(hit.localPosition().x()));
102 
103  // Store the time of the first SimHit in the i-th BX
104  if ((simHitIt->second).hit_info[1][iBXR] == 0 || tR < (simHitIt->second).hit_info[1][iBXR])
105  (simHitIt->second).hit_info[1][iBXR] = tR - (iBXR - mtd_digitizer::kInTimeBX) * bxTime_;
106  }
107 
108  // --- Left side
109  if (iBXL > 0 && iBXL < mtd_digitizer::kNumberOfBX) {
110  // Accumulate the energy of simHits in the same crystal
111  (simHitIt->second).hit_info[2][iBXL] += Npe * (1. - LCEpositionSlope_ * convertMmToCm(hit.localPosition().x()));
112 
113  // Store the time of the first SimHit in the i-th BX
114  if ((simHitIt->second).hit_info[3][iBXL] == 0 || tL < (simHitIt->second).hit_info[3][iBXL])
115  (simHitIt->second).hit_info[3][iBXL] = tL - (iBXL - mtd_digitizer::kInTimeBX) * bxTime_;
116  }
117 
118  } // hitRef loop
119 }
uint8_t geoId(const VFATFrame &frame)
retrieve the GEO information for this channel
int getMTDTopologyMode() const
Definition: MTDTopology.h:27
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int row(unsigned nrows=kCrystalsPerModuleV2) const
Definition: BTLDetId.h:93
const float LightCollSlopeR_
Definition: BTLDeviceSim.h:46
const float LightYield_
Definition: BTLDeviceSim.h:43
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const float LightCollSlopeL_
Definition: BTLDeviceSim.h:47
virtual const Topology & topology() const
Definition: GeomDet.cc:67
const MTDTopology * topo_
Definition: BTLDeviceSim.h:40
virtual const PixelTopology & specificTopology() const
const MTDGeometry * geom_
Definition: BTLDeviceSim.h:39
const edm::ESGetToken< MTDGeometry, MTDDigiGeometryRecord > geomToken_
Definition: BTLDeviceSim.h:37
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: BTLDeviceSim.cc:33
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
LocalPoint pixelToModuleLocalPoint(const LocalPoint &plp, int row, int col) const
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
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
const float bxTime_
Definition: BTLDeviceSim.h:42
const edm::ESGetToken< MTDTopology, MTDTopologyRcd > topoToken_
Definition: BTLDeviceSim.h:38
int nrows() const override
int column(unsigned nrows=kCrystalsPerModuleV2) const
Definition: BTLDetId.h:98
Definition: DetId.h:17
const float LCEpositionSlope_
Definition: BTLDeviceSim.h:49
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
const float PDE_
Definition: BTLDeviceSim.h:48
constexpr int kInTimeBX
std::pair< float, float > pitch() const override
static int position[264][3]
Definition: ReadPGInfo.cc:289
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:19
void getEventSetup(const edm::EventSetup &evt)
Definition: BTLDeviceSim.cc:28
col
Definition: cuy.py:1009
BTLDetId::CrysLayout crysLayoutFromTopoMode(const int &topoMode)
const float LightCollEff_
Definition: BTLDeviceSim.h:44
Log< level::Warning, false > LogWarning
constexpr int kNumberOfBX
BTLDeviceSim(const edm::ParameterSet &pset, edm::ConsumesCollector iC)
Definition: BTLDeviceSim.cc:15
BTLDetId geographicalId(CrysLayout lay) const
Definition: BTLDetId.cc:3