TruthSvc_test.cxx 27.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

/**
 * @author Elmar Ritsch <Elmar.Ritsch@cern.ch>
 * @date June, 2016
 * @brief Tests for ISF::TruthSvc.
 */

#undef NDEBUG

// Tested service
#include "../src/TruthSvc.h"

// Framework
#include "GaudiKernel/PhysicalConstants.h"
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/ISvcManager.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/SmartIF.h"
#include "AthenaBaseComps/AthAlgTool.h"

// Framework testing
#include "TestTools/initGaudi.h"

// Google Test
#include "gtest/gtest.h"
// Google Mock
#include "gmock/gmock.h"

// ISF
#include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ITruthIncident.h"
#include "ISF_HepMC_Interfaces/ITruthStrategy.h"

// CLHEP includes
#include "CLHEP/Vector/LorentzVector.h"
#include "CLHEP/Units/SystemOfUnits.h"

// HepMC
#include "HepMC/GenParticle.h"
#include "HepMC/GenVertex.h"
#include "HepMC/GenEvent.h"

// STL includes
#include <cstdlib> // quick_exit


namespace ISFTesting {

  // Athena Tool to emulate a TruthStrategy
  class MockTruthStrategy : public extends<AthAlgTool, ISF::ITruthStrategy> {
  public:
    MockTruthStrategy(const std::string& type, const std::string& name, const IInterface* parent)
      : base_class(type,name,parent)
    { };

    virtual ~MockTruthStrategy() {};

    // mock method which will be called by tested code
    MOCK_CONST_METHOD1(pass, bool(ISF::ITruthIncident&));
  };

  DECLARE_TOOL_FACTORY( MockTruthStrategy )

  class DummyTruthIncident : public ISF::ITruthIncident {
  public:
    DummyTruthIncident(AtlasDetDescr::AtlasRegion geoID, unsigned short numChildren)
      : ISF::ITruthIncident(geoID, numChildren)
    { };

    virtual ~DummyTruthIncident() {};
77
    virtual const HepMC::FourVector&  position() const {return m_myPosition;};
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    virtual int                       physicsProcessCategory() const { return 1;};
    virtual Barcode::PhysicsProcessCode physicsProcessCode() const {return 1;};
    virtual double                    parentP2() const {return 1.0;};
    virtual double                    parentPt2() const {return 1.0;};
    /** Return Ekin of the parent particle */
    virtual double                    parentEkin() const {return 1.0;};
    /** Return the PDG Code of the parent particle */
    virtual int                       parentPdgCode() const {return 1;};
    /** Return the parent particle as a HepMC particle type
        (only called for particles that will enter the HepMC truth event) */
    virtual HepMC::GenParticle*       parentParticle() const {return nullptr;};
    /** Return the barcode of the parent particle */
    virtual Barcode::ParticleBarcode  parentBarcode() const {return 1;};
    /** Return the extra barcode of the parent particle */
    virtual Barcode::ParticleBarcode  parentBCID() const {return 1;};
    /** Return a boolean whether or not the parent particle survives the incident */
    virtual bool                      parentSurvivesIncident() const {return false;};
    /** Return the parent particle after the TruthIncident vertex (and assign
        a new barcode to it) */
    virtual HepMC::GenParticle*       parentParticleAfterIncident(Barcode::ParticleBarcode) {return nullptr;};

    /** Return p^2 of the i-th child particle */
    virtual double                    childP2(unsigned short) const {return 1.0;};
    /** Return pT^2 of the i-th child particle */
    virtual double                    childPt2(unsigned short) const {return 1.0;};
    /** Return Ekin of the i-th child particle */
    virtual double                    childEkin(unsigned short) const {return 1.0;};
    /** Return the PDG Code of the i-th child particle */
    virtual int                       childPdgCode(unsigned short) const {return 1;};
    /** Return the i-th child as a HepMC particle type and assign the given
        Barcode to the simulator particle (only called for particles that will
        enter the HepMC truth event) */
    virtual HepMC::GenParticle*       childParticle(unsigned short,
                                                    Barcode::ParticleBarcode) const {return nullptr;};
    /** Update the properties of a child particle from a pre-defined
        interaction based on the properties of the ith child of the
        current TruthIncident (only used in quasi-stable particle
        simulation). */
    virtual HepMC::GenParticle*       updateChildParticle(unsigned short,
                                                          HepMC::GenParticle*) const {return nullptr;};
    /** Set the the barcode of all child particles to the given bc */
    virtual void                      setAllChildrenBarcodes(Barcode::ParticleBarcode) {};
  private:
121
    const HepMC::FourVector m_myPosition{0.0, 40.0, 0.0, 40.0};
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  };

