Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:03:04

0001 // Copyright 2023-2024, Simon Gardner
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 //
0005 
0006 #include <Evaluator/DD4hepUnits.h>
0007 #include <JANA/JApplication.h>
0008 #include <edm4eic/RawTrackerHit.h>
0009 #include <edm4eic/TrackSegment.h>
0010 #include <edm4eic/unit_system.h>
0011 #include <fmt/core.h>
0012 #include <math.h>
0013 #include <map>
0014 #include <memory>
0015 #include <string>
0016 #include <vector>
0017 
0018 #include "algorithms/interfaces/WithPodConfig.h"
0019 #include "algorithms/meta/SubDivideFunctors.h"
0020 #include "extensions/jana/JOmniFactoryGeneratorT.h"
0021 #include "factories/digi/SiliconTrackerDigi_factory.h"
0022 #include "factories/fardetectors/FarDetectorLinearProjection_factory.h"
0023 #include "factories/fardetectors/FarDetectorLinearTracking_factory.h"
0024 #include "factories/fardetectors/FarDetectorMLReconstruction_factory.h"
0025 #include "factories/fardetectors/FarDetectorTrackerCluster_factory.h"
0026 #include "factories/meta/CollectionCollector_factory.h"
0027 #include "factories/meta/SubDivideCollection_factory.h"
0028 
0029 extern "C" {
0030   void InitPlugin(JApplication *app) {
0031     InitJANAPlugin(app);
0032 
0033     using namespace eicrecon;
0034 
0035     std::string tracker_readout = "TaggerTrackerHits";
0036 
0037     // Digitization of silicon hits
0038     app->Add(new JOmniFactoryGeneratorT<SiliconTrackerDigi_factory>(
0039          "TaggerTrackerRawHits",
0040          {
0041            "TaggerTrackerHits"
0042          },
0043          {
0044            "TaggerTrackerRawHits",
0045            "TaggerTrackerRawHitAssociations"
0046          },
0047          {
0048            .threshold = 1.5 * dd4hep::keV,
0049            .timeResolution = 2 * dd4hep::ns,
0050          },
0051          app
0052     ));
0053 
0054     // Divide collection based on geometry segmentation labels
0055     // This should really be done before digitization as summing hits in the same cell couldn't even be mixed between layers. At the moment just prep for clustering.
0056     std::string readout = "TaggerTrackerHits";
0057     std::vector<std::string> geometryLabels {"module","layer"};
0058     std::vector<int> moduleIDs{1,2};
0059     std::vector<int> layerIDs {0,1,2,3};
0060     std::vector<std::vector<long int>> geometryDivisions{};
0061     std::vector<std::string> geometryDivisionCollectionNames;
0062     std::vector<std::string> outputClusterCollectionNames;
0063     std::vector<std::string> outputTrackTags;
0064     std::vector<std::vector<std::string>> moduleClusterTags;
0065 
0066     for(int mod_id : moduleIDs){
0067       outputTrackTags.push_back(fmt::format("TaggerTrackerM{}Tracks",mod_id));
0068       moduleClusterTags.push_back({});
0069       for(int lay_id : layerIDs){
0070         geometryDivisions.push_back({mod_id,lay_id});
0071         geometryDivisionCollectionNames.push_back(fmt::format("TaggerTrackerM{}L{}RawHits",mod_id,lay_id));
0072         outputClusterCollectionNames.push_back(fmt::format("TaggerTrackerM{}L{}ClusterPositions",mod_id,lay_id));
0073         moduleClusterTags.back().push_back(outputClusterCollectionNames.back());
0074       }
0075     }
0076 
0077     app->Add(new JOmniFactoryGeneratorT<SubDivideCollection_factory<edm4eic::RawTrackerHit>>(
0078          "TaggerTrackerSplitHits",
0079          {"TaggerTrackerRawHits"},
0080          geometryDivisionCollectionNames,
0081          {
0082           .function = GeometrySplit{geometryDivisions,readout,geometryLabels},
0083          },
0084          app
0085       )
0086     );
0087 
0088 
0089     app->Add(new JOmniFactoryGeneratorT<FarDetectorTrackerCluster_factory>(
0090         "TaggerTrackerClustering",
0091         geometryDivisionCollectionNames,
0092         outputClusterCollectionNames,
0093         {
0094           .readout = "TaggerTrackerHits",
0095           .x_field  = "x",
0096           .y_field  = "y",
0097           .hit_time_limit = 10 * edm4eic::unit::ns,
0098         },
0099         app
0100     ));
0101 
0102     // Linear tracking for each module, loop over modules
0103     for(int i=0; i<moduleIDs.size(); i++){
0104       std::string outputTrackTag = outputTrackTags[i];
0105       std::vector<std::string> inputClusterTags = moduleClusterTags[i];
0106 
0107       app->Add(new JOmniFactoryGeneratorT<FarDetectorLinearTracking_factory>(
0108           outputTrackTag,
0109           inputClusterTags,
0110           {outputTrackTag},
0111           {
0112             .layer_hits_max = 100,
0113             .chi2_max = 0.001,
0114             .n_layer = 4,
0115             .restrict_direction = true,
0116             .optimum_theta = -M_PI+0.026,
0117             .optimum_phi = 0,
0118             .step_angle_tolerance = 0.05,
0119           },
0120           app
0121       ));
0122     }
0123 
0124     // Combine the tracks from each module into one collection
0125     app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::TrackSegment>>(
0126          "TaggerTrackerTrackSegments",
0127          outputTrackTags,
0128          {"TaggerTrackerTrackSegments"},
0129          app
0130       )
0131     );
0132 
0133     // Project tracks onto a plane
0134     app->Add(new JOmniFactoryGeneratorT<FarDetectorLinearProjection_factory>(
0135          "TaggerTrackerProjectedTracks",
0136          {"TaggerTrackerTrackSegments"},
0137          {"TaggerTrackerProjectedTracks"},
0138          {
0139            .plane_position = {0.0,0.0,0.0},
0140            .plane_a = {0.0,1.0,0.0},
0141            .plane_b = {0.0,0.0,1.0},
0142          },
0143          app
0144     ));
0145 
0146     // Vector reconstruction at origin
0147     app->Add(new JOmniFactoryGeneratorT<FarDetectorMLReconstruction_factory>(
0148         "TaggerTrackerTrajectories",
0149         {"TaggerTrackerProjectedTracks","MCBeamElectrons"},
0150         {"TaggerTrackerTrajectories","TaggerTrackerTrackParameters","TaggerTrackerTracks"},
0151         {
0152           .modelPath = "calibrations/tmva/LowQ2_DNN_CPU.weights.xml",
0153           .methodName = "DNN_CPU",
0154         },
0155         app
0156     ));
0157 
0158   }
0159 }