CMS 3D CMS Logo

BtlSimHitsValidation.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Package: Validation/MtdValidation
5 // Class: BtlSimHitsValidation
6 //
15 #include <string>
16 
21 
24 
28 
30 
35 
38 
39 struct MTDHit {
40  float energy;
41  float time;
42  float x;
43  float y;
44  float z;
45 };
46 
48 public:
49  explicit BtlSimHitsValidation(const edm::ParameterSet&);
50  ~BtlSimHitsValidation() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
56 
57  void analyze(const edm::Event&, const edm::EventSetup&) override;
58 
59  // ------------ member data ------------
60 
62 
63  const float hitMinEnergy_;
64 
66 
67  // --- histograms declaration
68 
71 
74 
78 
80 
86 
94 };
95 
96 // ------------ constructor and destructor --------------
98  : folder_(iConfig.getParameter<std::string>("folder")),
99  hitMinEnergy_(iConfig.getParameter<double>("hitMinimumEnergy")) {
100  btlSimHitsToken_ = consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("inputTag"));
101 }
102 
104 
105 // ------------ method called for each event ------------
107  using namespace edm;
108  using namespace geant_units::operators;
109 
110  edm::ESHandle<MTDGeometry> geometryHandle;
111  iSetup.get<MTDDigiGeometryRecord>().get(geometryHandle);
112  const MTDGeometry* geom = geometryHandle.product();
113 
114  edm::ESHandle<MTDTopology> topologyHandle;
115  iSetup.get<MTDTopologyRcd>().get(topologyHandle);
116  const MTDTopology* topology = topologyHandle.product();
117 
118  auto btlSimHitsHandle = makeValid(iEvent.getHandle(btlSimHitsToken_));
119 
120  std::unordered_map<uint32_t, MTDHit> m_btlHits;
121  std::unordered_map<uint32_t, std::set<int> > m_btlTrkPerCell;
122 
123  // --- Loop over the BLT SIM hits
124  for (auto const& simHit : *btlSimHitsHandle) {
125  // --- Use only hits compatible with the in-time bunch-crossing
126  if (simHit.tof() < 0 || simHit.tof() > 25.)
127  continue;
128 
129  DetId id = simHit.detUnitId();
130 
131  m_btlTrkPerCell[id.rawId()].insert(simHit.trackId());
132 
133  auto simHitIt = m_btlHits.emplace(id.rawId(), MTDHit()).first;
134 
135  // --- Accumulate the energy (in MeV) of SIM hits in the same detector cell
136  (simHitIt->second).energy += convertUnitsTo(0.001_MeV, simHit.energyLoss());
137 
138  // --- Get the time of the first SIM hit in the cell
139  if ((simHitIt->second).time == 0 || simHit.tof() < (simHitIt->second).time) {
140  (simHitIt->second).time = simHit.tof();
141 
142  auto hit_pos = simHit.entryPoint();
143  (simHitIt->second).x = hit_pos.x();
144  (simHitIt->second).y = hit_pos.y();
145  (simHitIt->second).z = hit_pos.z();
146  }
147 
148  } // simHit loop
149 
150  // ==============================================================================
151  // Histogram filling
152  // ==============================================================================
153 
154  meNhits_->Fill(m_btlHits.size());
155 
156  for (auto const& hit : m_btlTrkPerCell)
157  meNtrkPerCell_->Fill((hit.second).size());
158 
159  for (auto const& hit : m_btlHits) {
160  if ((hit.second).energy < hitMinEnergy_)
161  continue;
162 
163  // --- Get the SIM hit global position
164  BTLDetId detId(hit.first);
165  DetId geoId = detId.geographicalId(static_cast<BTLDetId::CrysLayout>(topology->getMTDTopologyMode()));
166  const MTDGeomDet* thedet = geom->idToDet(geoId);
167  if (thedet == nullptr)
168  throw cms::Exception("BtlSimHitsValidation") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
169  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
170  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
171  const RectangularMTDTopology& topo = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
172 
173  Local3DPoint local_point(
174  convertMmToCm((hit.second).x), convertMmToCm((hit.second).y), convertMmToCm((hit.second).z));
175 
176  local_point = topo.pixelToModuleLocalPoint(local_point, detId.row(topo.nrows()), detId.column(topo.nrows()));
177  const auto& global_point = thedet->toGlobal(local_point);
178 
179  // --- Fill the histograms
180  meHitEnergy_->Fill((hit.second).energy);
181  meHitTime_->Fill((hit.second).time);
182 
183  meHitXlocal_->Fill((hit.second).x);
184  meHitYlocal_->Fill((hit.second).y);
185  meHitZlocal_->Fill((hit.second).z);
186 
187  meOccupancy_->Fill(global_point.z(), global_point.phi());
188 
189  meHitX_->Fill(global_point.x());
190  meHitY_->Fill(global_point.y());
191  meHitZ_->Fill(global_point.z());
192  meHitPhi_->Fill(global_point.phi());
193  meHitEta_->Fill(global_point.eta());
194 
195  meHitTvsE_->Fill((hit.second).energy, (hit.second).time);
196  meHitEvsPhi_->Fill(global_point.phi(), (hit.second).energy);
197  meHitEvsEta_->Fill(global_point.eta(), (hit.second).energy);
198  meHitEvsZ_->Fill(global_point.z(), (hit.second).energy);
199  meHitTvsPhi_->Fill(global_point.phi(), (hit.second).time);
200  meHitTvsEta_->Fill(global_point.eta(), (hit.second).time);
201  meHitTvsZ_->Fill(global_point.z(), (hit.second).time);
202 
203  } // hit loop
204 }
205 
206 // ------------ method for histogram booking ------------
208  edm::Run const& run,
209  edm::EventSetup const& iSetup) {
210  ibook.setCurrentFolder(folder_);
211 
212  // --- histograms booking
213 
214  meNhits_ = ibook.book1D("BtlNhits", "Number of BTL cells with SIM hits;N_{BTL cells}", 100, 0., 5000.);
215  meNtrkPerCell_ = ibook.book1D("BtlNtrkPerCell", "Number of tracks per BTL cell;N_{trk}", 10, 0., 10.);
216 
217  meHitEnergy_ = ibook.book1D("BtlHitEnergy", "BTL SIM hits energy;E_{SIM} [MeV]", 100, 0., 20.);
218  meHitTime_ = ibook.book1D("BtlHitTime", "BTL SIM hits ToA;ToA_{SIM} [ns]", 100, 0., 25.);
219 
220  meHitXlocal_ = ibook.book1D("BtlHitXlocal", "BTL SIM local X;X_{SIM}^{LOC} [mm]", 100, -30., 30.);
221  meHitYlocal_ = ibook.book1D("BtlHitYlocal", "BTL SIM local Y;Y_{SIM}^{LOC} [mm]", 100, -1.65, 1.65);
222  meHitZlocal_ = ibook.book1D("BtlHitZlocal", "BTL SIM local z;z_{SIM}^{LOC} [mm]", 100, -2., 2.);
223 
224  meOccupancy_ = ibook.book2D(
225  "BtlOccupancy", "BTL SIM hits occupancy;z_{SIM} [cm];#phi_{SIM} [rad]", 130, -260., 260., 200, -3.15, 3.15);
226 
227  meHitX_ = ibook.book1D("BtlHitX", "BTL SIM hits X;X_{SIM} [cm]", 100, -120., 120.);
228  meHitY_ = ibook.book1D("BtlHitY", "BTL SIM hits Y;Y_{SIM} [cm]", 100, -120., 120.);
229  meHitZ_ = ibook.book1D("BtlHitZ", "BTL SIM hits Z;Z_{SIM} [cm]", 100, -260., 260.);
230  meHitPhi_ = ibook.book1D("BtlHitPhi", "BTL SIM hits #phi;#phi_{SIM} [rad]", 200, -3.15, 3.15);
231  meHitEta_ = ibook.book1D("BtlHitEta", "BTL SIM hits #eta;#eta_{SIM}", 100, -1.55, 1.55);
232 
233  meHitTvsE_ =
234  ibook.bookProfile("BtlHitTvsE", "BTL SIM time vs energy;E_{SIM} [MeV];T_{SIM} [ns]", 50, 0., 20., 0., 100.);
235  meHitEvsPhi_ = ibook.bookProfile(
236  "BtlHitEvsPhi", "BTL SIM energy vs #phi;#phi_{SIM} [rad];E_{SIM} [MeV]", 50, -3.15, 3.15, 0., 100.);
237  meHitEvsEta_ =
238  ibook.bookProfile("BtlHitEvsEta", "BTL SIM energy vs #eta;#eta_{SIM};E_{SIM} [MeV]", 50, -1.55, 1.55, 0., 100.);
239  meHitEvsZ_ =
240  ibook.bookProfile("BtlHitEvsZ", "BTL SIM energy vs Z;Z_{SIM} [cm];E_{SIM} [MeV]", 50, -260., 260., 0., 100.);
241  meHitTvsPhi_ = ibook.bookProfile(
242  "BtlHitTvsPhi", "BTL SIM time vs #phi;#phi_{SIM} [rad];T_{SIM} [ns]", 50, -3.15, 3.15, 0., 100.);
243  meHitTvsEta_ =
244  ibook.bookProfile("BtlHitTvsEta", "BTL SIM time vs #eta;#eta_{SIM};T_{SIM} [ns]", 50, -1.55, 1.55, 0., 100.);
245  meHitTvsZ_ =
246  ibook.bookProfile("BtlHitTvsZ", "BTL SIM time vs Z;Z_{SIM} [cm];T_{SIM} [ns]", 50, -260., 260., 0., 100.);
247 }
248 
249 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
252 
253  desc.add<std::string>("folder", "MTD/BTL/SimHits");
254  desc.add<edm::InputTag>("inputTag", edm::InputTag("g4SimHits", "FastTimerHitsBarrel"));
255  desc.add<double>("hitMinimumEnergy", 1.); // [MeV]
256 
257  descriptions.add("btlSimHits", desc);
258 }
259 
MonitorElement * meHitEta_
T getParameter(std::string const &) const
MonitorElement * meHitZlocal_
MonitorElement * meHitPhi_
edm::EDGetTokenT< edm::PSimHitContainer > btlSimHitsToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string folder_
constexpr NumType convertUnitsTo(long double desiredUnits, NumType val)
Definition: GeantUnits.h:122
MonitorElement * meHitXlocal_
MonitorElement * meNtrkPerCell_
CaloTopology const * topology(0)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
virtual const Topology & topology() const
Definition: GeomDet.cc:81
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
int getMTDTopologyMode() const
Definition: MTDTopology.h:74
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
int nrows() const override
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void Fill(long long x)
MonitorElement * meHitEvsPhi_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:184
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BTLDetId geographicalId(CrysLayout lay) const
Definition: BTLDetId.cc:162
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
const std::string folder_
MonitorElement * meHitEnergy_
MonitorElement * meOccupancy_
virtual const PixelTopology & specificTopology() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * meHitEvsEta_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
LocalPoint pixelToModuleLocalPoint(const LocalPoint &plp, int row, int col) const
MonitorElement * meHitEvsZ_
MonitorElement * meHitYlocal_
MonitorElement * meHitTvsPhi_
MonitorElement * meHitTvsE_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DetId.h:18
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
BtlSimHitsValidation(const edm::ParameterSet &)
example_stream void bookHistograms(DQMStore::IBooker &,@example_stream edm::Run const &,@example_stream edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
MonitorElement * meHitTvsZ_
MonitorElement * meHitTime_
HLT enums.
T get() const
Definition: EventSetup.h:71
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:18
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:110
int column(unsigned nrows=16) const
Definition: BTLDetId.h:110
MonitorElement * meHitTvsEta_
auto makeValid(const U &iOtherHandleType) noexcept(false)
Definition: ValidHandle.h:59
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:45
int row(unsigned nrows=16) const
Definition: BTLDetId.h:105