54 void fillWithRecHits(std::map<DetId, const HGCRecHit*>&,
DetId,
unsigned int,
float,
int&,
float&);
84 : rawRecHits_(iConfig.getParameter<
bool>(
"rawRecHits")), debug_(iConfig.getParameter<
int>(
"debug")) {
95 recHitsFH_ = consumes<HGCRecHitCollection>(recHitsFH);
96 recHitsBH_ = consumes<HGCRecHitCollection>(recHitsBH);
102 recHitsFH_ = consumes<HGCRecHitCollection>(recHitsFH);
103 recHitsBH_ = consumes<HGCRecHitCollection>(recHitsBH);
132 ibooker.
book1D(
"hgcal_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
134 ibooker.
book1D(
"hgcal_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
136 ibooker.
book1D(
"hgcal_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
139 ibooker.
book1D(
"hgcal_ele_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
141 ibooker.
book1D(
"hgcal_ele_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
143 ibooker.
book1D(
"hgcal_ele_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
145 ibooker.
book1D(
"hgcal_ele_EoP_CPene_scint_calib_fraction",
"", 1000, -0.5, 2.5);
147 ibooker.
book1D(
"hgcal_photon_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
149 ibooker.
book1D(
"hgcal_photon_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
151 ibooker.
book1D(
"hgcal_photon_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
153 ibooker.
book1D(
"hgcal_photon_EoP_CPene_scint_calib_fraction",
"", 1000, -0.5, 2.5);
159 const unsigned int hitlayer,
163 if (hitmap.find(hitid) == hitmap.end()) {
166 <<
">>> Failed to find detid " << std::hex << hitid.
rawId() <<
std::dec <<
" Det " << hitid.
det() <<
" Subdet "
173 <<
">>> Wrong type of detid " << std::hex << hitid.
rawId() <<
std::dec <<
" Det " << hitid.
det() <<
" Subdet "
179 assert(hitlayer == layer);
182 if (seedEnergy < hitmap[hitid]->
energy()) {
183 seedEnergy = hitmap[hitid]->energy();
202 const std::vector<CaloParticle>&
caloParticles = *caloParticleHandle;
214 std::map<DetId, const HGCRecHit*> hitmap;
220 const auto& rechitsEE = *recHitHandleEE;
221 const auto& rechitsFH = *recHitHandleFH;
222 const auto& rechitsBH = *recHitHandleBH;
223 for (
unsigned int i = 0;
i < rechitsEE.size(); ++
i) {
224 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
226 for (
unsigned int i = 0;
i < rechitsFH.size(); ++
i) {
227 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
229 for (
unsigned int i = 0;
i < rechitsBH.size(); ++
i) {
230 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
237 for (
unsigned int i = 0;
i < rechitsEE.
size();
i++) {
238 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
245 const auto& rechitsFH = *recHitHandleFH;
246 const auto& rechitsBH = *recHitHandleBH;
247 for (
unsigned int i = 0;
i < rechitsFH.size();
i++) {
248 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
250 for (
unsigned int i = 0;
i < rechitsBH.size();
i++) {
251 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
262 float seedEnergy = 0.;
265 if (it_caloPart.g4Tracks()[0].eventId().event() != 0
or it_caloPart.g4Tracks()[0].eventId().bunchCrossing() != 0) {
266 LogDebug(
"HGCalHitCalibration") <<
"Excluding CaloParticles from event: "
267 << it_caloPart.g4Tracks()[0].eventId().event()
268 <<
" with BX: " << it_caloPart.g4Tracks()[0].eventId().bunchCrossing()
279 for (
const auto& it_sc : simClusterRefVector) {
282 <<
">>> SC.energy(): " << simCluster.
energy() <<
" SC.simEnergy(): " << simCluster.
simEnergy() << std::endl;
283 const std::vector<std::pair<uint32_t, float> >& hits_and_fractions = simCluster.
hits_and_fractions();
286 for (
const auto& it_haf : hits_and_fractions) {
288 DetId hitid = (it_haf.first);
295 fillWithRecHits(hitmap, hitid, hitlayer, it_haf.second, seedDet, seedEnergy);
300 auto sumCalibRecHitCalib_fraction =
303 <<
">>> MC Energy: " << it_caloPart.energy() <<
" reco energy: " << sumCalibRecHitCalib_fraction << std::endl;
308 const auto&
clusters = *hgcalMultiClustersHandle;
309 float total_energy = 0.;
310 float max_dR2 = 0.0025;
315 auto ERatio_a =
a.correctedEnergy() / it_caloPart.energy();
316 auto ERatio_b =
b.correctedEnergy() / it_caloPart.energy();
319 if (dR2_a < max_dR2 && dR2_b < max_dR2)
320 return ERatio_a > ERatio_b;
321 return dR2_a < dR2_b;
324 total_energy = closest->correctedEnergy();
334 auto closest_fcn = [&](
auto const&
a,
auto const&
b) {
337 auto ERatio_a =
a.energy() / it_caloPart.energy();
338 auto ERatio_b =
b.energy() / it_caloPart.energy();
341 if (dR2_a < max_dR2 && dR2_b < max_dR2)
342 return ERatio_a > ERatio_b;
343 return dR2_a < dR2_b;
346 if (PFElectronHandle.
isValid()) {
347 auto const& ele = (*PFElectronHandle);
348 auto closest = std::min_element(ele.begin(), ele.end(), closest_fcn);
349 if (closest != ele.end() &&
350 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
351 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
354 if (closest->superCluster()->seed()->seed().det() ==
DetId::HGCalHSc) {
364 if (PFPhotonHandle.
isValid()) {
365 auto const&
photon = (*PFPhotonHandle);
366 auto closest = std::min_element(
photon.begin(),
photon.end(), closest_fcn);
367 if (closest !=
photon.end() &&
368 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
369 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
384 desc.
add<
int>(
"debug", 0);
385 desc.
add<
bool>(
"rawRecHits",
true);
387 desc.
add<
int>(
"depletionFine", 100);
395 descriptions.
add(
"hgcalHitCalibrationDefault", desc);