40 #include "CLHEP/Units/SystemOfUnits.h"
42 #include <CLHEP/Vector/LorentzVector.h>
46 using CLHEP::HepLorentzVector;
54 const std::string&
name,
59 m_caloDmDescrManager(nullptr),
60 m_useParticleID(true),
62 m_energyMinCalib(20*
MeV),
65 m_MatchDmType(kMatchDmLoose)
67 declareInterface<CaloClusterCollectionProcessor> (
this);
123 for(
int im=0;
im<3;
im++) {
152 if (
name == vname.first ) {
160 msg() << MSG::ERROR <<
"Moment " <<
name
161 <<
" is not a valid Moment name and will be ignored! "
162 <<
"Valid names are:";
173 switch (vname.second) {
201 ATH_MSG_INFO(
"Usage of ParticleID was switched off (UseParticleID==False), no ENG_CALIB_FRAC_* moments will be available" );
207 if ( vname.first ==
name ) {
226 HepLorentzVector middle(1,0,0,1);
227 middle.setREtaPhi(1./cosh(eta0),eta0,0);
229 for (
int im=0;
im<3;
im++) {
238 HepLorentzVector cpoint(1,0,0,1);
240 double r = middle.angle(cpoint.vect());
241 for (
int im=0;
im<3;
im++) {
242 if (
r < x_rmaxOut[
im] ) {
243 if ( je < ietaMin[
im] )
245 if ( je > ietaMax[
im] )
250 for (
int im=0;
im<3;
im++) {
251 if ( ietaMin[
im] <= ietaMax[
im] ) {
254 theRange.iEtaMin = (
char)ietaMin[
im];
255 theRange.iEtaMax = (
char)ietaMax[
im];
269 return StatusCode::SUCCESS;
279 ATH_MSG_DEBUG(
"Starting CaloCalibClusterMomentsMaker2::execute");
283 bool foundAllContainers (
true);
284 std::vector<const CaloCalibrationHitContainer *> v_cchc;
293 msg(MSG::ERROR) <<
"SG does not contain calibration hit container " <<
key.key() <<
endmsg;
295 foundAllContainers =
false;
298 v_cchc.push_back(cchc.
cptr());
302 std::vector<const CaloCalibrationHitContainer *> v_dmcchc;
311 ATH_MSG_ERROR(
"SG does not contain DM calibration hit container " <<
key.key());
313 foundAllContainers =
false;
316 v_dmcchc.push_back(cchc.
cptr());
323 if ( !foundAllContainers )
return StatusCode::SUCCESS;
338 for( ;clusIter!=clusIterEnd;++clusIter,++iClus) {
344 for(; cellIter != cellIterEnd; cellIter++ ){
345 const CaloCell* pCell = (*cellIter);
350 if(bookmark == cellInfo.end() || bookmark->first != myId) {
352 if (bookmark != cellInfo.begin()) --bookmark;
353 cellInfo.emplace_hint (bookmark, myId, std::move(
info));
356 bookmark->second.Add(
info );
365 unsigned int nHitsTotal = 0;
366 unsigned int nHitsWithoutParticleID = 0;
373 if(
pos != cellInfo.end() ) {
376 for (
const std::pair<int, double>&
p :
pos->second) {
380 const int uniqueID = hit->particleID();
382 ATH_MSG_ERROR(
"Invalid uniqueID (barcode) detected - this sample cannot be properly analysed.");
385 clusInfoVec[iClus].Add(
weight * hit->energyTotal(), nsmp, (
unsigned int)(hit->particleID()));
387 clusInfoVec[iClus].Add(
weight * hit->energyTotal(), nsmp);
392 nHitsWithoutParticleID++;
402 ATH_MSG_INFO(
"Calibration hits do not have ParticleID, barcodes of particle-caused hits are always 0. Continuing without ParticleID machinery.");
403 useParticleID =
false;
410 if (doCalibFrac && !truthParticleContainerReadHandle.
isValid()){
415 std::vector<double> engCalibOut[3];
420 std::vector<std::vector <int > > clusListL;
421 std::vector<std::vector <int > > clusListM;
422 std::vector<std::vector <int > > clusListT;
430 for(
unsigned int ii=0;ii<3;ii++) {
434 engCalibOut[ii].resize(theClusColl->
size(),0);
442 if ( theCluster->eta() < 0 ) iEtaSign = -1;
448 unsigned int iEtaBin(jeta);
449 if ( jeta < 0 ) iEtaBin = abs(jeta)-1;
450 const std::vector<CalibHitIPhiIEtaRange>&
bins
453 int jp =
range.iPhi+jphi;
456 int jEtaMin = iEtaSign<0?-
range.iEtaMax-1:
range.iEtaMin;
457 int jEtaMax = iEtaSign<0?-
range.iEtaMin-1:
range.iEtaMax;
458 for(
int je = jEtaMin;je<=jEtaMax;je++ ) {
480 if(
pos == cellInfo.end() ) {
485 if(useParticleID)
uniqueID = hit->particleID();
492 for (
unsigned int ii=0;ii<3;ii++) {
493 std::vector<std::vector <int > > *pClusList=
nullptr;
495 pClusList = &clusListL;
497 pClusList = &clusListM;
499 pClusList = &clusListT;
502 double hitClusNorm(0.);
503 std::vector<int> hitClusIndex;
504 std::vector<double > hitClusEffEnergy;
515 hitClusNorm +=
pos->second.engTot;
516 hitClusEffEnergy.push_back(
pos->second.engTot);
517 hitClusIndex.push_back(iClus);
520 if ( hitClusNorm > 0 ) {
521 const double inv_hitClusNorm = 1. / hitClusNorm;
522 for(
unsigned int i_cls=0; i_cls<hitClusIndex.size(); i_cls++){
523 int iClus = hitClusIndex[i_cls];
524 double w = hitClusEffEnergy[i_cls] * inv_hitClusNorm;
525 engCalibOut[ii][iClus] +=
w*hit->energyTotal();
542 std::vector<std::vector <int > > *pClusList=
nullptr;
544 pClusList = &clusListL;
546 pClusList = &clusListM;
548 pClusList = &clusListT;
560 if(useParticleID)
uniqueID = hit->particleID();
573 int hitClusVecIndex = 0;
574 std::vector<int> hitClusIndex(theClusColl->
size());
575 std::vector<double > hitClusEffEnergy(theClusColl->
size());
576 double hitClusNorm = 0.0;
587 double engClusTruthUniqueIDCalib =
pos->second.engTot;
590 double sum_smp_energy = 0.0;
597 sum_smp_energy +=
pos->second.engSmp[nsmp];
600 if(sum_smp_energy > 0.0) {
601 double phi_diff=myCDDE->
phi()-theCluster->
phi();
602 if(phi_diff <= -
M_PI){
604 }
else if (phi_diff >
M_PI){
607 double eta_diff = (myCDDE->
eta()-theCluster->
eta());
608 float distance=sqrt(eta_diff * eta_diff + phi_diff * phi_diff);
612 hitClusIndex [hitClusVecIndex] = iClus;
613 hitClusEffEnergy [hitClusVecIndex++]= effEner;
614 hitClusNorm += effEner;
619 hitClusIndex.resize(hitClusVecIndex);
620 hitClusEffEnergy.resize(hitClusVecIndex);
624 if(hitClusNorm >0.0) {
625 const double inv_hitClusNorm = 1. / hitClusNorm;
626 for(
unsigned int i_cls=0; i_cls<hitClusIndex.size(); i_cls++){
627 int iClus = hitClusIndex[i_cls];
628 double dm_weight = hitClusEffEnergy[i_cls] * inv_hitClusNorm;
629 if(dm_weight > 1.0 || dm_weight < 0.0 ){
630 std::cout <<
"CaloCalibClusterMomentsMaker2::execute() ->Error! Strange weight " << dm_weight<< std::endl;
631 std::cout << hitClusEffEnergy[i_cls] <<
" " << hitClusNorm << std::endl;
633 clusInfoVec[iClus].engCalibDeadInArea[nDmArea] += hit->energyTotal()*dm_weight;
647 std::vector<double> engCalibFrac;
650 std::map<unsigned int,int> truthIDToPdgCodeMap;
653 for (
const auto *thisTruthParticle : *truthParticleContainerReadHandle){
655 if (!thisTruthParticle){
660 truthIDToPdgCodeMap[
HepMC::barcode(thisTruthParticle)] = thisTruthParticle->pdgId();
664 for( clusIter = theClusColl->
begin(),iClus=0; clusIter!=clusIterEnd;++clusIter,++iClus) {
694 double eng_calib_dead_unclass = eng_calib_dead_tot - eng_calib_dead_emb0 - eng_calib_dead_tile0
695 - eng_calib_dead_tileg3 - eng_calib_dead_eme0 - eng_calib_dead_hec0 - eng_calib_dead_fcal
696 - eng_calib_dead_leakage;
707 if (
auto it = truthIDToPdgCodeMap.find(
p.first);
it != truthIDToPdgCodeMap.end()) {
710 ATH_MSG_WARNING(
"truthIDToPdgCodeMap cannot find an entry with barcode " <<
p.first);
713 if( std::abs(pdg_id) == 211) {
715 }
else if( pdg_id == 111 || pdg_id == 22 || std::abs(pdg_id)==11) {
721 for(
size_t i=0;
i<engCalibFrac.size();
i++) engCalibFrac[
i] = engCalibFrac[
i]/clusInfo.
engCalibIn.
engTot;
728 moment_name_set::const_iterator vMomentsIter =
m_validMoments.begin();
729 moment_name_set::const_iterator vMomentsIterEnd =
m_validMoments.end();
732 for(; vMomentsIter!=vMomentsIterEnd; ++vMomentsIter,++iMoment) {
734 switch (vMomentsIter->second) {
740 myMoments[iMoment] = engCalibOut[0][iClus];
743 myMoments[iMoment] = engCalibOut[1][iClus];
746 myMoments[iMoment] = engCalibOut[2][iClus];
758 myMoments[iMoment] = eng_calib_dead_tot;
761 myMoments[iMoment] = eng_calib_dead_emb0;
764 myMoments[iMoment] = eng_calib_dead_tile0;
767 myMoments[iMoment] = eng_calib_dead_tileg3;
770 myMoments[iMoment] = eng_calib_dead_eme0;
773 myMoments[iMoment] = eng_calib_dead_hec0;
776 myMoments[iMoment] = eng_calib_dead_fcal;
779 myMoments[iMoment] = eng_calib_dead_leakage;
782 myMoments[iMoment] = eng_calib_dead_unclass;
798 theCluster->
insertMoment(vMomentsIter->second, myMoments[iMoment]);
803 return StatusCode::SUCCESS;
813 double eta = fabs(
x);
822 return ff*(1./
atan(5.0*1.7/200.0));