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