  class MockTruthIncident : public DummyTruthIncident {
  public:
    MockTruthIncident(AtlasDetDescr::AtlasRegion geoID, unsigned short numChildren)
      : DummyTruthIncident(geoID, numChildren)
    { };

    virtual ~MockTruthIncident() {};
    MOCK_METHOD0(geoID, AtlasDetDescr::AtlasRegion());
    //MOCK_CONST_METHOD0(position, HepMC::FourVector&());
    MOCK_CONST_METHOD0(physicsProcessCode, Barcode::PhysicsProcessCode());
    MOCK_CONST_METHOD0(parentParticle, HepMC::GenParticle*());
    MOCK_CONST_METHOD0(parentBarcode, Barcode::ParticleBarcode());
    MOCK_METHOD1(parentParticleAfterIncident, HepMC::GenParticle*(Barcode::ParticleBarcode));
    MOCK_METHOD1(setPassWholeVertices, void(bool));
    MOCK_CONST_METHOD0(numberOfChildren, unsigned short());
  };

  // class AllGoodMatcher : public ::testing::MatcherInterface<ISF::ITruthIncident> {
  // public:
  //   virtual bool MatchAndExplain(ISF::ITruthIncident n, ::testing::MatchResultListener* listener) const {
  //     return true;
  //   }

  //   virtual void DescribeTo(::std::ostream* os) const {
  //     *os << "is divisible by 7";
  //   }

  //   virtual void DescribeNegationTo(::std::ostream* os) const {
  //     *os << "is not divisible by 7";
  //   }
  // };

  // inline ::testing::Matcher<ISF::ITruthIncident> AllGood() {
  //   return ::testing::MakeMatcher(new AllGoodMatcher);
  // }

  class TruthSvc_test: public ::testing::Test {

  protected:
    virtual void SetUp() override {
      m_appMgr = Gaudi::createApplicationMgr();
      ASSERT_TRUE( m_appMgr!=nullptr );

      m_svcLoc = m_appMgr;
      ASSERT_TRUE( m_svcLoc.isValid() );

      m_svcMgr = m_appMgr;
      ASSERT_TRUE( m_svcMgr.isValid() );

      m_propMgr = m_appMgr;
      ASSERT_TRUE( m_propMgr.isValid() );
      ASSERT_TRUE( m_propMgr->setProperty( "EvtSel", "NONE" ).isSuccess() );
      ASSERT_TRUE( m_propMgr->setProperty( "JobOptionsType", "FILE" ).isSuccess() );
      ASSERT_TRUE( m_propMgr->setProperty( "JobOptionsPath", "TruthSvc_test.txt" ).isSuccess() );

      m_toolSvc = m_svcLoc->service("ToolSvc");
      ASSERT_TRUE( m_toolSvc.isValid() );

      ASSERT_TRUE( m_appMgr->configure().isSuccess() );
      ASSERT_TRUE( m_appMgr->initialize().isSuccess() );

      // the tested AthenaService
      const auto& truthSvcTypeAndName = "ISF::TruthSvc/TruthSvc";
      SmartIF<IService> svc = m_svcLoc->service(truthSvcTypeAndName);
      m_svc = dynamic_cast<ISF::TruthSvc*>(svc.get());
      ASSERT_NE(nullptr, m_svc);

      ASSERT_TRUE( m_svc->setProperties().isSuccess() );
      ASSERT_TRUE( m_svc->configure().isSuccess() );
    }

    virtual void TearDown() override {
      m_svcMgr->removeService(m_svc);
      ASSERT_TRUE( m_svc->finalize().isSuccess() );
      ASSERT_TRUE( m_svc->terminate().isSuccess() );
      ReleaseSmartIFComponent(m_svc);

      ASSERT_TRUE( m_appMgr->finalize().isSuccess() );
      ASSERT_TRUE( m_appMgr->terminate().isSuccess() );
      Gaudi::setInstance( static_cast<IAppMgrUI*>(nullptr)) ;
    }

