00001
00002
00003
00004
00005
00007 #include "SimG4CMS/Forward/interface/ZdcSD.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include "G4SDManager.hh"
00011 #include "G4Step.hh"
00012 #include "G4Track.hh"
00013 #include "G4VProcess.hh"
00014
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00017 #include "CLHEP/Random/RandPoissonQ.h"
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 #include "G4ios.hh"
00020 #include "G4Cerenkov.hh"
00021
00022 #include "CLHEP/Units/SystemOfUnits.h"
00023 #include "CLHEP/Random/Randomize.h"
00024
00025 ZdcSD::ZdcSD(G4String name, const DDCompactView & cpv,
00026 SensitiveDetectorCatalog & clg,
00027 edm::ParameterSet const & p,const SimTrackManager* manager) :
00028 CaloSD(name, cpv, clg, p, manager), numberingScheme(0) {
00029 edm::ParameterSet m_ZdcSD = p.getParameter<edm::ParameterSet>("ZdcSD");
00030 verbosity = m_ZdcSD.getParameter<int>("Verbosity");
00031 int verbn = verbosity/10;
00032 verbosity %= 10;
00033 setNumberingScheme(new ZdcNumberingScheme(verbn));
00034
00035 edm::LogInfo("ForwardSim")
00036 << "***************************************************\n"
00037 << "* *\n"
00038 << "* Constructing a ZdcSD with name " << name << "\n"
00039 << "* *\n"
00040 << "***************************************************";
00041 }
00042
00043 ZdcSD::~ZdcSD() {}
00044
00045 double ZdcSD::getEnergyDeposit(G4Step * aStep, edm::ParameterSet const & p ) {
00046
00047 float NCherPhot = 0.;
00048
00049 if (aStep == NULL) {
00050 LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: aStep is NULL!";
00051 return 0;
00052 }
00053 else {
00054
00055 G4SteppingControl stepControlFlag = aStep->GetControlFlag();
00056 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00057 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
00058 G4String nameVolume = currentPV->GetName();
00059
00060 G4ThreeVector hitPoint = preStepPoint->GetPosition();
00061 G4ThreeVector hit_mom = preStepPoint->GetMomentumDirection();
00062 G4double stepL = aStep->GetStepLength()/cm;
00063 G4double beta = preStepPoint->GetBeta();
00064 G4double charge = preStepPoint->GetCharge();
00065
00066
00067
00068
00069
00070
00071
00072
00073 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
00074 G4VPhysicalVolume* postPV = postStepPoint->GetPhysicalVolume();
00075 G4String postnameVolume = postPV->GetName();
00076
00077
00078 G4Track* theTrack = aStep->GetTrack();
00079 G4String particleType = theTrack->GetDefinition()->GetParticleName();
00080 G4int primaryID = theTrack->GetTrackID();
00081 G4double entot = theTrack->GetTotalEnergy();
00082 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
00083 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
00084
00085
00086 float costheta = vert_mom.z()/sqrt(vert_mom.x()*vert_mom.x()+
00087 vert_mom.y()*vert_mom.y()+
00088 vert_mom.z()*vert_mom.z());
00089 float theta = acos(std::min(std::max(costheta,float(-1.)),float(1.)));
00090 float eta = -log(tan(theta/2));
00091 float phi = -100.;
00092 if (vert_mom.x() != 0) phi = atan2(vert_mom.y(),vert_mom.x());
00093 if (phi < 0.) phi += twopi;
00094
00095
00096 double stepE = aStep->GetTotalEnergyDeposit();
00097 LogDebug("ForwardSim")
00098 << "ZdcSD:: getEnergyDeposit: "
00099 <<"*****************HHHHHHHHHHHHHHHHHHHHHHHHHHLLLLLLLLLlllllllllll&&&&&&&&&&\n"
00100 << " preStepPoint: " << nameVolume << "," << stepL << "," << stepE
00101 << "," << beta << "," << charge << "\n"
00102 << " postStepPoint: " << postnameVolume << "," << costheta << ","
00103 << theta << "," << eta << "," << phi << "," << particleType << ","
00104 << primaryID;
00105
00106 float bThreshold = 0.67;
00107 int status = 0;
00108 if ((beta > bThreshold) && (charge != 0) && (nameVolume == "ZDC_EMFiber" || nameVolume == "ZDC_HadFiber")) {
00109 status = 1;
00110 LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: pass ";
00111
00112 float nMedium = 1.4925;
00113
00114
00115
00116 float photEnSpectrDE = 1.24;
00117
00118
00119
00120
00121
00122 float effPMTandTransport = 0.15;
00123
00124
00125 float thFullRefl = 23.;
00126 float thFullReflRad = thFullRefl*pi/180.;
00127
00128 edm::ParameterSet m_ZdcSD = p.getParameter<edm::ParameterSet>("ZdcSD");
00129 thFibDir = m_ZdcSD.getParameter<double>("FiberDirection");
00130
00131 float thFibDirRad = thFibDir*pi/180.;
00132
00133
00134
00135
00136
00137 float costh = hit_mom.z()/sqrt(hit_mom.x()*hit_mom.x()+
00138 hit_mom.y()*hit_mom.y()+
00139 hit_mom.z()*hit_mom.z());
00140 float th = acos(std::min(std::max(costh,float(-1.)),float(1.)));
00141
00142 if (th < 0.) th += twopi;
00143
00144
00145 float costhcher =1./(nMedium*beta);
00146 float thcher = acos(std::min(std::max(costhcher,float(-1.)),float(1.)));
00147
00148
00149 float DelFibPart = fabs(th - thFibDirRad);
00150
00151
00152 float d = fabs(tan(th)-tan(thFibDirRad));
00153
00154
00155
00156 float a = tan(thFibDirRad)+tan(fabs(thFibDirRad-thFullReflRad));
00157 float r = tan(th)+tan(fabs(th-thcher));
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 float d_qz = -1;
00169 float variant = -1;
00170
00171
00172 if (DelFibPart > (thFullReflRad + thcher) ) {
00173 variant = 0.; d_qz = 0.;
00174 }
00175 else {
00176
00177 if ((th + thcher) < (thFibDirRad+thFullReflRad) && (th - thcher) > (thFibDirRad-thFullReflRad) ) {
00178 variant = 1.; d_qz = 1.;
00179 }
00180 else {
00181
00182 if ((thFibDirRad + thFullReflRad) < (th + thcher) && (thFibDirRad - thFullReflRad) > (th - thcher) ) {
00183 variant = 2.; d_qz = 0.;
00184 }
00185 else {
00186
00187 variant = 3.;
00188
00189
00190 float arg_arcos = 0.;
00191 float tan_arcos = 2.*a*d;
00192 if (tan_arcos != 0.) arg_arcos =(r*r-a*a-d*d)/tan_arcos;
00193
00194 arg_arcos = fabs(arg_arcos);
00195
00196 float th_arcos = acos(std::min(std::max(arg_arcos,float(-1.)),float(1.)));
00197
00198 d_qz = th_arcos/pi/2.;
00199
00200 d_qz = fabs(d_qz);
00201
00202 }
00203 }
00204 }
00205
00206
00207
00208 double meanNCherPhot = 0.;
00209 G4int poissNCherPhot = 0;
00210 if (d_qz > 0) {
00211 meanNCherPhot = 370.*charge*charge*( 1. - 1./(nMedium*nMedium*beta*beta) ) * photEnSpectrDE * stepL;
00212
00213
00214
00215 edm::Service<edm::RandomNumberGenerator> rng;
00216 if ( ! rng.isAvailable()) {
00217 throw cms::Exception("Configuration")
00218 << "ZdcSD requires the RandomNumberGeneratorService\n"
00219 << "which is not present in the configuration file. "
00220 << "You must add the service\n" << "in the configuration file "
00221 << "or remove the modules that require it.";
00222 }
00223 CLHEP::RandPoissonQ randPoisson(rng->getEngine());
00224 poissNCherPhot = (G4int) randPoisson.fire(meanNCherPhot);
00225
00226
00227 if (poissNCherPhot < 0) poissNCherPhot = 0;
00228
00229
00230 NCherPhot = poissNCherPhot * effPMTandTransport * d_qz;
00231 }
00232
00233 LogDebug("ForwardSim")
00234 << "ZdcSD:: getEnergyDeposit: gED: "
00235 << stepE
00236 << "," << costh
00237 << "," << th
00238 << "," << costhcher
00239 << "," << thcher
00240 << "," << DelFibPart
00241 << "," << d
00242 << "," << a
00243 << "," << r
00244 << "," << hitPoint
00245 << "," << hit_mom
00246 << "," << stepControlFlag
00247 << "," << entot
00248 << "," << vert_mom
00249 << "," << localPoint
00250 << "," << charge
00251 << "," << beta
00252 << "," << stepL
00253 << "," << d_qz
00254 << "," << variant
00255 << "," << meanNCherPhot
00256 << "," << poissNCherPhot
00257 << "," << NCherPhot;
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 }
00273 else {
00274
00275 status = 0;
00276 if (beta <= bThreshold)
00277 LogDebug("ForwardSim")
00278 << "ZdcSD:: getEnergyDeposit: fail beta=" << beta;
00279 if (charge == 0)
00280 LogDebug("ForwardSim")
00281 << "ZdcSD:: getEnergyDeposit: fail charge=0";
00282 if ( !(nameVolume == "ZDC_EMFiber" || nameVolume == "ZDC_HadFiber") )
00283 LogDebug("ForwardSim")
00284 << "ZdcSD:: getEnergyDeposit: fail nv=" << nameVolume;
00285 }
00286
00287
00288 return NCherPhot;
00289 }
00290 }
00291
00292 uint32_t ZdcSD::setDetUnitId(G4Step* aStep) {
00293 uint32_t returnNumber = 0;
00294 if(numberingScheme != 0)returnNumber = numberingScheme->getUnitID(aStep);
00295
00296 return returnNumber;
00297 }
00298
00299 void ZdcSD::setNumberingScheme(ZdcNumberingScheme* scheme) {
00300 if (scheme != 0) {
00301 edm::LogInfo("ForwardSim") << "ZdcSD: updates numbering scheme for "
00302 << GetName();
00303 if (numberingScheme) delete numberingScheme;
00304 numberingScheme = scheme;
00305 }
00306 }
00307
00308
00309