Skip to content

Commit

Permalink
ReducedTrackFinder implemented and running
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelzanno committed Nov 14, 2024
1 parent 50793a2 commit 511680b
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 66 deletions.
77 changes: 77 additions & 0 deletions Tracking/exampleConfigs/test_reduced_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from LDMX.Framework import ldmxcfg
p = ldmxcfg.Process('reduced_algo_v1_test')

p.maxTriesPerEvent = 100

from LDMX.Biasing import ecal
from LDMX.SimCore import generators as gen
from LDMX.SimCore import simulator as sim

#myGun = gen.single_4gev_e_upstream_tagger()
myGun = gen.multi( "mgpGen" )
myGun.vertex = [ 0., 0., -880] # mm
myGun.momentum = [0.,0.,4000.] # MeV
myGun.nParticles = 1
myGun.pdgID = 11
myGun.enablePoisson = False #True

mySim = sim.simulator( "mySim" ) # Build simulator object
det = 'ldmx-reduced-v1'
mySim.setDetector(det, True )
mySim.beamSpotSmear = [20.,80.,0.]
mySim.description = 'Reduced ECal Electron Gun (reduced) Tracking Algorithm Test'

mySim.generators = [ myGun ]
p.sequence = [ mySim ]
p.termLogLevel = 0


p.maxEvents = 1
p.run = 200

p.histogramFile = f'hist_reducedAlgoV1Test_seederONLY.root'
p.outputFiles = [f'events_1_reducedAlgoV1Test_seederONLY.root']

import LDMX.Ecal.EcalGeometry
import LDMX.Ecal.ecal_hardcoded_conditions
import LDMX.Ecal.digi as ecal_digi
import LDMX.Ecal.vetos as ecal_vetos

import LDMX.Hcal.HcalGeometry

ecalVeto = ecal_vetos.EcalVetoProcessor()
ecalVeto.num_ecal_layers = 6

p.sequence.extend([
ecal_digi.EcalDigiProducer(),
ecal_digi.EcalRecProducer(),
ecalVeto])

from LDMX.Tracking import tracking
from LDMX.Tracking import geo

from LDMX.Tracking.geo import TrackersTrackingGeometryProvider as trackgeo
trackgeo.get_instance().setDetector('ldmx-reduced-v1')

#smearings
uSmearing = 0.006 #mm #could bump up to 10 micron if we want
vSmearing = 0.000001 #mm #~unused

# Smearing Processor - Recoil
digiRecoil = tracking.DigitizationProcessor("DigitizationProcessorRecoil")
digiRecoil.hit_collection = "RecoilSimHits"
digiRecoil.out_collection = "DigiRecoilSimHits"
digiRecoil.merge_hits = True
digiRecoil.sigma_u = uSmearing
digiRecoil.sigma_v = vSmearing

reducedSeed = tracking.ReducedSeedFinder("ReducedSeedFinder")
reducedSeed.input_hit_collection = "DigiRecoilSimHits"
reducedSeed.input_recHits_collection = "EcalRecHits"
reducedSeed.out_seed_collection = "ReducedSeedTracks"

reducedTrack = tracking.ReducedTrackFinder("ReducedTrackFinder")
reducedTrack.seed_coll_name = "ReducedSeedTracks"
reducedTrack.out_trk_collection = "ReducedTrack"

