CMS 3D CMS Logo

BTLBarDeviceSim.cc
Go to the documentation of this file.
5 
11 
12 #include "CLHEP/Random/RandGaussQ.h"
13 
15  : geom_(nullptr),
16  topo_(nullptr),
17  bxTime_(pset.getParameter<double>("bxTime")),
18  LightYield_(pset.getParameter<double>("LightYield")),
19  LightCollEff_(pset.getParameter<double>("LightCollectionEff")),
20  LightCollSlopeR_(pset.getParameter<double>("LightCollectionSlopeR")),
21  LightCollSlopeL_(pset.getParameter<double>("LightCollectionSlopeL")),
22  PDE_(pset.getParameter<double>("PhotonDetectionEff")) {}
23 
26  evs.get<MTDDigiGeometryRecord>().get(geom);
27  geom_ = geom.product();
28 
30  evs.get<MTDTopologyRcd>().get(mtdTopo);
31  topo_ = mtdTopo.product();
32 }
33 
34 void BTLBarDeviceSim::getHitsResponse(const std::vector<std::tuple<int, uint32_t, float> >& hitRefs,
36  mtd_digitizer::MTDSimHitDataAccumulator* simHitAccumulator,
37  CLHEP::HepRandomEngine* hre) {
38  //loop over sorted simHits
39  for (auto const& hitRef : hitRefs) {
40  const int hitidx = std::get<0>(hitRef);
41  const uint32_t id = std::get<1>(hitRef);
42  const MTDDetId detId(id);
43  const PSimHit& hit = hits->at(hitidx);
44 
45  // --- Safety check on the detector ID
46  if (detId.det() != DetId::Forward || detId.mtdSubDetector() != 1)
47  continue;
48 
49  if (id == 0)
50  continue; // to be ignored at RECO level
51 
52  BTLDetId btlid(detId);
53  const int boundRef = btlid.modulesPerType(static_cast<BTLDetId::CrysLayout>(topo_->getMTDTopologyMode()));
54  DetId geoId = BTLDetId(btlid.mtdSide(), btlid.mtdRR(), btlid.module() + boundRef * (btlid.modType() - 1), 0, 1);
55  const MTDGeomDet* thedet = geom_->idToDet(geoId);
56 
57  if (thedet == nullptr) {
58  throw cms::Exception("BTLBarDeviceSim") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
59  << detId.rawId() << ") 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& pentry = hit.entryPoint();
65  Local3DPoint simscaled(0.1 * pentry.x(), 0.1 * pentry.y(), 0.1 * pentry.z()); // mm -> cm here is the switch
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("BTLBarDeviceSim") << "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 = 1000. * hit.energyLoss() * LightYield_ * LightCollEff_ * PDE_;
86 
87  // --- Get the simHit time of arrival
88  float toa = std::get<2>(hitRef);
89 
90  if (toa > bxTime_ || toa < 0) //just consider BX==0
91  continue;
92 
93  // --- Accumulate the energy of simHits in the same crystal for the BX==0
94  // this is to simulate the charge integration in a 25 ns window
95  (simHitIt->second).hit_info[0][0] += Npe;
96  (simHitIt->second).hit_info[0][1] += Npe;
97 
98  double distR = 0.5 * topo.pitch().second - 0.1 * hit.localPosition().y();
99  double distL = 0.5 * topo.pitch().second + 0.1 * hit.localPosition().y();
100 
101  // This is for the layout with bars along phi
104  distR = 0.5 * topo.pitch().first - 0.1 * hit.localPosition().x();
105  distL = 0.5 * topo.pitch().first + 0.1 * hit.localPosition().x();
106  }
107 
108  double tR = toa + LightCollSlopeR_ * distR;
109  double tL = toa + LightCollSlopeL_ * distL;
110 
111  // --- Store the time of the first SimHit
112  if ((simHitIt->second).hit_info[1][0] == 0 || tR < (simHitIt->second).hit_info[1][0])
113  (simHitIt->second).hit_info[1][0] = tR;
114 
115  if ((simHitIt->second).hit_info[1][1] == 0 || tL < (simHitIt->second).hit_info[1][1])
116  (simHitIt->second).hit_info[1][1] = tL;
117 
118  } // hitRef loop
119 }
const float LightCollEff_
int modulesPerType(CrysLayout lay) const
Definition: BTLDetId.cc:153
BTLBarDeviceSim(const edm::ParameterSet &pset)
virtual const Topology & topology() const
Definition: GeomDet.cc:67
#define nullptr
int getMTDTopologyMode() const
Definition: MTDTopology.h:73
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
std::pair< float, float > pitch() const override
int nrows() const override
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:160
const float LightCollSlopeL_
const MTDGeometry * geom_
Local3DPoint localPosition() const
Definition: PSimHit.h:52
virtual const PixelTopology & specificTopology() const
const MTDTopology * topo_
std::pair< float, float > pixel(const LocalPoint &p) const override
LocalPoint pixelToModuleLocalPoint(const LocalPoint &plp, int row, int col) const
int mtdRR() const
Definition: MTDDetId.h:64
const float LightYield_
int mtdSide() const
Definition: MTDDetId.h:59
Definition: DetId.h:17
void getEventSetup(const edm::EventSetup &evt)
const float PDE_
int module() const
Definition: BTLDetId.h:96
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:79
T get() const
Definition: EventSetup.h:73
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:18
col
Definition: cuy.py:1010
int column(unsigned nrows=16) const
Definition: BTLDetId.h:110
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)
T x() const
Definition: PV3DBase.h:59
T const * product() const
Definition: ESHandle.h:86
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:43
int modType() const
Definition: BTLDetId.h:99
const float LightCollSlopeR_
const float bxTime_
int row(unsigned nrows=16) const
Definition: BTLDetId.h:105