Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-18 08:15:09

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2025 Whitney Armstrong, Sylvester Joosten, Chao Peng, David Lawrence, Thomas Britton, Wouter Deconinck, Maria Zurek, Akshaya Vijay, Nathan Brei, Dmitry Kalinkin, Derek Anderson, Minho Kim
0003 
0004 #include <Evaluator/DD4hepUnits.h>
0005 #include <JANA/JApplicationFwd.h>
0006 #include <edm4eic/unit_system.h>
0007 #include <cmath>
0008 #include <string>
0009 #include <variant>
0010 
0011 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0012 #include "algorithms/calorimetry/SimCalorimeterHitProcessorConfig.h"
0013 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0014 #include "factories/calorimetry/CalorimeterClusterRecoCoG_factory.h"
0015 #include "factories/calorimetry/CalorimeterClusterShape_factory.h"
0016 #include "factories/calorimetry/CalorimeterHitDigi_factory.h"
0017 #include "factories/calorimetry/CalorimeterHitReco_factory.h"
0018 #include "factories/calorimetry/CalorimeterIslandCluster_factory.h"
0019 #include "factories/calorimetry/EnergyPositionClusterMerger_factory.h"
0020 #include "factories/calorimetry/ImagingClusterReco_factory.h"
0021 #include "factories/calorimetry/ImagingTopoCluster_factory.h"
0022 #include "factories/calorimetry/SimCalorimeterHitProcessor_factory.h"
0023 #include "factories/calorimetry/TruthEnergyPositionClusterMerger_factory.h"
0024 
0025 extern "C" {
0026 void InitPlugin(JApplication* app) {
0027 
0028   using namespace eicrecon;
0029 
0030   InitJANAPlugin(app);
0031 
0032   // Make sure left and right use the same value
0033   decltype(SimCalorimeterHitProcessorConfig::attenuationParameters) EcalBarrelScFi_attPars = {
0034       0.416212, 747.39875 * edm4eic::unit::mm, 7521.88383 * edm4eic::unit::mm};
0035   decltype(SimCalorimeterHitProcessorConfig::hitMergeFields) EcalBarrelScFi_hitMergeFields = {
0036       "fiber", "z"};
0037   decltype(SimCalorimeterHitProcessorConfig::contributionMergeFields)
0038       EcalBarrelScFi_contributionMergeFields = {"fiber"};
0039   decltype(SimCalorimeterHitProcessorConfig::inversePropagationSpeed)
0040       EcalBarrelScFi_inversePropagationSpeed = {(1. / 160) * edm4eic::unit::ns / edm4eic::unit::mm};
0041   decltype(SimCalorimeterHitProcessorConfig::fixedTimeDelay) EcalBarrelScFi_fixedTimeDelay = {
0042       2 * edm4eic::unit::ns};
0043 
0044   // Make sure digi and reco use the same value
0045   decltype(CalorimeterHitDigiConfig::capADC) EcalBarrelScFi_capADC = 16384; //16384,  14bit ADC
0046   decltype(CalorimeterHitDigiConfig::dyRangeADC) EcalBarrelScFi_dyRangeADC   = 1500 * dd4hep::MeV;
0047   decltype(CalorimeterHitDigiConfig::pedMeanADC) EcalBarrelScFi_pedMeanADC   = 100;
0048   decltype(CalorimeterHitDigiConfig::pedSigmaADC) EcalBarrelScFi_pedSigmaADC = 1;
0049   decltype(CalorimeterHitDigiConfig::resolutionTDC) EcalBarrelScFi_resolutionTDC =
0050       10 * dd4hep::picosecond;
0051   app->Add(new JOmniFactoryGeneratorT<SimCalorimeterHitProcessor_factory>(
0052       "EcalBarrelScFiPAttenuatedHits", {"EcalBarrelScFiHits"},
0053       {"EcalBarrelScFiPAttenuatedHits", "EcalBarrelScFiPAttenuatedHitContributions"},
0054       {
0055           .attenuationParameters            = EcalBarrelScFi_attPars,
0056           .readout                          = "EcalBarrelScFiHits",
0057           .attenuationReferencePositionName = "EcalBarrel_Readout_zmax",
0058           .hitMergeFields                   = EcalBarrelScFi_hitMergeFields,
0059           .contributionMergeFields          = EcalBarrelScFi_contributionMergeFields,
0060           .inversePropagationSpeed          = EcalBarrelScFi_inversePropagationSpeed,
0061           .fixedTimeDelay                   = EcalBarrelScFi_fixedTimeDelay,
0062       },
0063       app // TODO: Remove me once fixed
0064       ));
0065   app->Add(new JOmniFactoryGeneratorT<SimCalorimeterHitProcessor_factory>(
0066       "EcalBarrelScFiNAttenuatedHits", {"EcalBarrelScFiHits"},
0067       {"EcalBarrelScFiNAttenuatedHits", "EcalBarrelScFiNAttenuatedHitContributions"},
0068       {
0069           .attenuationParameters            = EcalBarrelScFi_attPars,
0070           .readout                          = "EcalBarrelScFiHits",
0071           .attenuationReferencePositionName = "EcalBarrel_Readout_zmin",
0072           .hitMergeFields                   = EcalBarrelScFi_hitMergeFields,
0073           .contributionMergeFields          = EcalBarrelScFi_contributionMergeFields,
0074           .inversePropagationSpeed          = EcalBarrelScFi_inversePropagationSpeed,
0075           .fixedTimeDelay                   = EcalBarrelScFi_fixedTimeDelay,
0076       },
0077       app // TODO: Remove me once fixed
0078       ));
0079   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitDigi_factory>(
0080       "EcalBarrelScFiRawHits", {"EcalBarrelScFiHits"},
0081       {"EcalBarrelScFiRawHits", "EcalBarrelScFiRawHitAssociations"},
0082       {
0083           .eRes          = {0.0 * sqrt(dd4hep::GeV), 0.0, 0.0 * dd4hep::GeV},
0084           .tRes          = 0.0 * dd4hep::ns,
0085           .threshold     = 0.0 * dd4hep::keV, // threshold is set in ADC in reco
0086           .capADC        = EcalBarrelScFi_capADC,
0087           .dyRangeADC    = EcalBarrelScFi_dyRangeADC,
0088           .pedMeanADC    = EcalBarrelScFi_pedMeanADC,
0089           .pedSigmaADC   = EcalBarrelScFi_pedSigmaADC,
0090           .resolutionTDC = EcalBarrelScFi_resolutionTDC,
0091           .corrMeanScale = "1.0",
0092           .readout       = "EcalBarrelScFiHits",
0093           .fields        = {"fiber", "z"},
0094       },
0095       app // TODO: Remove me once fixed
0096       ));
0097   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitReco_factory>(
0098       "EcalBarrelScFiRecHits", {"EcalBarrelScFiRawHits"}, {"EcalBarrelScFiRecHits"},
0099       {
0100           .capADC          = EcalBarrelScFi_capADC,
0101           .dyRangeADC      = EcalBarrelScFi_dyRangeADC,
0102           .pedMeanADC      = EcalBarrelScFi_pedMeanADC,
0103           .pedSigmaADC     = EcalBarrelScFi_pedSigmaADC, // not needed; use only thresholdValue
0104           .resolutionTDC   = EcalBarrelScFi_resolutionTDC,
0105           .thresholdFactor = 0.0, // use only thresholdValue
0106           .thresholdValue  = 5.0, // 16384 ADC counts/1500 MeV * 0.5 MeV (desired threshold) = 5.46
0107           .sampFrac        = "0.09285755",
0108           .readout         = "EcalBarrelScFiHits",
0109           .layerField      = "layer",
0110           .sectorField     = "sector",
0111           .localDetFields  = {"system"},
0112           // here we want to use grid center position (XY) but keeps the z information from fiber-segment
0113           // TODO: a more realistic way to get z is to reconstruct it from timing
0114           .maskPos       = "xy",
0115           .maskPosFields = {"fiber", "z"},
0116       },
0117       app // TODO: Remove me once fixed
0118       ));
0119   app->Add(new JOmniFactoryGeneratorT<CalorimeterIslandCluster_factory>(
0120       "EcalBarrelScFiProtoClusters", {"EcalBarrelScFiRecHits"}, {"EcalBarrelScFiProtoClusters"},
0121       {
0122           .adjacencyMatrix{},
0123           .peakNeighbourhoodMatrix{},
0124           .readout{},
0125           .sectorDist = 50. * dd4hep::mm,
0126           .localDistXY{},
0127           .localDistXZ = {80 * dd4hep::mm, 80 * dd4hep::mm},
0128           .localDistYZ{},
0129           .globalDistRPhi{},
0130           .globalDistEtaPhi{},
0131           .dimScaledLocalDistXY{},
0132           .splitCluster         = false,
0133           .minClusterHitEdep    = 5.0 * dd4hep::MeV,
0134           .minClusterCenterEdep = 100.0 * dd4hep::MeV,
0135           .transverseEnergyProfileMetric{},
0136           .transverseEnergyProfileScale{},
0137           .transverseEnergyProfileScaleUnits{},
0138       },
0139       app // TODO: Remove me once fixed
0140       ));
0141   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
0142       "EcalBarrelScFiClustersWithoutShapes",
0143       {"EcalBarrelScFiProtoClusters",         // edm4eic::ProtoClusterCollection
0144        "EcalBarrelScFiRawHitAssociations"},   // edm4eic::MCRecoCalorimeterHitAssociation
0145       {"EcalBarrelScFiClustersWithoutShapes", // edm4eic::Cluster
0146        "EcalBarrelScFiClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
0147       {.energyWeight = "log", .sampFrac = 1.0, .logWeightBase = 6.2, .enableEtaBounds = false},
0148       app // TODO: Remove me once fixed
0149       ));
0150   app->Add(new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
0151       "EcalBarrelScFiClusters",
0152       {"EcalBarrelScFiClustersWithoutShapes", "EcalBarrelScFiClusterAssociationsWithoutShapes"},
0153       {"EcalBarrelScFiClusters", "EcalBarrelScFiClusterAssociations"},
0154       {.longitudinalShowerInfoAvailable = true, .energyWeight = "log", .logWeightBase = 6.2}, app));
0155 
0156   // Make sure digi and reco use the same value
0157   decltype(CalorimeterHitDigiConfig::capADC) EcalBarrelImaging_capADC = 8192; //8192,  13bit ADC
0158   decltype(CalorimeterHitDigiConfig::dyRangeADC) EcalBarrelImaging_dyRangeADC = 3 * dd4hep::MeV;
0159   decltype(CalorimeterHitDigiConfig::pedMeanADC) EcalBarrelImaging_pedMeanADC =
0160       14; // Noise floor at 5 keV: 8192 / 3 * 0.005
0161   decltype(CalorimeterHitDigiConfig::pedSigmaADC) EcalBarrelImaging_pedSigmaADC =
0162       5; // Upper limit for sigma for AstroPix
0163   decltype(CalorimeterHitDigiConfig::resolutionTDC) EcalBarrelImaging_resolutionTDC =
0164       3.25 * dd4hep::nanosecond;
0165   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitDigi_factory>(
0166       "EcalBarrelImagingRawHits", {"EcalBarrelImagingHits"},
0167       {"EcalBarrelImagingRawHits", "EcalBarrelImagingRawHitAssociations"},
0168       {
0169           .eRes          = {0.0 * sqrt(dd4hep::GeV), 0.02, 0.0 * dd4hep::GeV},
0170           .tRes          = 0.0 * dd4hep::ns,
0171           .capADC        = EcalBarrelImaging_capADC,
0172           .dyRangeADC    = EcalBarrelImaging_dyRangeADC,
0173           .pedMeanADC    = EcalBarrelImaging_pedMeanADC,
0174           .pedSigmaADC   = EcalBarrelImaging_pedSigmaADC,
0175           .resolutionTDC = EcalBarrelImaging_resolutionTDC,
0176           .corrMeanScale = "1.0",
0177           .readout       = "EcalBarrelImagingHits",
0178       },
0179       app // TODO: Remove me once fixed
0180       ));
0181   app->Add(new JOmniFactoryGeneratorT<CalorimeterHitReco_factory>(
0182       "EcalBarrelImagingRecHits", {"EcalBarrelImagingRawHits"}, {"EcalBarrelImagingRecHits"},
0183       {
0184           .capADC          = EcalBarrelImaging_capADC,
0185           .dyRangeADC      = EcalBarrelImaging_dyRangeADC,
0186           .pedMeanADC      = EcalBarrelImaging_pedMeanADC,
0187           .pedSigmaADC     = EcalBarrelImaging_pedSigmaADC, // not needed; use only thresholdValue
0188           .resolutionTDC   = EcalBarrelImaging_resolutionTDC,
0189           .thresholdFactor = 0.0, // use only thresholdValue
0190           .thresholdValue  = 41,  // 8192 ADC counts/3 MeV * 0.015 MeV (desired threshold) = 41
0191           .sampFrac        = "0.00429453",
0192           .readout         = "EcalBarrelImagingHits",
0193           .layerField      = "layer",
0194           .sectorField     = "sector",
0195       },
0196       app // TODO: Remove me once fixed
0197       ));
0198   app->Add(new JOmniFactoryGeneratorT<ImagingTopoCluster_factory>(
0199       "EcalBarrelImagingProtoClusters", {"EcalBarrelImagingRecHits"},
0200       {"EcalBarrelImagingProtoClusters"},
0201       {
0202           .neighbourLayersRange = 2, //  # id diff for adjacent layer
0203           .localDistXY          = {2.0 * dd4hep::mm, 2 * dd4hep::mm},     //  # same layer
0204           .layerDistEtaPhi      = {10 * dd4hep::mrad, 10 * dd4hep::mrad}, //  # adjacent layer
0205           .sectorDist           = 3.0 * dd4hep::cm,
0206           .minClusterHitEdep    = 0,
0207           .minClusterCenterEdep = 0,
0208           .minClusterEdep       = 100 * dd4hep::MeV,
0209           .minClusterNhits      = 10,
0210       },
0211       app // TODO: Remove me once fixed
0212       ));
0213 
0214   app->Add(new JOmniFactoryGeneratorT<ImagingClusterReco_factory>(
0215       "EcalBarrelImagingClusters",
0216       {"EcalBarrelImagingProtoClusters", "EcalBarrelImagingRawHitAssociations"},
0217       {"EcalBarrelImagingClusters", "EcalBarrelImagingClusterAssociations",
0218        "EcalBarrelImagingLayers"},
0219       {
0220           .trackStopLayer = 6,
0221       },
0222       app // TODO: Remove me once fixed
0223       ));
0224   app->Add(new JOmniFactoryGeneratorT<EnergyPositionClusterMerger_factory>(
0225       "EcalBarrelClusters",
0226       {"EcalBarrelScFiClusters", "EcalBarrelScFiClusterAssociations", "EcalBarrelImagingClusters",
0227        "EcalBarrelImagingClusterAssociations"},
0228       {"EcalBarrelClusters", "EcalBarrelClusterAssociations"},
0229       {
0230           .energyRelTolerance = 0.5,
0231           .phiTolerance       = 0.1,
0232           .etaTolerance       = 0.2,
0233       },
0234       app // TODO: Remove me once fixed
0235       ));
0236   app->Add(new JOmniFactoryGeneratorT<TruthEnergyPositionClusterMerger_factory>(
0237       "EcalBarrelTruthClusters",
0238       {"MCParticles", "EcalBarrelScFiClusters", "EcalBarrelScFiClusterAssociations",
0239        "EcalBarrelImagingClusters", "EcalBarrelImagingClusterAssociations"},
0240       {"EcalBarrelTruthClusters", "EcalBarrelTruthClusterAssociations"},
0241       app // TODO: Remove me once fixed
0242       ));
0243 }
0244 }