9 #include "G4LogicalVolumeStore.hh"
10 #include "G4LogicalVolume.hh"
13 #include "G4VProcess.hh"
14 #include "G4Poisson.hh"
29 CaloSD(name, cpv, clg, p, manager) {
40 edm::LogInfo(
"EcalSim") <<
"Constructing a DreamSD with name " << GetName() <<
"\n"
41 <<
"DreamSD:: Use of Birks law is set to "
42 << useBirk <<
" with three constants kB = "
43 << birk1 <<
", C1 = " << birk2 <<
", C2 = "
45 <<
" Slope for Light yield is set to "
47 <<
" Parameterization of Cherenkov is set to "
48 << doCherenkov_ <<
" and readout both sides is "
58 <<
"please add it to config file";
60 ntuple_ = tfile->
make<TTree>(
"tree",
"Cherenkov photons");
100 G4String nameVolume =
preStepPoint->GetPhysicalVolume()->GetName();
107 LogDebug(
"EcalSim") <<
"DreamSD:: " << nameVolume <<
" Side " <<
side
108 <<
" Light Collection Efficiency " << weight
109 <<
" Weighted Energy Deposit " <<
edepositEM/MeV
118 double time = (aStep->GetPostStepPoint()->GetGlobalTime())/nanosecond;
120 if (
side < 0) unitID++;
129 if (primaryID == 0) {
130 edm::LogWarning(
"EcalSim") <<
"CaloSD: Problem with primaryID **** set by "
131 <<
"force to TkID **** "
132 <<
theTrack->GetTrackID() <<
" in Volume "
133 <<
preStepPoint->GetTouchable()->GetVolume(0)->GetName();
137 bool flag = (unitID > 0);
138 G4TouchableHistory* touch =(G4TouchableHistory*)(
theTrack->GetTouchable());
142 LogDebug(
"EcalSim") <<
"CaloSD:: GetStepInfo for"
143 <<
" PV " << touch->GetVolume(0)->GetName()
144 <<
" PVid = " << touch->GetReplicaNumber(0)
145 <<
" MVid = " << touch->GetReplicaNumber(1)
149 LogDebug(
"EcalSim") <<
"CaloSD:: GetStepInfo for"
150 <<
" PV " << touch->GetVolume(0)->GetName()
151 <<
" PVid = " << touch->GetReplicaNumber(0)
152 <<
" MVid = " << touch->GetReplicaNumber(1)
153 <<
" Unit " << std::hex << unitID << std::dec
165 DimensionMap::const_iterator ite =
xtalLMap.begin();
166 G4LogicalVolume* lv = (ite->first);
167 G4Material* material = lv->GetMaterial();
168 edm::LogInfo(
"EcalSim") <<
"DreamSD::initRun: Initializes for material "
169 << material->GetName() <<
" in " << lv->GetName();
173 edm::LogWarning(
"EcalSim") <<
"Couldn't retrieve material properties table\n"
174 <<
" Material = " << material->GetName();
183 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
184 uint32_t
id = (touch->GetReplicaNumber(1))*10 + (touch->GetReplicaNumber(0));
185 LogDebug(
"EcalSim") <<
"DreamSD:: ID " << id;
193 G4String attribute =
"ReadOutName";
201 const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
202 std::vector<G4LogicalVolume *>::const_iterator lvcite;
208 G4LogicalVolume* lv=0;
209 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
210 if ((*lvcite)->GetName() ==
name) {
214 LogDebug(
"EcalSim") <<
"DreamSD::initMap (for " << sd <<
"): Solid "
215 << name <<
" Shape " << sol.
shape() <<
" Parameter 0 = "
216 << paras[0] <<
" Logical Volume " << lv;
217 double length = 0,
width = 0;
220 length = 2.0*paras.back();
221 width = 2.0*paras.front();
225 LogDebug(
"EcalSim") <<
"DreamSD: Length Table for " << attribute <<
" = "
227 DimensionMap::const_iterator ite =
xtalLMap.begin();
229 for (; ite !=
xtalLMap.end(); ite++, i++) {
230 G4String
name =
"Unknown";
231 if (ite->first != 0) name = (ite->first)->GetName();
232 LogDebug(
"EcalSim") <<
" " << i <<
" " << ite->first <<
" " << name
233 <<
" L = " << ite->second.first
234 <<
" W = " << ite->second.second;
241 G4StepPoint* stepPoint = aStep->GetPreStepPoint();
242 G4LogicalVolume* lv = stepPoint->GetTouchable()->GetVolume(0)->GetLogicalVolume();
243 G4String nameVolume= lv->GetName();
246 G4ThreeVector localPoint =
setToLocal(stepPoint->GetPosition(),
247 stepPoint->GetTouchable());
249 double localz = localPoint.x();
250 double dapd = 0.5 * crlength - flag*localz;
251 if (dapd >= -0.1 || dapd <= crlength+0.1) {
255 edm::LogWarning(
"EcalSim") <<
"DreamSD: light coll curve : wrong distance "
256 <<
"to APD " << dapd <<
" crlength = "
257 << crlength <<
" crystal name = " << nameVolume
258 <<
" z of localPoint = " << localz
259 <<
" take weight = " <<
weight;
261 LogDebug(
"EcalSim") <<
"DreamSD, light coll curve : " << dapd
262 <<
" crlength = " << crlength
263 <<
" crystal name = " << nameVolume
264 <<
" z of localPoint = " << localz
265 <<
" take weight = " <<
weight;
273 DimensionMap::const_iterator ite =
xtalLMap.find(lv);
274 if (ite !=
xtalLMap.end()) length = ite->second.first;
283 DimensionMap::const_iterator ite =
xtalLMap.find(lv);
284 if (ite !=
xtalLMap.end()) width = ite->second.second;
295 double cherenkovEnergy = 0;
297 G4Material* material = aStep->GetTrack()->GetMaterial();
301 if ( Rindex ==
NULL ) {
303 return cherenkovEnergy;
308 int Rlength = Rindex->GetVectorLength() - 1;
309 double Pmin = Rindex->Energy(0);
310 double Pmax = Rindex->Energy(Rlength);
311 LogDebug(
"EcalSim") <<
"Material properties: " <<
"\n"
312 <<
" Pmin = " << Pmin
313 <<
" Pmax = " << Pmax;
316 G4StepPoint* pPreStepPoint = aStep->GetPreStepPoint();
317 G4StepPoint* pPostStepPoint = aStep->GetPostStepPoint();
318 G4ThreeVector x0 = pPreStepPoint->GetPosition();
319 G4ThreeVector p0 = aStep->GetDeltaPosition().unit();
320 const G4DynamicParticle* aParticle = aStep->GetTrack()->GetDynamicParticle();
321 const double charge = aParticle->GetDefinition()->GetPDGCharge();
323 double beta = 0.5*( pPreStepPoint->GetBeta() + pPostStepPoint->GetBeta() );
324 double BetaInverse = 1.0/
beta;
326 LogDebug(
"EcalSim") <<
"Particle properties: " <<
"\n"
327 <<
" charge = " << charge
328 <<
" beta = " <<
beta;
332 if ( meanNumberOfPhotons <= 0.0 ) {
333 LogDebug(
"EcalSim") <<
"Mean number of photons is zero: " << meanNumberOfPhotons
334 <<
", stopping here";
335 return cherenkovEnergy;
339 meanNumberOfPhotons *= aStep->GetStepLength();
342 int numPhotons =
static_cast<int>( G4Poisson(meanNumberOfPhotons) );
344 if ( numPhotons <= 0 ) {
345 LogDebug(
"EcalSim") <<
"Poission number of photons is zero: " << numPhotons
346 <<
", stopping here";
347 return cherenkovEnergy;
351 double dp = Pmax - Pmin;
352 double maxCos = BetaInverse / (*Rindex)[Rlength];
353 double maxSin2 = (1.0 - maxCos) * (1.0 + maxCos);
356 for (
int iPhoton = 0; iPhoton<numPhotons; ++iPhoton ) {
360 double sampledMomentum, sampledRI;
361 double cosTheta, sin2Theta;
365 randomNumber = G4UniformRand();
366 sampledMomentum = Pmin + randomNumber *
dp;
367 sampledRI = Rindex->Value(sampledMomentum);
368 cosTheta = BetaInverse / sampledRI;
370 sin2Theta = (1.0 - cosTheta)*(1.0 + cosTheta);
371 randomNumber = G4UniformRand();
373 }
while (randomNumber*maxSin2 > sin2Theta);
377 randomNumber = G4UniformRand();
379 double phi = twopi*randomNumber;
380 double sinPhi =
sin(phi);
381 double cosPhi =
cos(phi);
386 double sinTheta =
sqrt(sin2Theta);
387 double px = sinTheta*cosPhi;
388 double py = sinTheta*sinPhi;
389 double pz = cosTheta;
390 G4ThreeVector photonDirection(px, py, pz);
393 photonDirection.rotateUz(p0);
396 randomNumber = G4UniformRand();
397 G4ThreeVector photonPosition = x0 + randomNumber * aStep->GetDeltaPosition();
398 G4ThreeVector photonMomentum = sampledMomentum*photonDirection;
405 px_[iPhoton] = photonMomentum.x();
406 py_[iPhoton] = photonMomentum.y();
407 pz_[iPhoton] = photonMomentum.z();
408 x_[iPhoton] = photonPosition.x();
409 y_[iPhoton] = photonPosition.y();
410 z_[iPhoton] = photonPosition.z();
417 return cherenkovEnergy;
427 const G4Material* aMaterial,
428 G4MaterialPropertyVector* Rindex )
430 const G4double rFact = 369.81/(eV * cm);
432 if( beta <= 0.0 )
return 0.0;
434 double BetaInverse = 1./
beta;
441 int Rlength = Rindex->GetVectorLength() - 1;
442 double Pmin = Rindex->Energy(0);
443 double Pmax = Rindex->Energy(Rlength);
446 double nMin = (*Rindex)[0];
447 double nMax = (*Rindex)[Rlength];
452 double dp = 0., ge = 0., CAImin = 0.;
455 if ( nMax < BetaInverse) { }
458 else if (nMin > BetaInverse) {
468 Pmin = Rindex->Value(BetaInverse);
473 ge = CAImax - CAImin;
478 double numPhotons = rFact * charge/eplus * charge/eplus *
479 (dp - ge * BetaInverse*BetaInverse);
481 LogDebug(
"EcalSim") <<
"@SUB=getAverageNumberOfPhotons"
482 <<
"CAImin = " << CAImin <<
"\n"
483 <<
"CAImax = " << CAImax <<
"\n"
484 <<
"dp = " << dp <<
", ge = " << ge <<
"\n"
485 <<
"numPhotons = " << numPhotons;
500 if ( pbWO2Name != aMaterial->GetName() ) {
502 <<
"expecting " << pbWO2Name
503 <<
", got " << aMaterial->GetName();
507 G4MaterialPropertiesTable*
table =
new G4MaterialPropertiesTable();
511 const int nEntries = 14;
512 double PhotonEnergy[nEntries] = { 1.7712*eV, 1.8368*eV, 1.90745*eV, 1.98375*eV, 2.0664*eV,
513 2.15625*eV, 2.25426*eV, 2.3616*eV, 2.47968*eV, 2.61019*eV,
514 2.75521*eV, 2.91728*eV, 3.09961*eV, 3.30625*eV };
515 double RefractiveIndex[nEntries] = { 2.17728, 2.18025, 2.18357, 2.18753, 2.19285,
516 2.19813, 2.20441, 2.21337, 2.22328, 2.23619,
517 2.25203, 2.27381, 2.30282, 2.34666 };
519 table->AddProperty(
"RINDEX", PhotonEnergy, RefractiveIndex, nEntries );
520 aMaterial->SetMaterialPropertiesTable(table);
525 std::auto_ptr<G4PhysicsOrderedFreeVector>(
new G4PhysicsOrderedFreeVector() );
528 double currentRI = RefractiveIndex[
index];
529 double currentPM = PhotonEnergy[
index];
530 double currentCAI = 0.0;
532 double prevPM = currentPM;
533 double prevCAI = currentCAI;
534 double prevRI = currentRI;
535 while ( ++index < nEntries ) {
536 currentRI = RefractiveIndex[
index];
537 currentPM = PhotonEnergy[
index];
538 currentCAI = 0.5*(1.0/(prevRI*prevRI) + 1.0/(currentRI*currentRI));
539 currentCAI = prevCAI + (currentPM - prevPM) * currentCAI;
544 prevCAI = currentCAI;
548 LogDebug(
"EcalSim") <<
"Material properties set for " << aMaterial->GetName();
561 const G4ThreeVector&
x,
562 const G4Step* aStep )
575 G4StepPoint* stepPoint = aStep->GetPreStepPoint();
576 G4LogicalVolume* lv = stepPoint->GetTouchable()->GetVolume(0)->GetLogicalVolume();
577 G4String nameVolume= lv->GetName();
581 double dapd = 0.5 * crlength - x.x();
582 double y = p.y()/p.x()*dapd;
584 LogDebug(
"EcalSim") <<
"Distance to APD: " << dapd
585 <<
" - y at APD: " <<
y;
588 if ( fabs(y)>crwidth*0.5 ) {
593 double waveLength = p.mag()*1.239e8;
598 LogDebug(
"EcalSim") <<
"Wavelength: " << waveLength <<
" - Energy: " <<
energy;
G4ThreeVector setToLocal(G4ThreeVector, const G4VTouchable *)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
void addFilter(const DDFilter &, log_op op=AND)
virtual G4bool getStepInfo(G4Step *aStep)
double getPhotonEnergyDeposit_(const G4ParticleMomentum &p, const G4ThreeVector &x, const G4Step *aStep)
Returns energy deposit for a given photon.
std::pair< double, double > Doubles
virtual bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory)
Sin< T >::type sin(const T &t)
double getAverageNumberOfPhotons_(const double charge, const double beta, const G4Material *aMaterial, G4MaterialPropertyVector *rIndex)
Returns average number of photons created by track.
bool setPbWO2MaterialProperties_(G4Material *aMaterial)
Sets material properties at run-time...
std::auto_ptr< G4PhysicsOrderedFreeVector > chAngleIntegrals_
Table of Cherenkov angle integrals vs photon momentum.
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
virtual uint32_t setDetUnitId(G4Step *)
type of data representation of DDCompactView
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
A DDSolid represents the shape of a part.
bool next()
set current node to the next node in the filtered tree
Cos< T >::type cos(const T &t)
DreamSD(G4String, const DDCompactView &, SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
DDSolidShape shape(void) const
The type of the solid.
double getAttenuation(G4Step *aStep, double birk1, double birk2, double birk3)
G4MaterialPropertiesTable * materialPropertiesTable
const double crystalWidth(G4LogicalVolume *) const
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
G4StepPoint * preStepPoint
double cherenkovDeposit_(G4Step *aStep)
Returns the total energy due to Cherenkov radiation.
bool firstChild()
set the current node to the first child ...
T * make() const
make new ROOT object
void setCriteria(const DDValue &nameVal, comp_op, log_op l=AND, bool asString=true, bool merged=true)
const double crystalLength(G4LogicalVolume *) const
void initMap(G4String, const DDCompactView &)
const std::string & name() const
Returns the name.
double curve_LY(G4Step *, int)
static const double getEfficiency(const double &waveLengthNm)
Return efficiency for given photon wavelength (in nm)
CaloG4Hit * createNewHit()
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.