Go to the documentation of this file.00001 #include "SimG4CMS/ShowerLibraryProducer/interface/FiberSD.h"
00002 #include "SimDataFormats/CaloHit/interface/HFShowerPhoton.h"
00003 #include "DataFormats/Math/interface/Point3D.h"
00004
00005 #include "G4VPhysicalVolume.hh"
00006 #include "G4PVPlacement.hh"
00007 #include "G4HCofThisEvent.hh"
00008 #include "G4TouchableHistory.hh"
00009 #include "G4Track.hh"
00010 #include "G4Step.hh"
00011 #include "G4VSolid.hh"
00012 #include "G4DynamicParticle.hh"
00013 #include "G4ParticleDefinition.hh"
00014 #include "G4SDManager.hh"
00015 #include "G4ios.hh"
00016
00017 FiberSD::FiberSD(std::string name, const DDCompactView & cpv,
00018 SensitiveDetectorCatalog & clg, edm::ParameterSet const & p,
00019 const SimTrackManager* manager) :
00020 SensitiveCaloDetector(name, cpv, clg, p), theName(name),
00021 m_trackManager(manager), theHCID(-1), theHC(0) {
00022
00023 collectionName.insert(name);
00024 LogDebug("FiberSim") << "***************************************************"
00025 << "\n"
00026 << "* *"
00027 << "\n"
00028 << "* Constructing a FiberSD with name " << GetName()
00029 << "\n"
00030 << "* *"
00031 << "\n"
00032 << "***************************************************";
00033 theShower = new HFShower(name, cpv, p, 1);
00034
00035
00036
00037
00038 std::vector<std::string> lvNames = clg.logicalNames(name);
00039 this->Register();
00040 for (std::vector<std::string>::iterator it=lvNames.begin();
00041 it !=lvNames.end(); it++){
00042 this->AssignSD(*it);
00043 LogDebug("FiberSim") << "FiberSD : Assigns SD to LV " << (*it);
00044 }
00045 }
00046
00047 FiberSD::~FiberSD() {
00048
00049 if (theShower) delete theShower;
00050 if (theHC) delete theHC;
00051 }
00052
00053 void FiberSD::Initialize(G4HCofThisEvent * HCE) {
00054
00055 LogDebug("FiberSim") << "FiberSD : Initialize called for " << GetName();
00056 theHC = new FiberG4HitsCollection(GetName(), collectionName[0]);
00057 if (theHCID<0)
00058 theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
00059 HCE->AddHitsCollection(theHCID, theHC);
00060
00061 }
00062
00063 G4bool FiberSD::ProcessHits(G4Step * aStep, G4TouchableHistory*) {
00064
00065
00066 double zoffset = 1000;
00067 std::vector<HFShower::Hit> hits = theShower->getHits(aStep,true,zoffset);
00068
00069
00070 if (hits.size() > 0) {
00071 std::vector<HFShowerPhoton> thePE;
00072 for (unsigned int i=0; i<hits.size(); i++) {
00073
00074 HFShowerPhoton pe = HFShowerPhoton(hits[i].position.x(),
00075 hits[i].position.y(),
00076 hits[i].position.z(),
00077 hits[i].wavelength, hits[i].time);
00078 thePE.push_back(pe);
00079 }
00080 int trackID = aStep->GetTrack()->GetTrackID();
00081 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00082 const G4VTouchable* touch = preStepPoint->GetTouchable();
00083 G4LogicalVolume* lv = touch->GetVolume(0)->GetLogicalVolume();
00084 int depth = (touch->GetReplicaNumber(0))%10;
00085 int detID = setDetUnitId(aStep);
00086 math::XYZPoint theHitPos(preStepPoint->GetPosition().x(),
00087 preStepPoint->GetPosition().y(),
00088 preStepPoint->GetPosition().z());
00089
00090
00091 FiberG4Hit *aHit = new FiberG4Hit(lv, detID, depth, trackID);
00092 std::cout<<"hit size "<<hits.size()<<" npe"<<aHit->npe()<<std::endl;
00093 std::cout<<"pre hit position "<<aHit->hitPos()<<std::endl;
00094 aHit->setNpe(hits.size());
00095 aHit->setPos(theHitPos);
00096 aHit->setTime(preStepPoint->GetGlobalTime());
00097 aHit->setPhoton(thePE);
00098 std::cout<<"ShowerPhoton position "<<thePE[0].x()<<" "<<thePE[0].y()<<" "<<thePE[0].z()<<std::endl;
00099
00100 LogDebug("FiberSim") << "FiberSD: Hit created at " << lv->GetName()
00101 << " DetID: " << aHit->towerId() << " Depth: "
00102 << aHit->depth() << " Track ID: " << aHit->trackId()
00103 << " Nb. of Cerenkov Photons: " << aHit->npe()
00104 << " Time: " << aHit->time() << " at "
00105 << aHit->hitPos();
00106 for (unsigned int i=0; i<thePE.size(); i++)
00107 LogDebug("FiberSim") << "FiberSD: PE[" << i << "] " << thePE[i];
00108
00109 theHC->insert(aHit);
00110 }
00111 return true;
00112 }
00113
00114 void FiberSD::EndOfEvent(G4HCofThisEvent * HCE) {
00115
00116 LogDebug("FiberSim") << "FiberSD: Sees" << theHC->entries() << " hits";
00117 clear();
00118 std::cout<<"theHC entries = "<<theHC->entries()<<std::endl;
00119 }
00120
00121 void FiberSD::clear() {}
00122
00123 void FiberSD::DrawAll() {}
00124
00125 void FiberSD::PrintAll() {}
00126
00127 void FiberSD::update(const BeginOfRun *) {}
00128
00129 void FiberSD::update(const BeginOfEvent *) {}
00130
00131 void FiberSD::update(const ::EndOfEvent *) {}
00132
00133 void FiberSD::clearHits() {}
00134
00135 uint32_t FiberSD::setDetUnitId(G4Step* aStep) {
00136 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00137 int fibre = (touch->GetReplicaNumber(1))%10;
00138 int cell = (touch->GetReplicaNumber(2));
00139 int tower = (touch->GetReplicaNumber(3));
00140 return ((tower*1000+cell)*10+fibre);
00141 }
00142
00143 void FiberSD::fillHits(edm::PCaloHitContainer&, std::string) {}