CMS 3D CMS Logo

CaloSD Class Reference

#include <SimG4CMS/Calo/interface/CaloSD.h>

Inheritance diagram for CaloSD:

SensitiveCaloDetector Observer< const BeginOfRun * > Observer< const BeginOfEvent * > Observer< const EndOfTrack * > Observer< const EndOfEvent * > SensitiveDetector CastorSD DreamSD ECalSD EcalTBH4BeamSD HCalSD HcalTB02SD HcalTB06BeamSD ZdcSD

List of all members.

Public Member Functions

 CaloSD (G4String aSDname, const DDCompactView &cpv, SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *)
virtual void clear ()
virtual void DrawAll ()
virtual void EndOfEvent (G4HCofThisEvent *eventHC)
void fillHits (edm::PCaloHitContainer &, std::string n)
virtual double getEnergyDeposit (G4Step *step)
virtual void Initialize (G4HCofThisEvent *HCE)
virtual void PrintAll ()
virtual bool ProcessHits (G4GFlashSpot *aSpot, G4TouchableHistory *)
virtual bool ProcessHits (G4Step *step, G4TouchableHistory *tHistory)
virtual uint32_t setDetUnitId (G4Step *step)=0
virtual ~CaloSD ()

Protected Member Functions

G4bool checkHit ()
virtual void clearHits ()
CaloG4HitcreateNewHit ()
double getAttenuation (G4Step *aStep, double birk1, double birk2, double birk3)
virtual G4bool getStepInfo (G4Step *aStep)
G4bool hitExists ()
virtual void initRun ()
void resetForNewPrimary (G4ThreeVector, double)
G4ThreeVector setToLocal (G4ThreeVector, const G4VTouchable *)
virtual void update (const ::EndOfEvent *)
virtual void update (const EndOfTrack *trk)
 This routine will be called when the appropriate signal arrives.
virtual void update (const BeginOfEvent *)
 This routine will be called when the appropriate signal arrives.
virtual void update (const BeginOfRun *)
 This routine will be called when the appropriate signal arrives.
void updateHit (CaloG4Hit *)

Protected Attributes

int checkHits
double correctT
bool corrTOFBeam
CaloG4HitcurrentHit
CaloHitID currentID
float edepositEM
float edepositHAD
G4int emPDG
double energyCut
G4ThreeVector entranceLocal
G4ThreeVector entrancePoint
G4int epPDG
G4int gammaPDG
float incidentEnergy
double kmaxIon
double kmaxNeutron
double kmaxProton
const SimTrackManagerm_trackManager
G4ThreeVector posGlobal
G4StepPoint * preStepPoint
CaloHitID previousID
int primIDSaved
bool suppressHeavy
G4Track * theTrack
double tmaxHit
bool useMap

Private Member Functions

std::pair< bool, boolsaveHit (CaloG4Hit *)
void storeHit (CaloG4Hit *)
void summarize ()

Private Attributes

int hcID
std::map< CaloHitID, CaloG4Hit * > hitMap
std::vector< CaloG4Hit * > hitvec
CaloSlaveSDslave
CaloG4HitCollectiontheHC
std::map< int, TrackWithHistory * > tkMap


Detailed Description

Definition at line 40 of file CaloSD.h.


Constructor & Destructor Documentation

CaloSD::CaloSD ( G4String  aSDname,
const DDCompactView cpv,
SensitiveDetectorCatalog clg,
edm::ParameterSet const &  p,
const SimTrackManager manager 
)

Definition at line 19 of file CaloSD.cc.

References SensitiveDetector::AssignSD(), checkHits, correctT, corrTOFBeam, currentID, energyCut, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), it, kmaxIon, kmaxNeutron, kmaxProton, LogDebug, SensitiveDetectorCatalog::logicalNames(), previousID, SensitiveDetector::Register(), slave, suppressHeavy, tmaxHit, and useMap.

