29#include "HepPDT/ParticleDataTable.hh"
33#include "CLHEP/Random/RandFlat.h"
63 const std::string& name,
64 const IInterface* parent )
65: base_class(
type, name, parent)
82 return StatusCode::FAILURE;
87 if (resolvedFileName.empty()) {
89 return StatusCode::FAILURE;
91 ATH_MSG_INFO(
"[ punchthrough ] Parametrisation file found: " << resolvedFileName );
96 ATH_MSG_WARNING(
"[ punchthrough ] unable to open the lookup-table for the punch-through simulation (file does not exist)");
97 return StatusCode::FAILURE;
101 ATH_MSG_WARNING(
"[ punchthrough ] unable to open the lookup-table for the punch-through simulation (wrong or empty file?)");
102 return StatusCode::FAILURE;
108 ATH_MSG_WARNING(
"[ punchthrough ] unable to open or read the inverse CDF config");
109 return StatusCode::FAILURE;
115 ATH_MSG_WARNING(
"[ punchthrough ] unable to open or read the inverse PCA config");
116 return StatusCode::FAILURE;
122 ATH_MSG_WARNING(
"[ punchthrough ] size of infoMap for PCA and CDF differs! Something is wrong with input xml files.");
123 return StatusCode::FAILURE;
133 ATH_MSG_FATAL(
" [ punchthrough ] Could not get ParticleDataTable! Cannot associate pdg code with charge! Abort. " );
134 return StatusCode::FAILURE;
140 ATH_MSG_FATAL (
"[ punchthrough ] Could not retrieve GeometryIdentifier Service. Abort");
141 return StatusCode::FAILURE;
148 return StatusCode::FAILURE;
172 ATH_MSG_VERBOSE(
"[ punchthrough ] registering punch-through particle type with pdg = " << pdg );
173 if (
registerParticle( pdg, doAnti, minEnergy, maxNum, numFactor, energyFactor, posAngleFactor, momAngleFactor )
174 != StatusCode::SUCCESS)
176 ATH_MSG_ERROR(
"[ punchthrough ] unable to register punch-through particle type with pdg = " << pdg);
187 ATH_MSG_WARNING(
"[ punchthrough ] more punch-through particle correlations are given, than punch-through particle types are registered (skipping the last ones)");
192 for (
unsigned int num = 0; num < numCorrelations; num++ )
200 if ( ! pdg2)
continue;
202 if (
registerCorrelation(pdg1, pdg2, minCorrEnergy, fullCorrEnergy) != StatusCode::SUCCESS )
204 ATH_MSG_ERROR(
"[ punchthrough ] unable to register punch-through particle correlation for pdg1=" << pdg1 <<
" pdg2=" << pdg2 );
214 found1=
false; found2=
false;
216 for (
size_t i=0; i<rzCalo->size();++i)
218 const double r_tempCalo = rzCalo->at(i).first;
219 const double z_tempCalo = rzCalo->at(i).second;
223 for (
size_t j=0; j<rzMS->size();++j)
225 const double r_tempMS =rzMS->at(j).first;
226 const double z_tempMS =rzMS->at(j).second;
228 if (r_tempCalo==r_tempMS && z_tempCalo==z_tempMS && found1==
false )
231 m_z1=std::fabs(z_tempMS);
235 else if (r_tempCalo==r_tempMS && z_tempCalo==z_tempMS && r_tempCalo!=
m_R1 && std::fabs(z_tempCalo)!=
m_z1)
238 m_z2=std::fabs(z_tempMS);
243 if (found1==
true && found2==
true)
break;
248 if (found1 ==
false)
ATH_MSG_ERROR (
"first coordinate of calo-MS border not found");
249 if (found2 ==
false)
ATH_MSG_ERROR (
"second coordinate of calo-MS border not found; first one is: R1 ="<<
m_R1<<
" z1 ="<<
m_z1);
252 double r_temp, z_temp;
262 ATH_MSG_INFO(
"punchthrough initialization is successful" );
263 return StatusCode::SUCCESS;
280 return StatusCode::SUCCESS;
290 ATH_MSG_DEBUG(
"[ punchthrough ] starting punch-through simulation");
293 auto isfpCont = std::make_unique<ISF::ISFParticleVector>();
301 ATH_MSG_VERBOSE (
"[ GeoIDSvc ] input particle doesn't point to calorimeter"<<
"Next GeoID: "<<
m_geoIDSvc->identifyNextGeoID(isfp) );
313 for ( ; pdgIt != pdgItEnd; ++pdgIt, ++minEnergyIt)
315 if (std::abs(isfp.
pdgCode()) == *pdgIt){
316 if(std::sqrt( isfp.
momentum().mag2() + isfp.
mass()*isfp.
mass() ) < *minEnergyIt){
317 ATH_MSG_DEBUG(
"[ punchthrough ] particle does not meet initiator min energy requirement. Dropping it in the calo.");
325 if (pdgIt == pdgItEnd)
327 ATH_MSG_DEBUG(
"[ punchthrough ] particle is not registered as punch-through initiator. Dropping it in the calo.");
333 ATH_MSG_DEBUG(
"[ punchthrough ] particle does not meet initiator eta range requirement. Dropping it in the calo.");
341 double punchThroughClassifierRand = CLHEP::RandFlat::shoot(rndmEngine);
343 ATH_MSG_DEBUG(
"[ punchthrough ] punchThroughProbability output: " << punchThroughProbability <<
" RandFlat: " << punchThroughClassifierRand );
346 if( punchThroughClassifierRand > punchThroughProbability){
347 ATH_MSG_DEBUG(
"[ punchthrough ] particle not classified to create punch through. Dropping it in the calo.");
361 const double initEnergy = std::sqrt( isfp.
momentum().mag2() + isfp.
mass()*isfp.
mass() );
362 const double initEta = isfp.
position().eta();
368 std::map<int, int> corrPdgNumDone;
374 while(isfpCont->empty() && nTries < maxTries) {
379 int doPdg = currentParticle.first;
381 int corrPdg = currentParticle.second->getCorrelatedPdg();
387 std::map<int,int>::iterator pos = corrPdgNumDone.find(doPdg);
390 if ( pos == corrPdgNumDone.end() ) pos = corrPdgNumDone.find(corrPdg);
394 if ( pos == corrPdgNumDone.end() )
397 if ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) doPdg = corrPdg;
400 corrPdgNumDone[doPdg] =
getAllParticles(isfp, *isfpCont, rndmEngine, doPdg, interpEnergy, interpEta);
409 const int donePdg = pos->first;
410 const int doneNumPart = pos->second;
412 if (donePdg == doPdg) doPdg = corrPdg;
424 else getAllParticles(isfp, *isfpCont, rndmEngine, doPdg, interpEnergy, interpEta);
431 if (!isfpCont->empty())
ATH_MSG_DEBUG(
"[ punchthrough ] returning ISFparticle vector , size: "<<isfpCont->size() );
434 ATH_MSG_DEBUG(
"codes of produced punch through particle: pdg = "<< particle->pdgCode());
436 ATH_MSG_DEBUG(
"position of produced punch-through particle: x = "<< position.x() <<
" y = "<< position.y() <<
" z = "<< position.z());
438 ATH_MSG_DEBUG(
"momentum of produced punch-through particle: px = "<< momentum.x() <<
" py = "<< momentum.x() <<
" pz = "<< momentum.x() <<
" e = "<< particle->ekin() <<
" mass = " << particle->mass());
441 return isfpCont.release();
456 if ( numParticles < 0 )
459 std::vector<int> parameters;
460 parameters.push_back( std::round(interpEnergy) );
461 parameters.push_back( std::round(interpEta*100) );
464 int maxParticles = p->getMaxNumParticles();
470 numParticles = int( p->getNumParticlesPDF()->getRand(rndmEngine, parameters) );
473 numParticles = lround( numParticles *= p->getNumParticlesFactor() );
475 while ( (maxParticles >= 0.) && (numParticles > maxParticles) );
478 ATH_MSG_VERBOSE(
"[ punchthrough ] adding " << numParticles <<
" punch-through particles with pdg " << pdg);
481 double energyRest = std::sqrt( isfp.
momentum().mag2() + isfp.
mass()*isfp.
mass() );
482 double minEnergy = p->getMinEnergy();
485 for ( numCreated = 0; (numCreated < numParticles) && (energyRest > minEnergy); numCreated++ )
493 ATH_MSG_ERROR(
"[ punchthrough ] something went wrong while creating punch-through particles");
499 double curEnergy = std::sqrt(par->momentum().mag2() + restMass*restMass);
503 energyRest -= curEnergy;
506 isfpCont.push_back( par );
523 const double initEnergy = std::sqrt( isfp.
momentum().mag2() + isfp.
mass()*isfp.
mass() );
526 double rand = CLHEP::RandFlat::shoot(rndmEngine)
527 *(p->getFullCorrelationEnergy()-p->getMinCorrelationEnergy())
528 + p->getMinCorrelationEnergy();
529 if ( initEnergy < rand )
532 return getAllParticles(isfp, isfpCont, rndmEngine, pdg, interpEnergy, interpEta);
537 double *histDomains = p->getCorrelationHistDomains();
538 TH2F *hist2d =
nullptr;
541 if ( initEnergy < histDomains[1])
545 hist2d = p->getCorrelationLowEHist();
549 double rand = CLHEP::RandFlat::shoot(rndmEngine)*(histDomains[2]-histDomains[1])
551 hist2d = ( initEnergy < rand) ? p->getCorrelationLowEHist()
552 : p->getCorrelationHighEHist();
559 Int_t xbin = hist2d->GetXaxis()->FindFixBin(corrParticles);
560 int numParticles = 0;
561 int maxParticles = p->getMaxNumParticles();
566 double rand = CLHEP::RandFlat::shoot(rndmEngine);
568 for (
int ybin = 1; ybin <= hist2d->GetNbinsY(); ybin++ )
570 sum += hist2d->GetBinContent(xbin, ybin);
574 numParticles = ybin - 1;
579 numParticles = lround( numParticles * p->getNumParticlesFactor() );
581 while ( (maxParticles >= 0.) && (numParticles > maxParticles) );
584 return getAllParticles(isfp, isfpCont, rndmEngine, pdg, interpEnergy, interpEta, numParticles);
600 ATH_MSG_DEBUG(
"[ punchthrough ] passedPCAIterator ==> pcaCdfIterator = "<< pcaCdfIterator <<
" , pdg = "<< pdg <<
" , interpEnergy = "<< interpEnergy <<
" MeV, interpEta(*100) = "<< interpEta*100);
604 if ( p->getdoAnti() )
607 double rand = CLHEP::RandFlat::shoot(rndmEngine);
609 if (rand > 0.5) anti = -1;
614 std::vector<int> parInitEnergyEta;
615 parInitEnergyEta.push_back( std::round(interpEnergy) );
616 parInitEnergyEta.push_back( std::round(interpEta*100) );
620 double deltaTheta = 0.;
622 double momDeltaTheta = 0.;
623 double momDeltaPhi = 0.;
625 double principal_component_0 = 0.;
626 double principal_component_1 = 0.;
627 double principal_component_2 = 0.;
628 double principal_component_3 = 0.;
629 double principal_component_4 = 0.;
630 std::vector<double> transformed_variables;
633 principal_component_0 = p->getPCA0PDF()->getRand(rndmEngine, parInitEnergyEta);
634 principal_component_1 = p->getPCA1PDF()->getRand(rndmEngine, parInitEnergyEta);
635 principal_component_2 = p->getPCA2PDF()->getRand(rndmEngine, parInitEnergyEta);
636 principal_component_3 = p->getPCA3PDF()->getRand(rndmEngine, parInitEnergyEta);
637 principal_component_4 = p->getPCA4PDF()->getRand(rndmEngine, parInitEnergyEta);
639 ATH_MSG_DEBUG(
"Drawn punch through kinematics PCA components: PCA0 = "<< principal_component_0 <<
" PCA1 = "<< principal_component_1 <<
" PCA2 = "<< principal_component_2 <<
" PCA3 = "<< principal_component_3 <<
" PCA4 = "<< principal_component_4 );
641 std::vector<double> principal_components {
642 principal_component_0,
643 principal_component_1,
644 principal_component_2,
645 principal_component_3,
646 principal_component_4
649 transformed_variables =
inversePCA(pcaCdfIterator,principal_components);
657 ATH_MSG_DEBUG(
"Transformed punch through kinematics: energy = "<< energy <<
" MeV deltaTheta = "<< deltaTheta <<
" deltaPhi = "<<
deltaPhi <<
" momDeltaTheta = "<< momDeltaTheta <<
" momDeltaPhi = "<< momDeltaPhi );
659 energy *= p->getEnergyFactor();
660 if (energy < p->getMinEnergy()) {
661 energy = p->getMinEnergy() + 10;
671 deltaTheta *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.;
674 theta = isfp.
position().theta() + deltaTheta*p->getPosAngleFactor();
680 deltaPhi *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.;
692 double momTheta = 0.;
696 momDeltaTheta *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.;
699 momTheta =
theta + momDeltaTheta*p->getMomAngleFactor();
702 while ( (momTheta >
M_PI) || (momTheta < 0.) );
706 momDeltaPhi *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.;
708 double momPhi =
phi + momDeltaPhi*p->getMomAngleFactor();
710 while ( std::fabs(momPhi) > 2*
M_PI) momPhi /= 2.;
711 while (momPhi >
M_PI) momPhi -= 2*
M_PI;
712 while (momPhi < -
M_PI) momPhi += 2*
M_PI;
716 ATH_MSG_DEBUG(
"createExitPs input parameters: doAnti? = "<< pdg*anti <<
" energy = "<< energy <<
" theta = "<<
theta <<
" phi = "<<
phi <<
" momTheta = "<< momTheta <<
" momPhi " << momPhi );
726 return 0.5 * TMath::Erfc(-
x * M_SQRT1_2);
731 std::vector<double>
result;
733 for (
const auto&
r : m){
734 result.push_back(std::inner_product(v.begin(), v.end(),
r.begin(), 0.0));
743 constexpr char delimiters =
',';
744 std::vector<T> tokens;
746 std::string_view::size_type lastPos =
str.find_first_not_of(delimiters, 0);
748 std::string_view::size_type pos =
str.find_first_of(delimiters, lastPos);
750 while (std::string_view::npos != pos || std::string_view::npos != lastPos) {
752 std::string_view numbStr =
str.substr(lastPos, pos - lastPos);
754 std::from_chars(numbStr.data(), numbStr.data() + numbStr.size(), num);
755 tokens.push_back(num);
757 lastPos =
str.find_first_not_of(delimiters, pos);
759 pos =
str.find_first_of(delimiters, lastPos);
767 int pidStrSingle = std::abs(pid);
771 for (
unsigned int i = 0; i < mapvect.size(); i++){
772 const std::string &pidStr = mapvect[i].at(
"pidStr");
774 if(std::find(v.begin(), v.end(),pidStrSingle)==v.end())
continue;
775 const std::string &etaMinsStr = mapvect[i].at(
"etaMins");
776 const std::string &etaMaxsStr = mapvect[i].at(
"etaMaxs");
779 assert(etaMaxsVect.size() == etaMinsVect.size());
780 for (
unsigned int j = 0; j < etaMinsVect.size(); j++){
781 double etaMinToCompare = etaMinsVect[j];
782 double etaMaxToCompare = etaMaxsVect[j];
783 if((
eta >= etaMinToCompare) && (
eta < etaMaxToCompare)){
794 std::vector<std::map<std::string, std::string>> xml_info;
795 xmlDocPtr doc = xmlParseFile( xmlFilePath.c_str() );
798 for( xmlNodePtr nodeRoot = doc->children; nodeRoot !=
nullptr; nodeRoot = nodeRoot->next) {
799 if (xmlStrEqual( nodeRoot->name, BAD_CAST mainNode.c_str() )) {
800 for( xmlNodePtr nodeRootChild = nodeRoot->children; nodeRootChild !=
nullptr; nodeRootChild = nodeRootChild->next ) {
801 if (xmlStrEqual( nodeRootChild->name, BAD_CAST
"info" )) {
802 if (nodeRootChild->children != NULL) {
803 for( xmlNodePtr infoNode = nodeRootChild->children; infoNode !=
nullptr; infoNode = infoNode->next) {
804 if(xmlStrEqual( infoNode->name, BAD_CAST
"item" )){
805 std::map<std::string, std::string> xml_info_item;
806 xml_info_item.insert({
"name", (
const char*) xmlGetProp( infoNode, BAD_CAST
"name" ) });
807 xml_info_item.insert({
"etaMins", (
const char*) xmlGetProp( infoNode, BAD_CAST
"etaMins" ) });
808 xml_info_item.insert({
"etaMaxs", (
const char*) xmlGetProp( infoNode, BAD_CAST
"etaMaxs" ) });
809 xml_info_item.insert({
"pidStr", (
const char*) xmlGetProp( infoNode, BAD_CAST
"pidStr" ) });
810 xml_info.push_back(xml_info_item);
825 std::transform (transformed_variables.begin(), transformed_variables.end(),
m_PCA_means[pcaCdfIterator].begin(), transformed_variables.begin(), std::plus<double>());
827 return transformed_variables;
832 xmlDocPtr doc = xmlParseFile( inversePCAConfigFile.c_str() );
834 ATH_MSG_INFO(
"[ punchthrough ] Loading inversePCA: " << inversePCAConfigFile);
841 std::vector<std::vector<double>> PCA_matrix;
844 for( xmlNodePtr nodeRoot = doc->children; nodeRoot !=
nullptr; nodeRoot = nodeRoot->next) {
845 if (xmlStrEqual( nodeRoot->name, BAD_CAST
"PCAinverse" )) {
846 for( xmlNodePtr nodePCAinverse = nodeRoot->children; nodePCAinverse !=
nullptr; nodePCAinverse = nodePCAinverse->next ) {
848 if (xmlStrEqual( nodePCAinverse->name, BAD_CAST
m_xml_info_pca[i].at(
"name").c_str() )) {
849 if (nodePCAinverse->children != NULL) {
850 for( xmlNodePtr pcaNode = nodePCAinverse->children; pcaNode !=
nullptr; pcaNode = pcaNode->next) {
852 if (xmlStrEqual( pcaNode->name, BAD_CAST
"PCAmatrix" )) {
853 std::vector<double> PCA_matrix_row;
854 PCA_matrix_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"comp_0" ) ) );
855 PCA_matrix_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"comp_1" ) ) );
856 PCA_matrix_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"comp_2" ) ) );
857 PCA_matrix_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"comp_3" ) ) );
858 PCA_matrix_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"comp_4" ) ) );
859 PCA_matrix.push_back(PCA_matrix_row);
861 else if (xmlStrEqual( pcaNode->name, BAD_CAST
"PCAmeans" )) {
862 std::vector<double> PCA_means_row;
863 PCA_means_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"mean_0" ) ) );
864 PCA_means_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"mean_1" ) ) );
865 PCA_means_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"mean_2" ) ) );
866 PCA_means_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"mean_3" ) ) );
867 PCA_means_row.push_back( atof( (
const char*) xmlGetProp( pcaNode, BAD_CAST
"mean_4" ) ) );
882 return StatusCode::SUCCESS;
886 std::map<double, double> variable0_inverse_cdf_row;
887 std::map<double, double> variable1_inverse_cdf_row;
888 std::map<double, double> variable2_inverse_cdf_row;
889 std::map<double, double> variable3_inverse_cdf_row;
890 std::map<double, double> variable4_inverse_cdf_row;
894 xmlDocPtr doc = xmlParseFile( inverseCdfConfigFile.c_str() );
896 ATH_MSG_INFO(
"[ punchthrough ] Loading inverse CDF: " << inverseCdfConfigFile);
905 for( xmlNodePtr nodeRoot = doc->children; nodeRoot !=
nullptr; nodeRoot = nodeRoot->next) {
906 if (xmlStrEqual( nodeRoot->name, BAD_CAST
"CDFMappings" )) {
907 for( xmlNodePtr typeMappings = nodeRoot->children; typeMappings !=
nullptr; typeMappings = typeMappings->next ) {
908 if (xmlStrEqual( typeMappings->name, BAD_CAST
m_xml_info_cdf[i].at(
"name").c_str() )) {
909 if (typeMappings->children != NULL) {
910 for( xmlNodePtr nodeMappings = typeMappings->children; nodeMappings !=
nullptr; nodeMappings = nodeMappings->next) {
912 if (xmlStrEqual( nodeMappings->name, BAD_CAST
"variable0" )) {
915 else if (xmlStrEqual( nodeMappings->name, BAD_CAST
"variable1" )) {
918 else if (xmlStrEqual( nodeMappings->name, BAD_CAST
"variable2" )) {
921 else if (xmlStrEqual( nodeMappings->name, BAD_CAST
"variable3" )) {
924 else if (xmlStrEqual( nodeMappings->name, BAD_CAST
"variable4" )) {
941 return StatusCode::SUCCESS;
946 std::map<double, double> mappings;
948 for( xmlNodePtr
node = nodeParent->children;
node !=
nullptr;
node =
node->next ) {
950 if (xmlStrEqual(
node->
name, BAD_CAST
"CDFmap" )) {
951 double ref = atof( (
const char*) xmlGetProp(
node, BAD_CAST
"ref" ) );
952 double quant = atof( (
const char*) xmlGetProp(
node, BAD_CAST
"quant" ) );
954 mappings.insert(std::pair<double, double>(
ref,
quant) );
966 auto upper = inverse_cdf_map.upper_bound(norm_cdf);
967 auto lower =
upper--;
969 double m = (
upper->second - lower->second)/(
upper->first - lower->first);
970 double c = lower->second - m * lower->first;
971 double transformed = m * norm_cdf + c;
979 ATH_MSG_DEBUG(
"[ punchthrough ] interpolating incoming energy: " << energy);
981 std::string energyPointsString;
983 energyPointsString += std::to_string(element) +
" ";
986 ATH_MSG_DEBUG(
"[ punchthrough ] available energy points: " << energyPointsString);
991 ATH_MSG_DEBUG(
"[ punchthrough ] incoming energy > largest energy point, returning greatest energy point: " <<
m_energyPoints.back());
995 ATH_MSG_DEBUG(
"[ punchthrough ] incoming energy < smallest energy point, returning smallest energy point: " << *upperEnergy);
999 ATH_MSG_DEBUG(
"[ punchthrough ] energy points upper_bound: "<< *upperEnergy);
1001 double randomShoot = CLHEP::RandFlat::shoot(rndmEngine);
1003 ATH_MSG_DEBUG(
"[ punchthrough ] Shooting random number: "<< randomShoot);
1005 double midPoint = *std::prev(upperEnergy)*M_SQRT2;
1007 if(energy < midPoint){
1009 double distance = std::abs(energy - *std::prev(upperEnergy))/((midPoint) - *std::prev(upperEnergy));
1011 ATH_MSG_DEBUG(
"[ punchthrough ] incoming energy is closest to prev(upper_bound) in log(energy), distance: " << distance );
1013 if(randomShoot < distance){
1014 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot < distance, returning upper_bound " << *upperEnergy );
1015 return *upperEnergy;
1017 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot > distance, returning prev(upper_bound) " << *std::prev(upperEnergy) );
1019 return *std::prev(upperEnergy);
1021 else if(energy > midPoint){
1023 double distance = std::abs(energy - *upperEnergy)/((*upperEnergy - midPoint));
1025 ATH_MSG_DEBUG(
"[ punchthrough ] incoming energy is closest to upper_bound in log(energy), distance: " << distance );
1027 if(randomShoot < distance){
1028 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot < distance, returning prev(upper_bound) " << *std::prev(upperEnergy) );
1029 return *std::prev(upperEnergy);
1031 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot > distance, returning upper_bound " << *upperEnergy );
1032 return *upperEnergy;
1035 return *upperEnergy;
1040 double absEta = std::abs(
eta);
1042 ATH_MSG_DEBUG(
"[ punchthrough ] interpolating incoming abs(eta): " << absEta);
1044 std::string etaPointsString;
1046 etaPointsString += std::to_string(element) +
" ";
1049 ATH_MSG_DEBUG(
"[ punchthrough ] available eta points: " << etaPointsString);
1054 ATH_MSG_DEBUG(
"[ punchthrough ] incoming abs(eta) > largest eta point, returning greatest eta point: " <<
m_etaPoints.back());
1059 ATH_MSG_DEBUG(
"[ punchthrough ] eta points upper_bound: "<< *upperEta);
1061 double randomShoot = CLHEP::RandFlat::shoot(rndmEngine);
1063 ATH_MSG_DEBUG(
"[ punchthrough ] Shooting random number: "<< randomShoot);
1065 if(std::abs(absEta - *upperEta) < std::abs(absEta - *std::prev(upperEta))){
1067 double distance = std::abs(absEta - *upperEta)/((*upperEta - *std::prev(upperEta))/2);
1069 ATH_MSG_DEBUG(
"[ punchthrough ] abs(eta) is closer to eta points upper_bound, distance: " << distance );
1071 if(randomShoot > distance){
1072 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot > distance, returning upper_bound " << *upperEta );
1076 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot < distance, returning prev(upper_bound) " << *std::prev(upperEta) );
1078 return *std::prev(upperEta);
1080 else if(std::abs(absEta - *std::prev(upperEta)) < std::abs(absEta - *upperEta)){
1083 ATH_MSG_DEBUG(
"[ punchthrough ] prev of upper bound is begin, returning that: " << *std::prev(upperEta) );
1084 return *std::prev(upperEta);
1087 double distance = std::abs(absEta - *std::prev(upperEta))/((*std::prev(upperEta) - *std::prev(std::prev(upperEta)))/2);
1089 ATH_MSG_DEBUG(
"[ punchthrough ] abs(eta) is closer to eta points prev(upper_bound), distance: " << distance );
1091 if(randomShoot > distance){
1092 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot > distance, returning prev(prev(upper_bound)) " << *std::prev(std::prev(upperEta)) );
1094 return *std::prev(std::prev(upperEta));
1096 ATH_MSG_DEBUG(
"[ punchthrough ] randomShoot < distance, returning prev(upper_bound) " << *std::prev(upperEta) );
1098 return *std::prev(upperEta);
1101 return *std::prev(upperEta);
1111 double minEnergy,
int maxNumParticles,
double numParticlesFactor,
1112 double energyFactor,
double posAngleFactor,
double momAngleFactor)
1118 if (!pdf_num )
return StatusCode::FAILURE;
1124 return StatusCode::FAILURE;
1132 return StatusCode::FAILURE;
1140 return StatusCode::FAILURE;
1147 return StatusCode::FAILURE;
1154 return StatusCode::FAILURE;
1159 particle->setNumParticlesPDF(std::move(pdf_num));
1160 particle->setPCA0PDF(std::move(pdf_pca0));
1161 particle->setPCA1PDF(std::move(pdf_pca1));
1162 particle->setPCA2PDF(std::move(pdf_pca2));
1163 particle->setPCA3PDF(std::move(pdf_pca3));
1164 particle->setPCA4PDF(std::move(pdf_pca4));
1168 minEnergy = ( minEnergy > restMass ) ? minEnergy : restMass;
1169 particle->setMinEnergy(minEnergy);
1170 particle->setMaxNumParticles(maxNumParticles);
1171 particle->setNumParticlesFactor(numParticlesFactor);
1172 particle->setEnergyFactor(energyFactor);
1173 particle->setPosAngleFactor(posAngleFactor);
1174 particle->setMomAngleFactor(momAngleFactor);
1179 return StatusCode::SUCCESS;
1188 double minCorrEnergy,
double fullCorrEnergy)
1191 std::map<int, PunchThroughParticle*>::iterator location1 =
m_particles.find(pdgID1);
1192 std::map<int, PunchThroughParticle*>::iterator location2 =
m_particles.find(pdgID2);
1196 return StatusCode::FAILURE;
1199 std::stringstream name;
1200 name <<
"NumExitCorrelations/x_PDG" << std::abs(pdgID1) <<
"__y_PDG" << std::abs(pdgID2) <<
"__lowE";
1203 name <<
"NumExitCorrelations/x_PDG" << std::abs(pdgID1) <<
"__y_PDG" << std::abs(pdgID2) <<
"__highE";
1206 name <<
"NumExitCorrelations/x_PDG" << std::abs(pdgID2) <<
"__y_PDG" << std::abs(pdgID1) <<
"__lowE";
1209 name <<
"NumExitCorrelations/x_PDG" << std::abs(pdgID2) <<
"__y_PDG" << std::abs(pdgID1) <<
"__highE";
1212 if ( (!hist1_2_lowE) || (!hist2_1_lowE) || (!hist1_2_highE) || (!hist2_1_highE) )
1214 ATH_MSG_ERROR(
"[ punchthrough ] unable to retrieve the correlation data for PDG IDs " << pdgID1 <<
" and " << pdgID2);
1215 return StatusCode::FAILURE;
1227 m_particles[pdgID1]->setCorrelation(pdgID2, hist2_1_lowE, hist2_1_highE,
1228 minCorrEnergy, fullCorrEnergy,
1229 lowE, midE, upperE);
1231 m_particles[pdgID2]->setCorrelation(pdgID1, hist1_2_lowE, hist1_2_highE,
1232 minCorrEnergy, fullCorrEnergy,
1233 lowE, midE, upperE);
1234 return StatusCode::SUCCESS;
1249 std::unique_ptr<ISF::PDFcreator> pdf = std::make_unique<ISF::PDFcreator>();
1252 std::stringstream dirName;
1253 dirName << folderName << pdg;
1254 pdf->setName(dirName.str().c_str());
1259 ATH_MSG_ERROR(
"[ punchthrough ] unable to retrieve directory object ("<< folderName << pdg <<
")" );
1266 TIter keyList(dir->GetListOfKeys());
1269 while ((key = (TKey*)keyList())) {
1272 TH1* hist =
nullptr;
1274 std::string histName;
1275 if(strcmp(key->GetClassName(),
"TH1F") == 0){
1276 hist = (TH1*)key->ReadObj();
1277 histName = hist->GetName();
1281 std::string strEnergy = histName.substr( histName.find_first_of(
'E') + 1, histName.find_first_of(
'_')-histName.find_first_of(
'E') - 1 );
1282 histName.erase(0, histName.find_first_of(
'_') + 1);
1283 std::string strEtaMin = histName.substr( histName.find(
"etaMin") + 6, histName.find_first_of(
'_') - histName.find(
"etaMin") - 6 );
1284 histName.erase(0, histName.find(
'_') + 1);
1285 std::string strEtaMax = histName.substr( histName.find(
"etaMax") + 6, histName.length());
1288 const int energy = std::stoi(strEnergy);
1289 const int etaMin = std::stoi(strEtaMin);
1292 pdf->addToEnergyEtaHist1DMap(energy, etaMin, hist);
1295 const double energyDbl =
static_cast<double>(energy);
1296 const double etaDbl =
static_cast<double>(etaMin)/100.;
1319 double energy,
double theta,
double phi,
double momTheta,
double momPhi)
const
1332 Amg::setRThetaPhi( mom, std::sqrt(energy*energy - mass*mass), momTheta, momPhi);
1333 ATH_MSG_DEBUG(
"setRThetaPhi pre input parameters: energy = "<< energy <<
" mass = "<< mass);
1334 ATH_MSG_DEBUG(
"setRThetaPhi input parameters: std::sqrt(energy*energy - mass*mass) = "<< std::sqrt(energy*energy - mass*mass) <<
" momTheta = "<< momTheta <<
" momPhi = "<< momPhi);
1339 charge *= (pdg > 0.) ? 1. : -1.;
1341 const double pTime = 0;
1362 const std::string_view
str( cstr);
1363 const std::string_view pattern( cpattern);
1364 const size_t pos =
str.find(pattern);
1366 if ( pos == std::string::npos)
1368 ATH_MSG_WARNING(
"[ punchthrough ] unable to retrieve floating point number from string");
1369 return -999999999999.;
1371 const std::string_view substring =
str.substr(pos+pattern.length());
1372 std::from_chars(substring.data(), substring.data() + substring.size(), num);
1385 const double theta1 = atan (
m_R1/
m_z1);
1386 const double theta2 = atan (
m_R1/
m_z2);
1387 const double theta3 = atan (
m_R2/
m_z2);
1405 else if (
theta >= theta3 &&
theta < (TMath::Pi()-theta3) )
1410 else if (
theta >= (TMath::Pi()-theta3) &&
theta < (TMath::Pi()-theta2) )
1415 else if (
theta >= (TMath::Pi()-theta2) &&
theta < (TMath::Pi()-theta1) )
1420 else if (
theta >= (TMath::Pi()-theta1) &&
theta <= TMath::Pi() )
1429 ATH_MSG_WARNING (
"Given theta angle is incorrect, setting particle position to (0, 0, 0)");
1430 x = 0.0;
y = 0.0;
z = 0.0;
r = 0.0;
1437 ATH_MSG_DEBUG(
"position of produced punch-through particle: x = "<<
x <<
" y = "<<
y <<
" z = "<<
z<<
" r = "<< pos.perp() <<
"std::sqrt(x^2+y^2) = "<< std::sqrt(
x*
x+
y*
y) );
const boost::regex ref(r_ef)
Scalar eta() const
pseudorapidity method
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
double charge(const T &p)
An STL vector of pointers that by default owns its pointed-to elements.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::vector< RZPair > RZPairVector
The generic ISF particle definition,.
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
void setNextGeoID(AtlasDetDescr::AtlasRegion geoID)
register the next AtlasDetDescr::AtlasRegion
const Amg::Vector3D & position() const
The current position of the ISFParticle.
int pdgCode() const
PDG value.
double mass() const
mass of the particle
This class holds information for different properties of a punch-through particle (energy,...
void name(const std::string &n)
void setRThetaPhi(Amg::Vector3D &v, double r, double theta, double phi)
sets radius, the theta and phi angle of a vector.
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr int UNDEFINED_ID
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.