30 #include "boost/property_tree/ptree.hpp" 31 #include "boost/property_tree/json_parser.hpp" 206 edm::LogInfo(
"Initialization") <<
"Init NN models Global Cache " << std::endl;
255 EcalEtMinForClustering(iConfig.getParameter<double>(
"EcalEtMinForClustering")),
256 HcalEtMinForClustering(iConfig.getParameter<double>(
"HcalEtMinForClustering")),
257 EtMinForSeeding(iConfig.getParameter<double>(
"EtMinForSeeding")),
258 EtaRestriction(iConfig.getParameter<double>(
"EtaRestriction")),
259 CB_CE_split(iConfig.getParameter<double>(
"CB_CE_split")),
261 IdWp90_CB(iConfig.getParameter<double>(
"IdWp90_CB")),
262 IdWp95_CB(iConfig.getParameter<double>(
"IdWp95_CB")),
263 IdWp99_CB(iConfig.getParameter<double>(
"IdWp99_CB")),
265 IdWp90_CE(iConfig.getParameter<double>(
"IdWp90_CE")),
266 IdWp95_CE(iConfig.getParameter<double>(
"IdWp95_CE")),
267 IdWp99_CE(iConfig.getParameter<double>(
"IdWp99_CE")),
269 DEBUG(iConfig.getParameter<
bool>(
"DEBUG")) {
276 produces<BXVector<l1t::Tau>>(
"L1NNCaloTauCollectionBXV");
296 if (
hit.towerIEta() == -1016 &&
hit.towerIPhi() == -962) {
316 <<
" TOWERS WITH towerIeta=-1016 AND towerIphi=-962" << std::endl;
337 return a.towerEt >
b.towerEt;
341 std::vector<SimpleHGCluster> AllHGClusters;
345 auto& cl3d = *cl3dIt;
350 l1t::PFCluster cluster(cl3d.pt(), cl3d.eta(), cl3d.phi(), cl3d.hOverE());
354 float pt_new = cl3d.iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
356 cluster =
l1t::PFCluster(pt_new, cl3d.eta(), cl3d.phi(), hoe_new, isEM);
360 float had_old = cl3d.
pt() - cluster.emEt();
361 float em_new = cl3d.iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
362 float pt_new = had_old + em_new;
363 float hoe_new = em_new > 0 ? (had_old / em_new) : -1;
364 cluster =
l1t::PFCluster(pt_new, cl3d.eta(), cl3d.phi(), hoe_new, isEM);
367 float em_new = cl3d.iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
368 float hoe_new = em_new > 0 ? (cl3d.pt() / em_new - 1) : -1;
369 cluster =
l1t::PFCluster(cl3d.pt(), cl3d.eta(), cl3d.phi(), hoe_new, isEM);
380 HGCluster.
pt = cl3d.pt();
381 HGCluster.
eta = cl3d.eta();
382 HGCluster.
phi = cl3d.phi();
385 HGCluster.
spptot = cl3d.sigmaPhiPhiTot();
386 HGCluster.
szz = cl3d.sigmaZZ();
387 HGCluster.
srrtot = cl3d.sigmaRRTot();
388 HGCluster.
meanz = cl3d.zBarycenter();
390 AllHGClusters.push_back(HGCluster);
399 std::vector<SimpleTowerCluster> l1TowerClustersNxM_CB;
400 std::vector<SimpleTowerCluster> l1TowerClustersNxM_CE;
401 std::vector<SimpleHGCluster> HGClusters;
404 std::vector<SimpleTowerCluster> AllL1TowerClustersNxM_CE;
406 bool caloTauSeedingFinished =
false;
408 while (!caloTauSeedingFinished) {
417 l1CaloTower.stale4seed) {
425 caloTauSeedingFinished =
true;
429 clNxM.
seedIeta = l1CaloTower.towerIeta;
430 clNxM.
seedIphi = l1CaloTower.towerIphi;
431 clNxM.
seedEta = l1CaloTower.towerEta;
432 clNxM.
seedPhi = l1CaloTower.towerPhi;
433 if (l1CaloTower.isBarrel) {
437 clNxM.
rawEt += l1CaloTower.towerEt;
439 l1CaloTower.stale4seed =
true;
440 l1CaloTower.stale =
true;
455 d_Eta = l1CaloTower.towerEta - clNxM.
seedEta;
462 l1CaloTower.stale4seed =
true;
470 l1TowerClustersNxM_CB.push_back(clNxM);
472 AllL1TowerClustersNxM_CE.push_back(clNxM);
479 for (
auto& clNxM : l1TowerClustersNxM_CB) {
482 if (l1CaloTower.stale) {
492 if (l1CaloTower.isBarrel) {
493 d_iEta =
tower_dIEta(l1CaloTower.towerIeta, clNxM.seedIeta);
494 d_iPhi =
tower_dIPhi(l1CaloTower.towerIphi, clNxM.seedIphi);
498 d_Eta = l1CaloTower.towerEta - clNxM.seedEta;
501 int dieta = d_Eta / 0.0807;
502 int diphi = d_Phi / 0.0872;
509 clNxM.rawEt += l1CaloTower.towerEt;
510 clNxM.towerHits[hitIdx] = l1CaloTower;
511 l1CaloTower.stale =
true;
520 for (
auto& clNxM : AllL1TowerClustersNxM_CE) {
522 for (
auto& HGCluster : AllHGClusters) {
525 if (
matched || HGCluster.stale || HGCluster.pt < 4) {
529 float d_Eta = HGCluster.eta - clNxM.seedEta;
531 float d_R2 =
pow(d_Eta, 2) +
pow(d_Phi, 2);
534 HGCluster.stale =
true;
535 HGClusters.push_back(HGCluster);
536 l1TowerClustersNxM_CE.push_back(clNxM);
545 for (
auto& clNxM : l1TowerClustersNxM_CE) {
548 if (l1CaloTower.stale) {
558 if (l1CaloTower.isBarrel) {
559 d_iEta =
tower_dIEta(l1CaloTower.towerIeta, clNxM.seedIeta);
560 d_iPhi =
tower_dIPhi(l1CaloTower.towerIphi, clNxM.seedIphi);
564 d_Eta = l1CaloTower.towerEta - clNxM.seedEta;
567 int dieta = d_Eta / 0.0807;
568 int diphi = d_Phi / 0.0872;
575 clNxM.rawEt += l1CaloTower.towerEt;
576 clNxM.towerHits[hitIdx] = l1CaloTower;
577 l1CaloTower.stale =
true;
585 int batchSize_CB = (
int)(l1TowerClustersNxM_CB.size());
586 tensorflow::TensorShape imageShape_CB({batchSize_CB,
IEta_dim,
IPhi_dim, 2});
587 tensorflow::TensorShape positionShape_CB({batchSize_CB, 2});
588 tensorflow::Tensor TowerClusterImage_CB(tensorflow::DT_FLOAT, imageShape_CB);
589 tensorflow::Tensor TowerClusterPosition_CB(tensorflow::DT_FLOAT, positionShape_CB);
592 for (
auto& clNxM : l1TowerClustersNxM_CB) {
597 TowerClusterImage_CB.tensor<
float, 4>()(clIdx,
eta,
phi, 0) =
598 inputQuantizer(clNxM.towerHits[towerIdx].l1egTowerEt + clNxM.towerHits[towerIdx].towerEm, 0.25, 10);
599 TowerClusterImage_CB.tensor<
float, 4>()(clIdx,
eta,
phi, 1) =
604 TowerClusterPosition_CB.tensor<
float, 2>()(clIdx, 0) = clNxM.seedEta;
605 TowerClusterPosition_CB.tensor<
float, 2>()(clIdx, 1) = clNxM.seedPhi;
615 {
"TowerClusterPosition", TowerClusterPosition_CB}};
616 std::vector<tensorflow::Tensor> CNNmodel_CBoutputs;
618 CNNmodel_CBinputList,
619 {
"TauMinator_CB_conv/middleMan/concat"},
620 &CNNmodel_CBoutputs);
624 std::vector<tensorflow::Tensor> DNN_CBoutputsIdent;
627 {
"TauMinator_CB_ident/sigmoid_IDout/Sigmoid"},
628 &DNN_CBoutputsIdent);
631 std::vector<tensorflow::Tensor> DNN_CBoutputsCalib;
634 {
"TauMinator_CB_calib/LIN_DNNout/Relu"},
635 &DNN_CBoutputsCalib);
639 for (
auto& clNxM : l1TowerClustersNxM_CB) {
640 clNxM.IDscore = DNN_CBoutputsIdent[0].matrix<
float>()(0, clIdx);
641 clNxM.calibPt = DNN_CBoutputsCalib[0].matrix<
float>()(0, clIdx);
647 int batchSize_CE = (
int)(l1TowerClustersNxM_CE.size());
648 tensorflow::TensorShape imageShape_CE({batchSize_CE,
IEta_dim,
IPhi_dim, 2});
649 tensorflow::TensorShape positionShape_CE({batchSize_CE, 2});
650 tensorflow::TensorShape cl3dfeatShape_CE({batchSize_CE, 8});
651 tensorflow::Tensor TowerClusterImage_CE(tensorflow::DT_FLOAT, imageShape_CE);
652 tensorflow::Tensor TowerClusterPosition_CE(tensorflow::DT_FLOAT, positionShape_CE);
653 tensorflow::Tensor Cl3dShapeFeatures_CE(tensorflow::DT_FLOAT, cl3dfeatShape_CE);
656 for (
auto& clNxM : l1TowerClustersNxM_CE) {
664 TowerClusterImage_CE.tensor<
float, 4>()(clIdx,
eta,
phi, 0) =
665 inputQuantizer(clNxM.towerHits[towerIdx].l1egTowerEt + clNxM.towerHits[towerIdx].towerEm, 0.25, 10);
666 TowerClusterImage_CE.tensor<
float, 4>()(clIdx,
eta,
phi, 1) =
671 TowerClusterPosition_CE.tensor<
float, 2>()(clIdx, 0) = clNxM.seedEta;
672 TowerClusterPosition_CE.tensor<
float, 2>()(clIdx, 1) = clNxM.seedPhi;
675 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 1) =
679 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 4) =
682 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 6) =
684 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 7) =
695 {
"TowerClusterPosition", TowerClusterPosition_CE},
696 {
"AssociatedCl3dFeatures", Cl3dShapeFeatures_CE}};
697 std::vector<tensorflow::Tensor> CNNmodel_CEoutputs;
699 CNNmodel_CEinputList,
700 {
"TauMinator_CE_conv/middleMan/concat"},
701 &CNNmodel_CEoutputs);
705 std::vector<tensorflow::Tensor> DNN_CEoutputsIdent;
708 {
"TauMinator_CE_ident/sigmoid_IDout/Sigmoid"},
709 &DNN_CEoutputsIdent);
712 std::vector<tensorflow::Tensor> DNN_CEoutputsCalib;
715 {
"TauMinator_CE_calib/LIN_DNNout/Relu"},
716 &DNN_CEoutputsCalib);
720 for (
auto& clNxM : l1TowerClustersNxM_CE) {
721 clNxM.IDscore = DNN_CEoutputsIdent[0].matrix<
float>()(0, clIdx);
722 clNxM.calibPt = DNN_CEoutputsCalib[0].matrix<
float>()(0, clIdx);
728 for (
auto& clNxM : l1TowerClustersNxM_CB) {
756 l1Tau.setTowerIEta(clNxM.seedIeta);
757 l1Tau.setTowerIPhi(clNxM.seedIphi);
758 l1Tau.setRawEt(clNxM.rawEt);
760 L1NNCaloTauCollectionBXV->push_back(0,
l1Tau);
763 for (
auto& clNxM : l1TowerClustersNxM_CE) {
791 l1Tau.setTowerIEta(clNxM.seedIeta);
792 l1Tau.setTowerIPhi(clNxM.seedIphi);
793 l1Tau.setRawEt(clNxM.rawEt);
795 L1NNCaloTauCollectionBXV->push_back(0,
l1Tau);
799 iEvent.put(
std::move(L1NNCaloTauCollectionBXV),
"L1NNCaloTauCollectionBXV");
816 if (iEta_1 * iEta_2 > 0) {
817 return iEta_1 - iEta_2;
820 return iEta_1 - iEta_2 - 1;
822 return iEta_1 - iEta_2 + 1;
828 const float phi_step = 0.0872664;
830 return floor(
phi / phi_step) + 1;
832 return floor(
phi / phi_step) + 73;
837 const float eta_step = 0.0845;
838 return floor(
abs(
eta) / eta_step) * std::copysign(1,
eta);
842 return min(floor(inputF / LSB),
float(
pow(2, nbits) - 1)) * LSB;
846 float mean = (globalCache()->FeatScaler_CE).get_child(feature).get<
float>(
"mean");
847 float std = (globalCache()->FeatScaler_CE).get_child(feature).get<
float>(
"std");
858 edm::InputTag(
"l1tHGCalBackEndLayer2Producer",
"HGCalBackendLayer2Processor3DClustering"));
863 psd0.
add<
bool>(
"isPUFilter",
true);
870 std::vector<edm::ParameterSet> temp2;
876 temp2.push_back(temp3);
882 temp2.push_back(temp3);
888 temp2.push_back(temp3);
894 temp2.push_back(temp3);
900 temp2.push_back(temp3);
902 psd0.
addVPSet(
"variables", vpsd2, temp2);
905 "weightsFile",
"L1Trigger/Phase2L1ParticleFlow/data/hgcal_egID/Photon_Pion_vs_Neutrino_BDTweights_1116.xml.gz");
910 desc.add<
double>(
"EcalEtMinForClustering", 0.0);
911 desc.add<
double>(
"HcalEtMinForClustering", 0.0);
912 desc.add<
double>(
"EtMinForSeeding", 2.5);
913 desc.add<
double>(
"EtaRestriction", 2.4);
914 desc.add<
double>(
"CB_CE_split", 1.55);
916 desc.add<
std::string>(
"CNNmodel_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/CNNmodel_CB.pb");
917 desc.add<
std::string>(
"DNNident_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNident_CB.pb");
918 desc.add<
std::string>(
"DNNcalib_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNcalib_CB.pb");
919 desc.add<
std::string>(
"CNNmodel_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/CNNmodel_CE.pb");
920 desc.add<
std::string>(
"DNNident_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNident_CE.pb");
921 desc.add<
std::string>(
"DNNcalib_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNcalib_CE.pb");
922 desc.add<
std::string>(
"FeatScaler_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/Cl3dFeatScaler_CE.json");
924 desc.add<
double>(
"IdWp90_CB", 0.706);
925 desc.add<
double>(
"IdWp95_CB", 0.3432);
926 desc.add<
double>(
"IdWp99_CB", 0.0337);
927 desc.add<
double>(
"IdWp90_CE", 0.5711);
928 desc.add<
double>(
"IdWp95_CE", 0.2742);
929 desc.add<
double>(
"IdWp99_CE", 0.0394);
931 desc.add<
bool>(
"DEBUG",
false);
933 descriptions.
add(
"l1tNNCaloTauProducer",
desc);
edm::Handle< l1t::HGCalMulticlusterBxCollection > HGClusterHandle
boost::property_tree::ptree FeatScaler_CE
tensorflow::Session * CNNmodel_CEsession
constexpr double deltaPhi(double phi1, double phi2)
tensorflow::GraphDef * DNNident_CB
std::string DNNident_CE_path
std::string DNNcalib_CB_path
std::vector< NamedTensor > NamedTensorList
T getParameter(std::string const &) const
tensorflow::GraphDef * CNNmodel_CB
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
StringCutObjectSelector< l1t::HGCalMulticluster > preEmId
double pt() const final
transverse momentum
std::string fullPath() const
int tower_dIEta(int &iEta_1, int &iEta_2) const
GraphDef * loadGraphDef(const std::string &pbFile)
T const * product() const
tensorflow::Session * DNNident_CBsession
tensorflow::Session * DNNcalib_CEsession
edm::Handle< l1t::HGCalTowerBxCollection > hgcalTowersHandle
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string CNNmodel_CB_path
std::vector< SimpleTowerHit > towerHits
tensorflow::Session * DNNident_CEsession
BXVector< HGCalTower > HGCalTowerBxCollection
int endcap_ieta(float &eta) const
tensorflow::GraphDef * DNNcalib_CE
int tower_dIPhi(int &iPhi_1, int &iPhi_2) const
std::string CNNmodel_CE_path
void addParameter(std::string const &name, T const &value)
L1NNCaloTauProducer(const edm::ParameterSet &, const NNmodels_GlobalCache *)
BXVector< HGCalMulticluster > HGCalMulticlusterBxCollection
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Abs< T >::type abs(const T &t)
tensorflow::GraphDef * CNNmodel_CE
std::string DNNident_CB_path
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< l1t::HGCalMulticlusterBxCollection > HGClusterToken
double HcalEtMinForClustering
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double EcalEtMinForClustering
typename CacheTypes::GlobalCache GlobalCache
float inputScaler(float inputF, std::string feature)
edm::Handle< l1tp2::CaloTowerCollection > l1CaloTowerHandle
tensorflow::Session * DNNcalib_CBsession
float inputQuantizer(float inputF, float LSB, int nbits)
Session * createSession()
std::string DNNcalib_CE_path
Log< level::Info, false > LogInfo
static std::unique_ptr< NNmodels_GlobalCache > initializeGlobalCache(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
tensorflow::Session * CNNmodel_CBsession
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int endcap_iphi(float &phi) const
void InitHits(int N, int M)
l1tpf::HGC3DClusterEgID VsPuId
static void globalEndJob(const NNmodels_GlobalCache *)
tensorflow::GraphDef * DNNcalib_CB
edm::EDGetToken hgcalTowersToken
edm::EDGetTokenT< l1tp2::CaloTowerCollection > l1TowersToken
Log< level::Warning, false > LogWarning
float passID(l1t::HGCalMulticluster c, l1t::PFCluster &cpf)
std::string FeatScaler_CE_path
tensorflow::GraphDef * DNNident_CE
Power< A, B >::type pow(const A &a, const B &b)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.