Skip to content

Commit

Permalink
Code check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Jul 9, 2021
1 parent 4a76902 commit 0627027
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 66 deletions.
108 changes: 57 additions & 51 deletions SimG4CMS/Calo/src/HFCherenkov.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ HFCherenkov::HFCherenkov(edm::ParameterSet const& m_HF) {
ref_index = m_HF.getParameter<double>("RefIndex");
lambda1 = ((m_HF.getParameter<double>("Lambda1")) / pow(double(10), 7)) * CLHEP::cm;
lambda2 = ((m_HF.getParameter<double>("Lambda2")) / pow(double(10), 7)) * CLHEP::cm;
aperture = m_HF.getParameter<double>("Aperture");
aperture = m_HF.getParameter<double>("Aperture");
gain = m_HF.getParameter<double>("Gain");
checkSurvive = m_HF.getParameter<bool>("CheckSurvive");
UseNewPMT = m_HF.getParameter<bool>("UseR7600UPMT");
fibreR = m_HF.getParameter<double>("FibreR") * CLHEP::mm;
aperturetrapped=aperture/ref_index;
sinPsimax=1/ref_index;
UseNewPMT = m_HF.getParameter<bool>("UseR7600UPMT");
fibreR = m_HF.getParameter<double>("FibreR") * CLHEP::mm;

aperturetrapped = aperture / ref_index;
sinPsimax = 1 / ref_index;

edm::LogVerbatim("HFShower") << "HFCherenkov:: initialised with ref_index " << ref_index << " lambda1/lambda2 (cm) "
<< lambda1 / CLHEP::cm << "|" << lambda2 / CLHEP::cm << " aperture(trapped) " << aperture
<< "|" << aperturetrapped << " sinPsimax " << sinPsimax << " Check photon survival in HF "
<< checkSurvive << " Gain " << gain << " useNewPMT " << UseNewPMT << " FibreR "
<< fibreR;
<< lambda1 / CLHEP::cm << "|" << lambda2 / CLHEP::cm << " aperture(trapped) " << aperture
<< "|" << aperturetrapped << " sinPsimax " << sinPsimax
<< " Check photon survival in HF " << checkSurvive << " Gain " << gain << " useNewPMT "
<< UseNewPMT << " FibreR " << fibreR;

clearVectors();
}
Expand Down Expand Up @@ -118,67 +118,73 @@ int HFCherenkov::computeNPE(const G4Step* aStep,
double cosEta = sqrt(1. - sinEta * sinEta);
double sinPsi = sqrt(1. - w_ph * w_ph);
double cosKsi = cosEta * sinPsi;

#ifdef EDM_ML_DEBUG
if (cosKsi < aperturetrapped && w_ph > 0.) {
edm::LogVerbatim("HFShower") << "HFCherenkov::Trapped photon : " << u_ph << " " << v_ph << " " << w_ph << " " << xemit << " " << gam << " " << eps << " " << sinBeta << " " << rho << " " << sinEta << " " << cosEta << " " << " " << sinPsi << " " << cosKsi;
edm::LogVerbatim("HFShower") << "HFCherenkov::Trapped photon : " << u_ph << " " << v_ph << " " << w_ph << " "
<< xemit << " " << gam << " " << eps << " " << sinBeta << " " << rho << " "
<< sinEta << " " << cosEta << " "
<< " " << sinPsi << " " << cosKsi;
} else {
edm::LogVerbatim("HFShower") << "HFCherenkov::Rejected photon : " << u_ph << " " << v_ph << " " << w_ph << " " << xemit << " " << gam << " " << eps << " " << sinBeta << " " << rho << " " << sinEta << " " << cosEta << " " << " " << sinPsi << " " << cosKsi;
edm::LogVerbatim("HFShower") << "HFCherenkov::Rejected photon : " << u_ph << " " << v_ph << " " << w_ph << " "
<< xemit << " " << gam << " " << eps << " " << sinBeta << " " << rho << " "
<< sinEta << " " << cosEta << " "
<< " " << sinPsi << " " << cosKsi;
}
#endif
if (cosKsi < aperturetrapped // photon is trapped inside fiber
&& w_ph > 0. // and moves to PMT
&& sinPsi < sinPsimax) { // and is not reflected at fiber end
if (cosKsi < aperturetrapped // photon is trapped inside fiber
&& w_ph > 0. // and moves to PMT
&& sinPsi < sinPsimax) { // and is not reflected at fiber end
wltrap.push_back(lambda);
double prob_HF = 1.0;
double prob_HF = 1.0;
if (checkSurvive) {
double a0_inv = 0.1234; //meter^-1
double a0_inv = 0.1234; //meter^-1
double a_inv = a0_inv + 0.14 * pow(dose, 0.30); // ?
double z_meters = zFiber;
prob_HF = exp(-z_meters * a_inv);
double z_meters = zFiber;
prob_HF = exp(-z_meters * a_inv);
}
rand = G4UniformRand();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: probHF " << prob_HF
<< " Random " << rand << " Survive? " << (rand < prob_HF);
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: probHF " << prob_HF << " Random " << rand
<< " Survive? " << (rand < prob_HF);
#endif
if (rand < prob_HF) { // survived in HF
wlatten.push_back(lambda);
rand = G4UniformRand();
double effHEM = computeHEMEff(lambda);
// compute number of bounces in air guide
rand = G4UniformRand();
double phi = 0.5*M_PI*rand;
double rad_bundle = 19.; // bundle radius
double rad_lg = 25.; // light guide radius
rand = G4UniformRand();
double rad = rad_bundle*sqrt(rand);
double rho = rad*sin(phi);
double tlength = 2. * sqrt(rad_lg*rad_lg-rho*rho);
double length_lg = 430;
double sin_air = sinPsi * 1.46;
double tang = sin_air / sqrt(1. - sin_air * sin_air);
int nbounce = length_lg / tlength * tang + 0.5;
double eff = pow(effHEM, nbounce);
// compute number of bounces in air guide
rand = G4UniformRand();
double phi = 0.5 * M_PI * rand;
double rad_bundle = 19.; // bundle radius
double rad_lg = 25.; // light guide radius
rand = G4UniformRand();
double rad = rad_bundle * sqrt(rand);
double rho = rad * sin(phi);
double tlength = 2. * sqrt(rad_lg * rad_lg - rho * rho);
double length_lg = 430;
double sin_air = sinPsi * 1.46;
double tang = sin_air / sqrt(1. - sin_air * sin_air);
int nbounce = length_lg / tlength * tang + 0.5;
double eff = pow(effHEM, nbounce);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: w_ph " << w_ph << " effHEM " << effHEM
<< " eff " << eff << " Random " << rand << " Survive? " << (rand < eff);
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: w_ph " << w_ph << " effHEM " << effHEM << " eff "
<< eff << " Random " << rand << " Survive? " << (rand < eff);
#endif
if (rand<eff) { // survived HEM
wlhem.push_back(lambda);
double qEffic = computeQEff(lambda);
rand = G4UniformRand();
if (rand < eff) { // survived HEM
wlhem.push_back(lambda);
double qEffic = computeQEff(lambda);
rand = G4UniformRand();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: qEffic " << qEffic << " Random " << rand
<< " Survive? " << (rand < qEffic);
edm::LogVerbatim("HFShower") << "HFCherenkov::computeNPE: qEffic " << qEffic << " Random " << rand
<< " Survive? " << (rand < qEffic);
#endif
if (rand < qEffic) { // made photoelectron
npe_Dose += 1;
momZ.push_back(w_ph);
wl.push_back(lambda);
wlqeff.push_back(lambda);
} // made pe
} // passed HEM
if (rand < qEffic) { // made photoelectron
npe_Dose += 1;
momZ.push_back(w_ph);
wl.push_back(lambda);
wlqeff.push_back(lambda);
} // made pe
} // passed HEM
} // passed fiber
} // end of if(w_ph < w_aperture), trapped inside fiber
} // end of ++NbOfPhotons
Expand Down
12 changes: 6 additions & 6 deletions SimG4CMS/Calo/src/HFFibre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,27 @@ double HFFibre::zShift(const G4ThreeVector& point, int depth, int fromEndAbs) {
double hR = sqrt((point.x()) * (point.x()) + (point.y()) * (point.y()));

// Defines the Radius bin by radial subdivision
if (fromEndAbs >= 0) {
if (fromEndAbs >= 0) {
for (int i = nBinR - 1; i > 0; --i)
if (hR < radius[i])
ieta = nBinR - i - 1;
}

// Defines the full length of the fibre
// Defines the full length of the fibre
if (depth == 2) {
if (static_cast<int>(shortFL.size()) > ieta)
length = shortFL[ieta] + gpar[0];
} else {
if (static_cast<int>(longFL.size()) > ieta)
length = longFL[ieta];
}
zFibre = length; // from beginning of abs (full length)
zFibre = length; // from beginning of abs (full length)

if (fromEndAbs > 0) {
zFibre -= gpar[1]; // length from end of HF
zFibre -= gpar[1]; // length from end of HF
} else {
double zz = 0.5 * gpar[1] + point.z(); // depth of point of photon emission (from beginning of HF)
zFibre -= zz; // length of fiber from point of photon emission
double zz = 0.5 * gpar[1] + point.z(); // depth of point of photon emission (from beginning of HF)
zFibre -= zz; // length of fiber from point of photon emission
}

#ifdef EDM_ML_DEBUG
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/Calo/src/HFShower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ HFShower::HFShower(const std::string &name,
ignoreTimeShift_ = m_HF2.getParameter<bool>("IgnoreTimeShift");
probMax_ = m_HF2.getParameter<double>("ProbMax");

edm::LogVerbatim("HFShower") << "HFShower:: Maximum probability cut off " << probMax_ << " Check flag " << chkFibre_ << " ignoreTimeShift " << ignoreTimeShift_;
edm::LogVerbatim("HFShower") << "HFShower:: Maximum probability cut off " << probMax_ << " Check flag " << chkFibre_
<< " ignoreTimeShift " << ignoreTimeShift_;

cherenkov_ = std::make_unique<HFCherenkov>(m_HF);
fibre_ = std::make_unique<HFFibre>(name, hcalConstant_, hps, p);
Expand Down
29 changes: 22 additions & 7 deletions SimG4CMS/Calo/src/HFShowerLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ HFShowerLibrary::HFShowerLibrary(const std::string& name,

#ifdef EDM_ML_DEBUG
std::stringstream ss;
ss << "HFShowerLibrary: Library " << libVers << " ListVersion " << listVersion << " File version " << fileVersion_ << " Events Total " << totEvents << " and " << evtPerBin << " per bin\n";
ss << "HFShowerLibrary: Library " << libVers << " ListVersion " << listVersion << " File version " << fileVersion_
<< " Events Total " << totEvents << " and " << evtPerBin << " per bin\n";
ss << "HFShowerLibrary: Energies (GeV) with " << nMomBin << " bins\n";
for (int i = 0; i < nMomBin; ++i) {
if (i / 10 * 10 == i && i > 0) {
Expand All @@ -109,7 +110,12 @@ HFShowerLibrary::HFShowerLibrary(const std::string& name,
}

#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << " HFShowerLibrary:Branch " << emName << " has " << emBranch->GetEntries() << " entries and Branch " << hadName << " has " << hadBranch->GetEntries() << " entries\n HFShowerLibrary::No packing information - Assume x, y, z are not in packed form\n Maximum probability cut off " << probMax << " Back propagation of light probability " << backProb << " Flag for ignoring Time Shift " << ignoreTimeShift_;
edm::LogVerbatim("HFShower") << " HFShowerLibrary:Branch " << emName << " has " << emBranch->GetEntries()
<< " entries and Branch " << hadName << " has " << hadBranch->GetEntries()
<< " entries\n HFShowerLibrary::No packing information - Assume x, y, z are not in "
"packed form\n Maximum probability cut off "
<< probMax << " Back propagation of light probability " << backProb
<< " Flag for ignoring Time Shift " << ignoreTimeShift_;
#endif
fibre_ = std::make_unique<HFFibre>(name, hcalConstant_, hps, p);
photo = new HFShowerPhotonCollection;
Expand Down Expand Up @@ -160,7 +166,12 @@ std::vector<HFShowerLibrary::Hit> HFShowerLibrary::getHits(const G4Step* aStep,
const G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
double zoff = localPos.z() + 0.5 * gpar[1];

edm::LogVerbatim("HFShower") << "HFShowerLibrary::getHits " << partType << " of energy " << track->GetKineticEnergy() / CLHEP::GeV << " GeV weight= " << weight << " onlyLong: " << onlyLong << " dir.orts " << momDir.x() << ", " << momDir.y() << ", " << momDir.z() << " Pos x,y,z = " << hitPoint.x() << "," << hitPoint.y() << "," << hitPoint.z() << " (" << zoff << ") sphi,cphi,stheta,ctheta = " << sin(momDir.phi()) << "," << cos(momDir.phi()) << ", " << sin(momDir.theta()) << "," << cos(momDir.theta());
edm::LogVerbatim("HFShower") << "HFShowerLibrary::getHits " << partType << " of energy "
<< track->GetKineticEnergy() / CLHEP::GeV << " GeV weight= " << weight
<< " onlyLong: " << onlyLong << " dir.orts " << momDir.x() << ", " << momDir.y() << ", "
<< momDir.z() << " Pos x,y,z = " << hitPoint.x() << "," << hitPoint.y() << ","
<< hitPoint.z() << " (" << zoff << ") sphi,cphi,stheta,ctheta = " << sin(momDir.phi())
<< "," << cos(momDir.phi()) << ", " << sin(momDir.theta()) << "," << cos(momDir.theta());
#endif

double tSlice = (postStepPoint->GetGlobalTime()) / CLHEP::nanosecond;
Expand Down Expand Up @@ -289,7 +300,7 @@ std::vector<HFShowerLibrary::Hit> HFShowerLibrary::fillHits(const G4ThreeVector&
#endif
if (rInside(r) && r1 <= exp(-p * zv) && r2 <= probMax * weight && dfir > gpar[5] && zz >= gpar[4] &&
zz <= gpar[4] + gpar[1] && r3 <= backProb && (depth != 2 || zz >= gpar[4] + gpar[0])) {
double tdiff = (ignoreTimeShift_) ? 0 : (fibre_->tShift(lpos, depth, 1));
double tdiff = (ignoreTimeShift_) ? 0 : (fibre_->tShift(lpos, depth, 1));
oneHit.position = pos;
oneHit.depth = depth;
oneHit.time = (tSlice + (pe[i].t()) + tdiff);
Expand All @@ -309,7 +320,7 @@ std::vector<HFShowerLibrary::Hit> HFShowerLibrary::fillHits(const G4ThreeVector&
r1 = G4UniformRand();
r2 = G4UniformRand();
if (rInside(r) && r1 <= exp(-p * zv) && r2 <= probMax && dfir > gpar[5]) {
double tdiff = (ignoreTimeShift_) ? 0 : (fibre_->tShift(lpos, 2, 1));
double tdiff = (ignoreTimeShift_) ? 0 : (fibre_->tShift(lpos, 2, 1));
oneHit.position = pos;
oneHit.depth = 2;
oneHit.time = (tSlice + (pe[i].t()) + tdiff);
Expand Down Expand Up @@ -428,7 +439,9 @@ void HFShowerLibrary::loadEventInfo(TBranch* branch) {

void HFShowerLibrary::interpolate(int type, double pin) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Interpolate for Energy " << pin / CLHEP::GeV << " GeV with " << nMomBin << " momentum bins and " << evtPerBin << " entries/bin -- total " << totEvents;
edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Interpolate for Energy " << pin / CLHEP::GeV << " GeV with "
<< nMomBin << " momentum bins and " << evtPerBin << " entries/bin -- total "
<< totEvents;
#endif
int irc[2] = {0, 0};
double w = 0.;
Expand Down Expand Up @@ -507,7 +520,9 @@ void HFShowerLibrary::extrapolate(int type, double pin) {
double w = (pin - pmom[nMomBin - 1] * nrec) / pmom[nMomBin - 1];
nrec++;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Extrapolate for Energy " << pin / CLHEP::GeV << " GeV with " << nMomBin << " momentum bins and " << evtPerBin << " entries/bin -- " << "total " << totEvents << " using " << nrec << " records";
edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Extrapolate for Energy " << pin / CLHEP::GeV << " GeV with "
<< nMomBin << " momentum bins and " << evtPerBin << " entries/bin -- "
<< "total " << totEvents << " using " << nrec << " records";
#endif
std::vector<int> irc(nrec);

Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/Calo/src/HFShowerParam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ HFShowerParam::HFShowerParam(const std::string& name,
<< " Use of Gflash is set to " << useGflash << " P.E. per GeV " << pePerGeV_
<< ", ref. index of fibre " << ref_index_ << ", Track EM Flag " << trackEM_ << ", edMin "
<< edMin_ << " GeV, use of Short fibre info in"
<< " shower library set to " << !(onlyLong_) << " ignore flag for time shift in fire is set to " << ignoreTimeShift_
<< " shower library set to " << !(onlyLong_)
<< " ignore flag for time shift in fire is set to " << ignoreTimeShift_
<< ", use of parametrization for last part set to " << parametrizeLast_
<< ", Mean lambda " << lambdaMean << ", aperture (cutoff) " << aperture_
<< ", Application of Fiducial Cut " << applyFidCut_;
Expand Down

0 comments on commit 0627027

Please sign in to comment.