CMS 3D CMS Logo

HFShowerParam.cc

Go to the documentation of this file.
00001 
00002 // File: HFShowerParam.cc
00003 // Description: Parametrized version of HF hits
00005 
00006 #include "SimG4CMS/Calo/interface/HFShowerParam.h"
00007 #include "DetectorDescription/Core/interface/DDFilter.h"
00008 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00009 
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 
00012 #include "G4VPhysicalVolume.hh"
00013 #include "G4Step.hh"
00014 #include "G4Track.hh"
00015 #include "G4NavigationHistory.hh"
00016 #include "CLHEP/Units/PhysicalConstants.h"
00017 #include "CLHEP/Units/SystemOfUnits.h"
00018 
00019 HFShowerParam::HFShowerParam(std::string & name, const DDCompactView & cpv,
00020                              edm::ParameterSet const & p) : fibre(0) {
00021 
00022   edm::ParameterSet m_HF  = p.getParameter<edm::ParameterSet>("HFShower");
00023   pePerGeV                = m_HF.getParameter<double>("PEPerGeV");
00024   trackEM                 = m_HF.getParameter<bool>("TrackEM");
00025   edm::LogInfo("HFShower") << "HFShowerParam:: P.E. per GeV " << pePerGeV
00026                            << " and Track EM Flag " << trackEM;
00027   
00028   G4String attribute = "ReadOutName";
00029   G4String value     = name;
00030   DDSpecificsFilter filter;
00031   DDValue           ddv(attribute,value,0);
00032   filter.setCriteria(ddv,DDSpecificsFilter::equals);
00033   DDFilteredView fv(cpv);
00034   fv.addFilter(filter);
00035   bool dodet = fv.firstChild();
00036   if (dodet) {
00037     DDsvalues_type sv(fv.mergedSpecifics());
00038 
00039     //Special Geometry parameters
00040     gpar      = getDDDArray("gparHF",sv);
00041     edm::LogInfo("HFShower") << "HFShowerParam: " <<gpar.size() <<" gpar (cm)";
00042     for (unsigned int ig=0; ig<gpar.size(); ig++)
00043       edm::LogInfo("HFShower") << "HFShowerParam: gpar[" << ig << "] = "
00044                                << gpar[ig]/cm << " cm";
00045   } else {
00046     edm::LogError("HFShower") << "HFShowerParam: cannot get filtered "
00047                               << " view for " << attribute << " matching "
00048                               << name;
00049     throw cms::Exception("Unknown", "HFShowerParam")
00050       << "cannot match " << attribute << " to " << name <<"\n";
00051   }
00052   
00053   fibre = new HFFibre(name, cpv, p);
00054 }
00055 
00056 HFShowerParam::~HFShowerParam() {
00057   if (fibre) delete fibre;
00058 }
00059 
00060 std::vector<double> HFShowerParam::getHits(G4Step * aStep) {
00061 
00062   std::vector<double> edeps;
00063   hits.clear();
00064 
00065   G4StepPoint * preStepPoint  = aStep->GetPreStepPoint(); 
00066   G4Track *     track    = aStep->GetTrack();   
00067   G4ThreeVector hitPoint = preStepPoint->GetPosition();   
00068   G4String      partType = track->GetDefinition()->GetParticleName();
00069   G4ThreeVector localPoint = (preStepPoint->GetTouchable()->GetHistory()->GetTopTransform()).TransformPoint(hitPoint);
00070   double pin    = (preStepPoint->GetTotalEnergy())/GeV;
00071   double zint   = hitPoint.z(); 
00072   double zz     = std::abs(zint) - gpar[4];
00073   
00074   edm::LogInfo("HFShower") << "HFShowerParam: getHits " << partType
00075                        << " of energy " << pin << " GeV" 
00076                        << " Pos x,y,z = " << hitPoint.x() << "," 
00077                        << hitPoint.y() << "," << zint << " (" << zz << ","
00078                            << localPoint.z() << ", " << (localPoint.z()+0.5*gpar[1]) << ")";
00079 
00080   HFShowerParam::Hit hit;
00081   hit.position = hitPoint;
00082   // take only e+-/gamma
00083   if (partType == "e-" || partType == "e+" || partType == "gamma" ) {
00084     // Leave out the last part
00085     double edep = 0.;
00086     bool   kill = false;
00087     if ((!trackEM) && (zz < (gpar[1]-gpar[2]))) {
00088       edep = pin;
00089       kill = true;
00090     } else {
00091       edep = (aStep->GetTotalEnergyDeposit())/GeV;
00092     }
00093     if (edep > 0) {
00094       edep         *= 0.5*pePerGeV;
00095       double tSlice = (aStep->GetPostStepPoint()->GetGlobalTime());
00096 
00097       double time = fibre->tShift(hitPoint,1,false); // remaining part
00098       hit.depth   = 1;
00099       hit.time    = tSlice+time;
00100       edeps.push_back(edep);
00101       hits.push_back(hit);
00102       if (zz >= gpar[0]) {
00103         time      = fibre->tShift(hitPoint,2,false);
00104         hit.depth = 2;
00105         hit.time  = tSlice+time;
00106         edeps.push_back(edep);
00107         hits.push_back(hit);
00108       }
00109       if (kill) track->SetTrackStatus(fStopAndKill);
00110       edm::LogInfo("HFShower") << "HFShowerParam: getHits kill (" << kill
00111                                << ") track " << track->GetTrackID() 
00112                                << " and deposit " << edep << " " <<edeps.size()
00113                                << " times" << " ZZ " << zz << " " << gpar[0];
00114     }
00115   }
00116     
00117   return edeps;
00118 
00119 }
00120 G4ThreeVector HFShowerParam::getPosHit(int i) {
00121 
00122   G4ThreeVector pos;
00123   if (i < static_cast<int>(hits.size())) pos = (hits[i].position);
00124   LogDebug("HFShower") << "HFShowerParam::getPosHit (" << i << "/" 
00125                        << hits.size() << ") " << pos;
00126   return pos;
00127 }
00128 
00129 int HFShowerParam::getDepth(int i) {
00130 
00131   int depth = 0;
00132   if (i < static_cast<int>(hits.size())) depth = (hits[i].depth);
00133   LogDebug("HFShower") << "HFShowerParam::getDepth (" << i << "/" 
00134                        << hits.size() << ") "  << depth;
00135   return depth;
00136 }
00137  
00138 double HFShowerParam::getTSlice(int i) {
00139    
00140   double tim = 0.;
00141   if (i < static_cast<int>(hits.size())) tim = (hits[i].time);
00142   LogDebug("HFShower") << "HFShowerParam::getTSlice (" << i << "/" 
00143                        << hits.size()<< ") " << tim;
00144   return tim;
00145 }
00146 
00147 std::vector<double> HFShowerParam::getDDDArray(const std::string & str, 
00148                                                const DDsvalues_type & sv) {
00149 
00150   LogDebug("HFShower") << "HFShowerParam:getDDDArray called for " << str;
00151 
00152   DDValue value(str);
00153   if (DDfetch(&sv,value)) {
00154     LogDebug("HFShower") << value;
00155     const std::vector<double> & fvec = value.doubles();
00156     int nval = fvec.size();
00157     if (nval < 2) {
00158       edm::LogError("HFShower") << "HFShowerParam : # of " << str 
00159                                 << " bins " << nval << " < 2 ==> illegal";
00160       throw cms::Exception("Unknown", "HFShowerParam")
00161         << "nval < 2 for array " << str << "\n";
00162     }
00163 
00164     return fvec;
00165   } else {
00166     edm::LogError("HFShower") << "HFShowerParam : cannot get array " << str;
00167     throw cms::Exception("Unknown", "HFShowerParam") 
00168       << "cannot get array " << str << "\n";
00169   }
00170 }

Generated on Tue Jun 9 17:46:50 2009 for CMSSW by  doxygen 1.5.4