00021                                                                           : 
00022   SensitiveCaloDetector(name, cpv, clg, p),
00023   G4VGFlashSensitiveDetector(), 
00024   theTrack(0), preStepPoint(0), m_trackManager(manager), currentHit(0),
00025   hcID(-1), theHC(0){
00026 
00027   //Add Hcal Sentitive Detector Names
00028 
00029   collectionName.insert(name);
00030 
00031   //Parameters
00032   //  static SimpleConfigurable<float> pEmin(1.0,"CaloSD:EminTrack");
00033   //   static SimpleConfigurable<int>   pcheckHit(25,"CaloSD:CheckHits");
00034   //   static SimpleConfigurable<bool>  pUseMap(false,"CaloSD:UseMap");
00035   edm::ParameterSet m_CaloSD = p.getParameter<edm::ParameterSet>("CaloSD");
00036   energyCut    = m_CaloSD.getParameter<double>("EminTrack")*GeV;
00037   tmaxHit      = m_CaloSD.getParameter<double>("TmaxHit")*ns;
00038   suppressHeavy= m_CaloSD.getParameter<bool>("SuppressHeavy");
00039   kmaxIon      = m_CaloSD.getParameter<double>("IonThreshold")*MeV;
00040   kmaxProton   = m_CaloSD.getParameter<double>("ProtonThreshold")*MeV;
00041   kmaxNeutron  = m_CaloSD.getParameter<double>("NeutronThreshold")*MeV;
00042   checkHits    = m_CaloSD.getUntrackedParameter<int>("CheckHits", 25);
00043   useMap       = m_CaloSD.getUntrackedParameter<bool>("UseMap", true);
00044   int verbn    = m_CaloSD.getUntrackedParameter<int>("Verbosity", 0);
00045   bool on      = m_CaloSD.getUntrackedParameter<bool>("DetailedTiming");
00046   corrTOFBeam  = m_CaloSD.getUntrackedParameter<bool>("CorrectTOFBeam", false);
00047   double beamZ = m_CaloSD.getUntrackedParameter<double>("BeamPosition",0.0)*cm;
00048   correctT     = beamZ/c_light/nanosecond;
00049 
00050   SetVerboseLevel(verbn);
00051   LogDebug("CaloSim") << "***************************************************" 
00052                       << "\n"
00053                       << "*                                                 *" 
00054                       << "\n"
00055                       << "* Constructing a CaloSD  with name " << GetName()
00056                       << "\n"
00057                       << "*                                                 *" 
00058                       << "\n"
00059                       << "***************************************************";
00060 
00061   slave      = new CaloSlaveSD(name);
00062   currentID  = CaloHitID();
00063   previousID = CaloHitID();
00064 
00065   //
00066   // Now attach the right detectors (LogicalVolumes) to me
00067   //
00068   std::vector<std::string> lvNames = clg.logicalNames(name);
00069   this->Register();
00070   for (std::vector<std::string>::iterator it=lvNames.begin();
00071        it !=lvNames.end(); it++){
00072     this->AssignSD(*it);
00073     LogDebug("CaloSim") << "CaloSD : Assigns SD to LV " << (*it);
00074   }
00075 
00076   // timer initialization
00077   if (on) {
00078   //     string trname("CaloSD:");
00079   //     theHitTimer.init( trname + name + ":hits", true);
00080   //   }
00081   //   else {
00082   //     theHitTimer.init( "CaloSensitiveDetector:hits", true);
00083   }
00084 
00085   edm::LogInfo("CaloSim") << "CaloSD: Minimum energy of track for saving it " 
00086                           << energyCut/GeV  << " GeV" << "\n"
00087                           << "        Use of HitID Map " << useMap << "\n"
00088                           << "        Check last " << checkHits 
00089                           << " before saving the hit\n" 
00090                           << "        Correct TOF globally by " << correctT
00091                           << " ns (Flag =" << corrTOFBeam << ")\n"
00092                           << "        Save hits recorded before " << tmaxHit
00093                           << " ns";
00094 }

CaloSD::~CaloSD (  )  [virtual]

Definition at line 96 of file CaloSD.cc.

References slave, and theHC.

00096                 { 
00097   if (slave)           delete slave; 
00098   if (theHC)           delete theHC;
00099 }


Member Function Documentation

G4bool CaloSD::checkHit (  )  [protected]

Definition at line 329 of file CaloSD.cc.

References checkHits, currentHit, currentID, CaloG4Hit::getID(), hitMap, it, j, theHC, updateHit(), and useMap.

Referenced by HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), hitExists(), HCalSD::hitForFibre(), and ProcessHits().

00329                         {
00330 
00331   //look in the HitContainer whether a hit with the same ID already exists:
00332   bool       found = false;
00333   if (useMap) {
00334     std::map<CaloHitID,CaloG4Hit*>::const_iterator it = hitMap.find(currentID);
00335     if (it != hitMap.end()) {
00336       currentHit = it->second;
00337       found      = true;
00338     }
00339   } else {
00340     if (checkHits <= 0) return false;
00341     int  minhit= (theHC->entries()>checkHits ? theHC->entries()-checkHits : 0);
00342     int  maxhit= theHC->entries()-1;
00343 
00344     for (int j=maxhit; j>minhit&&!found; j--) {
00345       CaloG4Hit* aPreviousHit = (*theHC)[j];
00346       if (aPreviousHit->getID() == currentID) {
00347         currentHit = aPreviousHit;
00348         found      = true;
00349       }
00350     }          
00351   }
00352 
00353   if (found) {
00354     updateHit(currentHit);
00355     return true;
00356   } else {
00357     return false;
00358   }    
00359 
00360 }

void CaloSD::clear ( void   )  [virtual]

Definition at line 230 of file CaloSD.cc.

00230 {} 

void CaloSD::clearHits (  )  [protected, virtual]

Implements SensitiveDetector.

Definition at line 569 of file CaloSD.cc.

References hitMap, hitvec, CaloSlaveSD::Initialize(), LogDebug, previousID, primIDSaved, CaloHitID::reset(), and slave.

Referenced by update().

00569                        {
00570 
00571   hitvec.erase (hitvec.begin(), hitvec.end()); 
00572   hitMap.erase (hitMap.begin(), hitMap.end());
00573   previousID.reset();
00574   primIDSaved    = -99;
00575   LogDebug("CaloSim") << "CaloSD: Clears hit vector for " << GetName() << " " 
00576                       << slave;
00577   slave->Initialize();
00578   LogDebug("CaloSim") << "CaloSD: Initialises slave SD for " << GetName();
00579 }

CaloG4Hit * CaloSD::createNewHit (  )  [protected]

Definition at line 362 of file CaloSD.cc.

References currentID, CaloHitID::depth(), edepositEM, edepositHAD, energyCut, entranceLocal, entrancePoint, incidentEnergy, LogDebug, TrackWithHistory::momentum(), NULL, posGlobal, primIDSaved, TrackInformation::putInHistory(), TrackWithHistory::save(), CaloG4Hit::setEntry(), CaloG4Hit::setEntryLocal(), CaloG4Hit::setID(), CaloG4Hit::setIncidentEnergy(), CaloG4Hit::setPosition(), funct::sqrt(), storeHit(), TrackInformation::storeTrack(), theTrack, CaloHitID::timeSliceID(), tkMap, CaloHitID::trackID(), CaloHitID::unitID(), and updateHit().

Referenced by HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), HCalSD::hitForFibre(), ProcessHits(), DreamSD::ProcessHits(), and HCalSD::ProcessHits().

