Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-03 08:28:49

0001 // Copyright 2022, Dmitry Romanov
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 
0005 // SPDX-License-Identifier: LGPL-3.0-or-later
0006 // Copyright (C) 2024, Dmitry Kalinkin
0007 
0008 #include <Evaluator/DD4hepUnits.h>
0009 #include <JANA/JApplication.h>
0010 #include <JANA/JApplicationFwd.h>
0011 #include <JANA/Utils/JTypeInfo.h>
0012 #include <TMath.h>
0013 #include <edm4eic/unit_system.h>
0014 #include <edm4hep/SimTrackerHit.h>
0015 #include <cmath>
0016 #include <map>
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020 
0021 #include "algorithms/digi/SiliconChargeSharingConfig.h"
0022 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0023 #include "factories/digi/CFDROCDigitization_factory.h"
0024 #include "factories/digi/PulseCombiner_factory.h"
0025 #include "factories/digi/PulseGeneration_factory.h"
0026 #include "factories/digi/SiliconChargeSharing_factory.h"
0027 #include "factories/digi/SiliconPulseDiscretization_factory.h"
0028 #include "factories/digi/SiliconTrackerDigi_factory.h"
0029 #include "factories/reco/LGADHitCalibration_factory.h"
0030 #include "factories/tracking/LGADHitClustering_factory.h"
0031 #include "factories/tracking/TrackerHitReconstruction_factory.h"
0032 
0033 extern "C" {
0034 void InitPlugin(JApplication* app) {
0035   InitJANAPlugin(app);
0036 
0037   using namespace eicrecon;
0038 
0039   // Convert raw digitized hits into calibrated hits
0040   // time walk correction is still TBD
0041   app->Add(new JOmniFactoryGeneratorT<LGADHitCalibration_factory>(
0042       "TOFBarrelCalibratedHits", {"TOFBarrelADCTDC"}, // Input data collection tags
0043       {"TOFBarrelCalibratedHits"},                    // Output data tag
0044       {},
0045       app)); // Hit reco default config for factories
0046 
0047   // cluster all hits in a sensor into one hit location
0048   // Currently it's just a simple weighted average
0049   // More sophisticated algorithm TBD
0050   app->Add(new JOmniFactoryGeneratorT<LGADHitClustering_factory>(
0051       "TOFBarrelClusterHits", {"TOFBarrelSharedRecHits"}, // Input data collection tags
0052       {"TOFBarrelClusterHits"},                           // Output data tag
0053       {
0054           .readout = "TOFBarrelHits",
0055           .useAve  = true,
0056       },
0057       app));
0058 
0059   app->Add(new JOmniFactoryGeneratorT<SiliconChargeSharing_factory>(
0060       "TOFBarrelSharedHits", {"TOFBarrelHits"}, {"TOFBarrelSharedHits"},
0061       {
0062           .sigma_mode     = SiliconChargeSharingConfig::ESigmaMode::rel,
0063           .sigma_sharingx = 0.5,
0064           .sigma_sharingy = 0.5,
0065           .min_edep       = 6.0 * edm4eic::unit::keV,
0066           .readout        = "TOFBarrelHits",
0067       },
0068       app));
0069 
0070   // temporary steps to bypass pulse digitization and jump right from ChargeSharing to clusters
0071   // Avoid efficiency loss until we can simulate hardware accurately
0072   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0073       "TOFBarrelSharedRawHits", {"EventHeader", "TOFBarrelSharedHits"},
0074       {"TOFBarrelSharedRawHits", "TOFBarrelSharedRawHitLinks", "TOFBarrelSharedRawHitAssociations"},
0075       {
0076           .threshold      = 0.0,
0077           .timeResolution = 0.025, // [ns]
0078       },
0079       app));
0080 
0081   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0082   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0083       "TOFBarrelSharedRecHits", {"TOFBarrelSharedRawHits"}, // Input data collection tags
0084       {"TOFBarrelSharedRecHits"},                           // Output data tag
0085       {},
0086       app)); // Hit reco default config for factories
0087 
0088   // calculation of the extreme values for Landau distribution can be found on lin 514-520 of
0089   // https://root.cern.ch/root/html524/src/TMath.cxx.html#fsokrB Landau reaches minimum for mpv =
0090   // 0 and sigma = 1 at x = -0.22278
0091   const double x_when_landau_min = -0.22278;
0092   const double landau_min        = TMath::Landau(x_when_landau_min, 0, 1, true);
0093   const double sigma_analog      = 0.293951 * edm4eic::unit::ns;
0094   const double Vm                = 3e-4 * dd4hep::GeV;
0095   const double adc_range         = 256;
0096   // gain is set such that pulse reaches a height of adc_range when EDep = Vm
0097   // gain is negative as LGAD voltage is always negative
0098   const double gain = -adc_range / Vm / landau_min * sigma_analog;
0099   const int offset  = 3;
0100   app->Add(new JOmniFactoryGeneratorT<PulseGeneration_factory<edm4hep::SimTrackerHit>>(
0101       "LGADPulseGeneration", {"TOFBarrelSharedHits"}, {"TOFBarrelSmoothPulses"},
0102       {
0103           .pulse_shape_function = "LandauPulse",
0104           .pulse_shape_params   = {gain, sigma_analog, offset},
0105           .ignore_thres         = 0.05 * adc_range,
0106           .timestep             = 0.01 * edm4eic::unit::ns,
0107       },
0108       app));
0109 
0110   app->Add(new JOmniFactoryGeneratorT<PulseCombiner_factory>(
0111       "TOFBarrelPulseCombiner", {"TOFBarrelSmoothPulses"}, {"TOFBarrelCombinedPulses"},
0112       {
0113           .minimum_separation = 25 * edm4eic::unit::ns,
0114       },
0115       app));
0116 
0117   double risetime = 0.45 * edm4eic::unit::ns;
0118   app->Add(new JOmniFactoryGeneratorT<SiliconPulseDiscretization_factory>(
0119       "TOFBarrelPulses", {"TOFBarrelCombinedPulses"}, {"TOFBarrelPulses"},
0120       {
0121           .EICROC_period = 25 * edm4eic::unit::ns,
0122           .local_period  = 25 * edm4eic::unit::ns / 1024,
0123           .global_offset = -offset * sigma_analog + risetime,
0124       },
0125       app));
0126 
0127   app->Add(new JOmniFactoryGeneratorT<CFDROCDigitization_factory>(
0128       "CFDROCDigitization", {"TOFBarrelPulses"}, {"TOFBarrelADCTDC"}, {}, app));
0129 }
0130 } // extern "C"