CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/SimG4CMS/ShowerLibraryProducer/src/FiberSD.cc

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   // Now attach the right detectors (LogicalVolumes) to me
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   std::vector<HFShower::Hit> hits = theShower->getHits(aStep);
00066 
00067   if (hits.size() > 0) {
00068     std::vector<HFShowerPhoton> thePE;
00069     for (unsigned int i=0; i<hits.size(); i++) {
00070       HFShowerPhoton pe = HFShowerPhoton(hits[i].position.x(), 
00071                                          hits[i].position.y(), 
00072                                          hits[i].position.z(), 
00073                                          hits[i].wavelength, hits[i].time);
00074       thePE.push_back(pe);
00075     }
00076     int trackID = aStep->GetTrack()->GetTrackID();
00077     G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00078     const G4VTouchable* touch = preStepPoint->GetTouchable();
00079     G4LogicalVolume* lv = touch->GetVolume(0)->GetLogicalVolume();
00080     int depth = (touch->GetReplicaNumber(0))%10;
00081     int detID = setDetUnitId(aStep);
00082     math::XYZPoint theHitPos(preStepPoint->GetPosition().x(),
00083                              preStepPoint->GetPosition().y(),
00084                              preStepPoint->GetPosition().z());
00085     
00086     FiberG4Hit *aHit = new FiberG4Hit(lv, detID, depth, trackID);
00087     aHit->setNpe(hits.size());
00088     aHit->setPos(theHitPos);
00089     aHit->setTime(preStepPoint->GetGlobalTime());
00090     aHit->setPhoton(thePE);
00091 
00092     LogDebug("FiberSim") << "FiberSD: Hit created at " << lv->GetName()
00093                          << " DetID: " << aHit->towerId() << " Depth: " 
00094                          << aHit->depth() << " Track ID: " << aHit->trackId() 
00095                          << " Nb. of Cerenkov Photons: " << aHit->npe()
00096                          << " Time: " << aHit->time() << " at " 
00097                          << aHit->hitPos();
00098     for (unsigned int i=0; i<thePE.size(); i++) 
00099       LogDebug("FiberSim") << "FiberSD: PE[" << i << "] " << thePE[i];
00100 
00101     theHC->insert(aHit);
00102   }
00103   return true;
00104 }
00105 
00106 void FiberSD::EndOfEvent(G4HCofThisEvent * HCE) {
00107  
00108   LogDebug("FiberSim") << "FiberSD: Sees" << theHC->entries() << " hits";
00109   clear();
00110 }
00111 
00112 void FiberSD::clear() {}
00113 
00114 void FiberSD::DrawAll()  {}
00115 
00116 void FiberSD::PrintAll() {}
00117 
00118 void FiberSD::update(const BeginOfRun *) {}
00119 
00120 void FiberSD::update(const BeginOfEvent *) {}
00121 
00122 void FiberSD::update(const ::EndOfEvent *) {}
00123 
00124 void FiberSD::clearHits() {}
00125 
00126 uint32_t FiberSD::setDetUnitId(G4Step* aStep) {
00127   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00128   int fibre = (touch->GetReplicaNumber(1))%10;
00129   int cell  = (touch->GetReplicaNumber(2));
00130   int tower = (touch->GetReplicaNumber(3));
00131   return ((tower*1000+cell)*10+fibre);
00132 }
00133 
00134 void FiberSD::fillHits(edm::PCaloHitContainer&, std::string) {}