00362                                 {
00363 
00364   LogDebug("CaloSim") << "CaloSD::CreateNewHit for"
00365                       << " Unit " << currentID.unitID() 
00366                       << " " << currentID.depth()
00367                       << " Edeposit = " << edepositEM << " " << edepositHAD;
00368   LogDebug("CaloSim") << " primary "    << currentID.trackID()
00369                       << " time slice " << currentID.timeSliceID()
00370                       << " For Track  " << theTrack->GetTrackID()
00371                       << " which is a " <<theTrack->GetDefinition()->GetParticleName()
00372                       << " of energy "  << theTrack->GetKineticEnergy()/GeV
00373                       << " " << theTrack->GetMomentum().mag()/GeV
00374                       << " daughter of part. " << theTrack->GetParentID()
00375                       << " and created by " ;
00376   
00377   if (theTrack->GetCreatorProcess()!=NULL)
00378     LogDebug("CaloSim") << theTrack->GetCreatorProcess()->GetProcessName() ;
00379   else 
00380     LogDebug("CaloSim") << "NO process";
00381   
00382   CaloG4Hit* aHit = new CaloG4Hit;
00383   aHit->setID(currentID);
00384   aHit->setEntry(entrancePoint.x(),entrancePoint.y(),entrancePoint.z());
00385   aHit->setEntryLocal(entranceLocal.x(),entranceLocal.y(),entranceLocal.z());
00386   aHit->setPosition(posGlobal.x(),posGlobal.y(),posGlobal.z());
00387   aHit->setIncidentEnergy(incidentEnergy);
00388   updateHit(aHit);
00389   
00390   storeHit(aHit);
00391   double etrack = 0;
00392   if (currentID.trackID() == primIDSaved) { // The track is saved; nothing to be done
00393   } else if (currentID.trackID() == theTrack->GetTrackID()) {
00394     etrack= theTrack->GetKineticEnergy();
00395     if (etrack >= energyCut) {
00396       TrackInformation * trkInfo = 
00397         (TrackInformation *)(theTrack->GetUserInformation());
00398       trkInfo->storeTrack(true);
00399       trkInfo->putInHistory();
00400       LogDebug("CaloSim") << "CaloSD: set save the track " 
00401                           << currentID.trackID() << " with Hit";
00402     }
00403   } else {
00404     TrackWithHistory * trkh = tkMap[currentID.trackID()];
00405     LogDebug("CaloSim") << "CaloSD : TrackwithHistory pointer for " 
00406                         << currentID.trackID() << " is " << trkh;
00407     if (trkh != NULL) {
00408       etrack = sqrt(trkh->momentum().Mag2());
00409       if (etrack >= energyCut) {
00410         trkh->save();
00411         LogDebug("CaloSim") << "CaloSD: set save the track " 
00412                             << currentID.trackID() << " with Hit";
00413       }
00414     }
00415   }
00416   primIDSaved = currentID.trackID();
00417   return aHit;
00418 }        

void CaloSD::DrawAll (  )  [virtual]

Definition at line 232 of file CaloSD.cc.

00232 {} 

void CaloSD::EndOfEvent ( G4HCofThisEvent *  eventHC  )  [virtual]

Reimplemented from SensitiveDetector.

Definition at line 211 of file CaloSD.cc.

References hitvec, LogDebug, and theHC.

00211                                          {
00212 
00213   LogDebug("CaloSim") << "CaloSD: EndofEvent entered with " << theHC->entries()
00214                       << " entries";
00215   //  TimeMe("CaloSD:sortAndMergeHits",false);
00216 
00217   hitvec.reserve(theHC->entries());
00218 
00219   // here we loop over transient hits and make them persistent
00220   for (int ii=0; ii<theHC->entries(); ii++) {
00221     CaloG4Hit* aHit = (*theHC)[ii];
00222     LogDebug("CaloSim") << "CaloHit " << ii << " " << *aHit; 
00223     hitvec.push_back(aHit);
00224   }
00225 
00226   LogDebug("CaloSim") << "CaloSD: EndofEvent transfer " << hitvec.size() 
00227                       << " hits to vector" << " for " << GetName();
00228 }

void CaloSD::fillHits ( edm::PCaloHitContainer c,
std::string  n 
) [virtual]

Implements SensitiveCaloDetector.

Definition at line 239 of file CaloSD.cc.

References CaloSlaveSD::hits(), CaloSlaveSD::name(), and slave.

00239                                                          {
00240   if (slave->name() == n) c=slave->hits();
00241 }

double CaloSD::getAttenuation ( G4Step *  aStep,
double  birk1,
double  birk2,
double  birk3 
) [protected]

Definition at line 443 of file CaloSD.cc.

References funct::abs(), c, LogDebug, and weight.

Referenced by HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), EcalTBH4BeamSD::getEnergyDeposit(), HcalTB02SD::getEnergyDeposit(), HcalTB06BeamSD::getEnergyDeposit(), and DreamSD::getStepInfo().

00444                                             {
00445 
00446   double weight = 1.;
00447   double charge = aStep->GetPreStepPoint()->GetCharge();
00448 
00449   if (charge != 0. && aStep->GetStepLength() > 0) {
00450     G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
00451     double density = mat->GetDensity();
00452     double dedx    = aStep->GetTotalEnergyDeposit()/aStep->GetStepLength();
00453     double rkb     = birk1/density;
00454     double c       = birk2*rkb*rkb;
00455     if (std::abs(charge) >= 2.) rkb /= birk3; // based on alpha particle data
00456     weight = 1./(1.+rkb*dedx+c*dedx*dedx);
00457     LogDebug("CaloSim") << "CaloSD::getAttenuation in " << mat->GetName() 
00458                         << " Charge " << charge << " dE/dx " << dedx 
00459                         << " Birk Const " << rkb << ", " << c << " Weight = " 
00460                         << weight << " dE " << aStep->GetTotalEnergyDeposit();
00461   }
00462   return weight;
00463 }

