Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:53:40

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2023 - 2025 Friederike Bock, Wouter Deconinck
0003 
0004 #include <Evaluator/DD4hepUnits.h>
0005 #include <JANA/JApplicationFwd.h>
0006 #include <TString.h>
0007 #include <string>
0008 #include <variant>
0009 
0010 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0011 #include "algorithms/calorimetry/ImagingTopoClusterConfig.h"
0012 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0013 #include "factories/calorimetry/CalorimeterClusterRecoCoG_factory.h"
0014 #include "factories/calorimetry/CalorimeterClusterShape_factory.h"
0015 #include "factories/calorimetry/CalorimeterHitDigi_factory.h"
0016 #include "factories/calorimetry/CalorimeterHitReco_factory.h"
0017 #include "factories/calorimetry/CalorimeterHitsMerger_factory.h"
0018 #include "factories/calorimetry/CalorimeterIslandCluster_factory.h"
0019 #include "factories/calorimetry/CalorimeterTruthClustering_factory.h"
0020 #include "factories/calorimetry/HEXPLIT_factory.h"
0021 #include "factories/calorimetry/ImagingTopoCluster_factory.h"
0022 #include "factories/calorimetry/TrackClusterMergeSplitter_factory.h"
0023 
0024 extern "C" {
0025 void InitPlugin(JApplication* app) {
0026 
0027   using namespace eicrecon;
0028 
0029   InitJANAPlugin(app);
0030 
0031   // Make sure digi and reco use the same value
0032   decltype(CalorimeterHitDigiConfig::capADC) HcalEndcapPInsert_capADC           = 32768;
0033   decltype(CalorimeterHitDigiConfig::dyRangeADC) HcalEndcapPInsert_dyRangeADC   = 200 * dd4hep::MeV;
0034   decltype(CalorimeterHitDigiConfig::pedMeanADC) HcalEndcapPInsert_pedMeanADC   = 10;
0035   decltype(CalorimeterHitDigiConfig::pedSigmaADC) HcalEndcapPInsert_pedSigmaADC = 2;
0036   decltype(CalorimeterHitDigiConfig::resolutionTDC) HcalEndcapPInsert_resolutionTDC =
0037       10 * dd4hep::picosecond;
0038 
0039   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitDigi_factory>(
0040       "HcalEndcapPInsertRawHits", {"HcalEndcapPInsertHits"},
0041       {"HcalEndcapPInsertRawHits", "HcalEndcapPInsertRawHitAssociations"},
0042       {
0043           .eRes          = {},
0044           .tRes          = 0.0 * dd4hep::ns,
0045           .capADC        = HcalEndcapPInsert_capADC,
0046           .dyRangeADC    = HcalEndcapPInsert_dyRangeADC,
0047           .pedMeanADC    = HcalEndcapPInsert_pedMeanADC,
0048           .pedSigmaADC   = HcalEndcapPInsert_pedSigmaADC,
0049           .resolutionTDC = HcalEndcapPInsert_resolutionTDC,
0050           .corrMeanScale = "1.0",
0051           .readout       = "HcalEndcapPInsertHits",
0052       },
0053       app // TODO: Remove me once fixed
0054       ));
0055   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitReco_factory>(
0056       "HcalEndcapPInsertRecHits", {"HcalEndcapPInsertRawHits"}, {"HcalEndcapPInsertRecHits"},
0057       {
0058           .capADC          = HcalEndcapPInsert_capADC,
0059           .dyRangeADC      = HcalEndcapPInsert_dyRangeADC,
0060           .pedMeanADC      = HcalEndcapPInsert_pedMeanADC,
0061           .pedSigmaADC     = HcalEndcapPInsert_pedSigmaADC,
0062           .resolutionTDC   = HcalEndcapPInsert_resolutionTDC,
0063           .thresholdFactor = 0.,
0064           .thresholdValue  = 41.0, // 0.25 MeV --> 0.25 / 200 * 32768 = 41
0065 
0066           .sampFrac   = "1.0",
0067           .readout    = "HcalEndcapPInsertHits",
0068           .layerField = "layer",
0069       },
0070       app // TODO: Remove me once fixed
0071       ));
0072   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitsMerger_factory>(
0073       "HcalEndcapPInsertMergedHits", {"HcalEndcapPInsertRecHits"}, {"HcalEndcapPInsertMergedHits"},
0074       {.readout = "HcalEndcapPInsertHits", .fieldTransformations = {"layer:1", "slice:0"}},
0075       app // TODO: Remove me once fixed
0076       ));
0077   app->Add(new JOmniFactoryGeneratorT<CalorimeterTruthClustering_factory>(
0078       "HcalEndcapPInsertTruthProtoClusters",
0079       {"HcalEndcapPInsertMergedHits", "HcalEndcapPInsertHits"},
0080       {"HcalEndcapPInsertTruthProtoClusters"},
0081       app // TODO: Remove me once fixed
0082       ));
0083 
0084   app->Add(new JOmniFactoryGeneratorT<HEXPLIT_factory>(
0085       "HcalEndcapPInsertSubcellHits", {"HcalEndcapPInsertRecHits"},
0086       {"HcalEndcapPInsertSubcellHits"},
0087       {
0088           .MIP          = 480. * dd4hep::keV,
0089           .Emin_in_MIPs = 0.5,
0090           .tmax         = 162 * dd4hep::ns, //150 ns + (z at front face)/(speed of light)
0091       },
0092       app // TODO: Remove me once fixed
0093       ));
0094 
0095   app->Add(new JOmniFactoryGeneratorT<ImagingTopoCluster_factory>(
0096       "HcalEndcapPInsertImagingProtoClusters", {"HcalEndcapPInsertSubcellHits"},
0097       {"HcalEndcapPInsertImagingProtoClusters"},
0098       {
0099           .neighbourLayersRange = 1,
0100           .localDistXY =
0101               {"0.5 * max(HcalEndcapPInsertCellSizeLGRight, HcalEndcapPInsertCellSizeLGLeft)",
0102                "0.5 * max(HcalEndcapPInsertCellSizeLGRight, HcalEndcapPInsertCellSizeLGLeft) * "
0103                "sin(pi / 3)"},
0104           .layerDistXY =
0105               {"0.25 * max(HcalEndcapPInsertCellSizeLGRight, HcalEndcapPInsertCellSizeLGLeft)",
0106                "0.25 * max(HcalEndcapPInsertCellSizeLGRight, HcalEndcapPInsertCellSizeLGLeft) * "
0107                "sin(pi / 3)"},
0108           .layerMode            = eicrecon::ImagingTopoClusterConfig::ELayerMode::xy,
0109           .sectorDist           = 10.0 * dd4hep::cm,
0110           .minClusterHitEdep    = 5.0 * dd4hep::keV,
0111           .minClusterCenterEdep = 3.0 * dd4hep::MeV,
0112           .minClusterEdep       = 11.0 * dd4hep::MeV,
0113           .minClusterNhits      = 100,
0114       },
0115       app // TODO: Remove me once fixed
0116       ));
0117 
0118   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0119       "HcalEndcapPInsertTruthClustersWithoutShapes",
0120       {
0121           "HcalEndcapPInsertTruthProtoClusters", // edm4eic::ProtoClusterCollection
0122           "HcalEndcapPInsertRawHitAssociations" // edm4eic::MCRecoCalorimeterHitAssociationCollection
0123       },
0124       {"HcalEndcapPInsertTruthClustersWithoutShapes",             // edm4eic::Cluster
0125        "HcalEndcapPInsertTruthClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0126       {.energyWeight = "log", .sampFrac = 0.0257, .logWeightBase = 3.6, .enableEtaBounds = true},
0127       app // TODO: Remove me once fixed
0128       ));
0129 
0130   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0131       "HcalEndcapPInsertTruthClusters",
0132       {"HcalEndcapPInsertTruthClustersWithoutShapes",
0133        "HcalEndcapPInsertTruthClusterAssociationsWithoutShapes"},
0134       {"HcalEndcapPInsertTruthClusters", "HcalEndcapPInsertTruthClusterAssociations"},
0135       {.longitudinalShowerInfoAvailable = true, .energyWeight = "log", .logWeightBase = 3.6}, app));
0136 
0137   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0138       "HcalEndcapPInsertClustersWithoutShapes",
0139       {
0140           "HcalEndcapPInsertImagingProtoClusters", // edm4eic::ProtoClusterCollection
0141           "HcalEndcapPInsertRawHitAssociations" // edm4eic::MCRecoCalorimeterHitAssociationCollection
0142       },
0143       {"HcalEndcapPInsertClustersWithoutShapes",             // edm4eic::Cluster
0144        "HcalEndcapPInsertClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0145       {
0146           .energyWeight    = "log",
0147           .sampFrac        = 0.0257,
0148           .logWeightBase   = 6.2,
0149           .enableEtaBounds = false,
0150       },
0151       app // TODO: Remove me once fixed
0152       ));
0153 
0154   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0155       "HcalEndcapPInsertClusters",
0156       {"HcalEndcapPInsertClustersWithoutShapes",
0157        "HcalEndcapPInsertClusterAssociationsWithoutShapes"},
0158       {"HcalEndcapPInsertClusters", "HcalEndcapPInsertClusterAssociations"},
0159       {.longitudinalShowerInfoAvailable = true,
0160        .energyWeight                    = "log",
0161        .sampFrac                        = 0.0257,
0162        .logWeightBase                   = 6.2},
0163       app));
0164 
0165   // Make sure digi and reco use the same value
0166   decltype(CalorimeterHitDigiConfig::capADC) LFHCAL_capADC               = 65536;
0167   decltype(CalorimeterHitDigiConfig::dyRangeADC) LFHCAL_dyRangeADC       = 1 * dd4hep::GeV;
0168   decltype(CalorimeterHitDigiConfig::pedMeanADC) LFHCAL_pedMeanADC       = 50;
0169   decltype(CalorimeterHitDigiConfig::pedSigmaADC) LFHCAL_pedSigmaADC     = 10;
0170   decltype(CalorimeterHitDigiConfig::resolutionTDC) LFHCAL_resolutionTDC = 10 * dd4hep::picosecond;
0171 
0172   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitDigi_factory>(
0173       "LFHCALRawHits", {"LFHCALHits"}, {"LFHCALRawHits", "LFHCALRawHitAssociations"},
0174       {
0175           .eRes          = {},
0176           .tRes          = 0.0 * dd4hep::ns,
0177           .capADC        = LFHCAL_capADC,
0178           .capTime       = 100,
0179           .dyRangeADC    = LFHCAL_dyRangeADC,
0180           .pedMeanADC    = LFHCAL_pedMeanADC,
0181           .pedSigmaADC   = LFHCAL_pedSigmaADC,
0182           .resolutionTDC = LFHCAL_resolutionTDC,
0183           .corrMeanScale = "1.0",
0184           .readout       = "LFHCALHits",
0185           .fields        = {"layerz"},
0186       },
0187       app // TODO: Remove me once fixed
0188       ));
0189   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitReco_factory>(
0190       "LFHCALRecHits", {"LFHCALRawHits"}, {"LFHCALRecHits"},
0191       {
0192           .capADC          = LFHCAL_capADC,
0193           .dyRangeADC      = LFHCAL_dyRangeADC,
0194           .pedMeanADC      = LFHCAL_pedMeanADC,
0195           .pedSigmaADC     = LFHCAL_pedSigmaADC,
0196           .resolutionTDC   = LFHCAL_resolutionTDC,
0197           .thresholdFactor = 0.0,
0198           .thresholdValue  = 20, // 0.3 MeV deposition --> adc = 50 + 0.3 / 1000 * 65536 == 70
0199           .sampFrac        = "(rlayerz == 0) ? 0.019 : 0.037", // 0.019 only in the 0-th tile
0200           .readout         = "LFHCALHits",
0201           .layerField      = "rlayerz",
0202       },
0203       app // TODO: Remove me once fixed
0204       ));
0205   app->Add(new JOmniFactoryGeneratorT<CalorimeterTruthClustering_factory>(
0206       "LFHCALTruthProtoClusters", {"LFHCALRecHits", "LFHCALHits"}, {"LFHCALTruthProtoClusters"},
0207       app // TODO: Remove me once fixed
0208       ));
0209 
0210   // Magic constants:
0211   //  54 - number of modules in a row/column
0212   //  2  - number of towers in a module
0213   // sign for towerx and towery are *negative* to maintain linearity with global X and Y
0214   std::string cellIdx_1 = "(54*2-moduleIDx_1*2-towerx_1)";
0215   std::string cellIdx_2 = "(54*2-moduleIDx_2*2-towerx_2)";
0216   std::string cellIdy_1 = "(54*2-moduleIDy_1*2-towery_1)";
0217   std::string cellIdy_2 = "(54*2-moduleIDy_2*2-towery_2)";
0218   std::string cellIdz_1 = "rlayerz_1";
0219   std::string cellIdz_2 = "rlayerz_2";
0220   std::string deltaX    = Form("abs(%s-%s)", cellIdx_2.data(), cellIdx_1.data());
0221   std::string deltaY    = Form("abs(%s-%s)", cellIdy_2.data(), cellIdy_1.data());
0222   std::string deltaZ    = Form("abs(%s-%s)", cellIdz_2.data(), cellIdz_1.data());
0223   std::string neighbor  = Form("(%s+%s+%s==1)", deltaX.data(), deltaY.data(), deltaZ.data());
0224   std::string corner2D =
0225       Form("((%s==0&&%s==1&&%s==1)||(%s==1&&%s==0&&%s==1)||(%s==1&&%s==1&&%s==0))", deltaZ.data(),
0226            deltaX.data(), deltaY.data(), deltaZ.data(), deltaX.data(), deltaY.data(), deltaZ.data(),
0227            deltaX.data(), deltaY.data());
0228 
0229   app->Add(new JOmniFactoryGeneratorT<CalorimeterIslandCluster_factory>(
0230       "LFHCALIslandProtoClusters", {"LFHCALRecHits"}, {"LFHCALIslandProtoClusters"},
0231       {
0232           .adjacencyMatrix = Form("%s||%s", neighbor.data(), corner2D.data()),
0233           .peakNeighbourhoodMatrix{},
0234           .readout    = "LFHCALHits",
0235           .sectorDist = 0 * dd4hep::cm,
0236           .localDistXY{},
0237           .localDistXZ{},
0238           .localDistYZ{},
0239           .globalDistRPhi{},
0240           .globalDistEtaPhi{},
0241           .dimScaledLocalDistXY{},
0242           .splitCluster                  = false,
0243           .minClusterHitEdep             = 1 * dd4hep::MeV,
0244           .minClusterCenterEdep          = 100.0 * dd4hep::MeV,
0245           .transverseEnergyProfileMetric = "globalDistEtaPhi",
0246           .transverseEnergyProfileScale  = 1.,
0247           .transverseEnergyProfileScaleUnits{},
0248       },
0249       app // TODO: Remove me once fixed
0250       ));
0251 
0252   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0253       "LFHCALTruthClustersWithoutShapes",
0254       {
0255           "LFHCALTruthProtoClusters", // edm4eic::ProtoClusterCollection
0256           "LFHCALRawHitAssociations"  // edm4eic::MCRecoCalorimeterHitAssociationCollection
0257       },
0258       {"LFHCALTruthClustersWithoutShapes",             // edm4eic::Cluster
0259        "LFHCALTruthClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0260       {.energyWeight = "log", .sampFrac = 1.0, .logWeightBase = 4.5, .enableEtaBounds = false},
0261       app // TODO: Remove me once fixed
0262       ));
0263 
0264   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0265       "LFHCALTruthClusters",
0266       {"LFHCALTruthClustersWithoutShapes", "LFHCALTruthClusterAssociationsWithoutShapes"},
0267       {"LFHCALTruthClusters", "LFHCALTruthClusterAssociations"},
0268       {.longitudinalShowerInfoAvailable = true, .energyWeight = "log", .logWeightBase = 4.5}, app));
0269 
0270   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0271       "LFHCALClustersWithoutShapes",
0272       {
0273           "LFHCALIslandProtoClusters", // edm4eic::ProtoClusterCollection
0274           "LFHCALRawHitAssociations"   // edm4eic::MCRecoCalorimeterHitAssociationCollection
0275       },
0276       {"LFHCALClustersWithoutShapes",             // edm4eic::Cluster
0277        "LFHCALClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0278       {
0279           .energyWeight    = "log",
0280           .sampFrac        = 1.0,
0281           .logWeightBase   = 4.5,
0282           .enableEtaBounds = false,
0283       },
0284       app // TODO: Remove me once fixed
0285       ));
0286 
0287   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0288       "LFHCALClusters", {"LFHCALClustersWithoutShapes", "LFHCALClusterAssociationsWithoutShapes"},
0289       {"LFHCALClusters", "LFHCALClusterAssociations"},
0290       {.longitudinalShowerInfoAvailable = true, .energyWeight = "log", .logWeightBase = 4.5}, app));
0291 
0292   app->Add(new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
0293       "LFHCALSplitMergeProtoClusters", {"LFHCALIslandProtoClusters", "CalorimeterTrackProjections"},
0294       {"LFHCALSplitMergeProtoClusters"},
0295       {.idCalo                       = "LFHCAL_ID",
0296        .minSigCut                    = -2.0,
0297        .avgEP                        = 0.50,
0298        .sigEP                        = 0.25,
0299        .drAdd                        = 0.30,
0300        .sampFrac                     = 1.0,
0301        .transverseEnergyProfileScale = 1.0},
0302       app // TODO: remove me once fixed
0303       ));
0304 
0305   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0306       "LFHCALSplitMergeClustersWithoutShapes",
0307       {
0308           "LFHCALSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
0309           "LFHCALRawHitAssociations"       // edm4hep::MCRecoCalorimeterHitAssociationCollection
0310       },
0311       {"LFHCALSplitMergeClustersWithoutShapes",             // edm4eic::Cluster
0312        "LFHCALSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0313       {.energyWeight = "log", .sampFrac = 1.0, .logWeightBase = 4.5, .enableEtaBounds = false},
0314       app // TODO: Remove me once fixed
0315       ));
0316 
0317   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0318       "LFHCALSplitMergeClusters",
0319       {"LFHCALSplitMergeClustersWithoutShapes", "LFHCALSplitMergeClusterAssociationsWithoutShapes"},
0320       {"LFHCALSplitMergeClusters", "LFHCALSplitMergeClusterAssociations"},
0321       {.longitudinalShowerInfoAvailable = true}, app));
0322 }
0323 }