Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-30 07:30:29

0001 // Copyright 2022, Dmitry Romanov
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 //
0005 
0006 #include <DD4hep/Detector.h>
0007 #include <edm4eic/EDM4eicVersion.h>
0008 #include <Evaluator/DD4hepUnits.h>
0009 #include <JANA/JApplication.h>
0010 #include <JANA/JApplicationFwd.h>
0011 #include <JANA/JException.h>
0012 #include <JANA/Utils/JTypeInfo.h>
0013 #include <fmt/format.h>
0014 #include <spdlog/logger.h>
0015 #include <gsl/pointers>
0016 #include <memory>
0017 #include <stdexcept>
0018 #include <string>
0019 #include <vector>
0020 
0021 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0022 #include "factories/digi/MPGDTrackerDigi_factory.h"
0023 #include "factories/digi/SiliconTrackerDigi_factory.h"
0024 #include "factories/tracking/TrackerHitReconstruction_factory.h"
0025 #include "services/geometry/dd4hep/DD4hep_service.h"
0026 #include "services/log/Log_service.h"
0027 
0028 // 2D-STRIP DIGITIZATION
0029 // - Is produced by "MPGDTrackerDigi".
0030 // - Relies on 2DStrip version of "compact" geometry file.
0031 // PIXEL DIGITIZATION
0032 // - Is produced by "SiliconTrackerDigi".
0033 
0034 extern "C" {
0035 void InitPlugin(JApplication* app) {
0036   InitJANAPlugin(app);
0037 
0038   using namespace eicrecon;
0039 
0040   // ***** PIXEL or 2DSTRIP DIGITIZATION?
0041   // - This determines which of the MPGDTrackerDigi or SiliconTrackerDigi
0042   //  factory is used.
0043   // - It's encoded in XML constants "<detector>_2DStrip", which can be
0044   //  conveniently set in the XMLs of the MPGDs.
0045   // - It can be reset from command line via the "MPGD:SiFactoryPattern" option,
0046   //  which is a bit pattern: 0x1=CyMBaL, 0x2=OuterBarrel, ...
0047   // - It defaults (when neither XML constant nor command line option) to
0048   //  SiliconTrackerDigi.
0049   // Default
0050   unsigned int SiFactoryPattern = 0x3; // Full-scale SiliconTrackerDigi
0051   // XML constant
0052   auto log_service               = app->GetService<Log_service>();
0053   auto mLog                      = log_service->logger("tracking");
0054   const int nMPGDs               = 2;
0055   const char* MPGD_names[nMPGDs] = {"InnerMPGDBarrel", "MPGDOuterBarrel"};
0056   for (int mpgd = 0; mpgd < nMPGDs; mpgd++) {
0057     std::string MPGD_name(MPGD_names[mpgd]);
0058     std::string constant_name = MPGD_name + std::string("_2DStrip");
0059     try {
0060       auto detector = app->GetService<DD4hep_service>()->detector();
0061       int constant  = detector->constant<int>(constant_name);
0062       if (constant == 1) {
0063         SiFactoryPattern &= ~(0x1 << mpgd);
0064         mLog->info(R"(2DStrip XML loaded for "{}")", MPGD_name);
0065       } else {
0066         mLog->info(R"(pixel XML loaded for "{}")", MPGD_name);
0067       }
0068     } catch (const std::runtime_error&) {
0069       // Variable not present apply legacy pixel readout
0070     }
0071   }
0072   // Command line option
0073   std::string SiFactoryPattern_str;
0074   app->SetDefaultParameter("MPGD:SiFactoryPattern", SiFactoryPattern_str,
0075                            "Hexadecimal Pattern of MPGDs digitized via \"SiliconTrackerDigi\"");
0076   if (!SiFactoryPattern_str.empty()) {
0077     try {
0078       SiFactoryPattern = std::stoul(SiFactoryPattern_str, nullptr, 16);
0079     } catch (const std::invalid_argument& e) {
0080       throw JException(
0081           R"(Option "MPGD:SiFactoryPattern": Error ("%s") parsing input
0082         string: '%s'.)",
0083           e.what(), SiFactoryPattern_str.c_str());
0084     }
0085   }
0086   for (int mpgd = 0; mpgd < nMPGDs; mpgd++) {
0087     std::string MPGD_name(MPGD_names[mpgd]);
0088     if (SiFactoryPattern & (0x1 << mpgd)) {
0089       mLog->info(R"(pixel digitization will be applied to "{}")", MPGD_name);
0090     } else {
0091       mLog->info(R"(2DStrip digitization will be applied to "{}")", MPGD_name);
0092     }
0093   }
0094 
0095   // ***** "MPGDBarrel" (=CyMBaL)
0096   // Digitization
0097   if ((SiFactoryPattern & 0x1) != 0U) {
0098     app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0099         "MPGDBarrelRawHits", {"EventHeader", "MPGDBarrelHits"},
0100         {"MPGDBarrelRawHits",
0101 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0102          "MPGDBarrelRawHitLinks",
0103 #endif
0104          "MPGDBarrelRawHitAssociations"},
0105         {
0106             .threshold      = 100 * dd4hep::eV,
0107             .timeResolution = 10,
0108         },
0109         app));
0110   } else {
0111     app->Add(new JOmniFactoryGeneratorT<MPGDTrackerDigi_factory>("MPGDBarrelRawHits",
0112                                                                  {"EventHeader", "MPGDBarrelHits"},
0113                                                                  {"MPGDBarrelRawHits",
0114 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0115                                                                   "MPGDBarrelRawHitLinks",
0116 #endif
0117                                                                   "MPGDBarrelRawHitAssociations"},
0118                                                                  {
0119                                                                      .readout   = "MPGDBarrelHits",
0120                                                                      .threshold = 100 * dd4hep::eV,
0121                                                                      .timeResolution = 10,
0122                                                                  },
0123                                                                  app));
0124   }
0125 
0126   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0127   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0128       "MPGDBarrelRecHits", {"MPGDBarrelRawHits"}, // Input data collection tags
0129       {"MPGDBarrelRecHits"},                      // Output data tag
0130       {
0131           .timeResolution = 10,
0132       },
0133       app));
0134 
0135   // ***** OuterMPGDBarrel
0136   // Digitization
0137   if ((SiFactoryPattern & 0x2) != 0U) {
0138     app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0139         "OuterMPGDBarrelRawHits", {"EventHeader", "OuterMPGDBarrelHits"},
0140         {"OuterMPGDBarrelRawHits",
0141 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0142          "OuterMPGDBarrelRawHitLinks",
0143 #endif
0144          "OuterMPGDBarrelRawHitAssociations"},
0145         {
0146             .threshold      = 100 * dd4hep::eV,
0147             .timeResolution = 10,
0148         },
0149         app));
0150   } else {
0151     app->Add(new JOmniFactoryGeneratorT<MPGDTrackerDigi_factory>(
0152         "OuterMPGDBarrelRawHits", {"EventHeader", "OuterMPGDBarrelHits"},
0153         {"OuterMPGDBarrelRawHits",
0154 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0155          "OuterMPGDBarrelRawHitLinks",
0156 #endif
0157          "OuterMPGDBarrelRawHitAssociations"},
0158         {
0159             .readout        = "OuterMPGDBarrelHits",
0160             .threshold      = 100 * dd4hep::eV,
0161             .timeResolution = 10,
0162         },
0163         app));
0164   }
0165 
0166   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0167   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0168       "OuterMPGDBarrelRecHits", {"OuterMPGDBarrelRawHits"}, // Input data collection tags
0169       {"OuterMPGDBarrelRecHits"},                           // Output data tag
0170       {
0171           .timeResolution = 10,
0172       },
0173       app));
0174 
0175   // ***** "BackwardMPGDEndcap"
0176   // Digitization
0177   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0178       "BackwardMPGDEndcapRawHits", {"EventHeader", "BackwardMPGDEndcapHits"},
0179       {"BackwardMPGDEndcapRawHits",
0180 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0181        "BackwardMPGDEndcapRawHitLinks",
0182 #endif
0183        "BackwardMPGDEndcapRawHitAssociations"},
0184       {
0185           .threshold      = 100 * dd4hep::eV,
0186           .timeResolution = 10,
0187       },
0188       app));
0189 
0190   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0191   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0192       "BackwardMPGDEndcapRecHits", {"BackwardMPGDEndcapRawHits"}, // Input data collection tags
0193       {"BackwardMPGDEndcapRecHits"},                              // Output data tag
0194       {
0195           .timeResolution = 10,
0196       },
0197       app));
0198 
0199   // ""ForwardMPGDEndcap"
0200   // Digitization
0201   app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0202       "ForwardMPGDEndcapRawHits", {"EventHeader", "ForwardMPGDEndcapHits"},
0203       {"ForwardMPGDEndcapRawHits",
0204 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0205        "ForwardMPGDEndcapRawHitLinks",
0206 #endif
0207        "ForwardMPGDEndcapRawHitAssociations"},
0208       {
0209           .threshold      = 100 * dd4hep::eV,
0210           .timeResolution = 10,
0211       },
0212       app));
0213 
0214   // Convert raw digitized hits into hits with geometry info (ready for tracking)
0215   app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
0216       "ForwardMPGDEndcapRecHits", {"ForwardMPGDEndcapRawHits"}, // Input data collection tags
0217       {"ForwardMPGDEndcapRecHits"},                             // Output data tag
0218       {
0219           .timeResolution = 10,
0220       },
0221       app));
0222 }
0223 } // extern "C"