Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-04 07:52:38

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 <edm4eic/EDM4eicVersion.h>
0011 #include <JANA/JApplicationFwd.h>
0012 #include <JANA/Utils/JTypeInfo.h>
0013 #include <TMath.h>
0014 #include <edm4eic/unit_system.h>
0015 #include <edm4hep/SimTrackerHit.h>
0016 #include <cmath>
0017 #include <map>
0018 #include <memory>
0019 #include <string>
0020 #include <vector>
0021 
0022 #include "algorithms/digi/SiliconChargeSharingConfig.h"
0023 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0024 #include "factories/digi/CFDROCDigitization_factory.h"
0025 #include "factories/digi/PulseCombiner_factory.h"
0026 #include "factories/digi/PulseGeneration_factory.h"
0027 #include "factories/digi/SiliconChargeSharing_factory.h"
0028 #include "factories/digi/SiliconPulseDiscretization_factory.h"
0029 #include "factories/digi/SiliconTrackerDigi_factory.h"
0030 #include "factories/reco/LGADHitCalibration_factory.h"
0031 #include "factories/tracking/LGADHitClustering_factory.h"
0032 #include "factories/tracking/TrackerHitReconstruction_factory.h"
0033 
0034 extern "C" {
0035 void InitPlugin(JApplication* app) {
0036   InitJANAPlugin(app);
0037 
0038   using namespace eicrecon;
0039 
0040   // Convert raw digitized hits into calibrated hits
0041   // time walk correction is still TBD
0042   app->Add(new JOmniFactoryGeneratorT<LGADHitCalibration_factory>(
0043       "TOFBarrelCalibratedHits", {"TOFBarrelADCTDC"}, // Input data collection tags
0044       {"TOFBarrelCalibratedHits"},                    // Output data tag
0045       {},
0046       app)); // Hit reco default config for factories
0047 
0048   // cluster all hits in a sensor into one hit location
0049   // Currently it's just a simple weighted average
0050   // More sophisticated algorithm TBD
0051   app->Add(new JOmniFactoryGeneratorT<LGADHitClustering_factory>(
0052       "TOFBarrelClusterHits", {"TOFBarrelSharedRecHits"}, // Input data collection tags
0053       {"TOFBarrelClusterHits"},                           // Output data tag
0054       {
0055           .readout = "TOFBarrelHits",
0056           .useAve  = true,
0057       },
0058       app));
0059 
0060   app->Add(new JOmniFactoryGeneratorT<SiliconChargeSharing_factory>(
0061       "TOFBarrelSharedHits", {"TOFBarrelHits"}, {"TOFBarrelSharedHits"},
0062       {
0063           .sigma_mode     = SiliconChargeSharingConfig::ESigmaMode::rel,
0064           .sigma_sharingx = 0.5,
0065           .sigma_sharingy = 0.5,
0066           .min_edep       = 6.0 * edm4eic::unit::keV,
0067           .readout        = "TOFBarrelHits",
0068       },
0069       app));
0070 
0071   // temporary steps to bypass pulse digitization and jump right from ChargeSharing to clusters
0072   // Avoid efficiency loss until we can simulate hardware accurately
0073   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0074       "TOFBarrelSharedRawHits", {"EventHeader", "TOFBarrelSharedHits"},
0075       {"TOFBarrelSharedRawHits",
0076 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0077        "TOFBarrelSharedRawHitLinks",
0078 #endif
0079        "TOFBarrelSharedRawHitAssociations"},
0080       {
0081           .threshold      = 0.0,
0082           .timeResolution = 0.025, // [ns]
0083       },
0084       app));
0085 
0086   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0087   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0088       "TOFBarrelSharedRecHits", {"TOFBarrelSharedRawHits"}, // Input data collection tags
0089       {"TOFBarrelSharedRecHits"},                           // Output data tag
0090       {},
0091       app)); // Hit reco default config for factories
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"