54 void fillWithRecHits(std::map<DetId, const HGCRecHit*>&,
DetId,
unsigned int,
float,
int&,
float&);
86 rawRecHits_(iConfig.getParameter<
bool>(
"rawRecHits")),
87 debug_(iConfig.getParameter<
int>(
"debug")) {
98 recHitsFH_ = consumes<HGCRecHitCollection>(recHitsFH);
99 recHitsBH_ = consumes<HGCRecHitCollection>(recHitsBH);
105 recHitsFH_ = consumes<HGCRecHitCollection>(recHitsFH);
106 recHitsBH_ = consumes<HGCRecHitCollection>(recHitsBH);
135 ibooker.
book1D(
"hgcal_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
137 ibooker.
book1D(
"hgcal_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
139 ibooker.
book1D(
"hgcal_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
142 ibooker.
book1D(
"hgcal_ele_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
144 ibooker.
book1D(
"hgcal_ele_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
146 ibooker.
book1D(
"hgcal_ele_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
148 ibooker.
book1D(
"hgcal_ele_EoP_CPene_scint_calib_fraction",
"", 1000, -0.5, 2.5);
150 ibooker.
book1D(
"hgcal_photon_EoP_CPene_100_calib_fraction",
"", 1000, -0.5, 2.5);
152 ibooker.
book1D(
"hgcal_photon_EoP_CPene_200_calib_fraction",
"", 1000, -0.5, 2.5);
154 ibooker.
book1D(
"hgcal_photon_EoP_CPene_300_calib_fraction",
"", 1000, -0.5, 2.5);
156 ibooker.
book1D(
"hgcal_photon_EoP_CPene_scint_calib_fraction",
"", 1000, -0.5, 2.5);
162 const unsigned int hitlayer,
166 if (hitmap.find(hitid) == hitmap.end()) {
169 <<
">>> Failed to find detid " << std::hex << hitid.
rawId() <<
std::dec <<
" Det " << hitid.
det() <<
" Subdet "
176 <<
">>> Wrong type of detid " << std::hex << hitid.
rawId() <<
std::dec <<
" Det " << hitid.
det() <<
" Subdet "
185 if (seedEnergy < hitmap[hitid]->
energy()) {
186 seedEnergy = hitmap[hitid]->energy();
206 const std::vector<CaloParticle>&
caloParticles = *caloParticleHandle;
218 std::map<DetId, const HGCRecHit*> hitmap;
224 const auto& rechitsEE = *recHitHandleEE;
225 const auto& rechitsFH = *recHitHandleFH;
226 const auto& rechitsBH = *recHitHandleBH;
227 for (
unsigned int i = 0;
i < rechitsEE.size(); ++
i) {
228 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
230 for (
unsigned int i = 0;
i < rechitsFH.size(); ++
i) {
231 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
233 for (
unsigned int i = 0;
i < rechitsBH.size(); ++
i) {
234 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
241 for (
unsigned int i = 0;
i < rechitsEE.
size();
i++) {
242 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
249 const auto& rechitsFH = *recHitHandleFH;
250 const auto& rechitsBH = *recHitHandleBH;
251 for (
unsigned int i = 0;
i < rechitsFH.size();
i++) {
252 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
254 for (
unsigned int i = 0;
i < rechitsBH.size();
i++) {
255 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
266 float seedEnergy = 0.;
269 if (it_caloPart.g4Tracks()[0].eventId().event() != 0
or it_caloPart.g4Tracks()[0].eventId().bunchCrossing() != 0) {
270 LogDebug(
"HGCalHitCalibration") <<
"Excluding CaloParticles from event: "
271 << it_caloPart.g4Tracks()[0].eventId().event()
272 <<
" with BX: " << it_caloPart.g4Tracks()[0].eventId().bunchCrossing()
283 for (
const auto& it_sc : simClusterRefVector) {
286 <<
">>> SC.energy(): " << simCluster.
energy() <<
" SC.simEnergy(): " << simCluster.
simEnergy() << std::endl;
287 const std::vector<std::pair<uint32_t, float> >& hits_and_fractions = simCluster.
hits_and_fractions();
290 for (
const auto& it_haf : hits_and_fractions) {
292 DetId hitid = (it_haf.first);
299 fillWithRecHits(hitmap, hitid, hitlayer, it_haf.second, seedDet, seedEnergy);
304 auto sumCalibRecHitCalib_fraction =
307 <<
">>> MC Energy: " << it_caloPart.energy() <<
" reco energy: " << sumCalibRecHitCalib_fraction << std::endl;
312 const auto&
clusters = *hgcalMultiClustersHandle;
313 float total_energy = 0.;
314 float max_dR2 = 0.0025;
319 auto ERatio_a =
a.correctedEnergy() / it_caloPart.energy();
320 auto ERatio_b =
b.correctedEnergy() / it_caloPart.energy();
323 if (dR2_a < max_dR2 && dR2_b < max_dR2)
324 return ERatio_a > ERatio_b;
325 return dR2_a < dR2_b;
328 total_energy = closest->correctedEnergy();
338 auto closest_fcn = [&](
auto const&
a,
auto const&
b) {
341 auto ERatio_a =
a.energy() / it_caloPart.energy();
342 auto ERatio_b =
b.energy() / it_caloPart.energy();
345 if (dR2_a < max_dR2 && dR2_b < max_dR2)
346 return ERatio_a > ERatio_b;
347 return dR2_a < dR2_b;
350 if (PFElectronHandle.
isValid()) {
351 auto const& ele = (*PFElectronHandle);
352 auto closest = std::min_element(ele.begin(), ele.end(), closest_fcn);
353 if (closest != ele.end() &&
354 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
355 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
358 if (closest->superCluster()->seed()->seed().det() ==
DetId::HGCalHSc) {
368 if (PFPhotonHandle.
isValid()) {
369 auto const&
photon = (*PFPhotonHandle);
370 auto closest = std::min_element(
photon.begin(),
photon.end(), closest_fcn);
371 if (closest !=
photon.end() &&
372 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
373 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
388 desc.add<
int>(
"debug", 0);
389 desc.add<
bool>(
"rawRecHits",
true);
391 desc.add<
int>(
"depletionFine", 120);
399 descriptions.
add(
"hgcalHitCalibrationDefault",
desc);