Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:28:06

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2025 Sylvester Joosten, Chao, Chao Peng, Whitney Armstrong, Thomas Britton, David Lawrence, Dhevan Gangadharan, Wouter Deconinck, Dmitry Kalinkin, Derek Anderson
0003 
0004 #include <Evaluator/DD4hepUnits.h>
0005 #include <JANA/JApplicationFwd.h>
0006 #include <JANA/Utils/JTypeInfo.h>
0007 #include <cmath>
0008 #include <string>
0009 #include <variant>
0010 #include <vector>
0011 
0012 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0013 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0014 #include "factories/calorimetry/CalorimeterClusterRecoCoG_factory.h"
0015 #include "factories/calorimetry/CalorimeterHitDigi_factory.h"
0016 #include "factories/calorimetry/CalorimeterHitReco_factory.h"
0017 #include "factories/calorimetry/CalorimeterIslandCluster_factory.h"
0018 #include "factories/calorimetry/CalorimeterParticleIDPostML_factory.h"
0019 #include "factories/calorimetry/CalorimeterParticleIDPreML_factory.h"
0020 #include "factories/calorimetry/CalorimeterClusterShape_factory.h"
0021 #include "factories/calorimetry/CalorimeterTruthClustering_factory.h"
0022 #include "factories/calorimetry/TrackClusterMergeSplitter_factory.h"
0023 #include "factories/meta/ONNXInference_factory.h"
0024 
0025 extern "C" {
0026 void InitPlugin(JApplication* app) {
0027 
0028   using namespace eicrecon;
0029 
0030   InitJANAPlugin(app);
0031 
0032   // Make sure digi and reco use the same value
0033   decltype(CalorimeterHitDigiConfig::capADC) EcalEndcapN_capADC         = 16384; //65536,  16bit ADC
0034   decltype(CalorimeterHitDigiConfig::dyRangeADC) EcalEndcapN_dyRangeADC = 20.0 * dd4hep::GeV;
0035   decltype(CalorimeterHitDigiConfig::pedMeanADC) EcalEndcapN_pedMeanADC = 20;
0036   decltype(CalorimeterHitDigiConfig::pedSigmaADC) EcalEndcapN_pedSigmaADC = 1;
0037   decltype(CalorimeterHitDigiConfig::resolutionTDC) EcalEndcapN_resolutionTDC =
0038       10 * dd4hep::picosecond;
0039   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitDigi_factory>(
0040       "EcalEndcapNRawHits", {"EventHeader", "EcalEndcapNHits"},
0041       {"EcalEndcapNRawHits", "EcalEndcapNRawHitAssociations"},
0042       {
0043           .eRes        = {0.0 * sqrt(dd4hep::GeV), 0.0, 0.0 * dd4hep::GeV},
0044           .tRes        = 0.0 * dd4hep::ns,
0045           .threshold   = 0.0 * dd4hep::MeV, // Use ADC cut instead
0046           .readoutType = "sipm",
0047           // 18. pe/MeV is measured with PMT at 25% QE
0048           .lightYield = 18. / 0.25 / dd4hep::MeV,
0049           // Based on slide 6 of https://indico.bnl.gov/event/29076/contributions/110749/attachments/63706/109457/Calo_meeting_Jun25_Updated.pdf
0050           // Geometric factor for 16 of 3x3 mm^2 sensors covering 20x20 mm^2 area for sensor with 28% QE
0051           .photonDetectionEfficiency = (16 * (3. * 3.) / (20. * 20.)) * 0.28,
0052           // S14160-3015PS, 16 sensors per cell
0053           .numEffectiveSipmPixels = 39984ULL * 16,
0054           .capADC                 = EcalEndcapN_capADC,
0055           .dyRangeADC             = EcalEndcapN_dyRangeADC,
0056           .pedMeanADC             = EcalEndcapN_pedMeanADC,
0057           .pedSigmaADC            = EcalEndcapN_pedSigmaADC,
0058           .resolutionTDC          = EcalEndcapN_resolutionTDC,
0059           .corrMeanScale          = "1.0",
0060           .readout                = "EcalEndcapNHits",
0061       },
0062       app // TODO: Remove me once fixed
0063       ));
0064   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitReco_factory>(
0065       "EcalEndcapNRecHits", {"EcalEndcapNRawHits"}, {"EcalEndcapNRecHits"},
0066       {
0067           .capADC          = EcalEndcapN_capADC,
0068           .dyRangeADC      = EcalEndcapN_dyRangeADC,
0069           .pedMeanADC      = EcalEndcapN_pedMeanADC,
0070           .pedSigmaADC     = EcalEndcapN_pedSigmaADC,
0071           .resolutionTDC   = EcalEndcapN_resolutionTDC,
0072           .thresholdFactor = 0.0,
0073           .thresholdValue  = 4.0, // (20. GeV / 16384) * 4 ~= 5 MeV
0074           .sampFrac        = "0.96",
0075           .readout         = "EcalEndcapNHits",
0076       },
0077       app // TODO: Remove me once fixed
0078       ));
0079   app->Add(new JOmniFactoryGeneratorT<CalorimeterTruthClustering_factory>(
0080       "EcalEndcapNTruthProtoClusters", {"EcalEndcapNRecHits", "EcalEndcapNHits"},
0081       {"EcalEndcapNTruthProtoClusters"},
0082       app // TODO: Remove me once fixed
0083       ));
0084   app->Add(new JOmniFactoryGeneratorT<CalorimeterIslandCluster_factory>(
0085       "EcalEndcapNIslandProtoClusters", {"EcalEndcapNRecHits"}, {"EcalEndcapNIslandProtoClusters"},
0086       {
0087           .adjacencyMatrix         = "(abs(row_1 - row_2) + abs(column_1 - column_2)) == 1",
0088           .peakNeighbourhoodMatrix = "max(abs(row_1 - row_2), abs(column_1 - column_2)) == 1",
0089           .readout                 = "EcalEndcapNHits",
0090           .sectorDist              = 5.0 * dd4hep::cm,
0091           .localDistXY{},
0092           .localDistXZ{},
0093           .localDistYZ{},
0094           .globalDistRPhi{},
0095           .globalDistEtaPhi{},
0096           .dimScaledLocalDistXY{},
0097           .splitCluster                  = true,
0098           .minClusterHitEdep             = 1.0 * dd4hep::MeV,
0099           .minClusterCenterEdep          = 30.0 * dd4hep::MeV,
0100           .transverseEnergyProfileMetric = "globalDistEtaPhi",
0101           .transverseEnergyProfileScale  = 0.08,
0102           .transverseEnergyProfileScaleUnits{},
0103       },
0104       app // TODO: Remove me once fixed
0105       ));
0106 
0107   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0108       "EcalEndcapNTruthClustersWithoutShapes",
0109       {
0110           "EcalEndcapNTruthProtoClusters", // edm4eic::ProtoClusterCollection
0111           "EcalEndcapNRawHitAssociations"  // edm4eic::MCRecoCalorimeterHitAssociationCollection
0112       },
0113       {"EcalEndcapNTruthClustersWithoutShapes",             // edm4eic::Cluster
0114        "EcalEndcapNTruthClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0115       {.energyWeight = "log", .sampFrac = 1.0, .logWeightBase = 4.6, .enableEtaBounds = false},
0116       app // TODO: Remove me once fixed
0117       ));
0118 
0119   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0120       "EcalEndcapNTruthClusters",
0121       {"EcalEndcapNTruthClustersWithoutShapes", "EcalEndcapNTruthClusterAssociationsWithoutShapes"},
0122       {"EcalEndcapNTruthClusters", "EcalEndcapNTruthClusterAssociations"},
0123       {.energyWeight = "log", .logWeightBase = 4.6}, app));
0124 
0125   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0126       "EcalEndcapNClustersWithoutPIDAndShapes",
0127       {
0128           "EcalEndcapNIslandProtoClusters", // edm4eic::ProtoClusterCollection
0129           "EcalEndcapNRawHitAssociations"   // edm4eic::MCRecoCalorimeterHitAssociationCollection
0130       },
0131       {"EcalEndcapNClustersWithoutPIDAndShapes",             // edm4eic::Cluster
0132        "EcalEndcapNClusterAssociationsWithoutPIDAndShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0133       {
0134           .energyWeight    = "log",
0135           .sampFrac        = 1.0,
0136           .logWeightBase   = 3.6,
0137           .enableEtaBounds = false,
0138       },
0139       app // TODO: Remove me once fixed
0140       ));
0141 
0142   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0143       "EcalEndcapNClustersWithoutPID",
0144       {"EcalEndcapNClustersWithoutPIDAndShapes",
0145        "EcalEndcapNClusterAssociationsWithoutPIDAndShapes"},
0146       {"EcalEndcapNClustersWithoutPID", "EcalEndcapNClusterAssociationsWithoutPID"},
0147       {.energyWeight = "log", .logWeightBase = 3.6}, app));
0148 
0149   app->Add(new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
0150       "EcalEndcapNSplitMergeProtoClusters",
0151       {"EcalEndcapNIslandProtoClusters", "CalorimeterTrackProjections"},
0152       {"EcalEndcapNSplitMergeProtoClusters"},
0153       {.idCalo                       = "EcalEndcapN_ID",
0154        .minSigCut                    = -1.0,
0155        .avgEP                        = 1.0,
0156        .sigEP                        = 0.10,
0157        .drAdd                        = 0.08,
0158        .sampFrac                     = 1.0,
0159        .transverseEnergyProfileScale = 1.0},
0160       app // TODO: remove me once fixed
0161       ));
0162 
0163   app->Add(new JOmniFactoryGeneratorT<CalorimeterParticleIDPreML_factory>(
0164       "EcalEndcapNParticleIDPreML",
0165       {
0166           "EcalEndcapNClustersWithoutPID",
0167           "EcalEndcapNClusterAssociationsWithoutPID",
0168       },
0169       {
0170           "EcalEndcapNParticleIDInput_features",
0171           "EcalEndcapNParticleIDTarget",
0172       },
0173       app));
0174   app->Add(new JOmniFactoryGeneratorT<ONNXInference_factory>(
0175       "EcalEndcapNParticleIDInference",
0176       {
0177           "EcalEndcapNParticleIDInput_features",
0178       },
0179       {
0180           "EcalEndcapNParticleIDOutput_label",
0181           "EcalEndcapNParticleIDOutput_probability_tensor",
0182       },
0183       {
0184           .modelPath = "calibrations/onnx/EcalEndcapN_pi_rejection.onnx",
0185       },
0186       app));
0187   app->Add(new JOmniFactoryGeneratorT<CalorimeterParticleIDPostML_factory>(
0188       "EcalEndcapNParticleIDPostML",
0189       {
0190           "EcalEndcapNClustersWithoutPID",
0191           "EcalEndcapNClusterAssociationsWithoutPID",
0192           "EcalEndcapNParticleIDOutput_probability_tensor",
0193       },
0194       {
0195           "EcalEndcapNClusters",
0196           "EcalEndcapNClusterAssociations",
0197           "EcalEndcapNClusterParticleIDs",
0198       },
0199       app));
0200 
0201   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0202       "EcalEndcapNSplitMergeClustersWithoutShapes",
0203       {
0204           "EcalEndcapNSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
0205           "EcalEndcapNRawHitAssociations" // edm4hep::MCRecoCalorimeterHitAssociationCollection
0206       },
0207       {"EcalEndcapNSplitMergeClustersWithoutShapes",             // edm4eic::Cluster
0208        "EcalEndcapNSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0209       {.energyWeight = "log", .sampFrac = 1.0, .logWeightBase = 3.6, .enableEtaBounds = false},
0210       app // TODO: Remove me once fixed
0211       ));
0212 
0213   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0214       "EcalEndcapNSplitMergeClusters",
0215       {"EcalEndcapNSplitMergeClustersWithoutShapes",
0216        "EcalEndcapNSplitMergeClusterAssociationsWithoutShapes"},
0217       {"EcalEndcapNSplitMergeClusters", "EcalEndcapNSplitMergeClusterAssociations"},
0218       {.energyWeight = "log", .logWeightBase = 3.6}, app));
0219 }
0220 }