    void ReleaseSmartIFComponent(IInterface* comp) {
      size_t finalRefCount = 1; // keep one reference for the SmartIF destructor
      for (size_t refCount = comp->refCount(); refCount>finalRefCount; refCount--) {
        comp->release();
      }
    }

    //
    // accessors for private methods
    // NB: This works because TruthSvc_test is a friend
    //     of the tested TruthSvc service
    //
    template<typename... Args>
    HepMC::GenVertex* createGenVertexFromTruthIncident(Args&&... args) const {
      return m_svc->createGenVertexFromTruthIncident(std::forward<Args>(args)...);
    }

    template<typename... Args>
    void recordIncidentToMCTruth(Args&&... args) const {
      return m_svc->recordIncidentToMCTruth(std::forward<Args>(args)...);
    }

    template<typename... Args>
    void registerTruthIncident(Args&&... args) const {
      return m_svc->registerTruthIncident(std::forward<Args>(args)...);
    }

    template<typename... Args>
    void deleteChildVertex(Args&&... args) const {
      return m_svc->deleteChildVertex(std::forward<Args>(args)...);
    }

    ToolHandleArray<ISF::ITruthStrategy>& getIDTruthStrategies() const {
      return m_svc->m_geoStrategyHandles[AtlasDetDescr::fAtlasID];
    }

    // void forceEndVertexInID() const {
    //   m_svc->m_forceEndVtx[1] = true;
    // }

    // protected member variables
    //

    // Core Gaudi components
    IAppMgrUI*             m_appMgr = nullptr;
    SmartIF<ISvcLocator>   m_svcLoc;
    SmartIF<ISvcManager>   m_svcMgr;
    SmartIF<IToolSvc>      m_toolSvc;
    SmartIF<IProperty>     m_propMgr;

    ISF::TruthSvc*   m_svc; // the tested AthenaService

  };  // TruthSvc_test fixture


  TEST_F(TruthSvc_test, initialize_empty) {
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
  }


  TEST_F(TruthSvc_test, createGenVertexFromTruthIncident) {
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);

    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    HepMC::FourVector vtxPosition(0.0, 40.0, 0.0, 40.0);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(1)
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(1)
      .WillOnce(::testing::Return(inParticle3->barcode()));
    EXPECT_CALL(ti, parentParticle())
      .Times(1)
      .WillOnce(::testing::Return(inParticle3));
    HepMC::GenVertex *generated = createGenVertexFromTruthIncident(ti);

    ASSERT_EQ( vtxPosition, generated->position() );
    ASSERT_EQ( 1021, generated->id() );
    ASSERT_EQ( -2, generated->barcode() );
    ASSERT_EQ( 1, generated->particles_in_size());
    ASSERT_EQ( 0, generated->particles_out_size());
    ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin()));
  }


  TEST_F(TruthSvc_test, recordIncidentToMCTruth_noChildParticles) {
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);

    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    HepMC::FourVector vtxPosition(0.0, 40.0, 0.0, 40.0);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(2)
      .WillOnce(::testing::Return(21))
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(2)
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()));
    EXPECT_CALL(ti, parentParticle())
      .Times(2)
      .WillOnce(::testing::Return(inParticle3))
      .WillOnce(::testing::Return(inParticle3));
    EXPECT_CALL(ti, parentParticleAfterIncident(1010003))
      .Times(1)
      .WillOnce(::testing::Return(nullptr));

