Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:48:18

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   // Digitization
0041   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0042       "TOFBarrelRawHits", {"EventHeader", "TOFBarrelHits"},
0043       {"TOFBarrelRawHits",
0044 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0045        "TOFBarrelRawHitLinks",
0046 #endif
0047        "TOFBarrelRawHitAssociations"},
0048       {
0049           .threshold      = 6.0 * dd4hep::keV,
0050           .timeResolution = 0.025, // [ns]
0051       },
0052       app));
0053 
0054   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0055   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0056       "TOFBarrelRecHits", {"TOFBarrelRawHits"}, // Input data collection tags
0057       {"TOFBarrelRecHits"},                     // Output data tag
0058       {},
0059       app)); // Hit reco default config for factories
0060 
0061   // Convert raw digitized hits into calibrated hits
0062   // time walk correction is still TBD
0063   app->Add(new JOmniFactoryGeneratorT<LGADHitCalibration_factory>(
0064       "TOFBarrelCalibratedHits", {"TOFBarrelADCTDC"}, // Input data collection tags
0065       {"TOFBarrelCalibratedHits"},                    // Output data tag
0066       {},
0067       app)); // Hit reco default config for factories
0068 
0069   // cluster all hits in a sensor into one hit location
0070   // Currently it's just a simple weighted average
0071   // More sophisticated algorithm TBD
0072   app->Add(new JOmniFactoryGeneratorT<LGADHitClustering_factory>(
0073       "TOFBarrelClusterHits", {"TOFBarrelCalibratedHits"}, // Input data collection tags
0074       {"TOFBarrelClusterHits"},                            // Output data tag
0075       {}, app));
0076 
0077   app->Add(new JOmniFactoryGeneratorT<SiliconChargeSharing_factory>(
0078       "TOFBarrelSharedHits", {"TOFBarrelHits"}, {"TOFBarrelSharedHits"},
0079       {
0080           .sigma_mode     = SiliconChargeSharingConfig::ESigmaMode::rel,
0081           .sigma_sharingx = 1,
0082           .sigma_sharingy = 0.5,
0083           .min_edep       = 0.0 * edm4eic::unit::GeV,
0084           .readout        = "TOFBarrelHits",
0085       },
0086       app));
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"