double CaloSD::getEnergyDeposit ( G4Step *  step  )  [virtual]

Reimplemented in ECalSD, HCalSD, EcalTBH4BeamSD, CastorSD, HcalTB02SD, and HcalTB06BeamSD.

Definition at line 195 of file CaloSD.cc.

Referenced by getStepInfo().

00195                                              {
00196   return aStep->GetTotalEnergyDeposit();
00197 }

bool CaloSD::getStepInfo ( G4Step *  aStep  )  [protected, virtual]

Reimplemented in DreamSD.

Definition at line 243 of file CaloSD.cc.

References currentID, edepositEM, edepositHAD, emPDG, epPDG, gammaPDG, getEnergyDeposit(), TrackInformation::getIDonCaloSurface(), LogDebug, preStepPoint, setDetUnitId(), CaloHitID::setID(), theTrack, and CaloHitID::unitID().

Referenced by ProcessHits(), and HCalSD::ProcessHits().

00243                                       {
00244   
00245   preStepPoint = aStep->GetPreStepPoint(); 
00246   theTrack     = aStep->GetTrack();   
00247 
00248   G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
00249   if (particleCode == emPDG ||
00250       particleCode == epPDG ||
00251       particleCode == gammaPDG ) {
00252     edepositEM  = getEnergyDeposit(aStep); edepositHAD = 0.;
00253   } else {
00254     edepositEM  = 0.; edepositHAD = getEnergyDeposit(aStep);
00255   }
00256 
00257   double       time  = (aStep->GetPostStepPoint()->GetGlobalTime())/nanosecond;
00258   unsigned int unitID= setDetUnitId(aStep);
00259   TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
00260   int      primaryID;
00261 
00262   if (trkInfo)
00263     primaryID = trkInfo->getIDonCaloSurface();  
00264   else
00265     primaryID = 0;
00266 
00267   if (primaryID == 0) {
00268     edm::LogWarning("CaloSim") << "CaloSD: Problem with primaryID **** set by "
00269                                << "force to TkID **** " 
00270                                << theTrack->GetTrackID() << " in Volume "
00271                                << preStepPoint->GetTouchable()->GetVolume(0)->GetName();
00272     primaryID = theTrack->GetTrackID();
00273   }
00274 
00275   bool flag = (unitID > 0);
00276   G4TouchableHistory* touch =(G4TouchableHistory*)(theTrack->GetTouchable());
00277   if (flag) {
00278     currentID.setID(unitID, time, primaryID, 0);
00279 
00280     LogDebug("CaloSim") << "CaloSD:: GetStepInfo for"
00281                         << " PV "     << touch->GetVolume(0)->GetName()
00282                         << " PVid = " << touch->GetReplicaNumber(0)
00283                         << " MVid = " << touch->GetReplicaNumber(1)
00284                         << " Unit   " << currentID.unitID() 
00285                         << " Edeposit = " << edepositEM << " " << edepositHAD;
00286   } else {
00287     LogDebug("CaloSim") << "CaloSD:: GetStepInfo for"
00288                         << " PV "     << touch->GetVolume(0)->GetName()
00289                         << " PVid = " << touch->GetReplicaNumber(0)
00290                         << " MVid = " << touch->GetReplicaNumber(1)
00291                         << " Unit   " << std::hex << unitID << std::dec 
00292                         << " Edeposit = " << edepositEM << " " << edepositHAD;
00293   }
00294   return flag;
00295 }

G4bool CaloSD::hitExists (  )  [protected]

Definition at line 306 of file CaloSD.cc.

References checkHit(), currentHit, currentID, posGlobal, preStepPoint, previousID, resetForNewPrimary(), CaloHitID::trackID(), and updateHit().

Referenced by ProcessHits(), DreamSD::ProcessHits(), and HCalSD::ProcessHits().

00306                          {
00307    
00308   if (currentID.trackID()<1) {
00309     edm::LogWarning("CaloSim") << "***** CaloSD error: primaryID = " 
00310                                << currentID.trackID()
00311                                << " maybe detector name changed";
00312   }
00313   
00314   // Update if in the same detector, time-slice and for same track   
00315   if (currentID == previousID) {
00316     updateHit(currentHit);
00317     return true;
00318   }
00319    
00320   // Reset entry point for new primary
00321   posGlobal = preStepPoint->GetPosition();
00322   if (currentID.trackID() != previousID.trackID()) 
00323     resetForNewPrimary(preStepPoint->GetPosition(),
00324                        preStepPoint->GetKineticEnergy());
00325 
00326   return checkHit();
00327 }

void CaloSD::Initialize ( G4HCofThisEvent *  HCE  )  [virtual]

Reimplemented from SensitiveDetector.

Definition at line 199 of file CaloSD.cc.

References hcID, LogDebug, and theHC.

00199                                              { 
00200 
00201   LogDebug("CaloSim") << "CaloSD : Initialize called for " << GetName(); 
00202 
00203   //This initialization is performed at the beginning of an event
00204   //------------------------------------------------------------
00205   theHC = new CaloG4HitCollection(GetName(), collectionName[0]);
00206   if (hcID<0) 
00207     hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
00208   HCE->AddHitsCollection(hcID, theHC);
00209 }

void CaloSD::initRun (  )  [protected, virtual]

Reimplemented in HCalSD, and DreamSD.

Definition at line 581 of file CaloSD.cc.

