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.
8 
9 #include "G4VPhysicalVolume.hh"
10 #include "G4PVPlacement.hh"
11 #include "G4HCofThisEvent.hh"
12 #include "G4TouchableHistory.hh"
13 #include "G4Track.hh"
14 #include "G4Step.hh"
15 #include "G4VSolid.hh"
16 #include "G4DynamicParticle.hh"
17 #include "G4ParticleDefinition.hh"
18 #include "G4SDManager.hh"
19 #include "G4ios.hh"
20 
22  const SensitiveDetectorCatalog & clg, edm::ParameterSet const & p,
23  const SimTrackManager* manager) :
24  SensitiveCaloDetector(name, cpv, clg, p), theName(name),
25  m_trackManager(manager), theHCID(-1), theHC(0) {
26 
27  collectionName.insert(name);
28  LogDebug("FiberSim") << "***************************************************"
29  << "\n"
30  << "* *"
31  << "\n"
32  << "* Constructing a FiberSD with name " << GetName()
33  << "\n"
34  << "* *"
35  << "\n"
36  << "***************************************************";
37  theShower = new HFShower(name, cpv, p, 1);
38 
39  //
40  // Now attach the right detectors (LogicalVolumes) to me
41  //
42  const std::vector<std::string>& lvNames = clg.logicalNames(name);
43  this->Register();
44  for (std::vector<std::string>::const_iterator it=lvNames.begin();
45  it !=lvNames.end(); it++){
46  this->AssignSD(*it);
47  LogDebug("FiberSim") << "FiberSD : Assigns SD to LV " << (*it);
48  }
49 }
50 
52 
53  if (theShower) delete theShower;
54  if (theHC) delete theHC;
55 }
56 
57 void FiberSD::Initialize(G4HCofThisEvent * HCE) {
58 
59  LogDebug("FiberSim") << "FiberSD : Initialize called for " << GetName();
60  theHC = new FiberG4HitsCollection(GetName(), collectionName[0]);
61  if (theHCID<0)
62  theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
63  HCE->AddHitsCollection(theHCID, theHC);
64 
65 }
66 
67 G4bool FiberSD::ProcessHits(G4Step * aStep, G4TouchableHistory*) {
68 
69  //std::vector<HFShower::Hit> hits = theShower->getHits(aStep);
70  double zoffset = 1000;
71  std::vector<HFShower::Hit> hits = theShower->getHits(aStep,true,zoffset);
72 
73 
74  if (hits.size() > 0) {
75  std::vector<HFShowerPhoton> thePE;
76  for (unsigned int i=0; i<hits.size(); i++) {
77  //std::cout<<"hit position z "<<hits[i].position.z()<<std::endl;
78  HFShowerPhoton pe = HFShowerPhoton(hits[i].position.x(),
79  hits[i].position.y(),
80  hits[i].position.z(),
81  hits[i].wavelength, hits[i].time);
82  thePE.push_back(pe);
83  }
84  int trackID = aStep->GetTrack()->GetTrackID();
85  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
86  const G4VTouchable* touch = preStepPoint->GetTouchable();
87  G4LogicalVolume* lv = touch->GetVolume(0)->GetLogicalVolume();
88  int depth = (touch->GetReplicaNumber(0))%10;
89  int detID = setDetUnitId(aStep);
90  math::XYZPoint theHitPos(preStepPoint->GetPosition().x(),
91  preStepPoint->GetPosition().y(),
92  preStepPoint->GetPosition().z());
93  //std::cout<<"presteppoint position z "<<preStepPoint->GetPosition().z()<<std::endl;
94 
95  FiberG4Hit *aHit = new FiberG4Hit(lv, detID, depth, trackID);
96  std::cout<<"hit size "<<hits.size()<<" npe"<<aHit->npe()<<std::endl;
97  std::cout<<"pre hit position "<<aHit->hitPos()<<std::endl;
98  aHit->setNpe(hits.size());
99  aHit->setPos(theHitPos);
100  aHit->setTime(preStepPoint->GetGlobalTime());
101  aHit->setPhoton(thePE);
102  std::cout<<"ShowerPhoton position "<<thePE[0].x()<<" "<<thePE[0].y()<<" "<<thePE[0].z()<<std::endl;
103 
104  LogDebug("FiberSim") << "FiberSD: Hit created at " << lv->GetName()
105  << " DetID: " << aHit->towerId() << " Depth: "
106  << aHit->depth() << " Track ID: " << aHit->trackId()
107  << " Nb. of Cerenkov Photons: " << aHit->npe()
108  << " Time: " << aHit->time() << " at "
109  << aHit->hitPos();
110  for (unsigned int i=0; i<thePE.size(); i++)
111  LogDebug("FiberSim") << "FiberSD: PE[" << i << "] " << thePE[i];
112 
113  theHC->insert(aHit);
114  }
115  return true;
116 }
117 
118 void FiberSD::EndOfEvent(G4HCofThisEvent * HCE) {
119 
120  LogDebug("FiberSim") << "FiberSD: Sees" << theHC->entries() << " hits";
121  clear();
122  std::cout<<"theHC entries = "<<theHC->entries()<<std::endl;
123 }
124 
125 void FiberSD::clear() {}
126 
128 
130 
131 void FiberSD::update(const BeginOfJob * job) {
132 
133  const edm::EventSetup* es = (*job)();
135  es->get<HcalSimNumberingRecord>().get(hdc);
136  if (hdc.isValid()) {
137  HcalDDDSimConstants *hcalConstants = (HcalDDDSimConstants*)(&(*hdc));
138  theShower->initRun(0, hcalConstants);
139  } else {
140  edm::LogError("HcalSim") << "HCalSD : Cannot find HcalDDDSimConstant";
141  throw cms::Exception("Unknown", "HCalSD") << "Cannot find HcalDDDSimConstant" << "\n";
142  }
143 
144 }
145 
146 void FiberSD::update(const BeginOfRun *) {}
147 
149 
150 void FiberSD::update(const ::EndOfEvent *) {}
151 
153 
154 uint32_t FiberSD::setDetUnitId(G4Step* aStep) {
155  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
156  int fibre = (touch->GetReplicaNumber(1))%10;
157  int cell = (touch->GetReplicaNumber(2));
158  int tower = (touch->GetReplicaNumber(3));
159  return ((tower*1000+cell)*10+fibre);
160 }
161 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< PCaloHit > PCaloHitContainer
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
Definition: HFShower.cc:454
virtual void DrawAll()
Definition: FiberSD.cc:127
const std::vector< std::string > & logicalNames(const std::string &readoutName) const
virtual void update(const BeginOfJob *)
This routine will be called when the appropriate signal arrives.
Definition: FiberSD.cc:131
type of data representation of DDCompactView
Definition: DDCompactView.h:77
virtual void AssignSD(const std::string &vname)
virtual void fillHits(edm::PCaloHitContainer &, std::string)
Definition: FiberSD.cc:162
std::string const collectionName[nCollections]
Definition: Collections.h:45
virtual void PrintAll()
Definition: FiberSD.cc:129
std::vector< Hit > getHits(G4Step *aStep, double weight)
Definition: HFShower.cc:47
HFShower * theShower
Definition: FiberSD.h:60
virtual uint32_t setDetUnitId(G4Step *)
Definition: FiberSD.cc:154
FiberSD(std::string, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: FiberSD.cc:21
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:56
FiberG4HitsCollection * theHC
Definition: FiberSD.h:63
G4THitsCollection< FiberG4Hit > FiberG4HitsCollection
Definition: FiberG4Hit.h:59
static int position[264][3]
Definition: ReadPGInfo.cc:509
virtual void clearHits()
Definition: FiberSD.cc:152
tuple cout
Definition: gather_cfg.py:145
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: FiberSD.cc:57
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition: FiberSD.cc:118
virtual ~FiberSD()
Definition: FiberSD.cc:51
virtual void clear()
Definition: FiberSD.cc:125
G4int theHCID
Definition: FiberSD.h:62
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
Definition: FiberSD.cc:67