ghit
Loading...
Searching...
No Matches
ghit_example.cc
Go to the documentation of this file.
1// gemc
2#include "gtouchable.h"
3#include "gtouchable_options.h"
4#include "glogger.h"
5
6// ghit
7#include "ghit.h"
8
9using std::string;
10using std::vector;
11
12int main(int argc, char* argv[]) {
13 auto gopts =std::make_shared<GOptions>(argc, argv, gtouchable::defineOptions());
14 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, TOUCHABLE_LOGGER); // duplicate logger
15
16 HitBitSet hitBitSet;
17
18 auto a_ctof_gtouchable = GTouchable(gopts, "readout", "sector: 6, paddle: 10", {10.0, 20.0, 30.0});
19
20 auto a_hit = new GHit(std::make_shared<GTouchable>(a_ctof_gtouchable), hitBitSet);
21
22 // emulating GHitsCollection (which is G4THitsCollection<GHit>)
23 vector<GHit*> hits;
24 hits.emplace_back(a_hit); // pass ownership
25
26 for (unsigned i = 1; i < 100; i++) {
27 auto hit = GHit::create(gopts);
28
29 log->info(" GHit: ", *hit->getGTouchable(), " with total Edep: ", hit->getTotalEnergyDeposited(), " MeV");
30
31 // observing each std::unique_ptr<GHit> without copying it.
32 for (const auto& hit_in_v : hits) { if (hit->is_same_hit(hit_in_v)) { log->info(NORMAL, (*hit->getGTouchable()), " found in hit n. ", i); } }
33 }
34
35 return EXIT_SUCCESS;
36}
Represents a hit in the detector.
Definition ghit.h:30
static GHit * create(const std::shared_ptr< GOptions > &gopts)
Definition ghit.h:215
std::bitset< NHITBITS > HitBitSet
int main(int argc, char *argv[])