Skip to content

Commit af3c47b

Browse files
Added data class SmearedMCParticle (and everything else)
1 parent f30155d commit af3c47b

File tree

15 files changed

+791
-0
lines changed

15 files changed

+791
-0
lines changed

CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ======================================================================
2+
# boosteddmanalysis main build file
3+
# ======================================================================
4+
5+
cmake_minimum_required (VERSION 3.10)
6+
7+
project(boosteddmanalysis)
8+
9+
# cetbuildtools contains our cmake modules
10+
SET ( CETBUILDTOOLS_VERSION $ENV{CETBUILDTOOLS_VERSION} )
11+
IF (NOT CETBUILDTOOLS_VERSION)
12+
MESSAGE (FATAL_ERROR "ERROR: setup cetbuildtools to get the cmake modules")
13+
ENDIF()
14+
15+
set(CMAKE_MODULE_PATH $ENV{ART_DIR}/Modules
16+
$ENV{CETBUILDTOOLS_DIR}/Modules
17+
${CMAKE_MODULE_PATH}
18+
)
19+
20+
include(CetCMakeEnv)
21+
cet_cmake_env()
22+
23+
cet_set_compiler_flags(DIAGS PARANOID
24+
WERROR
25+
NO_UNDEFINED
26+
EXTRA_FLAGS -pedantic
27+
)
28+
29+
cet_report_compiler_flags()
30+
31+
# these are minimum required versions, not the actual product versions
32+
find_ups_product( larsoft v1_00_00 )
33+
find_ups_product( nutools v1_00_00 )
34+
find_ups_product( art v2_10_00 )
35+
find_ups_product( cetbuildtools v4_14_01 )
36+
37+
# macros for dictionary and simple_plugin
38+
include(ArtDictionary)
39+
include(ArtMake)
40+
include(BuildPlugins)
41+
42+
# source code subdirectories
43+
add_subdirectory(boosteddmanalysis)
44+
45+
# tests
46+
add_subdirectory(test)
47+
48+
# ups - table and config files
49+
add_subdirectory(ups)
50+
51+
# packaging utility
52+
include(UseCPack)

boosteddmanalysis/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
add_subdirectory(DataObjects)
3+
# add_subdirectory(Reconstruction)
4+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# this will create both the library and the dictionary
2+
art_make(
3+
LIB_LIBRARIES
4+
lardataobj_RecoBase
5+
${ROOT_EG} # TDatabasePDG
6+
${ROOT_GENVECTORS}
7+
${ROOT_CORE}
8+
DICT_LIBRARIES
9+
nusimdata_SimulationBase
10+
)
11+
12+
install_source()
13+
install_headers()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @file boosteddmanalysis/DataObjects/SmearedMCParticle.cxx
3+
* @brief Particle obtained from pseudo-reconstruction (implementation).
4+
* @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5+
* @date October 5, 2018
6+
* @see boosteddmanalysis/DataObjects/SmearedMCParticle.h
7+
* @ingroup BoostedDarkMatterData
8+
*
9+
*/
10+
11+
// library header
12+
#include "boosteddmanalysis/DataObjects/SmearedMCParticle.h"
13+
14+
15+
//------------------------------------------------------------------------------
16+
bdm::SmearedMCParticle::SmearedMCParticle(
17+
PDGID_t id,
18+
Momentum_t momentum,
19+
double energy,
20+
double time,
21+
Position_t startPosition,
22+
Position_t endPosition
23+
)
24+
: fEnergy(energy)
25+
, fMomentum(momentum)
26+
, fTime(time)
27+
, fStartingVertex(startPosition)
28+
, fEndVertex(endPosition)
29+
, fPDGID(id)
30+
{}
31+
32+
33+
//------------------------------------------------------------------------------
34+
TParticlePDG const* bdm::SmearedMCParticle::particleInfo() const {
35+
return hasParticleId()
36+
? TDatabasePDG::Instance()->GetParticle(particleId())
37+
: nullptr;
38+
} // bdm::SmearedMCParticle::particleInfo()
39+
40+
41+
//------------------------------------------------------------------------------
42+
std::string bdm::SmearedMCParticle::particleName() const {
43+
if (!hasParticleId()) return "<none>";
44+
auto const* info = particleInfo();
45+
return info? info->GetName(): "<ID=" + std::to_string(particleId()) + ">";
46+
} // bdm::SmearedMCParticle::particleName()
47+
48+
49+
//------------------------------------------------------------------------------
50+
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @file boosteddmanalysis/DataObjects/classes.h
3+
* @brief Dictionary selection for `TotallyCheatTracks` example data products.
4+
* @ingroup TotallyCheatTracks
5+
*
6+
*/
7+
8+
#include "boosteddmanalysis/DataObjects/SmearedMCParticle.h"
9+
10+
#include "nusimdata/SimulationBase/MCParticle.h"
11+
12+
#include "canvas/Persistency/Common/Wrapper.h"
13+
#include "canvas/Persistency/Common/Assns.h"
14+

0 commit comments

Comments
 (0)