Referenced by update().

00581 {}

void CaloSD::PrintAll (  )  [virtual]

Definition at line 234 of file CaloSD.cc.

References LogDebug, and theHC.

00234                       {
00235   LogDebug("CaloSim") << "CaloSD: Collection " << theHC->GetName();
00236   theHC->PrintAllHits();
00237 } 

bool CaloSD::ProcessHits ( G4GFlashSpot *  aSpot,
G4TouchableHistory *   
) [virtual]

Definition at line 117 of file CaloSD.cc.

References checkHit(), createNewHit(), currentHit, currentID, edepositEM, edepositHAD, emPDG, entranceLocal, entrancePoint, epPDG, gammaPDG, TrackInformation::getIDonCaloSurface(), incidentEnergy, LogDebug, NULL, posGlobal, previousID, setDetUnitId(), CaloHitID::setID(), theTrack, CaloHitID::trackID(), CaloHitID::unitID(), and updateHit().

00117                                                                  {
00118         
00119   if (aSpot != NULL) {
00120                 
00121     theTrack = const_cast<G4Track *>(aSpot->GetOriginatorTrack()->GetPrimaryTrack());
00122     G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
00123     TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
00124                 
00125     if (particleCode == emPDG ||
00126         particleCode == epPDG ||
00127         particleCode == gammaPDG ) {
00128       edepositEM  = aSpot->GetEnergySpot()->GetEnergy(); edepositHAD = 0.;
00129     } else {
00130       edepositEM  = 0.;  edepositHAD = 0.;
00131     }
00132         
00133     if (edepositEM>0.)  {
00134       G4Step *      fFakeStep          = new G4Step();
00135       G4StepPoint * fFakePreStepPoint  = fFakeStep->GetPreStepPoint();
00136       G4StepPoint * fFakePostStepPoint = fFakeStep->GetPostStepPoint();
00137       fFakePreStepPoint->SetPosition(aSpot->GetPosition());
00138       fFakePostStepPoint->SetPosition(aSpot->GetPosition());
00139       
00140       G4TouchableHandle fTouchableHandle   = aSpot->GetTouchableHandle();
00141       fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
00142       fFakeStep->SetTotalEnergyDeposit(aSpot->GetEnergySpot()->GetEnergy());
00143       
00144       double       time   = 0;
00145       unsigned int unitID = setDetUnitId(fFakeStep);
00146       int      primaryID;
00147 
00148       if (trkInfo)
00149         primaryID  = trkInfo->getIDonCaloSurface();
00150       else
00151         primaryID = 0;
00152       
00153       if (primaryID == 0) {
00154         edm::LogWarning("CaloSim") << "CaloSD: Spot Problem with primaryID "
00155                                    << "**** set by force to  **** " 
00156                                    << theTrack->GetTrackID(); 
00157         primaryID = theTrack->GetTrackID();
00158       }
00159       if (unitID > 0) {
00160         currentID.setID(unitID, time, primaryID, 0);
00161         LogDebug("CaloSim") << "CaloSD:: GetSpotInfo for"
00162                             << " Unit 0x" << std::hex << currentID.unitID() 
00163                             << std::dec << " Edeposit = " << edepositEM << " " 
00164                             << edepositHAD;
00165         // Update if in the same detector, time-slice and for same track   
00166         if (currentID == previousID) {
00167           updateHit(currentHit);
00168         } else {
00169         
00170           posGlobal = aSpot->GetEnergySpot()->GetPosition();
00171           // Reset entry point for new primary
00172           if (currentID.trackID() != previousID.trackID()) {
00173             entrancePoint  = aSpot->GetPosition();
00174             entranceLocal  = aSpot->GetTouchableHandle()->GetHistory()->
00175               GetTopTransform().TransformPoint(entrancePoint);
00176             incidentEnergy = theTrack->GetKineticEnergy();
00177             LogDebug("CaloSim") << "CaloSD: Incident energy " 
00178                                 << incidentEnergy/GeV << " GeV and" 
00179                                 << " entrance point " << entrancePoint 
00180                                 << " (Global) " << entranceLocal << " (Local)";
00181           }
00182         
00183           if (checkHit() == false) currentHit = createNewHit();
00184         }
00185       }
00186       
00187       delete    fFakeStep;
00188     }
00189     return true;
00190     
00191   } 
00192   return false;
00193 }                                   

bool CaloSD::ProcessHits ( G4Step *  step,
G4TouchableHistory *  tHistory 
) [virtual]

Implements SensitiveDetector.

Reimplemented in HCalSD, and DreamSD.

Definition at line 101 of file CaloSD.cc.

References createNewHit(), currentHit, edepositEM, edepositHAD, getStepInfo(), hitExists(), SensitiveDetector::NaNTrap(), and NULL.

00101                                                               {
00102   //  TimeMe t1( theHitTimer, false);
00103   
00104   NaNTrap( aStep ) ;
00105   
00106   if (aStep == NULL) {
00107     return true;
00108   } else {
00109     if (getStepInfo(aStep)) {
00110       if (hitExists() == false && edepositEM+edepositHAD>0.) 
00111         currentHit = createNewHit();
00112     }
00113   }
00114   return true;
00115 } 

void CaloSD::resetForNewPrimary ( G4ThreeVector  point,
double  energy 
) [protected]

Definition at line 433 of file CaloSD.cc.

References entranceLocal, entrancePoint, incidentEnergy, LogDebug, preStepPoint, and setToLocal().

Referenced by HCalSD::getFromLibrary(), HCalSD::getHitPMT(), hitExists(), and HCalSD::setTrackID().

