Skip to content

Commit 40a6d50

Browse files
Added flags to SmearedMCParticle
1 parent af3c47b commit 40a6d50

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set(CMAKE_MODULE_PATH $ENV{ART_DIR}/Modules
2020
include(CetCMakeEnv)
2121
cet_cmake_env()
2222

23-
cet_set_compiler_flags(DIAGS PARANOID
23+
cet_set_compiler_flags(DIAGS VIGILANT
2424
WERROR
2525
NO_UNDEFINED
2626
EXTRA_FLAGS -pedantic

boosteddmanalysis/DataObjects/SmearedMCParticle.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ bdm::SmearedMCParticle::SmearedMCParticle(
1919
double energy,
2020
double time,
2121
Position_t startPosition,
22-
Position_t endPosition
22+
Position_t endPosition,
23+
Flags_t flags
2324
)
2425
: fEnergy(energy)
2526
, fMomentum(momentum)
2627
, fTime(time)
2728
, fStartingVertex(startPosition)
2829
, fEndVertex(endPosition)
2930
, fPDGID(id)
31+
, fFlags(flags)
3032
{}
3133

3234

boosteddmanalysis/DataObjects/SmearedMCParticle.h

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ namespace bdm {
5252
using Momentum_t = geo::Vector_t; ///< Type to represent momenta.
5353
using PDGID_t = int; ///< Type of the particle ID.
5454

55+
using Flags_t = unsigned int; ///< Type of flags mask.
56+
57+
/// Flag: is the particle valid at all?
58+
static constexpr Flags_t flValid = 1 << 0;
59+
60+
5561
/// 4-momentum
5662
using FourMomentum_t
5763
= ROOT::Math::LorentzVector<ROOT::Math::Cartesian3D<double>>;
@@ -71,13 +77,15 @@ namespace bdm {
7177
* @param time time of appearance
7278
* @param startPosition initial position [cm]
7379
* @param endPosition final position [cm]
80+
* @param flags flags (see `flags()`)
7481
*
7582
* The particle is initialized with the specified values.
7683
*/
7784
SmearedMCParticle(
7885
PDGID_t id,
7986
Momentum_t momentum, double energy,
80-
double time, Position_t startPosition, Position_t endPosition
87+
double time, Position_t startPosition, Position_t endPosition,
88+
Flags_t flags = defaultFlags()
8189
);
8290

8391

@@ -135,6 +143,32 @@ namespace bdm {
135143
// --- END access to data --------------------------------------------------
136144

137145

146+
/// @{
147+
148+
149+
// --- BEGIN access to flags -----------------------------------------------
150+
/// @name Access to flags
151+
/// @{
152+
153+
/// Returns the full set of flags.
154+
Flags_t flags() const { return fFlags; }
155+
156+
/// Returns whether this particle is valid at all.
157+
bool isValid() const { return flags() & flValid; }
158+
159+
/// Returns whether this particle is not valid.
160+
bool isInvalid() const { return !isValid(); }
161+
162+
/// Returns the default set of flags for a reconstructed particle.
163+
static constexpr Flags_t defaultFlags() { return flValid; }
164+
165+
/// Returns a flag set for an invalid particle.
166+
static constexpr Flags_t invalidParticleFlags() { return 0U; }
167+
168+
/// @}
169+
// --- END access to flags -------------------------------------------------
170+
171+
138172
// --- BEGIN printing data -------------------------------------------------
139173
/// @{
140174
/// @name Printing data
@@ -186,12 +220,15 @@ namespace bdm {
186220

187221
double fEnergy = 0.0; ///< Reconstructed energy of the particle [GeV].
188222
Momentum_t fMomentum; ///< Reconstructed momentum of the particle [GeV/c].
189-
double fTime = 0.0; ///< Reconstructed creation time [ns].
223+
double fTime = 0.0; ///< Reconstructed creation time [ns].
190224
Position_t fStartingVertex; ///< Reconstructed starting position [cm].
191225
Position_t fEndVertex; ///< Reconstructed ending position [cm].
192226

193227
PDGID_t fPDGID = InvalidParticleID; ///< Particle ID in PDG standard.
194228

229+
/// Flags associated to this particle.
230+
Flags_t fFlags = invalidParticleFlags();
231+
195232
}; // class SmearedMCParticle
196233

197234

@@ -223,11 +260,22 @@ void bdm::SmearedMCParticle::dump(
223260
if (verbosity >= 1) {
224261
out << firstIndent
225262
<< "particle: ";
263+
if (isInvalid()) {
264+
out << "invalid";
265+
return;
266+
}
226267
auto const* pPDGinfo = particleInfo();
227268
if (pPDGinfo) out << pPDGinfo->GetName() << " (ID=" << particleId() << ")";
228269
else out << "ID " << particleId();
229270
}
230-
else out << firstIndent << "ID=" << particleId(); // <== verbosity: 0
271+
else {
272+
out << firstIndent;
273+
if (isInvalid()) {
274+
out << "invalid";
275+
return;
276+
}
277+
out << "ID=" << particleId(); // <== verbosity: 0
278+
}
231279

232280
if (verbosity >= 1) out << " starting";
233281
if (verbosity >= 3) out << " on " << time() << " ns";
@@ -237,7 +285,9 @@ void bdm::SmearedMCParticle::dump(
237285
// verbosity: 0
238286
out << "; E=" << energy() << " GeV, cp=" << momentum() << " GeV/c";
239287

240-
} // lar::example::CheatTrack::dump()
288+
// would print flags here, but there is none yet besides the "valid" one
289+
290+
} // bdm::SmearedMCParticle::dump()
241291

242292
//------------------------------------------------------------------------------
243293

boosteddmanalysis/DataObjects/classes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
#include "nusimdata/SimulationBase/MCParticle.h"
1111

12+
#include "canvas/Persistency/Common/PtrVector.h"
1213
#include "canvas/Persistency/Common/Wrapper.h"
14+
#include "canvas/Persistency/Common/Ptr.h"
1315
#include "canvas/Persistency/Common/Assns.h"
1416

17+
#include <vector>
18+

boosteddmanalysis/DataObjects/classes_def.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<!-- class -->
1313
<class name="bdm::SmearedMCParticle" ClassVersion="10" >
14-
<version ClassVersion="10" checksum="4037081950"/>
14+
<version ClassVersion="10" checksum="532383039"/>
1515
</class>
1616

1717
<!-- art pointers and wrappers -->
@@ -28,6 +28,16 @@
2828
<class name="std::pair<art::Ptr<simb::MCParticle>, art::Ptr<bdm::SmearedMCParticle>>" />
2929
<class name="art::Wrapper<art::Assns<simb::MCParticle, bdm::SmearedMCParticle, void>>" />
3030

31+
32+
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
33+
<!-- vectors of pointers to simb::MCParticle -->
34+
<class name="std::vector<art::Ptr<simb::MCParticle>>" />
35+
<class name="art::Wrapper<std::vector<art::Ptr<simb::MCParticle>>>" />
36+
37+
<class name="art::PtrVector<simb::MCParticle>" />
38+
<class name="art::Wrapper<art::PtrVector<simb::MCParticle>>" />
39+
40+
3141
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
3242

3343
</lcgdict>

test/DataObjects/SmearedMCParticle_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ void test_SmearedMCParticle_defaultConstructor() {
2525
using Momentum_t = bdm::SmearedMCParticle::Momentum_t;
2626
using Position_t = bdm::SmearedMCParticle::Position_t;
2727
using PDGID_t = bdm::SmearedMCParticle::PDGID_t;
28+
using Flags_t = bdm::SmearedMCParticle::Flags_t;
2829

2930
Momentum_t expected_momentum; // default-constructed
3031
double expected_energy = 0.0;
3132
Position_t expected_startPosition;
3233
Position_t expected_endPosition;
3334
double expected_time = 0.0;
3435
PDGID_t expected_id = bdm::SmearedMCParticle::InvalidParticleID;
36+
Flags_t expected_flags = bdm::SmearedMCParticle::invalidParticleFlags();
3537
TParticlePDG const* expected_info = nullptr;
3638

3739
bdm::SmearedMCParticle const particle;
@@ -48,6 +50,9 @@ void test_SmearedMCParticle_defaultConstructor() {
4850
BOOST_CHECK_EQUAL(particle.particleId(), expected_id);
4951
BOOST_CHECK_EQUAL(particle.particleInfo(), expected_info);
5052
BOOST_CHECK_EQUAL(particle.particleName(), "<none>");
53+
BOOST_CHECK_EQUAL(particle.flags(), expected_flags);
54+
BOOST_CHECK (!particle.isValid());
55+
BOOST_CHECK (particle.isInvalid());
5156

5257
std::cout << "Default-constructed particle: " << particle << std::endl;
5358
for (unsigned int verb = 0U; verb <= bdm::SmearedMCParticle::MaxDumpVerbosity;
@@ -68,13 +73,15 @@ void test_SmearedMCParticle_directConstructor() {
6873
using Momentum_t = bdm::SmearedMCParticle::Momentum_t;
6974
using Position_t = bdm::SmearedMCParticle::Position_t;
7075
using PDGID_t = bdm::SmearedMCParticle::PDGID_t;
76+
using Flags_t = bdm::SmearedMCParticle::Flags_t;
7177

7278
Momentum_t expected_momentum = { 3.0, 4.0, 12.0 }; // default-constructed
7379
double expected_energy = 13.0;
7480
Position_t expected_startPosition = { -1.0, -3.0, -2.0 };
7581
Position_t expected_endPosition = expected_startPosition + expected_momentum;
7682
double expected_time = 1234.0;
7783
PDGID_t expected_id = 11; // electron
84+
Flags_t expected_flags = bdm::SmearedMCParticle::flValid;
7885
TParticlePDG const* expected_info
7986
= TDatabasePDG::Instance()->GetParticle(expected_id);
8087

@@ -95,6 +102,9 @@ void test_SmearedMCParticle_directConstructor() {
95102
BOOST_CHECK_EQUAL(particle.particleId(), expected_id);
96103
BOOST_CHECK_EQUAL(particle.particleInfo(), expected_info);
97104
BOOST_CHECK_EQUAL(particle.particleName(), "e-");
105+
BOOST_CHECK_EQUAL(particle.flags(), expected_flags);
106+
BOOST_CHECK (particle.isValid());
107+
BOOST_CHECK (!particle.isInvalid());
98108

99109
std::cout << "Particle: " << particle << std::endl;
100110
for (unsigned int verb = 0U; verb <= bdm::SmearedMCParticle::MaxDumpVerbosity;

0 commit comments

Comments
 (0)