Skip to content

Commit

Permalink
Merge pull request #220 from JeffersonLab/ecal_libs
Browse files Browse the repository at this point in the history
Ecal libs
  • Loading branch information
staylorjlab authored Apr 24, 2024
2 parents 9d522f3 + 2a18fc2 commit 19b0b2b
Show file tree
Hide file tree
Showing 8 changed files with 719 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ else
endif

DANALIBS = -L$(HALLD_RECON_HOME)/$(BMS_OSNAME)/lib -lHDGEOMETRY -lDANA \
-lANALYSIS -lBCAL -lCCAL -lCDC -lCERE -lTRD -lDIRC -lFCAL \
-lANALYSIS -lBCAL -lCCAL -lECAL -lCDC -lCERE -lTRD -lDIRC -lFCAL \
-lFDC -lFMWPC -lHDDM -lPAIR_SPECTROMETER -lPID -lRF \
-lSTART_COUNTER -lTAGGER -lTOF -lTPOL -lTRACKING \
-lTRIGGER -lDAQ -lTTAB -lEVENTSTORE -lKINFITTER -lTAC \
Expand Down
9 changes: 9 additions & 0 deletions src/GlueXDetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "GlueXSensitiveDetectorFCALinsert.hh"
#include "GlueXSensitiveDetectorGCAL.hh"
#include "GlueXSensitiveDetectorCCAL.hh"
#include "GlueXSensitiveDetectorECAL.hh"
#include "GlueXSensitiveDetectorFTOF.hh"
#include "GlueXSensitiveDetectorDIRC.hh"
#include "GlueXSensitiveDetectorCERE.hh"
Expand Down Expand Up @@ -280,6 +281,7 @@ void GlueXDetectorConstruction::ConstructSDandField()
GlueXSensitiveDetectorFCALinsert* fcalInsertHandler = 0;
GlueXSensitiveDetectorGCAL* gcalHandler = 0;
GlueXSensitiveDetectorCCAL* ccalHandler = 0;
GlueXSensitiveDetectorECAL* ecalHandler = 0;
GlueXSensitiveDetectorFTOF* ftofHandler = 0;
GlueXSensitiveDetectorDIRC* dircHandler = 0;
GlueXSensitiveDetectorCERE* cereHandler = 0;
Expand Down Expand Up @@ -377,6 +379,13 @@ void GlueXDetectorConstruction::ConstructSDandField()
}
iter->second->SetSensitiveDetector(ccalHandler);
}
else if (volname == "XTBL") {
if (ecalHandler == 0) {
ecalHandler = new GlueXSensitiveDetectorECAL("ecal");
SDman->AddNewDetector(ecalHandler);
}
iter->second->SetSensitiveDetector(ecalHandler);
}
else if (volname == "FTOC" || volname == "FTOX" ||
volname == "FTOH" || volname == "FTOL")
{
Expand Down
95 changes: 95 additions & 0 deletions src/GlueXHitECALblock.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// GlueXHitECALblock - class implementation
//

#include "GlueXHitECALblock.hh"

G4ThreadLocal G4Allocator<GlueXHitECALblock>* GlueXHitECALblockAllocator = 0;

GlueXHitECALblock::GlueXHitECALblock(G4int column, G4int row)
: G4VHit(),
column_(column),
row_(row)
{}

GlueXHitECALblock::GlueXHitECALblock(const GlueXHitECALblock &src)
{
column_ = src.column_;
row_ = src.row_;
hits = src.hits;
}

int GlueXHitECALblock::operator==(const GlueXHitECALblock &right) const
{
if (column_ != right.column_ || row_ != right.row_) {
return 0;
}
else if (hits.size() != right.hits.size()) {
return 0;
}

for (int ih=0; ih < (int)hits.size(); ++ih) {
if (hits[ih].E_GeV != right.hits[ih].E_GeV ||
hits[ih].t_ns != right.hits[ih].t_ns ||
hits[ih].dE_lightguide_GeV != right.hits[ih].dE_lightguide_GeV ||
hits[ih].t_lightguide_ns != right.hits[ih].t_lightguide_ns)
{
return 0;
}
}
return 1;
}

GlueXHitECALblock &GlueXHitECALblock::operator+=(const GlueXHitECALblock &right)
{
if (column_ != right.column_ || row_ != right.row_) {
G4cerr << "Error in GlueXHitECALblock::operator+=() - "
<< "illegal attempt to merge hits from two different blocks!"
<< G4endl;
return *this;
}
std::vector<GlueXHitECALblock::hitinfo_t>::iterator hiter = hits.begin();
std::vector<GlueXHitECALblock::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 GlueXHitECALblock::Draw() const
{
// not yet implemented
}

void GlueXHitECALblock::Print() const
{
G4cout << "GlueXHitECALblock: "
<< " column = " << column_
<< ", row = " << row_ << G4endl;
std::vector<hitinfo_t>::const_iterator hiter;
for (hiter = hits.begin(); hiter != hits.end(); ++hiter) {
G4cout << " E = " << hiter->E_GeV << " GeV" << G4endl
<< " t = " << hiter->t_ns << " ns" << G4endl
<< " E(lightguide) = "
<< hiter->dE_lightguide_GeV << " GeV" << G4endl
<< " t(lightguide) = "
<< hiter->t_lightguide_ns << " ns" << G4endl
<< G4endl;
}
}

void printallhits(GlueXHitsMapECALblock *hitsmap)
{
std::map<int, GlueXHitECALblock*> *map = hitsmap->GetMap();
std::map<int, GlueXHitECALblock*>::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();
}
}
66 changes: 66 additions & 0 deletions src/GlueXHitECALblock.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// GlueXHitECALblock - class header
//
// 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 GlueXHitECALblock_h
#define GlueXHitECALblock_h 1

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

class GlueXHitECALblock : public G4VHit
{
public:
GlueXHitECALblock() {}
GlueXHitECALblock(G4int column, G4int row);
GlueXHitECALblock(const GlueXHitECALblock &src);
int operator==(const GlueXHitECALblock &right) const;
GlueXHitECALblock &operator+=(const GlueXHitECALblock &right);

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

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

// no reason to hide hit data

G4int column_; // ECAL block column, from 1 increasing x
G4int row_; // ECAL block row, from 1 increasing y

struct hitinfo_t {
G4double E_GeV; // energy deposition (GeV)
G4double t_ns; // pulse leading-edge time (ns)
G4double dE_lightguide_GeV; // light guide energy deposition (GeV)
G4double t_lightguide_ns; // light guide pulse leading-edge time (ns)
};
std::vector<hitinfo_t> hits;

G4int GetKey() const { return GetKey(column_, row_); }
static G4int GetKey(G4int column, G4int row) {
return ((row + 1) << 16) + column + 1;
}
};

typedef G4THitsMap<GlueXHitECALblock> GlueXHitsMapECALblock;

extern G4ThreadLocal G4Allocator<GlueXHitECALblock>* GlueXHitECALblockAllocator;

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

inline void GlueXHitECALblock::operator delete(void *aHit)
{
GlueXHitECALblockAllocator->FreeSingle((GlueXHitECALblock*) aHit);
}

#endif
86 changes: 86 additions & 0 deletions src/GlueXHitECALpoint.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// GlueXHitECALpoint - class implementation
//

#include "GlueXHitECALpoint.hh"

G4ThreadLocal G4Allocator<GlueXHitECALpoint>* GlueXHitECALpointAllocator = 0;

GlueXHitECALpoint::GlueXHitECALpoint(const GlueXHitECALpoint &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 GlueXHitECALpoint::operator==(const GlueXHitECALpoint &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;
}

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

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

void GlueXHitECALpoint::Print() const
{
G4cout << "GlueXHitECALpoint:" << 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(GlueXHitsMapECALpoint *hitsmap)
{
std::map<int, GlueXHitECALpoint*> *map = hitsmap->GetMap();
std::map<int, GlueXHitECALpoint*>::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();
}
}
64 changes: 64 additions & 0 deletions src/GlueXHitECALpoint.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// GlueXHitECALpoint - class header
//
// 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 GlueXHitECALpoint_h
#define GlueXHitECALpoint_h 1

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

class GlueXHitECALpoint : public G4VHit
{
public:
GlueXHitECALpoint() {}
GlueXHitECALpoint(const GlueXHitECALpoint &src);
int operator==(const GlueXHitECALpoint &right) const;
GlueXHitECALpoint &operator+=(const GlueXHitECALpoint &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 shower particle at this point
G4bool primary_; // true if track belongs to from a primary particle
G4int ptype_G3; // G3 type of particle making this shower
G4double px_GeV; // momentum (GeV/c) of shower particle at point, x component
G4double py_GeV; // momentum (GeV/c) of shower particle at point, y component
G4double pz_GeV; // momentum (GeV/c) of shower particle at point, z component
G4double x_cm; // global x coordinate of shower particle at point (cm)
G4double y_cm; // global y coordinate of shower particle at point (cm)
G4double z_cm; // global z coordinate of shower particle at point (cm)
G4double t_ns; // time of shower particle crossing at point (ns)
G4int track_; // Geant4 track ID of particle making this shower
G4int trackID_; // GlueX-assigned track ID of particle making this shower

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

typedef G4THitsMap<GlueXHitECALpoint> GlueXHitsMapECALpoint;

extern G4ThreadLocal G4Allocator<GlueXHitECALpoint>* GlueXHitECALpointAllocator;

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

inline void GlueXHitECALpoint::operator delete(void *aHit)
{
GlueXHitECALpointAllocator->FreeSingle((GlueXHitECALpoint*) aHit);
}

#endif
Loading

0 comments on commit 19b0b2b

Please sign in to comment.