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();
204 const std::vector<CaloParticle>&
caloParticles = *caloParticleHandle;
216 std::map<DetId, const HGCRecHit*> hitmap;
222 const auto& rechitsEE = *recHitHandleEE;
223 const auto& rechitsFH = *recHitHandleFH;
224 const auto& rechitsBH = *recHitHandleBH;
225 for (
unsigned int i = 0;
i < rechitsEE.size(); ++
i) {
226 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
228 for (
unsigned int i = 0;
i < rechitsFH.size(); ++
i) {
229 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
231 for (
unsigned int i = 0;
i < rechitsBH.size(); ++
i) {
232 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
239 for (
unsigned int i = 0;
i < rechitsEE.
size();
i++) {
240 hitmap[rechitsEE[
i].detid()] = &rechitsEE[
i];
247 const auto& rechitsFH = *recHitHandleFH;
248 const auto& rechitsBH = *recHitHandleBH;
249 for (
unsigned int i = 0;
i < rechitsFH.size();
i++) {
250 hitmap[rechitsFH[
i].detid()] = &rechitsFH[
i];
252 for (
unsigned int i = 0;
i < rechitsBH.size();
i++) {
253 hitmap[rechitsBH[
i].detid()] = &rechitsBH[
i];
264 float seedEnergy = 0.;
267 if (it_caloPart.g4Tracks()[0].eventId().event() != 0
or it_caloPart.g4Tracks()[0].eventId().bunchCrossing() != 0) {
268 LogDebug(
"HGCalHitCalibration") <<
"Excluding CaloParticles from event: "
269 << it_caloPart.g4Tracks()[0].eventId().event()
270 <<
" with BX: " << it_caloPart.g4Tracks()[0].eventId().bunchCrossing()
281 for (
const auto& it_sc : simClusterRefVector) {
284 <<
">>> SC.energy(): " << simCluster.
energy() <<
" SC.simEnergy(): " << simCluster.
simEnergy() << std::endl;
285 const std::vector<std::pair<uint32_t, float> >& hits_and_fractions = simCluster.
hits_and_fractions();
288 for (
const auto& it_haf : hits_and_fractions) {
290 DetId hitid = (it_haf.first);
297 fillWithRecHits(hitmap, hitid, hitlayer, it_haf.second, seedDet, seedEnergy);
302 auto sumCalibRecHitCalib_fraction =
305 <<
">>> MC Energy: " << it_caloPart.energy() <<
" reco energy: " << sumCalibRecHitCalib_fraction << std::endl;
310 const auto&
clusters = *hgcalMultiClustersHandle;
311 float total_energy = 0.;
312 float max_dR2 = 0.0025;
317 auto ERatio_a =
a.correctedEnergy() / it_caloPart.energy();
318 auto ERatio_b =
b.correctedEnergy() / it_caloPart.energy();
321 if (dR2_a < max_dR2 && dR2_b < max_dR2)
322 return ERatio_a > ERatio_b;
323 return dR2_a < dR2_b;
326 total_energy = closest->correctedEnergy();
336 auto closest_fcn = [&](
auto const&
a,
auto const&
b) {
339 auto ERatio_a =
a.energy() / it_caloPart.energy();
340 auto ERatio_b =
b.energy() / it_caloPart.energy();
343 if (dR2_a < max_dR2 && dR2_b < max_dR2)
344 return ERatio_a > ERatio_b;
345 return dR2_a < dR2_b;
348 if (PFElectronHandle.
isValid()) {
349 auto const& ele = (*PFElectronHandle);
350 auto closest = std::min_element(ele.begin(), ele.end(), closest_fcn);
351 if (closest != ele.end() &&
352 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
353 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
356 if (closest->superCluster()->seed()->seed().det() ==
DetId::HGCalHSc) {
366 if (PFPhotonHandle.
isValid()) {
367 auto const&
photon = (*PFPhotonHandle);
368 auto closest = std::min_element(
photon.begin(),
photon.end(), closest_fcn);
369 if (closest !=
photon.end() &&
370 (closest->superCluster()->seed()->seed().det() ==
DetId::Forward ||
371 closest->superCluster()->seed()->seed().det() ==
DetId::HGCalEE) &&
386 desc.
add<
int>(
"debug", 0);
387 desc.
add<
bool>(
"rawRecHits",
true);
389 desc.
add<
int>(
"depletionFine", 100);
397 descriptions.
add(
"hgcalHitCalibrationDefault", desc);