Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-01 09:26:24

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   // Hit time resolution, shared by the digitization smearing and TrackerHit::timeError
0071   const double timeResolution = 25 * edm4eic::unit::ps;
0072 
0073   // temporary steps to bypass pulse digitization and jump right from ChargeSharing to clusters
0074   // Avoid efficiency loss until we can simulate hardware accurately
0075   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0076       "TOFBarrelSharedRawHits", {"EventHeader", "TOFBarrelSharedHits"},
0077       {"TOFBarrelSharedRawHits", "TOFBarrelSharedRawHitLinks", "TOFBarrelSharedRawHitAssociations"},
0078       {
0079           .threshold      = 0.0,
0080           .timeResolution = timeResolution,
0081       },
0082       app));
0083 
0084   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0085   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0086       "TOFBarrelSharedRecHits", {"TOFBarrelSharedRawHits"}, // Input data collection tags
0087       {"TOFBarrelSharedRecHits"},                           // Output data tag
0088       {
0089           .timeResolution = timeResolution,
0090       },
0091       app));
0092 
0093   // calculation of the extreme values for Landau distribution can be found on lin 514-520 of
0094   // https://root.cern.ch/root/html524/src/TMath.cxx.html#fsokrB Landau reaches minimum for mpv =
0095   // 0 and sigma = 1 at x = -0.22278
0096   const double x_when_landau_min = -0.22278;
0097   const double landau_min        = TMath::Landau(x_when_landau_min, 0, 1, true);
0098   const double sigma_analog      = 0.293951 * edm4eic::unit::ns;
0099   const double Vm                = 3e-4 * dd4hep::GeV;
0100   const double adc_range         = 256;
0101   // gain is set such that pulse reaches a height of adc_range when EDep = Vm
0102   // gain is negative as LGAD voltage is always negative
0103   const double gain = -adc_range / Vm / landau_min * sigma_analog;
0104   const int offset  = 3;
0105   app->Add(new JOmniFactoryGeneratorT<PulseGeneration_factory<edm4hep::SimTrackerHit>>(
0106       "LGADPulseGeneration", {"TOFBarrelSharedHits"}, {"TOFBarrelSmoothPulses"},
0107       {
0108           .pulse_shape_function = "LandauPulse",
0109           .pulse_shape_params   = {gain, sigma_analog, offset},
0110           .ignore_thres         = 0.05 * adc_range,
0111           .timestep             = 0.01 * edm4eic::unit::ns,
0112       },
0113       app));
0114 
0115   app->Add(new JOmniFactoryGeneratorT<PulseCombiner_factory>(
0116       "TOFBarrelPulseCombiner", {"TOFBarrelSmoothPulses"}, {"TOFBarrelCombinedPulses"},
0117       {
0118           .minimum_separation = 25 * edm4eic::unit::ns,
0119       },
0120       app));
0121 
0122   double risetime = 0.45 * edm4eic::unit::ns;
0123   app->Add(new JOmniFactoryGeneratorT<SiliconPulseDiscretization_factory>(
0124       "TOFBarrelPulses", {"TOFBarrelCombinedPulses"}, {"TOFBarrelPulses"},
0125       {
0126           .EICROC_period = 25 * edm4eic::unit::ns,
0127           .local_period  = 25 * edm4eic::unit::ns / 1024,
0128           .global_offset = -offset * sigma_analog + risetime,
0129       },
0130       app));
0131 
0132   app->Add(new JOmniFactoryGeneratorT<CFDROCDigitization_factory>(
0133       "CFDROCDigitization", {"TOFBarrelPulses"}, {"TOFBarrelADCTDC"}, {}, app));
0134 }
0135 } // extern "C"