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