Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions TrigScint/exampleConfigs/runClusterstxt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#example config which makes digis, clusters, and writes clusters
#to .txt file using ClusterTripletMaker

from LDMX.Framework import ldmxcfg

p = ldmxcfg.Process('nontruthclusters')
p.input_files = ["SimSamples.root"]
p.output_files = ["Clusters.root"]
#an additional output file called clusters.txt will be created as well

from LDMX.TrigScint.trig_scint import TrigScintDigiProducer

pad_num = 1

digis = [TrigScintDigiProducer.pad1(),
TrigScintDigiProducer.pad2(),
TrigScintDigiProducer.pad3()
]

for digi in digis:
digi.input_collection = f"TriggerPad{pad_num}SimHits"
pad_num+=1

from LDMX.TrigScint.trig_scint import TrigScintClusterProducer

clusters = [
TrigScintClusterProducer.pad1(),
TrigScintClusterProducer.pad2(),
TrigScintClusterProducer.pad3(),
]

for cluster, digi in zip(clusters, digis):
cluster.input_collection = digi.output_collection
cluster.ampl_weighting = False
cluster.clustering_threshold = 3.0

from LDMX.TrigScint.trig_scint import ClusterTripletMaker

triplets = ClusterTripletMaker("tripletmaker")
triplets.output_collection = "clusters.txt"

p.sequence = [
#*truth_hits,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want these commented here as an indication that including them is optional, i suggest either

  • adding a comment saying something like "uncomment to make truth tables" (but i think you need some more stuff for that to work, right? you'd need to define truth_hits and use them as input collection to the later processors (at least digi))
  • adding a more elaborate setup which does all of the needed steps to use truth hits, and toggle with some boolean, doing {if [that boolean], define stuff, p.sequence.append(truth_hits), then digi etc}

*digis,
*clusters,
triplets
]


15 changes: 15 additions & 0 deletions TrigScint/exampleConfigs/runLUTana.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#config file to make LUT for tracking using PatternLUTMaker

from LDMX.Framework import ldmxcfg

p = ldmxcfg.Process("LUTmaker")
p.input_files = ["Clusters.root"] #necessary to define but unused, the real input file is defined below

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what @cjbarton151 means here: you're not really using ldmx-sw capabilities to manage ROOT tree input and output objects for this, but rather an auxiliary file structure where you have a messy input list and an ordered output list. So in that sense he is right that it's more of a tool and I think moving these files (stuff not reading/writing TS info from/to a tree) to Tools is a good idea. Reach out to one of us if this seems too complicated and we can discuss


from LDMX.TrigScint.trig_scint import PatternLUTMaker

make_lut = PatternLUTMaker("LUTmaker")
make_lut.lut_threshold = 1.0/1000 #or whichever threshold you like
make_lut.input_collection = "clusters.txt" #here! input list of cluster triplets as produced by ClusterTripletMaker
make_lut.output_collection = "LUT.txt"

p.sequence = [make_lut]
27 changes: 27 additions & 0 deletions TrigScint/exampleConfigs/runLUTtracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#Performs tracking with TrigScintTrackProducer, with and without LUT method for comparison
from LDMX.Framework import ldmxcfg

p = ldmxcfg.Process('tracking')
p.input_files = ["Clusters.root"]
p.output_files = ["Tracks.root"]

from LDMX.TrigScint.trig_scint import TrigScintTrackProducer

tstp_tracks = TrigScintTrackProducer("tstp")
lut_tracks = TrigScintTrackProducer("lut")

tstp_tracks.delta_max = 1.0
tstp_tracks.verbosity = 1
tstp_tracks.output_collection = "tstpTracks"

lut_tracks.delta_max = 1.0
lut_tracks.verbosity = 1
lut_tracks.lut_tracking = True
lut_tracks.lut_file = "LUT.txt"
lut_tracks.output_collection = "lutTracks"
Comment on lines +17 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these settings differ from the default ones specified in trig_scint.py? if not, i suggest omitting them


p.logger.term_level = 1

p.sequence = [tstp_tracks,
lut_tracks
]
62 changes: 62 additions & 0 deletions TrigScint/include/TrigScint/ClusterTripletMaker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file ClusterTripletMaker.h
* @brief Writes cluster combinations to text file
* @author Lucia Kvarnstrom, Lund University

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ö ;)

*/

#ifndef TRIGSCINT_CLUSTERTRIPLETMAKER_H
#define TRIGSCINT_CLUSTERTRIPLETMAKER_H

// LDMX Framework
#include "Framework/Configure/Parameters.h"
#include "Framework/Event.h"
#include "Framework/EventProcessor.h"

// TrigScint
#include <fstream>
#include <string>
#include <vector>

#include "TrigScint/Event/TrigScintCluster.h"

namespace trigscint {

/**
* @class ClusterTripletMaker
* @brief Write trigger scintillator cluster triplets to a text file
*/

class ClusterTripletMaker : public framework::Analyzer {
public:
ClusterTripletMaker(const std::string& name, framework::Process& process);

virtual ~ClusterTripletMaker() = default;

void configure(framework::config::Parameters& ps) override;

void analyze(const framework::Event& event) override;

void onProcessStart() override;

void onProcessEnd() override;

private:
// verbosity
int verbose_{0};

// specific pass name
std::string pass_name_{""};

// input cluster collections
std::vector<std::string> cluster_input_collections_;

// output text file
std::string output_collection_{"clusters.txt"};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you name it something else than collection since it's not going to be on a ROOT TTree ?


// output stream
std::ofstream output_stream_;
};

} // namespace trigscint