00433                                                                   {
00434   
00435   entrancePoint  = point;
00436   entranceLocal  = setToLocal(entrancePoint, preStepPoint->GetTouchable());
00437   incidentEnergy = energy;
00438   LogDebug("CaloSim") << "CaloSD: Incident energy " << incidentEnergy/GeV 
00439                       << " GeV and" << " entrance point " << entrancePoint 
00440                       << " (Global) " << entranceLocal << " (Local)";
00441 }

std::pair< bool, bool > CaloSD::saveHit ( CaloG4Hit aHit  )  [private]

Definition at line 596 of file CaloSD.cc.

References correctT, corrTOFBeam, CaloG4Hit::getDepth(), CaloG4Hit::getEM(), CaloG4Hit::getHadr(), CaloG4Hit::getTimeSlice(), CaloG4Hit::getTrackID(), CaloG4Hit::getUnitID(), SimTrackManager::idSavedTrack(), LogDebug, m_trackManager, CaloSlaveSD::processHits(), slave, and tmaxHit.

Referenced by update().

00596                                                   {
00597 
00598   int tkID;
00599   bool ok   = true;
00600   bool save = false;
00601   if (m_trackManager) {
00602     tkID = m_trackManager->idSavedTrack(aHit->getTrackID());
00603     if (tkID == 0) ok = false;
00604   } else {
00605     tkID = aHit->getTrackID();
00606     ok = false;
00607   }
00608   LogDebug("CaloSim") << "CalosD: Track ID " << aHit->getTrackID() 
00609                       << " changed to " << tkID << " by SimTrackManager"
00610                       << " Status " << ok;
00611 
00612   double time = aHit->getTimeSlice();
00613   if (corrTOFBeam) time += correctT;
00614   if (time <= tmaxHit) {
00615     save = true;
00616     slave->processHits(aHit->getUnitID(), aHit->getEM()/GeV, 
00617                        aHit->getHadr()/GeV, time, tkID, aHit->getDepth());
00618     LogDebug("CaloSim") << "CaloSD: Store Hit at " << std::hex 
00619                         << aHit->getUnitID() << std::dec << " " 
00620                         << aHit->getDepth() << " due to " << tkID 
00621                         << " in time " << time << " of energy " 
00622                         << aHit->getEM()/GeV << " GeV (EM) and " 
00623                         << aHit->getHadr()/GeV << " GeV (Hadr)";
00624   }
00625   return std::pair<bool,bool>(ok,save);
00626 }

virtual uint32_t CaloSD::setDetUnitId ( G4Step *  step  )  [pure virtual]

Implements SensitiveDetector.

Implemented in ECalSD, HCalSD, DreamSD, EcalTBH4BeamSD, CastorSD, ZdcSD, HcalTB02SD, and HcalTB06BeamSD.

Referenced by getStepInfo(), and ProcessHits().

G4ThreeVector CaloSD::setToLocal ( G4ThreeVector  global,
const G4VTouchable *  touch 
) [protected]

Definition at line 297 of file CaloSD.cc.

Referenced by HcalTB02SD::curve_LY(), ECalSD::curve_LY(), DreamSD::curve_LY(), resetForNewPrimary(), and HcalTB06BeamSD::setDetUnitId().

00298                                                             {
00299 
00300   G4ThreeVector localPoint = 
00301     touch->GetHistory()->GetTopTransform().TransformPoint(global);
00302   
00303   return localPoint;  
00304 }

void CaloSD::storeHit ( CaloG4Hit hit  )  [private]

Definition at line 583 of file CaloSD.cc.

References hitMap, previousID, theHC, CaloHitID::trackID(), and useMap.

Referenced by createNewHit().

00583                                     {
00584 
00585   if (previousID.trackID()<0) return;
00586   if (hit == 0) {
00587     edm::LogWarning("CaloSim") << "CaloSD: hit to be stored is NULL !!";
00588     return;
00589   }
00590 
00591   theHC->insert(hit);
00592   if (useMap) hitMap.insert(std::pair<CaloHitID,CaloG4Hit*>(previousID,hit));
00593 
00594 }

void CaloSD::summarize (  )  [private]

Definition at line 628 of file CaloSD.cc.

Referenced by update().

00628 {}

void CaloSD::update ( const ::EndOfEvent  )  [protected, virtual]

Definition at line 510 of file CaloSD.cc.

References count, em, hitvec, i, j, LogDebug, saveHit(), python::multivaluedict::sort(), summarize(), and useMap.

00510                                        {
00511   
00512   LogDebug("CaloSim") << "CaloSD::update: Start saving hits for " << GetName()
00513                       << " with " << hitvec.size() << " hits";
00514   int kount = 0, count = 0, wrong = 0, tcut = 0;
00515   std::vector<CaloG4Hit*>::iterator i;
00516   std::pair<bool,bool> ok;
00517 
00518   if (useMap) {
00519     for (i=hitvec.begin(); i!=hitvec.end(); i++) {
00520       ok = saveHit(*i);
00521       if ((ok.second)) {
00522         count++;
00523         if (!(ok.first))  wrong++;
00524       } else {
00525         tcut++;
00526       }
00527       kount++;
00528     }
00529   } else {
00530     sort(hitvec.begin(), hitvec.end(), CaloG4HitLess());
00531     LogDebug("CaloSim") << "CaloSD: EndofEvent sort the hits in buffer ";
00532 
00533     std::vector<CaloG4Hit*>::iterator j;
00534     CaloG4HitEqual equal;
00535     for (i=hitvec.begin(); i!=hitvec.end(); i++) {
00536       int jump = 0;
00537       for (j = i+1; j<hitvec.end() && equal(*i, *j); j++) {
00538         jump++;
00539         // merge j to i
00540         (**i).addEnergyDeposit(**j);
00541         double em = 0.;
00542         double eh = 0.;
00543         (**j).setEM(em);
00544         (**j).setHadr(eh);
00545       }
00546 
00547       kount++;
00548       LogDebug("CaloSim") << "CaloSD: Merge " << jump << " hits to hit " 
00549                           << kount;
00550       ok = saveHit(*i);
00551       if ((ok.second)) {
00552         count++;
00553         if (!(ok.first))  wrong++;
00554       } else {
00555         tcut++;
00556       }
00557       i+=jump;
00558       kount += jump;
00559     }
00560   }
00561   
00562   edm::LogInfo("CaloSim") << "CaloSD: " << GetName() << " store " << count
00563                           << " hits out of " << kount << " recorded with " 
00564                           << wrong << " track IDs not given properly and "
00565                           << tcut << " hits with time above cutoff";
00566   summarize();
00567 }

