CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FiberSD.cc
Go to the documentation of this file.
4 
5 #include "G4VPhysicalVolume.hh"
6 #include "G4PVPlacement.hh"
7 #include "G4HCofThisEvent.hh"
8 #include "G4TouchableHistory.hh"
9 #include "G4Track.hh"
10 #include "G4Step.hh"
11 #include "G4VSolid.hh"
12 #include "G4DynamicParticle.hh"
13 #include "G4ParticleDefinition.hh"
14 #include "G4SDManager.hh"
15 #include "G4ios.hh"
16 
17 FiberSD::FiberSD(std::string name, const DDCompactView & cpv,
19  const SimTrackManager* manager) :
20  SensitiveCaloDetector(name, cpv, clg, p), theName(name),
21  m_trackManager(manager), theHCID(-1), theHC(0) {
22 
23  collectionName.insert(name);
24  LogDebug("FiberSim") << "***************************************************"
25  << "\n"
26  << "* *"
27  << "\n"
28  << "* Constructing a FiberSD with name " << GetName()
29  << "\n"
30  << "* *"
31  << "\n"
32  << "***************************************************";
33  theShower = new HFShower(name, cpv, p, 1);
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") << "FiberSD : Assigns SD to LV " << (*it);
44  }
45 }
46 
48 
49  if (theShower) delete theShower;
50  if (theHC) delete theHC;
51 }
52 
53 void FiberSD::Initialize(G4HCofThisEvent * HCE) {
54 
55  LogDebug("FiberSim") << "FiberSD : Initialize called for " << GetName();
56  theHC = new FiberG4HitsCollection(GetName(), collectionName[0]);
57  if (theHCID<0)
58  theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
59  HCE->AddHitsCollection(theHCID, theHC);
60 
61 }
62 
63 G4bool FiberSD::ProcessHits(G4Step * aStep, G4TouchableHistory*) {
64 
65  std::vector<HFShower::Hit> hits = theShower->getHits(aStep);
66 
67  if (hits.size() > 0) {
68  std::vector<HFShowerPhoton> thePE;
69  for (unsigned int i=0; i<hits.size(); i++) {
70  HFShowerPhoton pe = HFShowerPhoton(hits[i].position.x(),
71  hits[i].position.y(),
72  hits[i].position.z(),
73  hits[i].wavelength, hits[i].time);
74  thePE.push_back(pe);
75  }
76  int trackID = aStep->GetTrack()->GetTrackID();
77  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
78  const G4VTouchable* touch = preStepPoint->GetTouchable();
79  G4LogicalVolume* lv = touch->GetVolume(0)->GetLogicalVolume();
80  int depth = (touch->GetReplicaNumber(0))%10;
81  int detID = setDetUnitId(aStep);
82  math::XYZPoint theHitPos(preStepPoint->GetPosition().x(),
83  preStepPoint->GetPosition().y(),
84  preStepPoint->GetPosition().z());
85 
86  FiberG4Hit *aHit = new FiberG4Hit(lv, detID, depth, trackID);
87  aHit->setNpe(hits.size());
88  aHit->setPos(theHitPos);
89  aHit->setTime(preStepPoint->GetGlobalTime());
90  aHit->setPhoton(thePE);
91 
92  LogDebug("FiberSim") << "FiberSD: Hit created at " << lv->GetName()
93  << " DetID: " << aHit->towerId() << " Depth: "
94  << aHit->depth() << " Track ID: " << aHit->trackId()
95  << " Nb. of Cerenkov Photons: " << aHit->npe()
96  << " Time: " << aHit->time() << " at "
97  << aHit->hitPos();
98  for (unsigned int i=0; i<thePE.size(); i++)
99  LogDebug("FiberSim") << "FiberSD: PE[" << i << "] " << thePE[i];
100 
101  theHC->insert(aHit);
102  }
103  return true;
104 }
105 
106 void FiberSD::EndOfEvent(G4HCofThisEvent * HCE) {
107 
108  LogDebug("FiberSim") << "FiberSD: Sees" << theHC->entries() << " hits";
109  clear();
110 }
111 
112 void FiberSD::clear() {}
113 
115 
117 
118 void FiberSD::update(const BeginOfRun *) {}
119 
121 
122 void FiberSD::update(const ::EndOfEvent *) {}
123 
125 
126 uint32_t FiberSD::setDetUnitId(G4Step* aStep) {
127  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
128  int fibre = (touch->GetReplicaNumber(1))%10;
129  int cell = (touch->GetReplicaNumber(2));
130  int tower = (touch->GetReplicaNumber(3));
131  return ((tower*1000+cell)*10+fibre);
132 }
133 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< PCaloHit > PCaloHitContainer
std::vector< std::string > logicalNames(std::string &readoutName)
virtual void DrawAll()
Definition: FiberSD.cc:114
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::vector< Hit > getHits(G4Step *aStep)
Definition: HFShower.cc:70
virtual void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
Definition: FiberSD.cc:118
virtual void fillHits(edm::PCaloHitContainer &, std::string)
Definition: FiberSD.cc:134
std::string const collectionName[nCollections]
Definition: Collections.h:39
virtual void PrintAll()
Definition: FiberSD.cc:116
FiberSD(std::string, const DDCompactView &, SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: FiberSD.cc:17
HFShower * theShower
Definition: FiberSD.h:57
virtual uint32_t setDetUnitId(G4Step *)
Definition: FiberSD.cc:126
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
FiberG4HitsCollection * theHC
Definition: FiberSD.h:60
G4THitsCollection< FiberG4Hit > FiberG4HitsCollection
Definition: FiberG4Hit.h:59
virtual void AssignSD(std::string &vname)
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual void clearHits()
Definition: FiberSD.cc:124
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: FiberSD.cc:53
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition: FiberSD.cc:106
virtual ~FiberSD()
Definition: FiberSD.cc:47
virtual void clear()
Definition: FiberSD.cc:112
G4int theHCID
Definition: FiberSD.h:59
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
Definition: FiberSD.cc:63