Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /EICrecon/src/detectors/FHCAL/FHCAL.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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