358
    recordIncidentToMCTruth(ti,false);
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
    ASSERT_EQ( vtxPosition, generated->position() );
    ASSERT_EQ( 1021, generated->id() );
    ASSERT_EQ( -2, generated->barcode() ); // by construction at the moment
    ASSERT_EQ( 1, generated->particles_in_size());
    ASSERT_EQ( 0, generated->particles_out_size());
    ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin()));
  }


  TEST_F(TruthSvc_test, registerTruthIncident_noStrat_noForceEndVtx) {
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);

    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(1)
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(2)
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()));

    registerTruthIncident(ti);
    HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
    HepMC::GenVertex* expectedVtx(nullptr);
    ASSERT_EQ( expectedVtx, generated);
  }


  TEST_F(TruthSvc_test, registerTruthIncident_noStrat_ForceEndVtx) {
    bool forceEndVtx[AtlasDetDescr::fNumAtlasRegions] = {true, true, true, true, true, true};
    ASSERT_TRUE( m_svc->setProperty( "ForceEndVtxInRegions", forceEndVtx ).isSuccess() );
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);

    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    HepMC::FourVector vtxPosition(0.0, 40.0, 0.0, 40.0);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(2)
      .WillOnce(::testing::Return(21))
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(3)
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()));
    EXPECT_CALL(ti, parentParticle())
      .Times(1)
      .WillOnce(::testing::Return(inParticle3));

    registerTruthIncident(ti);
    HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
    ASSERT_EQ( vtxPosition, generated->position() );
    ASSERT_EQ( 1021, generated->id() );
    ASSERT_EQ( -2, generated->barcode() ); // by construction at the moment
    ASSERT_EQ( 1, generated->particles_in_size());
    ASSERT_EQ( 0, generated->particles_out_size());
    ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin()));
  }


  TEST_F(TruthSvc_test, registerTruthIncident_failMockStrat_ForceEndVtx) {
    bool forceEndVtx[AtlasDetDescr::fNumAtlasRegions] = {true, true, true, true, true, true};
    ASSERT_TRUE( m_svc->setProperty( "ForceEndVtxInRegions", forceEndVtx ).isSuccess() );
    // retrieve mockable TruthStrategy tool and point InputConverter to the same instance
    m_svc->setProperty("IDTruthStrategies", "['ISFTesting::MockTruthStrategy/DummyTruthStrategy']");
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    ToolHandleArray<ISF::ITruthStrategy>& idTruthStrategies = getIDTruthStrategies();
    const unsigned int expectedSize(1);
    ASSERT_EQ (idTruthStrategies.size(), expectedSize);
    MockTruthStrategy* truthStrategy = dynamic_cast<MockTruthStrategy*>(&*(idTruthStrategies[0]));
    ASSERT_TRUE( truthStrategy );

    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);


    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    HepMC::FourVector vtxPosition(0.0, 40.0, 0.0, 40.0);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(2)
      .WillOnce(::testing::Return(21))
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(3)
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()));
    EXPECT_CALL(ti, parentParticle())
      .Times(1)
      .WillOnce(::testing::Return(inParticle3));
    // _ is a matcher where the argument can be any value of the
    // correct type. Needed because the argument to the pass method is
    // a reference to an abstract interface class (ITruthIncident).
    EXPECT_CALL(*truthStrategy, pass(::testing::_))
      .Times(1)
      .WillOnce(::testing::Return(false));

    registerTruthIncident(ti);
    HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
    ASSERT_EQ( vtxPosition, generated->position() );
    ASSERT_EQ( 1021, generated->id() );
    ASSERT_EQ( -2, generated->barcode() ); // by construction at the moment
    ASSERT_EQ( 1, generated->particles_in_size());
    ASSERT_EQ( 0, generated->particles_out_size());
    ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin()));
  }


  TEST_F(TruthSvc_test, registerTruthIncident_passMockStrat_parentSurvives) {
    // retrieve mockable TruthStrategy tool and point InputConverter to the same instance
    m_svc->setProperty("IDTruthStrategies", "['ISFTesting::MockTruthStrategy/DummyTruthStrategy']");
    ASSERT_TRUE( m_svc->initialize().isSuccess() );
    ToolHandleArray<ISF::ITruthStrategy>& idTruthStrategies = getIDTruthStrategies();
    const unsigned int expectedSize(1);
    ASSERT_EQ (idTruthStrategies.size(), expectedSize);
    MockTruthStrategy* truthStrategy = dynamic_cast<MockTruthStrategy*>(&*(idTruthStrategies[0]));
    ASSERT_TRUE( truthStrategy );

    /// Create dummy GenEvent
    const int process_id1(20);
    const int event_number1(17);
    const int pdgid1(-13);
    const int pdgid2(13);
    std::unique_ptr<HepMC::GenEvent> anEvent = std::make_unique<HepMC::GenEvent>(process_id1, event_number1);
    const CLHEP::HepLorentzVector myPos( 0.0, 0.0, 0.0, 0.0);
    HepMC::GenVertex *myVertex = new HepMC::GenVertex( myPos, -1 );
    const HepMC::FourVector fourMomentum1( 0.0, 0.0, 1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle1 = new HepMC::GenParticle(fourMomentum1, pdgid1, 2);
    myVertex->add_particle_in(inParticle1);
    const HepMC::FourVector fourMomentum2( 0.0, 0.0, -1.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle2 = new HepMC::GenParticle(fourMomentum2, pdgid2, 2);
    myVertex->add_particle_in(inParticle2);
    const HepMC::FourVector fourMomentum3( 0.0, 1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle3 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    myVertex->add_particle_out(inParticle3);
    const HepMC::FourVector fourMomentum4( 0.0, -1.0, 0.0, 1.0*CLHEP::TeV);
    HepMC::GenParticle* inParticle4 = new HepMC::GenParticle(fourMomentum4, pdgid2, 1);
    myVertex->add_particle_out(inParticle4);
    anEvent->add_vertex( myVertex );
    anEvent->set_signal_process_vertex( myVertex );
    anEvent->set_beam_particles(inParticle1,inParticle2);
    HepMC::GenParticle* inParticle5 = new HepMC::GenParticle(fourMomentum3, pdgid1, 1);
    inParticle5->suggest_barcode(1010003);
    inParticle5->set_status(1);

    MockTruthIncident ti(AtlasDetDescr::fAtlasID, 2);
    HepMC::FourVector vtxPosition(0.0, 40.0, 0.0, 40.0);
    EXPECT_CALL(ti, physicsProcessCode())
      .Times(2)
      .WillOnce(::testing::Return(21))
      .WillOnce(::testing::Return(21));
    EXPECT_CALL(ti, parentBarcode())
      .Times(3)
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()))
      .WillOnce(::testing::Return(inParticle3->barcode()));
    EXPECT_CALL(ti, parentParticle())
      .Times(2)
      .WillOnce(::testing::Return(inParticle3))
      .WillOnce(::testing::Return(inParticle3));
    EXPECT_CALL(ti, parentParticleAfterIncident(1010003))
      .Times(1)
      .WillOnce(::testing::Return(inParticle5));
    // _ is a matcher where the argument can be any value of the
    // correct type. Needed because the argument to the pass method is
    // a reference to an abstract interface class (ITruthIncident).
    EXPECT_CALL(*truthStrategy, pass(::testing::_))
      .Times(1)
      .WillOnce(::testing::Return(true));

    registerTruthIncident(ti);
    HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
    ASSERT_EQ( vtxPosition, generated->position() );
    ASSERT_EQ( 1021, generated->id() );
    ASSERT_EQ( -2, generated->barcode() ); // by construction at the moment
    ASSERT_EQ( 1, generated->particles_in_size());
    ASSERT_EQ( inParticle3, *(generated->particles_in_const_begin()));
    ASSERT_EQ( 1, generated->particles_out_size());
    ASSERT_EQ( inParticle5, *(generated->particles_out_const_begin()));
  }

  //TODO Add tests for the following cases:
  // 1) parent destroyed, all child particles pass cuts
  // 2) parent destroyed, some child particles pass cuts
  // 3) parent survives, all child particles pass cuts
  // 4) parent survives, some child particles pass cuts
  // 5) quasi-stable particle, pre-defined decay
  // 6) quasi-stable particle, additional interaction, survives, no child particles pass cuts
  // 7) quasi-stable particle, additional interaction, survives, some child particles pass cuts
  // 8) quasi-stable particle, additional interaction, destroyed, no child particles pass cuts
  // 9) quasi-stable particle, additional interaction, destroyed, some child particles pass cuts

} // <-- namespace ISFTesting

int main(int argc, char *argv[]) {
  ::testing::InitGoogleTest( &argc, argv );

  // gets stuck forever while trying to finalize boost ***REMOVED*** SGTools:
  //return RUN_ALL_TESTS();
  // skips proper finalization:
  std::quick_exit( RUN_ALL_TESTS() );
}

// // retrieve mockable GenParticleFilter tool and point InputConverter to the same instance
// m_svc->setProperty("GenParticleFilters", "['ISFTesting::MockFilterTool/DummyFilter']");
// ASSERT_TRUE( m_svc->initialize().isSuccess() );