void CaloSD::update ( const EndOfTrack  )  [protected, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfTrack * >.

Definition at line 485 of file CaloSD.cc.

References TrackInformation::getIDonCaloSurface(), int, it, LogDebug, m_trackManager, NULL, tkMap, SimTrackManager::trackContainer(), and TrackWithHistory::trackID().

00485                                           {
00486 
00487   int id = (*trk)()->GetTrackID();
00488   TrackInformation *trkI =(TrackInformation *)((*trk)()->GetUserInformation());
00489   int lastTrackID = -1;
00490   if (trkI) lastTrackID = trkI->getIDonCaloSurface();
00491   if (id == lastTrackID) {
00492     const TrackContainer * trksForThisEvent = m_trackManager->trackContainer();
00493     if (trksForThisEvent != NULL) {
00494       int it = (int)(trksForThisEvent->size()) - 1;
00495       if (it >= 0) {
00496         TrackWithHistory * trkH = (*trksForThisEvent)[it];
00497         LogDebug("CaloSim") << "CaloSD: get track " << it << " from "
00498                             << "Container of size " << trksForThisEvent->size()
00499                             << " with ID " << trkH->trackID();
00500         if (trkH->trackID() == (unsigned int)(id)) tkMap[id] = trkH;
00501       } else {
00502         LogDebug("CaloSim") << "CaloSD: get track " << it << " from "
00503                             << "Container of size " << trksForThisEvent->size()
00504                             << " with no ID";
00505       }
00506     }
00507   }
00508 }

void CaloSD::update ( const BeginOfEvent  )  [protected, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 478 of file CaloSD.cc.

References clearHits(), LogDebug, and tkMap.

00478                                         {
00479   LogDebug("CaloSim")  << "CaloSD: Dispatched BeginOfEvent for " << GetName() 
00480                        << " !" ;
00481   clearHits();
00482   tkMap.erase (tkMap.begin(), tkMap.end());
00483 }

void CaloSD::update ( const BeginOfRun  )  [protected, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 465 of file CaloSD.cc.

References emPDG, epPDG, gammaPDG, initRun(), and LogDebug.

00465                                       {
00466 
00467   G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
00468   G4String particleName;
00469   emPDG = theParticleTable->FindParticle(particleName="e-")->GetPDGEncoding();
00470   epPDG = theParticleTable->FindParticle(particleName="e+")->GetPDGEncoding();
00471   gammaPDG = theParticleTable->FindParticle(particleName="gamma")->GetPDGEncoding();
00472   LogDebug("CaloSim") << "CaloSD: Particle code for e- = " << emPDG
00473                       << " for e+ = " << epPDG << " for gamma = " << gammaPDG;
00474 
00475   initRun();
00476 } 

void CaloSD::updateHit ( CaloG4Hit aHit  )  [protected]

Definition at line 420 of file CaloSD.cc.

References CaloG4Hit::addEnergyDeposit(), currentID, edepositEM, edepositHAD, LogDebug, and previousID.

Referenced by checkHit(), createNewHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), hitExists(), HCalSD::hitForFibre(), and ProcessHits().

00420                                       {
00421 
00422   if (edepositEM+edepositHAD != 0) {
00423     aHit->addEnergyDeposit(edepositEM,edepositHAD);
00424     LogDebug("CaloSim") << "CaloSD: Add energy deposit in " << currentID 
00425                         << " em " << edepositEM/MeV << " hadronic " 
00426                         << edepositHAD/MeV << " MeV"; 
00427   }
00428 
00429   // buffer for next steps:
00430   previousID = currentID;
00431 }


Member Data Documentation

int CaloSD::checkHits [protected]

Definition at line 111 of file CaloSD.h.

Referenced by CaloSD(), and checkHit().

double CaloSD::correctT [protected]

Definition at line 119 of file CaloSD.h.

Referenced by CaloSD(), and saveHit().

bool CaloSD::corrTOFBeam [protected]

Definition at line 118 of file CaloSD.h.

Referenced by CaloSD(), and saveHit().

CaloG4Hit* CaloSD::currentHit [protected]

Definition at line 115 of file CaloSD.h.

Referenced by checkHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), hitExists(), HCalSD::hitForFibre(), ProcessHits(), DreamSD::ProcessHits(), and HCalSD::ProcessHits().

CaloHitID CaloSD::currentID [protected]

Definition at line 104 of file CaloSD.h.

Referenced by CaloSD(), checkHit(), createNewHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), getStepInfo(), DreamSD::getStepInfo(), hitExists(), HCalSD::hitForFibre(), ProcessHits(), and updateHit().

float CaloSD::edepositEM [protected]

Definition at line 108 of file CaloSD.h.

Referenced by createNewHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), getStepInfo(), DreamSD::getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), DreamSD::ProcessHits(), HCalSD::ProcessHits(), and updateHit().

float CaloSD::edepositHAD [protected]

