CMS 3D CMS Logo

GEMSimHitValidation.cc
Go to the documentation of this file.
4 
6  : GEMBaseValidation(pset, "GEMSimHitValidation") {
7  const auto& simhit_pset = pset.getParameterSet("gemSimHit");
8  const auto& simhit_tag = simhit_pset.getParameter<edm::InputTag>("inputTag");
9  simhit_token_ = consumes<edm::PSimHitContainer>(simhit_tag);
10 
11  tof_range_ = pset.getUntrackedParameter<std::vector<Double_t> >("TOFRange");
12  geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
13  geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
14 }
15 
17 
19  const GEMGeometry* gem = &setup.getData(geomTokenBeginRun_);
20 
21  // NOTE Time of flight
22  booker.setCurrentFolder("MuonGEMHitsV/GEMHitsTask/TimeOfFlight");
23 
24  TString tof_xtitle = "Time of flight [ns]";
25  TString tof_ytitle = "Entries";
26 
27  const auto& regionsVec = gem->regions();
28  if (regionsVec.empty() || regionsVec[0] == nullptr) {
29  edm::LogError(kLogCategory_) << "Regions missing or null.";
30  return;
31  } else {
32  for (const auto& station : regionsVec[0]->stations()) {
33  Int_t station_id = station->station();
34  const auto [tof_min, tof_max] = getTOFRange(station_id);
35  auto tof_name = TString::Format("tof_muon_st%d", station_id);
36  auto tof_title = TString::Format("SimHit Time Of Flight (Muon only) : Station %d", station_id);
37 
38  me_tof_mu_[station_id] = booker.book1D(tof_name, tof_title, 40, tof_min, tof_max);
39  } // end for
40  } // end else
41 
42  if (detail_plot_) {
43  for (const auto& region : gem->regions()) {
44  Int_t region_id = region->region();
45 
46  for (const auto& station : region->stations()) {
47  Int_t station_id = station->station();
48 
49  const auto [tof_min, tof_max] = getTOFRange(station_id);
50  const auto& superChamberVec = station->superChambers();
51  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
52  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
53  << " and station = " << station_id;
54  } else {
55  const GEMSuperChamber* super_chamber = superChamberVec.front();
56 
57  for (const auto& chamber : super_chamber->chambers()) {
58  Int_t layer_id = chamber->id().layer();
59  ME3IdsKey key3{region_id, station_id, layer_id};
60 
61  me_detail_tof_[key3] = bookHist1D(
62  booker, key3, "tof", "Time of Flight of Muon SimHits", 40, tof_min, tof_max, tof_xtitle, tof_ytitle);
63 
65  booker, key3, "tof_muon", "SimHit TOF (Muon only)", 40, tof_min, tof_max, tof_xtitle, tof_ytitle);
66  } // chamber loop
67  } // end else
68  } // station loop
69  } // region loop
70  } // detail plot
71 
72  // NOTE Energy Loss
73  booker.setCurrentFolder("MuonGEMHitsV/GEMHitsTask/EnergyLoss");
74 
75  TString eloss_xtitle = "Energy loss [eV]";
76  TString eloss_ytitle = "Entries / 100 eV";
77 
78  for (const auto& station : gem->regions()[0]->stations()) {
79  Int_t station_id = station->station();
80 
81  auto eloss_name = TString::Format("eloss_muon_st%d", station_id);
82  auto eloss_title = TString::Format("SimHit Energy Loss (Muon only) : Station %d", station_id);
83 
84  me_eloss_mu_[station_id] =
85  booker.book1D(eloss_name, eloss_title + ";" + eloss_xtitle + ";" + eloss_ytitle, 60, 0.0, 6000.0);
86  } // station loop
87 
88  if (detail_plot_) {
89  for (const auto& region : gem->regions()) {
90  Int_t region_id = region->region();
91  for (const auto& station : region->stations()) {
92  Int_t station_id = station->station();
93  const auto& superChamberVec = station->superChambers();
94  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
95  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
96  << " and station = " << station_id;
97  } else {
98  for (const auto& chamber : superChamberVec.front()->chambers()) {
99  Int_t layer_id = chamber->id().layer();
100  ME3IdsKey key3{region_id, station_id, layer_id};
101 
102  me_detail_eloss_[key3] =
103  bookHist1D(booker, key3, "eloss", "SimHit Energy Loss", 60, 0.0, 6000.0, eloss_xtitle, eloss_ytitle);
104 
105  me_detail_eloss_mu_[key3] = bookHist1D(booker,
106  key3,
107  "eloss_muon",
108  "SimHit Energy Loss (Muon Only)",
109  60,
110  0.0,
111  6000.0,
112  eloss_xtitle,
113  eloss_ytitle);
114 
115  } // chamber loop
116  } // end else
117  } // station loop
118  } // region loop
119  } // detail plot
120 
121  // NOTE Occupancy
122  booker.setCurrentFolder("MuonGEMHitsV/GEMHitsTask/Occupancy");
123 
124  for (const auto& region : gem->regions()) {
125  Int_t region_id = region->region();
126 
127  me_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "simhit", "SimHit");
128 
129  for (const auto& station : region->stations()) {
130  Int_t station_id = station->station();
131  ME2IdsKey key2{region_id, station_id};
132 
133  me_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "simhit", "SimHit");
134 
135  const auto& superChamberVec = station->superChambers();
136  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
137  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
138  << " and station = " << station_id;
139  } else {
140  const GEMSuperChamber* super_chamber = superChamberVec.front();
141  for (const auto& chamber : super_chamber->chambers()) {
142  Int_t layer_id = chamber->id().layer();
143  ME3IdsKey key3{region_id, station_id, layer_id};
144 
145  me_occ_xy_[key3] = bookXYOccupancy(booker, key3, "simhit", "SimHit");
146  } // layer loop
147  } // end else
148  } // station loop
149  } // region loop
150 }
151 
152 std::tuple<Double_t, Double_t> GEMSimHitValidation::getTOFRange(Int_t station_id) {
153  UInt_t start_index = station_id == 1 ? 0 : 2;
154  Double_t tof_min = tof_range_[start_index];
155  Double_t tof_max = tof_range_[start_index + 1];
156  return std::make_tuple(tof_min, tof_max);
157 }
158 
160  const GEMGeometry* gem = &setup.getData(geomToken_);
161 
162  edm::Handle<edm::PSimHitContainer> simhit_container;
163  event.getByToken(simhit_token_, simhit_container);
164  if (not simhit_container.isValid()) {
165  edm::LogError(kLogCategory_) << "Cannot get GEMHits by Token simhitLabel" << std::endl;
166  return;
167  }
168 
169  for (const auto& simhit : *simhit_container.product()) {
170  const GEMDetId gemid(simhit.detUnitId());
171 
172  if (gem->idToDet(gemid) == nullptr) {
173  edm::LogError(kLogCategory_) << "SimHit did not matched with GEM Geometry." << std::endl;
174  continue;
175  }
176 
177  Int_t region_id = gemid.region();
178  Int_t station_id = gemid.station();
179  Int_t layer_id = gemid.layer();
180  Int_t chamber_id = gemid.chamber();
181  Int_t roll_id = gemid.roll();
182 
183  ME2IdsKey key2{region_id, station_id};
184  ME3IdsKey key3{region_id, station_id, layer_id};
185 
186  GlobalPoint&& simhit_global_pos = gem->idToDet(gemid)->surface().toGlobal(simhit.localPosition());
187 
188  Float_t simhit_g_r = simhit_global_pos.perp();
189  Float_t simhit_g_x = simhit_global_pos.x();
190  Float_t simhit_g_y = simhit_global_pos.y();
191  Float_t simhit_g_abs_z = std::fabs(simhit_global_pos.z());
192 
193  Float_t energy_loss = kEnergyCF_ * simhit.energyLoss();
194  Float_t tof = simhit.timeOfFlight();
195 
196  // NOTE Fill MonitorElement
197  Int_t bin_x = getDetOccBinX(chamber_id, layer_id);
198 
199  me_occ_zr_[region_id]->Fill(simhit_g_abs_z, simhit_g_r);
200  me_occ_det_[key2]->Fill(bin_x, roll_id);
201  me_occ_xy_[key3]->Fill(simhit_g_x, simhit_g_y);
202 
203  bool is_muon_simhit = isMuonSimHit(simhit);
204  if (is_muon_simhit) {
205  me_tof_mu_[station_id]->Fill(tof);
206  me_eloss_mu_[station_id]->Fill(energy_loss);
207  }
208 
209  if (detail_plot_) {
210  me_detail_tof_[key3]->Fill(tof);
211  me_detail_eloss_[key3]->Fill(energy_loss);
212 
213  if (is_muon_simhit) {
214  me_detail_tof_mu_[key3]->Fill(tof);
215  me_detail_eloss_mu_[key3]->Fill(energy_loss);
216  }
217 
218  } // detail_plot
219  } // simhit loop
220 }
ME2IdsKey
std::tuple< Int_t, Int_t > ME2IdsKey
Definition: GEMValidationUtils.h:16
GEMSimHitValidation::tof_range_
std::vector< Double_t > tof_range_
Definition: GEMSimHitValidation.h:25
Handle.h
GEMBaseValidation::bookHist1D
dqm::impl::MonitorElement * bookHist1D(DQMStore::IBooker &booker, const T &key, const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *x_title="", const char *y_title="Entries")
Definition: GEMBaseValidation.h:210
GEMSuperChamber::chambers
const std::vector< const GEMChamber * > & chambers() const
Return the chambers in the super chamber.
Definition: GEMSuperChamber.cc:23
edm::Handle::product
T const * product() const
Definition: Handle.h:70
GEMBaseValidation::detail_plot_
Bool_t detail_plot_
Definition: GEMBaseValidation.h:88
GEMSuperChamber
Definition: GEMSuperChamber.h:19
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
GEMSimHitValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: GEMSimHitValidation.cc:18
GEMBaseValidation::bookDetectorOccupancy
dqm::impl::MonitorElement * bookDetectorOccupancy(DQMStore::IBooker &booker, const T &key, const GEMStation *station, const char *name_prfix, const char *title_prefix)
Definition: GEMBaseValidation.h:161
relativeConstraints.station
station
Definition: relativeConstraints.py:67
GEMSimHitValidation::geomToken_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Definition: GEMSimHitValidation.h:23
PSimHitContainer.h
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
GEMSimHitValidation::me_detail_eloss_
MEMap3Ids me_detail_eloss_
Definition: GEMSimHitValidation.h:32
GEMSimHitValidation::me_detail_tof_mu_
MEMap3Ids me_detail_tof_mu_
Definition: GEMSimHitValidation.h:30
GEMSimHitValidation::me_occ_zr_
MEMap1Ids me_occ_zr_
Definition: GEMSimHitValidation.h:34
edm::Handle< edm::PSimHitContainer >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
GEMSimHitValidation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: GEMSimHitValidation.cc:159
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
GEMBaseValidation::isMuonSimHit
Bool_t isMuonSimHit(const PSimHit &)
Definition: GEMBaseValidation.cc:25
GEMBaseValidation::bookZROccupancy
dqm::impl::MonitorElement * bookZROccupancy(DQMStore::IBooker &booker, Int_t region_id, const char *name_prfix, const char *title_prefix)
Definition: GEMBaseValidation.cc:27
GEMSimHitValidation::me_occ_det_
MEMap2Ids me_occ_det_
Definition: GEMSimHitValidation.h:35
GEMBaseValidation::bookXYOccupancy
dqm::impl::MonitorElement * bookXYOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
Definition: GEMBaseValidation.h:134
Point3DBase< float, GlobalTag >
GEMSimHitValidation::geomTokenBeginRun_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
Definition: GEMSimHitValidation.h:24
GEMSimHitValidation::me_detail_eloss_mu_
MEMap3Ids me_detail_eloss_mu_
Definition: GEMSimHitValidation.h:33
edm::ParameterSet
Definition: ParameterSet.h:47
GEMDetId
Definition: GEMDetId.h:18
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88272
GEMBaseValidation
Definition: GEMBaseValidation.h:18
GEMSimHitValidation::me_occ_xy_
MEMap3Ids me_occ_xy_
Definition: GEMSimHitValidation.h:36
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
gem
Definition: AMC13Event.h:6
GEMSimHitValidation::GEMSimHitValidation
GEMSimHitValidation(const edm::ParameterSet &)
Definition: GEMSimHitValidation.cc:5
GEMSimHitValidation::getTOFRange
std::tuple< Double_t, Double_t > getTOFRange(Int_t station_id)
Definition: GEMSimHitValidation.cc:152
writedatasetfile.run
run
Definition: writedatasetfile.py:27
GEMSimHitValidation::me_detail_tof_
MEMap3Ids me_detail_tof_
Definition: GEMSimHitValidation.h:29
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
ME3IdsKey
std::tuple< Int_t, Int_t, Int_t > ME3IdsKey
Definition: GEMValidationUtils.h:19
GEMSimHitValidation::simhit_token_
edm::EDGetTokenT< edm::PSimHitContainer > simhit_token_
Definition: GEMSimHitValidation.h:22
dqm::implementation::IBooker
Definition: DQMStore.h:43
GEMGeometry
Definition: GEMGeometry.h:24
GEMSimHitValidation.h
GEMSimHitValidation::me_tof_mu_
std::map< Int_t, MonitorElement * > me_tof_mu_
Definition: GEMSimHitValidation.h:28
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
GEMSimHitValidation::~GEMSimHitValidation
~GEMSimHitValidation() override
Definition: GEMSimHitValidation.cc:16
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
GEMSimHitValidation::kEnergyCF_
const Float_t kEnergyCF_
Definition: GEMSimHitValidation.h:39
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
GEMBaseValidation::getDetOccBinX
Int_t getDetOccBinX(Int_t chamber_id, Int_t layer_id)
Definition: GEMBaseValidation.cc:23
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
GEMBaseValidation::kLogCategory_
const std::string kLogCategory_
Definition: GEMBaseValidation.h:92
GEMSimHitValidation::me_eloss_mu_
MEMap1Ids me_eloss_mu_
Definition: GEMSimHitValidation.h:31