Skip to content

Commit

Permalink
Create event class TrackDeDxMassEstimate
Browse files Browse the repository at this point in the history
  • Loading branch information
danyi211 authored and tvami committed Sep 17, 2024
1 parent 2fc7f8c commit b63ea6f
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Recon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if(BUILD_EVENT_ONLY)
class "PFCandidate" type "collection" )
register_event_object( module_path "Recon/Event" namespace "ldmx"
class "BeamElectronTruth" type "collection" )
register_event_object( module_path "Recon/Event" namespace "ldmx"
class "TrackDeDxMassEstimate" type "collection" )
setup_library(module Recon name Event
dependencies ROOT::Core
register_target)
Expand Down
110 changes: 110 additions & 0 deletions Recon/include/Recon/Event/TrackDeDxMassEstimate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @file TrackDeDxMassEstimate.h
* @brief Class that represents the estimated mass of a particle
* using tracker dE/dx information
* @author Danyi Zhang, UCSB
*/

#ifndef RECON_TRACKDEDXMASSESTIMATOR_H_
#define RECON_TRACKDEDXMASSESTIMATOR_H_

#include <iostream>

// ROOT
#include "TObject.h" //For ClassDef

// LDMX
// #include "Event/Track.h"
// #include "Event/Measurement.h"

namespace ldmx {
/**
* @class TrackDeDxMassEstimate
* @brief Represents the estimated mass of a particle
* using tracker dE/dx information
* @note This class represents the estimated mass information
* from a tracker including mass, track index, and the track type
*/

class TrackDeDxMassEstimate {
public:
/**
* Class constructor.
*/
TrackDeDxMassEstimate();

/**
* Class destructor.
*/
virtual ~TrackDeDxMassEstimate();

/**
* Clear the data in the object.
*/
void Clear();

/**
* Print out the object.
*/
void Print() const;


/**
* Set the estimated mass of the particle/track.
* @param mass The estimated mass of the particle/track.
*/
void setMass(double mass) { mass_ = mass; }

/**
* Set the index of the track.
* @param trackIndex The index of the track.
* 1: tagger track, 2: recoil track
*/
void setTrackIndex(int trackIndex) { trackIndex_ = trackIndex; }

/**
* Set the type of the track.
* @param trackType The type of the track.
*/
void setTrackType(int trackType) { trackType_ = trackType; }

/**
* Get the estimated mass of the particle/track.
* @return The estimated mass of the particle/track.
*/
double getMass() const { return mass_; }

/**
* Get the index of the track.
* @return The index of the track.
*/
int getTrackIndex() const { return trackIndex_; }

/**
* Get the type of the track.
* @return The type of the track.
*/
int getTrackType() const { return trackType_; }




private:
/* The estimated mass of the particle/track */
double mass_{0.};

/* The index of the track */
int trackIndex_{0};

/* The type of the track */
int trackType_{0};

/**
* The ROOT class definition.
*/
ClassDef(TrackDeDxMassEstimate, 1);

};
} // namespace ldmx

#endif // RECON_TRACKDEDXMASSESTIMATOR_H_
6 changes: 6 additions & 0 deletions Recon/include/Recon/TrackDeDxMassEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "Framework/Configure/Parameters.h"
#include "Framework/EventProcessor.h"

#include "Tracking/Event/Track.h"
#include "Tracking/Event/Measurement.h"
#include "Recon/Event/TrackDeDxMassEstimate.h"

namespace recon {

/**
Expand All @@ -35,6 +39,8 @@ class TrackDeDxMassEstimator : public framework::Producer {

// name of input track collection
std::string trackCollection_;
// name of input measurement collection
std::string measCollection_{"DigiTaggerSimHits"};

}; // TrackDeDxMassEstimator

Expand Down
24 changes: 24 additions & 0 deletions Recon/src/Recon/Event/TrackDeDxMassEstimate.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Recon/Event/TrackDeDxMassEstimate.h"

ClassImp(ldmx::TrackDeDxMassEstimate);

namespace ldmx {
TrackDeDxMassEstimate::TrackDeDxMassEstimate() {}

TrackDeDxMassEstimate::~TrackDeDxMassEstimate() { Clear(); }

void TrackDeDxMassEstimate::Clear() {
mass_ = 0.;
trackIndex_ = 0;
trackType_ = 0;
}

void TrackDeDxMassEstimate::Print() const {
std::cout << "TrackDeDxMassEstimate { "
<< "Mass: " << mass_ << ", "
<< "Track Index: " << trackIndex_ << ", "
<< "Track Type: " << trackType_
<< " }" << std::endl;
}

} // namespace ldmx
46 changes: 42 additions & 4 deletions Recon/src/Recon/TrackDeDxMassEstimator.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <iostream>
#include "Recon/TrackDeDxMassEstimator.h"
#include "Tracking/Event/Track.h"
#include "Recon/Event/TrackDeDxMassEstimate.h"

namespace recon {

Expand All @@ -19,9 +19,47 @@ void TrackDeDxMassEstimator::produce(framework::Event &event) {
<< " not in event" << std::endl;
return;
}
auto tracks{event.getCollection<ldmx::Track>(trackCollection_)};

const std::vector<ldmx::Track> tracks{event.getCollection<ldmx::Track>(trackCollection_)};

// Retrieve the measurements
if (!event.exists(measCollection_)) return;
auto measurements{event.getCollection<ldmx::Measurement>(measCollection_)};

std::vector<ldmx::TrackDeDxMassEstimate> massEstimates;

// Loop over the collection of tracks
// for (auto &track : tracks) {
for (uint i = 0; i < tracks.size(); i++) {
auto track = tracks.at(i);
// If track momentum doen't exist, skip
if (track.getMomentum().empty()) {
ldmx_log(debug) << "Track " << i << " is empty" << std::endl;
continue;
}

// Get the track momentum magnitude
float p = sqrt(pow(track.getMomentum()[0], 2)
+ pow(track.getMomentum()[1], 2)
+ pow(track.getMomentum()[2], 2));
std::cout << "Track " << i << " has momentum " << p << std::endl;

/// Get the hits associated with the track
ldmx::TrackDeDxMassEstimate mes;
float sum_dedx = 0;
for (auto imeas : track.getMeasurementsIdxs()) {
auto meas = measurements.at(imeas);
if (meas.getEdep() >= 0)
sum_dedx += meas.getEdep();

}
mes.setMass(100.);
mes.setTrackIndex(i);
mes.setTrackType(2);
massEstimates.push_back(mes);
}

// Add the mass estimates to the event
event.add("TrackDeDxMassEstimate", massEstimates);


// // Loop over the collection of hits and print the hit details
Expand Down
4 changes: 4 additions & 0 deletions Tracking/include/Tracking/Event/Measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class Measurement {
/// @return the sim particle IDs that compose the measurement
std::vector<unsigned int> getTrackIds() { return trackIds_; };

/// @return The energy deposited in the sensor where the measurement took
/// place.
float getEdep() const { return edep_; };

/**
* Overload the stream insertion operator to output a string representation of
* this Measurement.
Expand Down

0 comments on commit b63ea6f

Please sign in to comment.