Definition at line 108 of file CaloSD.h.

Referenced by createNewHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), getStepInfo(), DreamSD::getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), DreamSD::ProcessHits(), HCalSD::ProcessHits(), and updateHit().

G4int CaloSD::emPDG [protected]

Definition at line 122 of file CaloSD.h.

Referenced by HCalSD::getFromLibrary(), getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), and update().

double CaloSD::energyCut [protected]

Definition at line 110 of file CaloSD.h.

Referenced by CaloSD(), createNewHit(), HCalSD::getFromLibrary(), and HCalSD::getHitPMT().

G4ThreeVector CaloSD::entranceLocal [protected]

Definition at line 99 of file CaloSD.h.

Referenced by createNewHit(), ProcessHits(), and resetForNewPrimary().

G4ThreeVector CaloSD::entrancePoint [protected]

Definition at line 98 of file CaloSD.h.

Referenced by createNewHit(), ProcessHits(), and resetForNewPrimary().

G4int CaloSD::epPDG [protected]

Definition at line 122 of file CaloSD.h.

Referenced by HCalSD::getFromLibrary(), getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), and update().

G4int CaloSD::gammaPDG [protected]

Definition at line 122 of file CaloSD.h.

Referenced by HCalSD::getFromLibrary(), getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), and update().

int CaloSD::hcID [private]

Definition at line 127 of file CaloSD.h.

Referenced by Initialize().

std::map<CaloHitID,CaloG4Hit*> CaloSD::hitMap [private]

Definition at line 129 of file CaloSD.h.

Referenced by checkHit(), clearHits(), and storeHit().

std::vector<CaloG4Hit*> CaloSD::hitvec [private]

Definition at line 131 of file CaloSD.h.

Referenced by clearHits(), EndOfEvent(), and update().

float CaloSD::incidentEnergy [protected]

Definition at line 101 of file CaloSD.h.

Referenced by createNewHit(), ProcessHits(), and resetForNewPrimary().

double CaloSD::kmaxIon [protected]

Definition at line 120 of file CaloSD.h.

Referenced by CaloSD(), ECalSD::ECalSD(), HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), and HCalSD::HCalSD().

double CaloSD::kmaxNeutron [protected]

Definition at line 120 of file CaloSD.h.

Referenced by CaloSD(), ECalSD::ECalSD(), HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), and HCalSD::HCalSD().

double CaloSD::kmaxProton [protected]

Definition at line 120 of file CaloSD.h.

Referenced by CaloSD(), ECalSD::ECalSD(), HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), and HCalSD::HCalSD().

const SimTrackManager* CaloSD::m_trackManager [protected]

Definition at line 114 of file CaloSD.h.

Referenced by saveHit(), and update().

G4ThreeVector CaloSD::posGlobal [protected]

Definition at line 100 of file CaloSD.h.

Referenced by createNewHit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), hitExists(), HCalSD::hitForFibre(), and ProcessHits().

G4StepPoint* CaloSD::preStepPoint [protected]

Definition at line 107 of file CaloSD.h.

Referenced by CastorSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), EcalTBH4BeamSD::getEnergyDeposit(), ZdcSD::getEnergyDeposit(), HcalTB02SD::getEnergyDeposit(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), getStepInfo(), DreamSD::getStepInfo(), hitExists(), HCalSD::hitForFibre(), resetForNewPrimary(), HcalTB06BeamSD::setDetUnitId(), HCalSD::setDetUnitId(), and HCalSD::setTrackID().

CaloHitID CaloSD::previousID [protected]

Definition at line 104 of file CaloSD.h.

Referenced by CaloSD(), clearHits(), HCalSD::getFromLibrary(), HCalSD::getFromParam(), HCalSD::getHitPMT(), hitExists(), HCalSD::hitForFibre(), ProcessHits(), HCalSD::setTrackID(), storeHit(), and updateHit().

int CaloSD::primIDSaved [protected]

Definition at line 102 of file CaloSD.h.

Referenced by clearHits(), and createNewHit().

CaloSlaveSD* CaloSD::slave [private]

Definition at line 126 of file CaloSD.h.

Referenced by CaloSD(), clearHits(), fillHits(), saveHit(), and ~CaloSD().

bool CaloSD::suppressHeavy [protected]

Definition at line 118 of file CaloSD.h.

Referenced by CaloSD(), ECalSD::ECalSD(), HCalSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), and HCalSD::HCalSD().

CaloG4HitCollection* CaloSD::theHC [private]

Definition at line 128 of file CaloSD.h.

Referenced by checkHit(), EndOfEvent(), Initialize(), PrintAll(), storeHit(), and ~CaloSD().

G4Track* CaloSD::theTrack [protected]

Definition at line 105 of file CaloSD.h.

Referenced by createNewHit(), HCalSD::getEnergyDeposit(), CastorSD::getEnergyDeposit(), ECalSD::getEnergyDeposit(), ZdcSD::getEnergyDeposit(), HCalSD::getFromLibrary(), HCalSD::getHitPMT(), getStepInfo(), DreamSD::getStepInfo(), HCalSD::hitForFibre(), ProcessHits(), and HCalSD::setTrackID().

std::map<int,TrackWithHistory*> CaloSD::tkMap [private]

Definition at line 132 of file CaloSD.h.

Referenced by createNewHit(), and update().

double CaloSD::tmaxHit [protected]

Definition at line 110 of file CaloSD.h.

Referenced by CaloSD(), and saveHit().

bool CaloSD::useMap [protected]

Definition at line 112 of file CaloSD.h.

Referenced by CaloSD(), checkHit(), storeHit(), and update().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:15:54 2009 for CMSSW by  doxygen 1.5.4