43 #include "CLHEP/Units/SystemOfUnits.h"
45 #include <CLHEP/Vector/LorentzVector.h>
49 using CLHEP::HepLorentzVector;
57 const std::string&
name,
62 m_caloDmDescrManager(nullptr),
63 m_useParticleID(true),
65 m_energyMinCalib(20*
MeV),
68 m_MatchDmType(kMatchDmLoose)
70 declareInterface<CaloClusterCollectionProcessor> (
this);
126 for(
int im=0;
im<3;
im++) {
155 if (
name == vname.first ) {
163 msg() << MSG::ERROR <<
"Moment " <<
name
164 <<
" is not a valid Moment name and will be ignored! "
165 <<
"Valid names are:";
176 switch (vname.second) {
204 ATH_MSG_INFO(
"Usage of ParticleID was switched off (UseParticleID==False), no ENG_CALIB_FRAC_* moments will be available" );
210 if ( vname.first ==
name ) {
229 HepLorentzVector middle(1,0,0,1);
230 middle.setREtaPhi(1./cosh(eta0),eta0,0);
232 for (
int im=0;
im<3;
im++) {
241 HepLorentzVector cpoint(1,0,0,1);
243 double r = middle.angle(cpoint.vect());
244 for (
int im=0;
im<3;
im++) {
245 if (
r < x_rmaxOut[
im] ) {
246 if ( je < ietaMin[
im] )
248 if ( je > ietaMax[
im] )
253 for (
int im=0;
im<3;
im++) {
254 if ( ietaMin[
im] <= ietaMax[
im] ) {
257 theRange.iEtaMin = (
char)ietaMin[
im];
258 theRange.iEtaMax = (
char)ietaMax[
im];
272 return StatusCode::SUCCESS;
282 ATH_MSG_DEBUG(
"Starting CaloCalibClusterMomentsMaker2::execute");
286 bool foundAllContainers (
true);
287 std::vector<const CaloCalibrationHitContainer *> v_cchc;
296 msg(MSG::ERROR) <<
"SG does not contain calibration hit container " <<
key.key() <<
endmsg;
298 foundAllContainers =
false;
301 v_cchc.push_back(cchc.
cptr());
305 std::vector<const CaloCalibrationHitContainer *> v_dmcchc;
314 ATH_MSG_ERROR(
"SG does not contain DM calibration hit container " <<
key.key());
316 foundAllContainers =
false;
319 v_dmcchc.push_back(cchc.
cptr());
326 if ( !foundAllContainers )
return StatusCode::SUCCESS;
341 for( ;clusIter!=clusIterEnd;++clusIter,++iClus) {
347 for(; cellIter != cellIterEnd; cellIter++ ){
348 const CaloCell* pCell = (*cellIter);
353 if(bookmark == cellInfo.end() || bookmark->first != myId) {
355 if (bookmark != cellInfo.begin()) --bookmark;
356 cellInfo.emplace_hint (bookmark, myId, std::move(
info));
359 bookmark->second.Add(
info );
368 unsigned int nHitsTotal = 0;
369 unsigned int nHitsWithoutParticleID = 0;
376 if(
pos != cellInfo.end() ) {
379 for (
const std::pair<int, double>&
p :
pos->second.m_ClusWeights) {
383 clusInfoVec[iClus].Add(
weight * hit->energyTotal(), nsmp, hit->particleID());
385 clusInfoVec[iClus].Add(
weight * hit->energyTotal(), nsmp);
390 nHitsWithoutParticleID++;
400 msg(MSG::INFO) <<
"Calibration hits do not have ParticleID, i.e. barcode of particle caused hits is always 0. Continuing without ParticleID machinery."<<
endmsg;
401 useParticleID =
false;
408 if (doCalibFrac && !truthParticleContainerReadHandle.
isValid()){
413 std::vector<double> engCalibOut[3];
418 std::vector<std::vector <int > > clusListL;
419 std::vector<std::vector <int > > clusListM;
420 std::vector<std::vector <int > > clusListT;
428 for(
unsigned int ii=0;ii<3;ii++) {
432 engCalibOut[ii].resize(theClusColl->
size(),0);
440 if ( theCluster->eta() < 0 ) iEtaSign = -1;
446 unsigned int iEtaBin(jeta);
447 if ( jeta < 0 ) iEtaBin = abs(jeta)-1;
448 const std::vector<CalibHitIPhiIEtaRange>&
bins
451 int jp =
range.iPhi+jphi;
454 int jEtaMin = iEtaSign<0?-
range.iEtaMax-1:
range.iEtaMin;
455 int jEtaMax = iEtaSign<0?-
range.iEtaMin-1:
range.iEtaMax;
456 for(
int je = jEtaMin;je<=jEtaMax;je++ ) {
478 if(
pos == cellInfo.end() ) {
483 if(useParticleID)
pid = hit->particleID();
490 for (
unsigned int ii=0;ii<3;ii++) {
491 std::vector<std::vector <int > > *pClusList=
nullptr;
493 pClusList = &clusListL;
495 pClusList = &clusListM;
497 pClusList = &clusListT;
500 double hitClusNorm(0.);
501 std::vector<int> hitClusIndex;
502 std::vector<double > hitClusEffEnergy;
513 hitClusNorm +=
pos->second.engTot;
514 hitClusEffEnergy.push_back(
pos->second.engTot);
515 hitClusIndex.push_back(iClus);
518 if ( hitClusNorm > 0 ) {
519 const double inv_hitClusNorm = 1. / hitClusNorm;
520 for(
unsigned int i_cls=0; i_cls<hitClusIndex.size(); i_cls++){
521 int iClus = hitClusIndex[i_cls];
522 double w = hitClusEffEnergy[i_cls] * inv_hitClusNorm;
523 engCalibOut[ii][iClus] +=
w*hit->energyTotal();
540 std::vector<std::vector <int > > *pClusList=
nullptr;
542 pClusList = &clusListL;
544 pClusList = &clusListM;
546 pClusList = &clusListT;
558 if(useParticleID)
pid = hit->particleID();
571 int hitClusVecIndex = 0;
572 std::vector<int> hitClusIndex(theClusColl->
size());
573 std::vector<double > hitClusEffEnergy(theClusColl->
size());
574 double hitClusNorm = 0.0;
585 double engClusPidCalib =
pos->second.engTot;
588 double sum_smp_energy = 0.0;
595 sum_smp_energy +=
pos->second.engSmp[nsmp];
598 if(sum_smp_energy > 0.0) {
599 double phi_diff=myCDDE->
phi()-theCluster->
phi();
600 if(phi_diff <= -
M_PI){
602 }
else if (phi_diff >
M_PI){
605 double eta_diff = (myCDDE->
eta()-theCluster->
eta());
606 float distance=sqrt(eta_diff * eta_diff + phi_diff * phi_diff);
610 hitClusIndex [hitClusVecIndex] = iClus;
611 hitClusEffEnergy [hitClusVecIndex++]= effEner;
612 hitClusNorm += effEner;
617 hitClusIndex.resize(hitClusVecIndex);
618 hitClusEffEnergy.resize(hitClusVecIndex);
622 if(hitClusNorm >0.0) {
623 const double inv_hitClusNorm = 1. / hitClusNorm;
624 for(
unsigned int i_cls=0; i_cls<hitClusIndex.size(); i_cls++){
625 int iClus = hitClusIndex[i_cls];
626 double dm_weight = hitClusEffEnergy[i_cls] * inv_hitClusNorm;
627 if(dm_weight > 1.0 || dm_weight < 0.0 ){
628 std::cout <<
"CaloCalibClusterMomentsMaker2::execute() ->Error! Strange weight " << dm_weight<< std::endl;
629 std::cout << hitClusEffEnergy[i_cls] <<
" " << hitClusNorm << std::endl;
631 clusInfoVec[iClus].engCalibDeadInArea[nDmArea] += hit->energyTotal()*dm_weight;
645 std::vector<double> engCalibFrac;
648 std::map<unsigned int,int> truthBarcodeToPdgCodeMap;
651 for (
const auto *thisTruthParticle : *truthParticleContainerReadHandle){
653 if (!thisTruthParticle){
658 truthBarcodeToPdgCodeMap[
HepMC::barcode(thisTruthParticle)] = thisTruthParticle->pdgId();
662 for( clusIter = theClusColl->
begin(),iClus=0; clusIter!=clusIterEnd;++clusIter,++iClus) {
692 double eng_calib_dead_unclass = eng_calib_dead_tot - eng_calib_dead_emb0 - eng_calib_dead_tile0
693 - eng_calib_dead_tileg3 - eng_calib_dead_eme0 - eng_calib_dead_hec0 - eng_calib_dead_fcal
694 - eng_calib_dead_leakage;
703 moment_name_set::const_iterator vMomentsIter =
m_validMoments.begin();
704 moment_name_set::const_iterator vMomentsIterEnd =
m_validMoments.end();
707 for(; vMomentsIter!=vMomentsIterEnd; ++vMomentsIter,++iMoment) {
709 switch (vMomentsIter->second) {
715 myMoments[iMoment] = engCalibOut[0][iClus];
718 myMoments[iMoment] = engCalibOut[1][iClus];
721 myMoments[iMoment] = engCalibOut[2][iClus];
733 myMoments[iMoment] = eng_calib_dead_tot;
736 myMoments[iMoment] = eng_calib_dead_emb0;
739 myMoments[iMoment] = eng_calib_dead_tile0;
742 myMoments[iMoment] = eng_calib_dead_tileg3;
745 myMoments[iMoment] = eng_calib_dead_eme0;
748 myMoments[iMoment] = eng_calib_dead_hec0;
751 myMoments[iMoment] = eng_calib_dead_fcal;
754 myMoments[iMoment] = eng_calib_dead_leakage;
757 myMoments[iMoment] = eng_calib_dead_unclass;
773 theCluster->
insertMoment(vMomentsIter->second, myMoments[iMoment]);
778 return StatusCode::SUCCESS;
788 double eta = fabs(
x);
797 return ff*(1./
atan(5.0*1.7/200.0));
806 const MyClusInfo& clusInfo, std::vector<double> &engFrac)
const
811 for (
const std::pair<const int, MyClusInfo::ClusCalibEnergy>&
p : clusInfo.
engCalibParticle) {
814 try { pdg_id = truthBarcodeToPdgCodeMap.at(
barcode); }
815 catch (
const std::out_of_range&
e){
820 if( abs(pdg_id) == 211) {
822 }
else if( pdg_id == 111 || pdg_id == 22 || abs(pdg_id)==11) {