|
| 1 | +/** |
| 2 | + * @file boosteddmanalysis/DataObjects/SmearedMCParticle.h |
| 3 | + * @brief Particle obtained from pseudo-reconstruction. |
| 4 | + * @author Gianluca Petrillo (petrillo@slac.stanford.edu) |
| 5 | + * @date October 5, 2018 |
| 6 | + * @version 10 |
| 7 | + * @see boosteddmanalysis/DataObjects/SmearedMCParticle.h |
| 8 | + * @ingroup BoostedDarkMatterData |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef BOOSTEDDMANALYSIS_DATAOBJECTS_SMEAREDMCPARTICLE_H |
| 13 | +#define BOOSTEDDMANALYSIS_DATAOBJECTS_SMEAREDMCPARTICLE_H |
| 14 | + |
| 15 | + |
| 16 | +// LArSoft libraries |
| 17 | +#include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Point_t... |
| 18 | +#include "Math/GenVector/LorentzVector.h" |
| 19 | + |
| 20 | + |
| 21 | +// ROOT libraries |
| 22 | +#include "TDatabasePDG.h" |
| 23 | +#include "TParticlePDG.h" |
| 24 | + |
| 25 | +// C/C++ standard libraries |
| 26 | +#include <ostream> |
| 27 | +#include <string> |
| 28 | +#include <utility> // std::move(), std::forward() |
| 29 | + |
| 30 | +/** |
| 31 | + * @brief Namespace for Boosted Dark Matter analysis code. |
| 32 | + * @addtogroup BoostedDarkMatterData |
| 33 | + */ |
| 34 | +namespace bdm { |
| 35 | + |
| 36 | + // BEGIN BoostedDarkMatterData group ----------------------------------------- |
| 37 | + /// @ingroup BoostedDarkMatterData |
| 38 | + /// @{ |
| 39 | + |
| 40 | + /** |
| 41 | + * @brief Particle obtained from pseudo-reconstruction. |
| 42 | + * |
| 43 | + * This class represents a simulated particle which undergo a parametrised |
| 44 | + * simulation and reconstruction. |
| 45 | + * |
| 46 | + */ |
| 47 | + class SmearedMCParticle { |
| 48 | + |
| 49 | + public: |
| 50 | + |
| 51 | + using Position_t = geo::Point_t; ///< Type to represent positions. |
| 52 | + using Momentum_t = geo::Vector_t; ///< Type to represent momenta. |
| 53 | + using PDGID_t = int; ///< Type of the particle ID. |
| 54 | + |
| 55 | + /// 4-momentum |
| 56 | + using FourMomentum_t |
| 57 | + = ROOT::Math::LorentzVector<ROOT::Math::Cartesian3D<double>>; |
| 58 | + |
| 59 | + /// Value of a particle ID that denotes it as invalid. |
| 60 | + static constexpr PDGID_t InvalidParticleID = 0; |
| 61 | + |
| 62 | + |
| 63 | + /// Default constructor, only for ROOT I/O (do not use it!). |
| 64 | + SmearedMCParticle() = default; |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Constructor from trajectory (stolen) and particle ID. |
| 68 | + * @param id type of particle, in PDG ID standard |
| 69 | + * @param momentum momentum vector [GeV/c] |
| 70 | + * @param energy energy [GeV] |
| 71 | + * @param time time of appearance |
| 72 | + * @param startPosition initial position [cm] |
| 73 | + * @param endPosition final position [cm] |
| 74 | + * |
| 75 | + * The particle is initialized with the specified values. |
| 76 | + */ |
| 77 | + SmearedMCParticle( |
| 78 | + PDGID_t id, |
| 79 | + Momentum_t momentum, double energy, |
| 80 | + double time, Position_t startPosition, Position_t endPosition |
| 81 | + ); |
| 82 | + |
| 83 | + |
| 84 | + // --- BEGIN access to data ------------------------------------------------ |
| 85 | + /// @{ |
| 86 | + /// @name Access to data |
| 87 | + |
| 88 | + //@{ |
| 89 | + /// Returns the initial momentum of the particle [GeV/c]. |
| 90 | + Momentum_t const& momentum() const { return fMomentum; } |
| 91 | + Momentum_t const& cp() const { return momentum(); } |
| 92 | + //@} |
| 93 | + |
| 94 | + //@{ |
| 95 | + /// Returns the initial energy of the particle [GeV]. |
| 96 | + double energy() const { return fEnergy; } |
| 97 | + double E() const { return energy(); } |
| 98 | + //@} |
| 99 | + |
| 100 | + /// Returns the position where the particle was created, in world |
| 101 | + /// coordinates [cm]. |
| 102 | + Position_t const& startPosition() const { return fStartingVertex; } |
| 103 | + |
| 104 | + /// Returns the position where the particle ends, in world coordinates [cm]. |
| 105 | + Position_t const& endPosition() const { return fEndVertex; } |
| 106 | + |
| 107 | + //@{ |
| 108 | + /// Returns reconstructed time of particle [ns] since hardware trigger time. |
| 109 | + double time() const { return fTime; } |
| 110 | + double t() const { return fTime; } |
| 111 | + //@} |
| 112 | + |
| 113 | + |
| 114 | + /// Returns whether the particle ID is valid. |
| 115 | + bool hasParticleId() const { return particleId() != InvalidParticleID; } |
| 116 | + |
| 117 | + /// Returns the particle ID, in PDG standard. |
| 118 | + PDGID_t particleId() const { return fPDGID; } |
| 119 | + |
| 120 | + /** |
| 121 | + * @brief Returns particle information from a database. |
| 122 | + * @return a pointer to the information (TParticlePDG) or `nullptr` if none |
| 123 | + * |
| 124 | + * The information is provided by ROOT's particle database. |
| 125 | + * |
| 126 | + * If the particle is not known to ROOT, or if there is no particle ID |
| 127 | + * (`!hasParticleId()`), a null pointer is returned instead. |
| 128 | + */ |
| 129 | + TParticlePDG const* particleInfo() const; |
| 130 | + |
| 131 | + /// Returns a string with the name of the type of particle. |
| 132 | + std::string particleName() const; |
| 133 | + |
| 134 | + /// @} |
| 135 | + // --- END access to data -------------------------------------------------- |
| 136 | + |
| 137 | + |
| 138 | + // --- BEGIN printing data ------------------------------------------------- |
| 139 | + /// @{ |
| 140 | + /// @name Printing data |
| 141 | + |
| 142 | + /// Default verbosity level. |
| 143 | + static constexpr unsigned int DefaultDumpVerbosity = 1U; |
| 144 | + |
| 145 | + /// Maximum verbosity level. |
| 146 | + static constexpr unsigned int MaxDumpVerbosity = 3U; |
| 147 | + |
| 148 | + |
| 149 | + //@{ |
| 150 | + /** |
| 151 | + * @brief Prints the content of this object into an output stream. |
| 152 | + * @tparam Stream type of the output text stream |
| 153 | + * @param out the output text stream |
| 154 | + * @param verbosity the amount of information printed |
| 155 | + * (_default: `DefaultDumpVerbosity`_) |
| 156 | + * @param indent indentation string for all output except the first line |
| 157 | + * (_default: none_) |
| 158 | + * @param firstIndent indentation string for the first line |
| 159 | + * (_default: as `indent`_) |
| 160 | + * |
| 161 | + * Verbosity levels: |
| 162 | + * * 0: ID (compact), energy and momentum |
| 163 | + * * 1: ID in expanded form, starting position, energy and momentum |
| 164 | + * * 2: added end position (`endPosition()`) |
| 165 | + * * 3: added particle time (`time()`) |
| 166 | + * |
| 167 | + */ |
| 168 | + template <typename Stream> |
| 169 | + void dump( |
| 170 | + Stream&& out, unsigned int verbosity, |
| 171 | + std::string indent, std::string firstIndent |
| 172 | + ) const; |
| 173 | + template <typename Stream> |
| 174 | + void dump( |
| 175 | + Stream&& out, unsigned int verbosity = DefaultDumpVerbosity, |
| 176 | + std::string indent = "" |
| 177 | + ) const |
| 178 | + { dump(std::forward<Stream>(out), verbosity, indent, indent); } |
| 179 | + //@} |
| 180 | + |
| 181 | + ///@} |
| 182 | + |
| 183 | + // --- END printing data --------------------------------------------------- |
| 184 | + |
| 185 | + private: |
| 186 | + |
| 187 | + double fEnergy = 0.0; ///< Reconstructed energy of the particle [GeV]. |
| 188 | + Momentum_t fMomentum; ///< Reconstructed momentum of the particle [GeV/c]. |
| 189 | + double fTime = 0.0; ///< Reconstructed creation time [ns]. |
| 190 | + Position_t fStartingVertex; ///< Reconstructed starting position [cm]. |
| 191 | + Position_t fEndVertex; ///< Reconstructed ending position [cm]. |
| 192 | + |
| 193 | + PDGID_t fPDGID = InvalidParticleID; ///< Particle ID in PDG standard. |
| 194 | + |
| 195 | + }; // class SmearedMCParticle |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + /// Prints the content of the track into a text stream. |
| 200 | + /// @related bdm::SmearedMCParticle |
| 201 | + /// @ingroup BoostedDarkMatterData |
| 202 | + inline std::ostream& operator<< |
| 203 | + (std::ostream& out, bdm::SmearedMCParticle const& particle) |
| 204 | + { particle.dump(out); return out; } |
| 205 | + |
| 206 | + /// @} |
| 207 | + // END BoostedDarkMatterData group ------------------------------------------- |
| 208 | + |
| 209 | +} // namespace bdm |
| 210 | + |
| 211 | + |
| 212 | +//------------------------------------------------------------------------------ |
| 213 | +//--- template implementation |
| 214 | +//------------------------------------------------------------------------------ |
| 215 | +template <typename Stream> |
| 216 | +void bdm::SmearedMCParticle::dump( |
| 217 | + Stream&& out, unsigned int verbosity, |
| 218 | + std::string /* indent */, std::string firstIndent |
| 219 | + ) const |
| 220 | +{ |
| 221 | + // we could use ROOT's TDatabasePDG to get the name of the ID, but we'd rather |
| 222 | + // not depend on ROOT here... |
| 223 | + if (verbosity >= 1) { |
| 224 | + out << firstIndent |
| 225 | + << "particle: "; |
| 226 | + auto const* pPDGinfo = particleInfo(); |
| 227 | + if (pPDGinfo) out << pPDGinfo->GetName() << " (ID=" << particleId() << ")"; |
| 228 | + else out << "ID " << particleId(); |
| 229 | + } |
| 230 | + else out << firstIndent << "ID=" << particleId(); // <== verbosity: 0 |
| 231 | + |
| 232 | + if (verbosity >= 1) out << " starting"; |
| 233 | + if (verbosity >= 3) out << " on " << time() << " ns"; |
| 234 | + if (verbosity >= 1) out << " at " << startPosition() << " cm"; |
| 235 | + if (verbosity >= 2) out << " and ending at " << endPosition() << " cm"; |
| 236 | + |
| 237 | + // verbosity: 0 |
| 238 | + out << "; E=" << energy() << " GeV, cp=" << momentum() << " GeV/c"; |
| 239 | + |
| 240 | +} // lar::example::CheatTrack::dump() |
| 241 | + |
| 242 | +//------------------------------------------------------------------------------ |
| 243 | + |
| 244 | + |
| 245 | +#endif // BOOSTEDDMANALYSIS_DATAOBJECTS_SMEAREDMCPARTICLE_H |
0 commit comments