Skip to content

Commit

Permalink
Merge pull request #200 from JeffersonLab/CPPTof
Browse files Browse the repository at this point in the history
Scintillators for CPP experiment
  • Loading branch information
rjones30 authored Jan 1, 2022
2 parents 2c44c50 + df09e9f commit bfafade
Show file tree
Hide file tree
Showing 8 changed files with 800 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/GlueXDetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "GlueXSensitiveDetectorPSC.hh"
#include "GlueXSensitiveDetectorPS.hh"
#include "GlueXSensitiveDetectorTPOL.hh"
#include "GlueXSensitiveDetectorCTOF.hh"


#include "G4Version.hh"
#include "G4LogicalVolume.hh"
Expand Down Expand Up @@ -286,6 +288,7 @@ void GlueXDetectorConstruction::ConstructSDandField()
GlueXSensitiveDetectorPSC* pscHandler = 0;
GlueXSensitiveDetectorPS* psHandler = 0;
GlueXSensitiveDetectorTPOL* tpolHandler = 0;
GlueXSensitiveDetectorCTOF* ctofHandler = 0;

// During geometry building, certain logical volumes were marked as
// sensitive by adding them to a list. Now we need to go down that
Expand Down Expand Up @@ -384,6 +387,14 @@ void GlueXDetectorConstruction::ConstructSDandField()
}
iter->second->SetSensitiveDetector(ftofHandler);
}
else if (volname == "CTOF")
{
if (ctofHandler == 0) {
ctofHandler = new GlueXSensitiveDetectorCTOF("ctof");
SDman->AddNewDetector(ctofHandler);
}
iter->second->SetSensitiveDetector(ctofHandler);
}
// radiator volume: BNNM (NN = bar number 0-47 and M is sub-bar character A-D)
else if (volname == "PIXV" ||
(volname[0] == 'B' &&
Expand Down
90 changes: 90 additions & 0 deletions src/GlueXHitCTOFbar.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// GlueXHitCTOFbar - class implementation
//
// author: staylor at jlab.org
// version: october 25, 2016

#include "GlueXHitCTOFbar.hh"

G4ThreadLocal G4Allocator<GlueXHitCTOFbar>* GlueXHitCTOFbarAllocator = 0;

GlueXHitCTOFbar::GlueXHitCTOFbar(G4int bar)
: G4VHit(),
bar_(bar)
{}

GlueXHitCTOFbar::GlueXHitCTOFbar(const GlueXHitCTOFbar &src)
{
bar_ = src.bar_;
hits = src.hits;
}

int GlueXHitCTOFbar::operator==(const GlueXHitCTOFbar &right) const
{
if (bar_ != right.bar_ )
return 0;
else if (hits.size() != right.hits.size())
return 0;

for (int ih=0; ih < (int)hits.size(); ++ih) {
if (hits[ih].end_ != right.hits[ih].end_ ||
hits[ih].dE_GeV != right.hits[ih].dE_GeV ||
hits[ih].t_ns != right.hits[ih].t_ns
)
{
return 0;
}

}
return 1;
}

GlueXHitCTOFbar &GlueXHitCTOFbar::operator+=(const GlueXHitCTOFbar &right)
{
if (bar_ != right.bar_) {
G4cerr << "Error in GlueXHitCTOFbar::operator+=() - "
<< "illegal attempt to merge hits from two different bars!"
<< G4endl;
return *this;
}
std::vector<GlueXHitCTOFbar::hitinfo_t>::iterator hiter = hits.begin();
std::vector<GlueXHitCTOFbar::hitinfo_t>::const_iterator hitsrc;
for (hitsrc = right.hits.begin(); hitsrc != right.hits.end(); ++hitsrc) {
for (; hiter != hits.end(); ++hiter) {
if (hiter->t_ns > hitsrc->t_ns)
break;
}
hiter = hits.insert(hiter, *hitsrc);
}
return *this;
}

void GlueXHitCTOFbar::Draw() const
{
// not yet implemented
}

void GlueXHitCTOFbar::Print() const
{
G4cout << "GlueXHitCTOFbar: "
<< " bar = " << bar_ << G4endl;
std::vector<hitinfo_t>::const_iterator hiter;
for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
G4cout << " end = " << hiter->end_ << G4endl
<< " dE = " << hiter->dE_GeV << " GeV" << G4endl
<< " t = " << hiter->t_ns << " ns" << G4endl;
G4cout << G4endl;
}
}

void printallhits(GlueXHitsMapCTOFbar *hitsmap)
{
std::map<int, GlueXHitCTOFbar*> *map = hitsmap->GetMap();
std::map<int, GlueXHitCTOFbar*>::const_iterator iter;
G4cout << "G4THitsMap " << hitsmap->GetName() << " with " << hitsmap->entries()
<< " entries:" << G4endl;
for (iter = map->begin(); iter != map->end(); ++iter) {
G4cout << " key=" << iter->first << " ";
iter->second->Print();
}
}
67 changes: 67 additions & 0 deletions src/GlueXHitCTOFbar.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// GlueXHitCTOFbar - class header
//
// author: staylor at jlab.org
// version: october 25, 2021
//
// In the context of the Geant4 event-level multithreading model,
// this class is "thread-local", ie. has thread-local state. Its
// allocator is designed to run within a worker thread context.
// This class is final, do NOT try to derive another class from it.

#ifndef GlueXHitCTOFbar_h
#define GlueXHitCTOFbar_h 1

#include "G4VHit.hh"
#include "G4THitsMap.hh"
#include "G4Allocator.hh"

class GlueXHitCTOFbar : public G4VHit
{
public:
GlueXHitCTOFbar() {}
GlueXHitCTOFbar(G4int bar);
GlueXHitCTOFbar(const GlueXHitCTOFbar &src);
int operator==(const GlueXHitCTOFbar &right) const;
GlueXHitCTOFbar &operator+=(const GlueXHitCTOFbar &right);

void *operator new(size_t);
void operator delete(void *aHit);

void Draw() const;
void Print() const;

// no reason to hide hit data

G4int bar_; // bar number (see hdds)

struct hitinfo_t {
G4int end_; // end=0: top, end=1: bottom
G4double dE_GeV; // energy deposition by track(GeV)
G4double t_ns; // pulse leading-edge time (ns)
};
std::vector<hitinfo_t> hits;

G4int GetKey() const { return GetKey(bar_); }
static G4int GetKey(G4int bar) {
return bar;
}
};

typedef G4THitsMap<GlueXHitCTOFbar> GlueXHitsMapCTOFbar;

extern G4ThreadLocal G4Allocator<GlueXHitCTOFbar>* GlueXHitCTOFbarAllocator;

inline void* GlueXHitCTOFbar::operator new(size_t)
{
if (!GlueXHitCTOFbarAllocator)
GlueXHitCTOFbarAllocator = new G4Allocator<GlueXHitCTOFbar>;
return (void *) GlueXHitCTOFbarAllocator->MallocSingle();
}

inline void GlueXHitCTOFbar::operator delete(void *aHit)
{
GlueXHitCTOFbarAllocator->FreeSingle((GlueXHitCTOFbar*) aHit);
}

#endif
88 changes: 88 additions & 0 deletions src/GlueXHitCTOFpoint.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// GlueXHitCTOFpoint - class implementation
//
// author: staylor at jlab.org
// version: october 25, 2021

#include "GlueXHitCTOFpoint.hh"

G4ThreadLocal G4Allocator<GlueXHitCTOFpoint>* GlueXHitCTOFpointAllocator = 0;

GlueXHitCTOFpoint::GlueXHitCTOFpoint(const GlueXHitCTOFpoint &src)
{
E_GeV = src.E_GeV;
primary_ = src.primary_;
ptype_G3 = src.ptype_G3;
px_GeV = src.px_GeV;
py_GeV = src.py_GeV;
pz_GeV = src.pz_GeV;
x_cm = src.x_cm;
y_cm = src.y_cm;
z_cm = src.z_cm;
t_ns = src.t_ns;
track_ = src.track_;
trackID_ = src.trackID_;
}

int GlueXHitCTOFpoint::operator==(const GlueXHitCTOFpoint &right) const
{
if (E_GeV != right.E_GeV ||
primary_ != right.primary_ ||
ptype_G3 != right.ptype_G3 ||
px_GeV != right.px_GeV ||
py_GeV != right.py_GeV ||
pz_GeV != right.pz_GeV ||
x_cm != right.x_cm ||
y_cm != right.y_cm ||
z_cm != right.z_cm ||
t_ns != right.t_ns ||
track_ != right.track_ ||
trackID_ != right.trackID_ )
{
return 0;
}
return 1;
}

GlueXHitCTOFpoint &GlueXHitCTOFpoint::operator+=(const GlueXHitCTOFpoint &right)
{
G4cerr << "Error in GlueXHitCTOFpoint::operator+= - "
<< "illegal attempt to merge two TruthPoint objects in the fTOF!"
<< G4endl;
return *this;
}

void GlueXHitCTOFpoint::Draw() const
{
// not yet implemented
}

void GlueXHitCTOFpoint::Print() const
{
G4cout << "GlueXHitCTOFpoint:" << G4endl
<< " track = " << track_ << G4endl
<< " trackID = " << trackID_ << G4endl
<< " E = " << E_GeV << " GeV" << G4endl
<< " primary = " << primary_ << G4endl
<< " ptype = " << ptype_G3 << G4endl
<< " px = " << px_GeV << " GeV/c" << G4endl
<< " py = " << py_GeV << " GeV/c" << G4endl
<< " pz = " << pz_GeV << " GeV/c" << G4endl
<< " x = " << x_cm << " cm" << G4endl
<< " y = " << y_cm << " cm" << G4endl
<< " z = " << z_cm << " cm" << G4endl
<< " t = " << t_ns << " ns" << G4endl
<< G4endl;
}

void printallhits(GlueXHitsMapCTOFpoint *hitsmap)
{
std::map<int, GlueXHitCTOFpoint*> *map = hitsmap->GetMap();
std::map<int, GlueXHitCTOFpoint*>::const_iterator iter;
G4cout << "G4THitsMap " << hitsmap->GetName() << " with " << hitsmap->entries()
<< " entries:" << G4endl;
for (iter = map->begin(); iter != map->end(); ++iter) {
G4cout << " key=" << iter->first << " ";
iter->second->Print();
}
}
67 changes: 67 additions & 0 deletions src/GlueXHitCTOFpoint.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// GlueXHitCTOFpoint - class header
//
// author: staylor at jlab.org
// version: october 25, 2021
//
// In the context of the Geant4 event-level multithreading model,
// this class is "thread-local", ie. has thread-local state. Its
// allocator is designed to run within a worker thread context.
// This class is final, do NOT try to derive another class from it.

#ifndef GlueXHitCTOFpoint_h
#define GlueXHitCTOFpoint_h 1

#include "G4VHit.hh"
#include "G4THitsMap.hh"
#include "G4Allocator.hh"

class GlueXHitCTOFpoint : public G4VHit
{
public:
GlueXHitCTOFpoint() {}
GlueXHitCTOFpoint(const GlueXHitCTOFpoint &src);
int operator==(const GlueXHitCTOFpoint &right) const;
GlueXHitCTOFpoint &operator+=(const GlueXHitCTOFpoint &right);

void *operator new(size_t);
void operator delete(void *aHit);

void Draw() const;
void Print() const;

// no reason to hide hit data

G4double E_GeV; // total energy (GeV) of this track at this point
G4bool primary_; // true if track belongs to from a primary particle
G4int ptype_G3; // G3 type of particle making this track
G4double px_GeV; // momentum (GeV/c) of track at point, x component
G4double py_GeV; // momentum (GeV/c) of track at point, y component
G4double pz_GeV; // momentum (GeV/c) of track at point, z component
G4double x_cm; // global x coordinate of track at point (cm)
G4double y_cm; // global y coordinate of track at point (cm)
G4double z_cm; // global z coordinate of track at point (cm)
G4double t_ns; // time of track crossing at point (ns)
G4int track_; // Geant4 track ID of particle making this track
G4int trackID_; // GlueX-assigned track ID of particle making this track

G4int GetKey() const { return (track_ << 20) + int(t_ns * 100); }
};

typedef G4THitsMap<GlueXHitCTOFpoint> GlueXHitsMapCTOFpoint;

extern G4ThreadLocal G4Allocator<GlueXHitCTOFpoint>* GlueXHitCTOFpointAllocator;

inline void* GlueXHitCTOFpoint::operator new(size_t)
{
if (!GlueXHitCTOFpointAllocator)
GlueXHitCTOFpointAllocator = new G4Allocator<GlueXHitCTOFpoint>;
return (void *) GlueXHitCTOFpointAllocator->MallocSingle();
}

inline void GlueXHitCTOFpoint::operator delete(void *aHit)
{
GlueXHitCTOFpointAllocator->FreeSingle((GlueXHitCTOFpoint*) aHit);
}

#endif
Loading

0 comments on commit bfafade

Please sign in to comment.