test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HFWedgeSD.cc
Go to the documentation of this file.
3 
4 #include "G4VPhysicalVolume.hh"
5 #include "G4PVPlacement.hh"
6 #include "G4HCofThisEvent.hh"
7 #include "G4TouchableHistory.hh"
8 #include "G4Track.hh"
9 #include "G4Step.hh"
10 #include "G4VSolid.hh"
11 #include "G4DynamicParticle.hh"
12 #include "G4ParticleDefinition.hh"
13 #include "G4SDManager.hh"
14 #include "G4ios.hh"
15 
16 #include "G4PhysicalConstants.hh"
17 #include "G4SystemOfUnits.hh"
18 
21  const SimTrackManager* manager) :
22  SensitiveCaloDetector(name, cpv, clg, p), theName(name),
23  m_trackManager(manager), hcID(-1), theHC(0), currentHit(0) {
24 
25  collectionName.insert(name);
26  LogDebug("FiberSim") << "***************************************************"
27  << "\n"
28  << "* *"
29  << "\n"
30  << "* Constructing a HFWedgeSD with name " << GetName()
31  << "\n"
32  << "* *"
33  << "\n"
34  << "***************************************************";
35  //
36  // Now attach the right detectors (LogicalVolumes) to me
37  //
38  std::vector<std::string> lvNames = clg.logicalNames(name);
39  this->Register();
40  for (std::vector<std::string>::iterator it=lvNames.begin();
41  it !=lvNames.end(); it++){
42  this->AssignSD(*it);
43  LogDebug("FiberSim") << "HFWedgeSD : Assigns SD to LV " << (*it);
44  }
45 }
46 
48  if (theHC) delete theHC;
49 }
50 
51 void HFWedgeSD::Initialize(G4HCofThisEvent * HCE) {
52 
53  LogDebug("FiberSim") << "HFWedgeSD : Initialize called for " << GetName();
54  theHC = new HFShowerG4HitsCollection(GetName(), collectionName[0]);
55  if (hcID<0)
56  hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
57  HCE->AddHitsCollection(hcID, theHC);
58 
59  clearHits();
60 }
61 
62 G4bool HFWedgeSD::ProcessHits(G4Step * aStep, G4TouchableHistory*) {
63 
64  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
65  const G4VTouchable* touch = preStepPoint->GetTouchable();
66  currentID = setDetUnitId(aStep);
67  trackID = aStep->GetTrack()->GetTrackID();
68  edep = aStep->GetTotalEnergyDeposit();
69  time = (preStepPoint->GetGlobalTime())/ns;
70 
71  globalPos = preStepPoint->GetPosition();
72  localPos = touch->GetHistory()->GetTopTransform().TransformPoint(globalPos);
73  const G4DynamicParticle* particle = aStep->GetTrack()->GetDynamicParticle();
74  momDir = particle->GetMomentumDirection();
75 
76  if (hitExists() == false && edep>0.)
78 
79  return true;
80 }
81 
82 void HFWedgeSD::EndOfEvent(G4HCofThisEvent * HCE) {
83 
84  LogDebug("FiberSim") << "HFWedgeSD: Sees" << theHC->entries() << " hits";
85  clear();
86 }
87 
89 
91 
93 
95 
96  // Update if in the same detector, time-slice and for same track
97  if (currentID == previousID) {
99  return true;
100  }
101 
102  std::map<int,HFShowerG4Hit*>::const_iterator it = hitMap.find(currentID);
103  if (it != hitMap.end()) {
105  return true;
106  }
107 
108  return false;
109 }
110 
112 
113  LogDebug("FiberSim") << "HFWedgeSD::CreateNewHit for ID " << currentID
114  << " Track " << trackID << " Edep: " << edep/MeV
115  << " MeV; Time: " << time << " ns; Position (local) "
116  << localPos << " (global ) " << globalPos
117  << " direction " << momDir;
118  HFShowerG4Hit* aHit = new HFShowerG4Hit;
119  aHit->setHitId(currentID);
120  aHit->setTrackId(trackID);
121  aHit->setTime(time);
122  aHit->setLocalPos(localPos);
123  aHit->setGlobalPos(globalPos);
124  aHit->setPrimMomDir(momDir);
125  updateHit(aHit);
126 
127  theHC->insert(aHit);
128  hitMap.insert(std::pair<int,HFShowerG4Hit*>(previousID,aHit));
129 
130  return aHit;
131 }
132 
134 
135  if (edep != 0) {
136  aHit->updateEnergy(edep);
137  LogDebug("FiberSim") << "HFWedgeSD: Add energy deposit in " << currentID
138  << " edep " << edep/MeV << " MeV";
139  }
141 }
142 
144  hitMap.erase (hitMap.begin(), hitMap.end());
145  previousID = -1;
146 }
147 
148 uint32_t HFWedgeSD::setDetUnitId(G4Step* aStep) {
149  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
150  return (touch->GetReplicaNumber(0));
151 }
152 
#define LogDebug(id)
virtual void PrintAll()
Definition: HFWedgeSD.cc:92
virtual void clearHits()
Definition: HFWedgeSD.cc:143
std::vector< PCaloHit > PCaloHitContainer
std::vector< std::string > logicalNames(std::string &readoutName)
int previousID
Definition: HFWedgeSD.h:58
void updateHit(HFShowerG4Hit *)
Definition: HFWedgeSD.cc:133
int hcID
Definition: HFWedgeSD.h:54
G4ThreeVector momDir
Definition: HFWedgeSD.h:60
void setLocalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:47
virtual uint32_t setDetUnitId(G4Step *)
Definition: HFWedgeSD.cc:148
type of data representation of DDCompactView
Definition: DDCompactView.h:77
const double MeV
virtual void clear()
Definition: HFWedgeSD.cc:88
virtual void EndOfEvent(G4HCofThisEvent *eventHC)
Definition: HFWedgeSD.cc:82
std::string const collectionName[nCollections]
Definition: Collections.h:45
double edep
Definition: HFWedgeSD.h:59
void setTrackId(G4int trackId)
Definition: HFShowerG4Hit.h:43
int trackID
Definition: HFWedgeSD.h:58
G4bool hitExists()
Definition: HFWedgeSD.cc:94
G4ThreeVector localPos
Definition: HFWedgeSD.h:60
void setHitId(G4int hitId)
Definition: HFShowerG4Hit.h:42
void setTime(G4double t)
Definition: HFShowerG4Hit.h:46
HFShowerG4HitsCollection * theHC
Definition: HFWedgeSD.h:55
void setPrimMomDir(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:49
HFShowerG4Hit * currentHit
Definition: HFWedgeSD.h:61
virtual void AssignSD(std::string &vname)
void setGlobalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:48
double time
Definition: HFWedgeSD.h:59
void updateEnergy(G4double edep)
Definition: HFShowerG4Hit.h:45
HFShowerG4Hit * createNewHit()
Definition: HFWedgeSD.cc:111
int currentID
Definition: HFWedgeSD.h:58
virtual bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory)
Definition: HFWedgeSD.cc:62
virtual void DrawAll()
Definition: HFWedgeSD.cc:90
std::map< int, HFShowerG4Hit * > hitMap
Definition: HFWedgeSD.h:56
virtual ~HFWedgeSD()
Definition: HFWedgeSD.cc:47
virtual void fillHits(edm::PCaloHitContainer &, std::string)
Definition: HFWedgeSD.cc:153
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: HFWedgeSD.cc:51
G4THitsCollection< HFShowerG4Hit > HFShowerG4HitsCollection
Definition: HFShowerG4Hit.h:60
G4ThreeVector globalPos
Definition: HFWedgeSD.h:60
HFWedgeSD(std::string name, const DDCompactView &cpv, SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *)
Definition: HFWedgeSD.cc:19