00001
00002
00003
00005
00006 #include "SimG4CMS/Calo/interface/HFShowerPMT.h"
00007 #include "DetectorDescription/Core/interface/DDFilter.h"
00008 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00009 #include "DetectorDescription/Core/interface/DDValue.h"
00010
00011 #include "FWCore/Utilities/interface/Exception.h"
00012
00013 #include "G4VPhysicalVolume.hh"
00014 #include "G4Step.hh"
00015 #include "G4Track.hh"
00016 #include "CLHEP/Units/PhysicalConstants.h"
00017 #include "CLHEP/Units/SystemOfUnits.h"
00018
00019 HFShowerPMT::HFShowerPMT(std::string & name, const DDCompactView & cpv,
00020 edm::ParameterSet const & p) {
00021
00022 edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShower");
00023 pePerGeV = m_HF.getParameter<double>("PEPerGeVPMT");
00024
00025 G4String attribute = "ReadOutName";
00026 G4String value = name;
00027 DDSpecificsFilter filter0;
00028 DDValue ddv0(attribute,value,0);
00029 filter0.setCriteria(ddv0,DDSpecificsFilter::equals);
00030 DDFilteredView fv0(cpv);
00031 fv0.addFilter(filter0);
00032 if (fv0.firstChild()) {
00033 DDsvalues_type sv0(fv0.mergedSpecifics());
00034
00035
00036 rTable = getDDDArray("rTable",sv0);
00037 edm::LogInfo("HFShower") << "HFShowerPMT: " << rTable.size()
00038 << " rTable (cm)";
00039 for (unsigned int ig=0; ig<rTable.size(); ig++)
00040 edm::LogInfo("HFShower") << "HFShowerPMT: rTable[" << ig << "] = "
00041 << rTable[ig]/cm << " cm";
00042 } else {
00043 edm::LogError("HFShower") << "HFShowerPMT: cannot get filtered "
00044 << " view for " << attribute << " matching "
00045 << value;
00046 throw cms::Exception("Unknown", "HFShowerPMT")
00047 << "cannot match " << attribute << " to " << name <<"\n";
00048 }
00049
00050 attribute = "Volume";
00051 value = "HFPMT";
00052 DDSpecificsFilter filter1;
00053 DDValue ddv1(attribute,value,0);
00054 filter1.setCriteria(ddv1,DDSpecificsFilter::equals);
00055 DDFilteredView fv1(cpv);
00056 fv1.addFilter(filter1);
00057 if (fv1.firstChild()) {
00058 DDsvalues_type sv1(fv1.mergedSpecifics());
00059 std::vector<double> neta;
00060 neta = getDDDArray("indexPMTR",sv1);
00061 for (unsigned int ii=0; ii<neta.size(); ii++) {
00062 int index = static_cast<int>(neta[ii]);
00063 int ir=-1, ifib=-1;
00064 if (index >= 0) {
00065 ir = index/10; ifib = index%10;
00066 }
00067 pmtR1.push_back(ir);
00068 pmtFib1.push_back(ifib);
00069 }
00070 neta = getDDDArray("indexPMTL",sv1);
00071 for (unsigned int ii=0; ii<neta.size(); ii++) {
00072 int index = static_cast<int>(neta[ii]);
00073 int ir=-1, ifib=-1;
00074 if (index >= 0) {
00075 ir = index/10; ifib = index%10;
00076 }
00077 pmtR2.push_back(ir);
00078 pmtFib2.push_back(ifib);
00079 }
00080 edm::LogInfo("HFShower") << "HFShowerPMT: gets the Index matches for "
00081 << neta.size() << " PMTs";
00082 for (unsigned int ii=0; ii<neta.size(); ii++)
00083 edm::LogInfo("HFShower") << "HFShowerPMT: rIndexR[" << ii << "] = "
00084 << pmtR1[ii] << " fibreR[" << ii << "] = "
00085 << pmtFib1[ii] << " rIndexL[" << ii << "] = "
00086 << pmtR2[ii] << " fibreL[" << ii << "] = "
00087 << pmtFib2[ii];
00088 } else {
00089 edm::LogWarning("HFShower") << "HFShowerPMT: cannot get filtered "
00090 << " view for " << attribute << " matching "
00091 << value;
00092 }
00093
00094 }
00095
00096 HFShowerPMT::~HFShowerPMT() {}
00097
00098 double HFShowerPMT::getHits(G4Step * aStep) {
00099
00100 double edep = aStep->GetTotalEnergyDeposit();
00101 indexR = indexF = -1;
00102
00103 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
00104 const G4VTouchable* touch = preStepPoint->GetTouchable();
00105 int boxNo = touch->GetReplicaNumber(2);
00106 int pmtNo = touch->GetReplicaNumber(1);
00107 if (boxNo <= 1) {
00108 indexR = pmtR1[pmtNo-1];
00109 indexF = pmtFib1[pmtNo-1];
00110 } else {
00111 indexR = pmtR2[pmtNo-1];
00112 indexF = pmtFib2[pmtNo-1];
00113 }
00114
00115 LogDebug("HFShower") << "HFShowerPMT: Box " << boxNo << " PMT "
00116 << pmtNo << " Mapped Indices " << indexR << ", "
00117 << indexF << " Edeposit " << edep/MeV << " MeV; PE "
00118 << edep*pePerGeV/GeV;
00119 if (indexR >= 0 && indexF > 0) return edep*pePerGeV/GeV;
00120 else return 0;
00121 }
00122
00123 double HFShowerPMT::getRadius() {
00124
00125 double r = 0.;
00126 if (indexR >= 0 && indexR+1 < (int)(rTable.size()))
00127 r = 0.5*(rTable[indexR]+rTable[indexR+1]);
00128 else
00129 LogDebug("HFShower") << "HFShowerPMT::getRadius: R " << indexR
00130 << " F " << indexF;
00131 if (indexF == 2) r =-r;
00132 LogDebug("HFShower") << "HFShower: Radius (" << indexR << "/" << indexF
00133 << ") " << r;
00134 return r;
00135 }
00136
00137 std::vector<double> HFShowerPMT::getDDDArray(const std::string & str,
00138 const DDsvalues_type & sv) {
00139
00140 LogDebug("HFShower") << "HFShowerPMT:getDDDArray called for " << str;
00141
00142 DDValue value(str);
00143 if (DDfetch(&sv,value)) {
00144 LogDebug("HFShower") << value;
00145 const std::vector<double> & fvec = value.doubles();
00146 int nval = fvec.size();
00147 if (nval < 2) {
00148 edm::LogError("HFShower") << "HFShowerPMT : # of " << str
00149 << " bins " << nval << " < 2 ==> illegal";
00150 throw cms::Exception("Unknown", "HFShowerPMT")
00151 << "nval < 2 for array " << str << "\n";
00152 }
00153
00154 return fvec;
00155 } else {
00156 edm::LogError("HFShower") << "HFShowerPMT : cannot get array " << str;
00157 throw cms::Exception("Unknown", "HFShowerPMT")
00158 << "cannot get array " << str << "\n";
00159 }
00160 }