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;
586 int batchSize_CB = (
int)(l1TowerClustersNxM_CB.size());
587 tensorflow::TensorShape imageShape_CB({batchSize_CB,
IEta_dim,
IPhi_dim, 2});
588 tensorflow::TensorShape positionShape_CB({batchSize_CB, 2});
589 tensorflow::Tensor TowerClusterImage_CB(tensorflow::DT_FLOAT, imageShape_CB);
590 tensorflow::Tensor TowerClusterPosition_CB(tensorflow::DT_FLOAT, positionShape_CB);
593 for (
auto& clNxM : l1TowerClustersNxM_CB) {
598 TowerClusterImage_CB.tensor<
float, 4>()(clIdx,
eta,
phi, 0) =
599 inputQuantizer(clNxM.towerHits[towerIdx].l1egTowerEt + clNxM.towerHits[towerIdx].towerEm, 0.25, 10);
600 TowerClusterImage_CB.tensor<
float, 4>()(clIdx,
eta,
phi, 1) =
605 TowerClusterPosition_CB.tensor<
float, 2>()(clIdx, 0) = clNxM.seedEta;
606 TowerClusterPosition_CB.tensor<
float, 2>()(clIdx, 1) = clNxM.seedPhi;
616 {
"TowerClusterPosition", TowerClusterPosition_CB}};
617 std::vector<tensorflow::Tensor> CNNmodel_CBoutputs;
619 CNNmodel_CBinputList,
620 {
"TauMinator_CB_conv/middleMan/concat"},
621 &CNNmodel_CBoutputs);
625 std::vector<tensorflow::Tensor> DNN_CBoutputsIdent;
628 {
"TauMinator_CB_ident/sigmoid_IDout/Sigmoid"},
629 &DNN_CBoutputsIdent);
632 std::vector<tensorflow::Tensor> DNN_CBoutputsCalib;
635 {
"TauMinator_CB_calib/LIN_DNNout/Relu"},
636 &DNN_CBoutputsCalib);
640 for (
auto& clNxM : l1TowerClustersNxM_CB) {
641 clNxM.IDscore = DNN_CBoutputsIdent[0].matrix<
float>()(0, clIdx);
642 clNxM.calibPt = DNN_CBoutputsCalib[0].matrix<
float>()(0, clIdx);
648 int batchSize_CE = (
int)(l1TowerClustersNxM_CE.size());
649 tensorflow::TensorShape imageShape_CE({batchSize_CE,
IEta_dim,
IPhi_dim, 2});
650 tensorflow::TensorShape positionShape_CE({batchSize_CE, 2});
651 tensorflow::TensorShape cl3dfeatShape_CE({batchSize_CE, 8});
652 tensorflow::Tensor TowerClusterImage_CE(tensorflow::DT_FLOAT, imageShape_CE);
653 tensorflow::Tensor TowerClusterPosition_CE(tensorflow::DT_FLOAT, positionShape_CE);
654 tensorflow::Tensor Cl3dShapeFeatures_CE(tensorflow::DT_FLOAT, cl3dfeatShape_CE);
657 for (
auto& clNxM : l1TowerClustersNxM_CE) {
665 TowerClusterImage_CE.tensor<
float, 4>()(clIdx,
eta,
phi, 0) =
666 inputQuantizer(clNxM.towerHits[towerIdx].l1egTowerEt + clNxM.towerHits[towerIdx].towerEm, 0.25, 10);
667 TowerClusterImage_CE.tensor<
float, 4>()(clIdx,
eta,
phi, 1) =
672 TowerClusterPosition_CE.tensor<
float, 2>()(clIdx, 0) = clNxM.seedEta;
673 TowerClusterPosition_CE.tensor<
float, 2>()(clIdx, 1) = clNxM.seedPhi;
676 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 1) =
680 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 4) =
683 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 6) =
685 Cl3dShapeFeatures_CE.tensor<
float, 2>()(clIdx, 7) =
696 {
"TowerClusterPosition", TowerClusterPosition_CE},
697 {
"AssociatedCl3dFeatures", Cl3dShapeFeatures_CE}};
698 std::vector<tensorflow::Tensor> CNNmodel_CEoutputs;
700 CNNmodel_CEinputList,
701 {
"TauMinator_CE_conv/middleMan/concat"},
702 &CNNmodel_CEoutputs);
706 std::vector<tensorflow::Tensor> DNN_CEoutputsIdent;
709 {
"TauMinator_CE_ident/sigmoid_IDout/Sigmoid"},
710 &DNN_CEoutputsIdent);
713 std::vector<tensorflow::Tensor> DNN_CEoutputsCalib;
716 {
"TauMinator_CE_calib/LIN_DNNout/Relu"},
717 &DNN_CEoutputsCalib);
721 for (
auto& clNxM : l1TowerClustersNxM_CE) {
722 clNxM.IDscore = DNN_CEoutputsIdent[0].matrix<
float>()(0, clIdx);
723 clNxM.calibPt = DNN_CEoutputsCalib[0].matrix<
float>()(0, clIdx);
729 for (
auto& clNxM : l1TowerClustersNxM_CB) {
757 l1Tau.setTowerIEta(clNxM.seedIeta);
758 l1Tau.setTowerIPhi(clNxM.seedIphi);
759 l1Tau.setRawEt(clNxM.rawEt);
761 L1NNCaloTauCollectionBXV->push_back(0,
l1Tau);
764 for (
auto& clNxM : l1TowerClustersNxM_CE) {
792 l1Tau.setTowerIEta(clNxM.seedIeta);
793 l1Tau.setTowerIPhi(clNxM.seedIphi);
794 l1Tau.setRawEt(clNxM.rawEt);
796 L1NNCaloTauCollectionBXV->push_back(0,
l1Tau);
800 iEvent.put(
std::move(L1NNCaloTauCollectionBXV),
"L1NNCaloTauCollectionBXV");
817 if (iEta_1 * iEta_2 > 0) {
818 return iEta_1 - iEta_2;
821 return iEta_1 - iEta_2 - 1;
823 return iEta_1 - iEta_2 + 1;
829 const float phi_step = 0.0872664;
831 return floor(
phi / phi_step) + 1;
833 return floor(
phi / phi_step) + 73;
838 const float eta_step = 0.0845;
839 return floor(
abs(
eta) / eta_step) * std::copysign(1,
eta);
843 return min(floor(inputF / LSB),
float(
pow(2, nbits) - 1)) * LSB;
847 float mean = (globalCache()->FeatScaler_CE).get_child(feature).get<
float>(
"mean");
848 float std = (globalCache()->FeatScaler_CE).get_child(feature).get<
float>(
"std");
859 edm::InputTag(
"l1tHGCalBackEndLayer2Producer",
"HGCalBackendLayer2Processor3DClustering"));
864 psd0.
add<
bool>(
"isPUFilter",
true);
871 std::vector<edm::ParameterSet> temp2;
877 temp2.push_back(temp3);
883 temp2.push_back(temp3);
889 temp2.push_back(temp3);
895 temp2.push_back(temp3);
901 temp2.push_back(temp3);
903 psd0.
addVPSet(
"variables", vpsd2, temp2);
906 "weightsFile",
"L1Trigger/Phase2L1ParticleFlow/data/hgcal_egID/Photon_Pion_vs_Neutrino_BDTweights_1116.xml.gz");
911 desc.add<
double>(
"EcalEtMinForClustering", 0.0);
912 desc.add<
double>(
"HcalEtMinForClustering", 0.0);
913 desc.add<
double>(
"EtMinForSeeding", 2.5);
914 desc.add<
double>(
"EtaRestriction", 2.4);
915 desc.add<
double>(
"CB_CE_split", 1.55);
917 desc.add<
std::string>(
"CNNmodel_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/CNNmodel_CB.pb");
918 desc.add<
std::string>(
"DNNident_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNident_CB.pb");
919 desc.add<
std::string>(
"DNNcalib_CB_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNcalib_CB.pb");
920 desc.add<
std::string>(
"CNNmodel_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/CNNmodel_CE.pb");
921 desc.add<
std::string>(
"DNNident_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNident_CE.pb");
922 desc.add<
std::string>(
"DNNcalib_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/v22/DNNcalib_CE.pb");
923 desc.add<
std::string>(
"FeatScaler_CE_path",
"L1Trigger/L1CaloTrigger/data/Phase2_NNCaloTaus/Cl3dFeatScaler_CE.json");
925 desc.add<
double>(
"IdWp90_CB", 0.706);
926 desc.add<
double>(
"IdWp95_CB", 0.3432);
927 desc.add<
double>(
"IdWp99_CB", 0.0337);
928 desc.add<
double>(
"IdWp90_CE", 0.5711);
929 desc.add<
double>(
"IdWp95_CE", 0.2742);
930 desc.add<
double>(
"IdWp99_CE", 0.0394);
932 desc.add<
bool>(
"DEBUG",
false);
934 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
void setLogging(const std::string &level="3")
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.