#endif // TRIGSCINT_CLUSTERTRIPLETMAKER_H
64 changes: 64 additions & 0 deletions TrigScint/include/TrigScint/PatternLUTMaker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file PatternLUTMaker.h
* @brief Writes LUT based on frequency of track propagation patterns for
* LUT-based TS tracking.
* @author Lucia Kvarnstrom, Lund University
*/

#ifndef TRIGSCINT_PATTERNLUTMAKER_H
#define TRIGSCINT_PATTERNLUTMAKER_H
#include <fstream>
#include <map>
#include <string>
#include <utility>
#include <vector>

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

namespace trigscint {

class PatternLUTMaker : public framework::Analyzer {
public:
struct Line {
int event_;
float p1_, p2_, p3_;
};

PatternLUTMaker(const std::string& name, framework::Process& process);

virtual ~PatternLUTMaker() = default;

void configure(framework::config::Parameters& parameters) override;

void analyze(const framework::Event& event) override;

void onProcessStart() override;

void onProcessEnd() override;

private:
// verbosity
int verbose_{0};

// input text file of clusters
std::string input_collection_;

// output LUT file name
std::string output_collection_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment, rename from collection if possible


// minimum frequency of a specific pattern to be written to the LUT
double lut_threshold_{0.0008};

std::ifstream infile_;
std::ofstream outfile_;

// to group cluster combinations by track pattern
std::map<std::pair<float, float>, std::vector<Line>> groups_;

int total_lines_{0};
};

} // namespace trigscint

#endif /* TRIGSCINT_PATTERNLUTMAKER_H */
26 changes: 24 additions & 2 deletions TrigScint/include/TrigScint/TrigScintTrackProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define TRIGSCINT_TRIGSCINTTRACKPRODUCER_H

// LDMX Framework
#include <unordered_set>

#include "Framework/Configure/Parameters.h" // Needed to import parameters from configuration file
#include "Framework/Event.h"
#include "Framework/EventProcessor.h" //Needed to declare processor
Expand Down Expand Up @@ -44,8 +46,8 @@ class TrigScintTrackProducer : public framework::Producer {
// in the next pad tolerated to form a track
double max_delta_{0.};

double max_delta_vert{0.};
double bar_length_y_{30.};
double max_delta_vert_{0.};
double bar_length_y_{30.};

// producer specific verbosity
int verbose_{0};
Expand All @@ -65,6 +67,9 @@ class TrigScintTrackProducer : public framework::Producer {
// allow forming tracks without match in the last collection
bool skip_last_{false};

// do tracking using LUT method instead of with max_delta
bool lut_tracking_{false};

// vertical bar start index
int vert_bar_start_idx_{52};

Expand All @@ -88,6 +93,23 @@ class TrigScintTrackProducer : public framework::Producer {
// track residual in units of channel nb (will not be content weighted)
// float residual_{0.};

struct LUTKey {
float p1_, p2_, p3_;

bool operator==(const LUTKey &other) const {
return p1_ == other.p1_ && p2_ == other.p2_ && p3_ == other.p3_;
}
};

struct LUTKeyHash {
size_t operator()(const LUTKey &k) const {
return std::hash<float>()(k.p1_) ^ (std::hash<float>()(k.p2_) << 1) ^
(std::hash<float>()(k.p3_) << 2);
}
};

std::unordered_set<LUTKey, LUTKeyHash> lut_;

float bar_width_y_{3.}; // mm
float bar_gap_y_{2.1}; // mm
float bar_width_x_{3.}; // mm
Expand Down
25 changes: 24 additions & 1 deletion TrigScint/python/trig_scint.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ class TrigScintTrackProducer(Processor):
input_pass_name: str = ""
output_collection: str = "TriggerPadTracks"
verbosity: int = 0

lut_tracking: bool = False
lut_file: str = "LUT.txt"


trig_scint_track = TrigScintTrackProducer(instance_name="trig_scint_track")

Expand Down Expand Up @@ -506,3 +508,24 @@ class TestBeamClusterAnalyzer(Processor):
input_hit_pass_name: str = ""
start_sample: int = 2
dead_channels: list[int] = [8]


@processor("trigscint::ClusterTripletMaker", "TrigScint")
class ClusterTripletMaker(Processor) :
"""Configuration for cluster text file maker for Trigger Scintillators"""

cluster_input_collections: list[str] = ["TriggerPad1Clusters", "TriggerPad2Clusters","TriggerPad3Clusters"]
pass_name: str = ""
output_collection: str = "clusters.txt"
verbosity: int = 0


@processor("trigscint::PatternLUTMaker", "TrigScint")
class PatternLUTMaker(Processor) :
"""Configuration for track-pattern LUT-writing analyzer for Trigger Scintillators"""

input_collection: str ="clusters.txt"
input_pass_name: str = ""
output_collection: str ="LUT.txt"
lut_threshold: float = 0.0008
verbosity: int = 0
Loading