Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-09 03:15:24

0001 #ifndef SimG4CMS_CaloG4Hit_h
0002 #define SimG4CMS_CaloG4Hit_h 1
0003 ///////////////////////////////////////////////////////////////////////////////
0004 // File: CaloG4Hit.h
0005 // Date: 10.02 Taken from CMSCaloHit
0006 //
0007 // Hit class for Calorimeters (Ecal, Hcal, ...)
0008 //
0009 // One Hit object should be created
0010 // -for each new particle entering the calorimeter
0011 // -for each detector unit (= crystal or fibre or scintillator layer)
0012 // -for each nanosecond of the shower development
0013 //
0014 // This implies that all hit objects created for a given shower
0015 // have the same value for
0016 // - Entry (= local coordinates of the entrance point of the particle
0017 //            in the unit where the shower starts)
0018 // - the TrackID (= Identification number of the incident particle)
0019 // - the IncidentEnergy (= energy of that particle)
0020 //
0021 // Modified:
0022 //
0023 ///////////////////////////////////////////////////////////////////////////////
0024 
0025 #include "SimG4CMS/Calo/interface/CaloHitID.h"
0026 #include "DataFormats/Math/interface/Point3D.h"
0027 #include <iostream>
0028 
0029 #include "G4Allocator.hh"
0030 #include "G4VHit.hh"
0031 
0032 class CaloG4Hit : public G4VHit {
0033 public:
0034   CaloG4Hit();
0035   ~CaloG4Hit() override;
0036   CaloG4Hit(const CaloG4Hit& right);
0037   const CaloG4Hit& operator=(const CaloG4Hit& right);
0038   bool operator==(const CaloG4Hit&) { return false; }
0039   inline void* operator new(size_t);
0040   inline void operator delete(void* CaloG4Hit);
0041 
0042   void Draw() override {}
0043   void Print() override;
0044 
0045 public:
0046   math::XYZPoint getEntry() const { return entry; }
0047   void setEntry(double x, double y, double z) { entry.SetCoordinates(x, y, z); }
0048 
0049   math::XYZPoint getEntryLocal() const { return entryLocal; }
0050   void setEntryLocal(double x, double y, double z) { entryLocal.SetCoordinates(x, y, z); }
0051 
0052   math::XYZPoint getPosition() const { return pos; }
0053   void setPosition(double x, double y, double z) { pos.SetCoordinates(x, y, z); }
0054 
0055   double getEM() const { return elem; }
0056   void setEM(double e) { elem = e; }
0057 
0058   double getHadr() const { return hadr; }
0059   void setHadr(double e) { hadr = e; }
0060 
0061   double getIncidentEnergy() const { return theIncidentEnergy; }
0062   void setIncidentEnergy(double e) { theIncidentEnergy = e; }
0063 
0064   int getTrackID() const { return hitID.trackID(); }
0065 
0066   uint32_t getUnitID() const { return hitID.unitID(); }
0067   double getTimeSlice() const { return hitID.timeSlice(); }
0068   int getTimeSliceID() const { return hitID.timeSliceID(); }
0069   uint16_t getDepth() const { return hitID.depth(); }
0070   bool isFinecaloTrackID() const { return hitID.isFinecaloTrackID(); }
0071 
0072   CaloHitID getID() const { return hitID; }
0073   void setID(uint32_t i, double d, int j, uint16_t k = 0) { hitID.setID(i, d, j, k); }
0074   void setID(const CaloHitID& id) { hitID = id; }
0075 
0076   void addEnergyDeposit(double em, double hd);
0077   void addEnergyDeposit(const CaloG4Hit& aHit);
0078 
0079   double getEnergyDeposit() const { return (elem + hadr); }
0080 
0081 private:
0082   math::XYZPoint entry;       //Entry point (Global coordinate)
0083   math::XYZPoint entryLocal;  //Entry point (Local  coordinate)
0084   math::XYZPoint pos;         //Position    (Global coordinate)
0085   double elem;                //EnergyDeposit of EM particles
0086   double hadr;                //EnergyDeposit of HD particles
0087   double theIncidentEnergy;   //Energy of the primary particle
0088   CaloHitID hitID;            //Identification number of the hit given
0089                               //by primary particle, Cell ID, Time of
0090                               //the hit
0091 };
0092 
0093 class CaloG4HitLess {
0094 public:
0095   bool operator()(const CaloG4Hit* a, const CaloG4Hit* b) {
0096     if (a->getTrackID() != b->getTrackID()) {
0097       return (a->getTrackID() < b->getTrackID());
0098     } else if (a->getUnitID() != b->getUnitID()) {
0099       return (a->getUnitID() < b->getUnitID());
0100     } else if (a->getDepth() != b->getDepth()) {
0101       return (a->getDepth() < b->getDepth());
0102     } else {
0103       return (a->getTimeSliceID() < b->getTimeSliceID());
0104     }
0105   }
0106 };
0107 
0108 class CaloG4HitEqual {
0109 public:
0110   bool operator()(const CaloG4Hit* a, const CaloG4Hit* b) {
0111     return (a->getTrackID() == b->getTrackID() && a->getUnitID() == b->getUnitID() && a->getDepth() == b->getDepth() &&
0112             a->getTimeSliceID() == b->getTimeSliceID());
0113   }
0114 };
0115 
0116 extern G4ThreadLocal G4Allocator<CaloG4Hit>* fpCaloG4HitAllocator;
0117 
0118 inline void* CaloG4Hit::operator new(size_t) {
0119   if (!fpCaloG4HitAllocator)
0120     fpCaloG4HitAllocator = new G4Allocator<CaloG4Hit>;
0121   return (void*)fpCaloG4HitAllocator->MallocSingle();
0122 }
0123 
0124 inline void CaloG4Hit::operator delete(void* aHit) { fpCaloG4HitAllocator->FreeSingle((CaloG4Hit*)aHit); }
0125 
0126 std::ostream& operator<<(std::ostream&, const CaloG4Hit&);
0127 
0128 #endif