CMS 3D CMS Logo

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