p.sequence.extend([digiRecoil, reducedSeed, reducedTrack])
28 changes: 14 additions & 14 deletions Tracking/include/Tracking/Event/ReducedTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,25 @@ namespace ldmx {

protected:
//Actual Track Parameters
double ax_{0};
double ay_{0};
double bx_{0};
double by_{0};
double distance_to_Ecal_{0};
double ax_;
double ay_;
double bx_;
double by_;
double distance_to_Ecal_;

std::array<double, 3> firstSensor_{0., 0., 0.};
std::array<double, 3> secondSensor_{0., 0., 0.};
std::array<double, 3> ecalRecHit_{0., 0., 0.};
std::array<double, 3> firstSensor_;
std::array<double, 3> secondSensor_;
std::array<double, 3> ecalRecHit_;

int n_hits_{0};
int ndf_{0};
int n_shared_hits_{0};
double chi2_{0};
int n_hits_;
int ndf_;
int n_shared_hits_;
double chi2_;

// The target location
std::array<double, 3> targetPos_{0., 0., 0.};
std::array<double, 3> targetPos_;
// The ecal first layer position
std::array<double, 3> ecalLayer1Pos_{0., 0., 0.};
std::array<double, 3> ecalLayer1Pos_;

// ID of the matched particle in the SimParticles map
// int trackID_{-1}; COME BACK AND SETUP TRACK ID ONCE YOU CONFIGURE TRUTH STUFF
Expand Down
14 changes: 0 additions & 14 deletions Tracking/include/Tracking/Reco/ReducedSeedFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class ReducedSeedFinder : public TrackingGeometryUser {
std::string input_hits_collection_{"DigiRecoilSimHits"};
/// The name of the tagger Tracks (only for Recoil Seeding)
std::string input_recHits_collection_{"EcalRecHits"};
/// Location of the perigee for the helix track parameters.
std::vector<double> perigee_location_{0., 0., 0};

double piover2_{1.5708};

Expand All @@ -118,18 +116,6 @@ class ReducedSeedFinder : public TrackingGeometryUser {

std::vector<double> recoil_uncertainty_{0.006, 0.12};

std::vector<double> zpos_digi_tot_;
std::vector<double> xpos_digi_tot_;
std::vector<double> ypos_digi_tot_;
std::vector<double> edep_digi_;

std::vector<double> ecal_end_x_;
std::vector<double> ecal_end_y_;
std::vector<double> ecal_end_z_;

std::vector<std::array<double, 4>> digiPoints_;
std::vector<std::array<double, 3>> firstLayerEcalRecHits_;

// Check failures
// long ndoubles_{0};
long nmissing_{0};
Expand Down
79 changes: 79 additions & 0 deletions Tracking/include/Tracking/Reco/ReducedTrackFinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

//--- Framework ---//
#include "Framework/Configure/Parameters.h"
#include "Framework/EventProcessor.h"
#include "Framework/RandomNumberSeedService.h"

//--- C++ ---//
#include <memory>
#include <random>

//--- LDMX ---//
#include "Tracking/Reco/TrackingGeometryUser.h"

//--- Tracking ---//
#include "TFile.h"
#include "TTree.h"
#include "Tracking/Event/Measurement.h"
#include "Tracking/Event/ReducedTrack.h"

namespace tracking {
namespace reco {

class ReducedTrackFinder : public TrackingGeometryUser {
public:
/**
* Constructor.
*
* @param name The name of the instance of this object.
* @param process The process running this producer.
*/
ReducedTrackFinder(const std::string &name, framework::Process &process);

/// Destructor
~ReducedTrackFinder();

/**
*
*/
void onProcessStart() override;
/**
*
*/
void onProcessEnd() override;

/**
* Configure the processor using the given user specified parameters.
*
* @param parameters Set of parameters used to configure this processor.
*/
void configure(framework::config::Parameters &parameters) override;

/**
* Run the processor
*
* @param event The event to process.
*/
void produce(framework::Event &event) override;

private:
int nevents_{0};
double processing_time_{0.};

// The output track collection
std::string out_trk_collection_{"ReducedTracks"};

// The seed track collection
std::string seed_coll_name_{"ReducedSeedTracks"};

int nseeds_{0};
int ntracks_{0};
int eventnr_{0};

std::vector<ldmx::ReducedTrack> findTracks(const std::vector<ldmx::ReducedTrack>& trackSeeds);

}; // ReducedTrackFinder

} // namespace reco
} // namespace tracking
29 changes: 29 additions & 0 deletions Tracking/python/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ def __init__(self, instance_name="ReducedSeedFinder"):
self.recoil_uncertainty = [0.006, 0.12]
self.ecal_uncertainty = 3.87
self.ecal_distance_threshold = 15.0

class ReducedTrackFinder(Producer):
""" Producer to find Seeds for the reduced geometry track finding
Parameters
----------
instance_name : str
Unique name for this instance.
Attributes
----------
input_hits_collection : string
The name of the input collection of hits to be used for seed finding.
input_recHits_collection : string
The name of the input collection of Ecal RecHits (from layer 1) to give a degree of freedom to seed finding.
out_seed_collection : string
The name of the ouput collection of seeds to be stored.
recoil_uncertainty : double
The position uncertainty in [x, y] of a recoil tracker double-layer from combining an axial-stereo sensor pair to make one 3D position
ecal_uncertainty : double
The radius of an ECal hexagonal cell
ecal_distance_threshold : double
The maximum distance on the Ecal First Layer at which we still allow a seed to be saved
"""

def __init__(self, instance_name="ReducedTrackFinder"):
super().__init__(instance_name, 'tracking::reco::ReducedTrackFinder', 'Tracking')
self.seed_coll_name = 'ReducedSeedTracks'
self.out_trk_collection = 'ReducedTracks'

class SeedFinderProcessor(Producer):
""" Producer to find Seeds for the KF-based track finding.
Expand Down
60 changes: 22 additions & 38 deletions Tracking/src/Tracking/Reco/ReducedSeedFinder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,35 @@ void ReducedSeedFinder::produce(framework::Event& event) {
const std::vector<ldmx::Measurement> recoilHits = event.getCollection<ldmx::Measurement>(input_hits_collection_);
const std::vector<ldmx::EcalHit> ecalRecHit = event.getCollection<ldmx::EcalHit>(input_recHits_collection_);

std::vector<std::array<double, 4>> digiPoints;
std::vector<std::array<double, 3>> firstLayerEcalRecHits;

for (const auto& x_digi : recoilHits) {
zpos_digi_tot_.push_back(x_digi.getGlobalPosition()[0]);
xpos_digi_tot_.push_back(x_digi.getGlobalPosition()[1]);
ypos_digi_tot_.push_back(x_digi.getGlobalPosition()[2]);
edep_digi_.push_back(x_digi.getEdep());
digiPoints.push_back({x_digi.getGlobalPosition()[0], x_digi.getGlobalPosition()[1], x_digi.getGlobalPosition()[2], x_digi.getEdep()});
} //for loop to create digiPoints array

// Combine (z, x, y, edep) recoil hits into a 3D position vector
for (size_t i = 0; i < zpos_digi_tot_.size(); ++i) {
digiPoints_.push_back({zpos_digi_tot_[i], xpos_digi_tot_[i], ypos_digi_tot_[i], edep_digi_[i]});
} //for positions in recoil tracker

for (const auto& x_ecal : ecalRecHit) {
if (x_ecal.getZPos() < 250) {
ecal_end_x_.push_back(x_ecal.getXPos());
ecal_end_y_.push_back(x_ecal.getYPos());
ecal_end_z_.push_back(x_ecal.getZPos());
firstLayerEcalRecHits.push_back({x_ecal.getZPos(), x_ecal.getXPos(), x_ecal.getYPos()});
} //if first layer of Ecal
} //for positions in ecalRecHit

// Combine (z, x, y) ecalRecHits into a 3D position vector
for (size_t i = 0; i < ecal_end_z_.size(); ++i) {
firstLayerEcalRecHits_.push_back({ecal_end_z_[i], ecal_end_x_[i], ecal_end_y_[i]});
} //for loop to create ecal_endpoint array


// ! Check if we would fit empty seeds !
if (digiPoints_.size() < 2 || firstLayerEcalRecHits_.empty() || uniqueSensorsHit(digiPoints_) < 2) {
if (digiPoints.size() < 2 || firstLayerEcalRecHits.empty() || uniqueSensorsHit(digiPoints) < 2) {
nmissing_++;
ntracks_ += reduced_seed_tracks.size();
event.add(out_seed_collection_, reduced_seed_tracks);
return;
}

auto [firstSensor, secondSensor] = combineMultiGlobalHits(digiPoints_);
auto [firstSensor, secondSensor] = combineMultiGlobalHits(digiPoints);

for (const auto& firstPoint : firstSensor) {
for (const auto& secondPoint : secondSensor) {
for (const auto& recHit : firstLayerEcalRecHits_) {
for (const auto& recHit : firstLayerEcalRecHits) {
ldmx::ReducedTrack seedTrack = SeedTracker(firstPoint, secondPoint, recHit);
reduced_seed_tracks.push_back(seedTrack);
if (seedTrack.getChi2() > 0.0) {
reduced_seed_tracks.push_back(seedTrack);
}
} //for recHits
} //for second recoil tracker
} //for first recoil tracker
Expand All @@ -95,17 +84,8 @@ void ReducedSeedFinder::produce(framework::Event& event) {
auto diff = end - start;
processing_time_ += std::chrono::duration<double, std::milli>(diff).count();

digiPoints_.clear();
firstLayerEcalRecHits_.clear();

zpos_digi_tot_.clear();
xpos_digi_tot_.clear();
ypos_digi_tot_.clear();
edep_digi_.clear();

ecal_end_x_.clear();
ecal_end_y_.clear();
ecal_end_z_.clear();
digiPoints.clear();
firstLayerEcalRecHits.clear();

} //produce

Expand All @@ -114,7 +94,7 @@ ldmx::ReducedTrack ReducedSeedFinder::SeedTracker(const std::array<double, 3> re
auto [ax, bx, ay, by] = fit3DLine(recoilOne, recoilTwo, ecalOne);
std::array<double, 3> tempExtrapolatedPoint = {ecalOne[0], ax * ecalOne[0] + bx, ay * ecalOne[0] + by};
double tempDistance = calculateDistance(tempExtrapolatedPoint, ecalOne);

ldmx::ReducedTrack trk = ldmx::ReducedTrack();

if (tempDistance < ecal_distance_threshold_) {
Expand All @@ -125,7 +105,7 @@ ldmx::ReducedTrack ReducedSeedFinder::SeedTracker(const std::array<double, 3> re

trk.setFirstSensorPosition(recoilOne);
trk.setSecondSensorPosition(recoilTwo);
trk.setEcalLayer1Location(ecalOne);
trk.setFirstLayerEcalRecHit(ecalOne);
trk.setDistancetoEcalRecHit(tempDistance);

trk.setTargetLocation(0.0, bx, by);
Expand All @@ -134,9 +114,13 @@ ldmx::ReducedTrack ReducedSeedFinder::SeedTracker(const std::array<double, 3> re
trk.setNhits(3);
trk.setNdf(1);
trk.setNsharedHits(0);

return trk;
} //check whether the track is close enough to EcalRecHit

return trk;
else {
trk.setChi2(-1);
return trk;
} //does not pass the threshold
}

void ReducedSeedFinder::onProcessEnd() { //HAVE TO FIX THESE VALUES
Expand Down
Loading

0 comments on commit 511680b

Please sign in to comment.