diff --git a/Recon/CMakeLists.txt b/Recon/CMakeLists.txt index b7c10ea00..f793a931e 100644 --- a/Recon/CMakeLists.txt +++ b/Recon/CMakeLists.txt @@ -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) diff --git a/Recon/include/Recon/Event/TrackDeDxMassEstimate.h b/Recon/include/Recon/Event/TrackDeDxMassEstimate.h new file mode 100644 index 000000000..0f9d77a66 --- /dev/null +++ b/Recon/include/Recon/Event/TrackDeDxMassEstimate.h @@ -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 + +// 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_ diff --git a/Recon/include/Recon/TrackDeDxMassEstimator.h b/Recon/include/Recon/TrackDeDxMassEstimator.h index bdd0be22f..e6a44f6f7 100644 --- a/Recon/include/Recon/TrackDeDxMassEstimator.h +++ b/Recon/include/Recon/TrackDeDxMassEstimator.h @@ -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 { /** @@ -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 diff --git a/Recon/src/Recon/Event/TrackDeDxMassEstimate.cxx b/Recon/src/Recon/Event/TrackDeDxMassEstimate.cxx new file mode 100644 index 000000000..0dc2222de --- /dev/null +++ b/Recon/src/Recon/Event/TrackDeDxMassEstimate.cxx @@ -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 \ No newline at end of file diff --git a/Recon/src/Recon/TrackDeDxMassEstimator.cxx b/Recon/src/Recon/TrackDeDxMassEstimator.cxx index cd7a9d7a8..3e1978d11 100644 --- a/Recon/src/Recon/TrackDeDxMassEstimator.cxx +++ b/Recon/src/Recon/TrackDeDxMassEstimator.cxx @@ -1,6 +1,6 @@ - +#include #include "Recon/TrackDeDxMassEstimator.h" -#include "Tracking/Event/Track.h" +#include "Recon/Event/TrackDeDxMassEstimate.h" namespace recon { @@ -19,9 +19,47 @@ void TrackDeDxMassEstimator::produce(framework::Event &event) { << " not in event" << std::endl; return; } - auto tracks{event.getCollection(trackCollection_)}; - + const std::vector tracks{event.getCollection(trackCollection_)}; + + // Retrieve the measurements + if (!event.exists(measCollection_)) return; + auto measurements{event.getCollection(measCollection_)}; + + std::vector 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 diff --git a/Tracking/include/Tracking/Event/Measurement.h b/Tracking/include/Tracking/Event/Measurement.h index a3fb527e5..2e12418bd 100644 --- a/Tracking/include/Tracking/Event/Measurement.h +++ b/Tracking/include/Tracking/Event/Measurement.h @@ -113,6 +113,10 @@ class Measurement { /// @return the sim particle IDs that compose the measurement std::vector 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.