20 #ifdef HcalNumberingTest 43 #include "G4LogicalVolume.hh" 44 #include "G4LogicalVolumeStore.hh" 45 #include "G4NavigationHistory.hh" 46 #include "G4ParticleTable.hh" 47 #include "G4PhysicalVolumeStore.hh" 48 #include "G4Region.hh" 49 #include "G4RegionStore.hh" 51 #include "G4SystemOfUnits.hh" 54 #include "G4UnitsTable.hh" 55 #include "G4UserSteppingAction.hh" 56 #include "G4VPhysicalVolume.hh" 57 #include "G4VTouchable.hh" 69 public Observer<const BeginOfEvent*>,
89 void NaNTrap(
const G4Step*)
const;
91 void fillHit(uint32_t
id,
double dE,
double time,
int primID, uint16_t
depth,
double em,
int flag);
92 uint16_t
getDepth(
bool flag,
double crystalDepth,
double radl)
const;
93 double curve_LY(
double crystalLength,
double crystalDepth)
const;
102 #ifdef HcalNumberingTest 104 std::unique_ptr<HcalNumberingFromDDD> hcNumbering_;
114 std::map<const G4LogicalVolume*, std::string>
mapLV_;
121 typedef std::tuple<const G4LogicalVolume*, uint32_t, int, int, double, double, double, double, double, double, double>
132 allSteps_(iC_.getParameter<
int>(
"AllSteps")),
133 slopeLY_(iC_.getParameter<double>(
"SlopeLightYield")),
134 birkC1EC_(iC_.getParameter<double>(
"BirkC1EC")),
135 birkSlopeEC_(iC_.getParameter<double>(
"BirkSlopeEC")),
136 birkCutEC_(iC_.getParameter<double>(
"BirkCutEC")),
137 birkC1HC_(iC_.getParameter<double>(
"BirkC1HC")),
138 birkC2HC_(iC_.getParameter<double>(
"BirkC2HC")),
139 birkC3HC_(iC_.getParameter<double>(
"BirkC3HC")),
140 timeSliceUnit_(iC_.getUntrackedParameter<double>(
"TimeSliceUnit", 1.0)),
166 #ifdef HcalNumberingTest 167 hcNumbering_.reset(
nullptr);
171 produces<edm::PCaloHitContainer>(
nameHitC_[
k]);
174 produces<edm::PassiveHitContainer>(
"AllPassiveHits");
179 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: --------> Total number of " 180 <<
"selected entries : " <<
count_;
184 #ifdef HcalNumberingTest 186 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::Initialize ESGetToken for HcalDDDSimConstants";
193 auto product = std::make_unique<edm::PCaloHitContainer>();
206 <<
slave_[
type].get()->hits().size() <<
" hits";
213 for (
const auto& element :
store_) {
214 auto lv = std::get<0>(element);
215 auto it =
mapLV_.find(lv);
218 std::get<1>(element),
219 std::get<5>(element),
220 std::get<6>(element),
221 std::get<4>(element),
222 std::get<2>(element),
223 std::get<3>(element),
224 std::get<7>(element),
225 std::get<8>(element),
226 std::get<9>(element),
227 std::get<10>(element));
228 cc.emplace_back(
hit);
236 #ifdef HcalNumberingTest 240 <<
"HcalNumberingFromDDD";
241 hcNumbering_ = std::make_unique<HcalNumberingFromDDD>(hcons_);
247 int irun = (*run)()->GetRunID();
250 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
252 std::map<const std::string, const G4LogicalVolume*> nameMap;
253 std::map<const std::string, const G4LogicalVolume*>::const_iterator itr;
254 for (
auto lvi = lvs->begin(), lve = lvs->end(); lvi != lve; ++lvi) {
255 nameMap.emplace((*lvi)->GetName(), *lvi);
257 mapLV_[*lvi] = (*lvi)->GetName();
261 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
263 if (lvname.find(
name) != std::string::npos) {
265 int type = (lvname.find(
"refl") == std::string::npos) ? -1 : 1;
266 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
267 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
268 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second,
dz *
type));
270 mapLV_[itr->second] = itr->first;
275 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
277 if (lvname.find(
name) != std::string::npos) {
279 int type = (lvname.find(
"refl") == std::string::npos) ? 1 : -1;
280 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
281 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
282 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second,
dz *
type));
284 mapLV_[itr->second] = itr->first;
290 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
292 if (lvname.find(
name) != std::string::npos) {
295 mapLV_[itr->second] = itr->first;
312 for (
auto itr =
mapLV_.begin(); itr !=
mapLV_.end(); ++itr) {
313 edm::LogVerbatim(
"Step") <<
"[" <<
k <<
"] " << itr->second <<
":" << itr->first;
335 auto lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
340 if (hc || eb || ee) {
341 double dEStep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
342 auto const theTrack = aStep->GetTrack();
343 double time = theTrack->GetGlobalTime() / CLHEP::nanosecond;
344 int primID = theTrack->GetTrackID();
346 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
347 auto const& hitPoint = aStep->GetPreStepPoint()->GetPosition();
349 int depth = (touch->GetReplicaNumber(0)) % 10 + 1;
350 int lay = (touch->GetReplicaNumber(0) / 10) % 100 + 1;
351 int det = (touch->GetReplicaNumber(1)) / 1000;
353 if (unitID > 0 && dEStep > 0.0) {
355 (aStep->GetStepLength() / CLHEP::cm),
356 aStep->GetPreStepPoint()->GetCharge(),
357 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3)));
362 int size = touch->GetHistoryDepth() + 1;
368 theBaseNumber.
addLevel(touch->GetVolume(
ii)->GetName(), touch->GetReplicaNumber(
ii));
372 if (unitID > 0 && dEStep > 0.0) {
373 auto local = touch->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
375 double crystalLength = ((ite ==
xtalMap_.end()) ? 230.0 :
std::abs(ite->second));
376 double crystalDepth =
378 double radl = aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() / CLHEP::mm;
379 bool flag = ((ite ==
xtalMap_.end()) ?
true : (((ite->second) >= 0) ?
true :
false));
382 (aStep->GetStepLength() / CLHEP::cm),
383 aStep->GetPreStepPoint()->GetCharge(),
384 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3))) *
385 curve_LY(crystalLength, crystalDepth));
392 auto it =
mapLV_.find(lv);
394 double energy = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
395 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
396 double time = aStep->GetTrack()->GetGlobalTime() / CLHEP::nanosecond;
397 int trackId = aStep->GetTrack()->GetTrackID();
398 int pdg = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
399 double stepl = (aStep->GetStepLength() / CLHEP::cm);
400 double xp = aStep->GetPreStepPoint()->GetPosition().x() / CLHEP::cm;
401 double yp = aStep->GetPreStepPoint()->GetPosition().y() / CLHEP::cm;
402 double zp = aStep->GetPreStepPoint()->GetPosition().z() / CLHEP::cm;
404 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: Volume " << lv->GetName() <<
" History " 405 << touch->GetHistoryDepth() <<
" Pointers " << aStep->GetPostStepPoint() <<
":" 406 << aStep->GetTrack()->GetNextVolume() <<
":" << aStep->IsLastStepInVolume() <<
" E " 407 <<
energy <<
" T " <<
time <<
" PDG " <<
pdg <<
" step " << stepl <<
" Position (" << xp
408 <<
", " << yp <<
", " << zp <<
")";
411 if (((aStep->GetPostStepPoint() ==
nullptr) || (aStep->GetTrack()->GetNextVolume() ==
nullptr)) &&
412 (aStep->IsLastStepInVolume())) {
413 energy += (aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::MeV);
415 time = aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::nanosecond;
417 copy = (touch->GetHistoryDepth() < 1)
418 ? static_cast<uint32_t>(touch->GetReplicaNumber(0))
419 : static_cast<uint32_t>(touch->GetReplicaNumber(0) + 1000 * touch->GetReplicaNumber(1));
421 PassiveData key(std::make_tuple(lv,
copy, trackId,
pdg,
time,
energy,
energy, stepl, xp, yp, zp));
431 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: EndOfEvent " << (*evt)()->GetEventID();
435 auto currentPos = aStep->GetTrack()->GetPosition();
436 double xyz = currentPos.x() + currentPos.y() + currentPos.z();
437 auto currentMom = aStep->GetTrack()->GetMomentum();
438 xyz += currentMom.x() + currentMom.y() + currentMom.z();
441 auto pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
442 auto& nameOfVol = pCurrentVol->GetName();
444 <<
" Corrupted Event - NaN detected in volume " << nameOfVol <<
"\n";
450 #ifdef HcalNumberingTest 462 double edepEM = (em ? dE : 0);
463 double edepHAD = (em ? 0 : dE);
464 std::pair<int, CaloHitID> evID = std::make_pair(
eventID_, currentID);
467 (it->second).addEnergyDeposit(edepEM, edepHAD);
471 aHit.
setID(currentID);
479 uint16_t depth2 = (uint16_t)floor(crystalDepth / radl);
482 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getDepth radl " << radl <<
":" << crystalDepth <<
" depth " <<
depth;
489 double dapd = crystalLength - crystalDepth;
490 if (dapd >= -0.1 || dapd <= crystalLength + 0.1) {
494 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::curve_LY " << crystalDepth <<
":" << crystalLength <<
":" << dapd
498 edm::LogWarning(
"Step") <<
"CaloSteppingAction: light coll curve : wrong " 499 <<
"distance to APD " << dapd <<
" crlength = " << crystalLength
500 <<
" crystal Depth = " << crystalDepth <<
" weight = " <<
weight;
508 double dedx = dEStep /
step;
518 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkL3 Charge " <<
charge <<
" dE/dx " << dedx <<
" Birk Const " 519 << rkb <<
" Weight = " <<
weight <<
" dE " << dEStep <<
" step " <<
step;
528 double dedx = dEStep /
step;
533 weight = 1. / (1. + rkb * dedx +
c * dedx * dedx);
535 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkHC Charge " <<
charge <<
" dE/dx " << dedx <<
" Birk Const " 536 << rkb <<
", " <<
c <<
" Weight = " <<
weight <<
" dE " << dEStep;
548 0.001 *
hit.second.getEM(),
549 0.001 *
hit.second.getHadr(),
550 hit.second.getTimeSlice(),
551 hit.second.getTrackID(),
552 hit.second.getDepth());
std::map< std::pair< int, CaloHitID >, CaloGVHit > hitMap_[nSD_]
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
std::vector< const G4LogicalVolume * > volEBSD_
void setID(uint32_t i, double d, int j, uint16_t k=0)
std::vector< PCaloHit > PCaloHitContainer
const std::vector< std::string > nameHitC_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const std::vector< std::string > nameEESD_
static const int kEcalDepthRefz
constexpr bool isNotFinite(T x)
void produce(edm::Event &, const edm::EventSetup &) override
uint32_t cc[maxCellsPerHit]
void registerConsumes(edm::ConsumesCollector) override
std::map< const G4LogicalVolume *, double > xtalMap_
std::vector< const G4LogicalVolume * > volHCSD_
const std::vector< std::string > nameEBSD_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
uint16_t getDepth(bool flag, double crystalDepth, double radl) const
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
void fillHits(edm::PCaloHitContainer &cc, int type)
void NaNTrap(const G4Step *) const
void addLevel(const std::string &name, const int ©Number)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
CaloSteppingAction(const edm::ParameterSet &p)
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
static const int kEcalDepthMask
Abs< T >::type abs(const T &t)
static const int kEcalDepthOffset
const double birkSlopeEC_
std::map< const G4LogicalVolume *, std::string > mapLV_
const edm::ParameterSet iC_
uint32_t getDetIDHC(int det, int lay, int depth, const math::XYZVectorD &pos) const
void fillPassiveHits(edm::PassiveHitContainer &cc)
std::vector< PassiveHit > PassiveHitContainer
void addEnergyDeposit(double em, double hd)
std::unique_ptr< CaloSlaveSD > slave_[nSD_]
void fillHit(uint32_t id, double dE, double time, int primID, uint16_t depth, double em, int flag)
const double timeSliceUnit_
double getBirkHC(double dE, double step, double chg, double dens) const
std::unique_ptr< HcalNumberingFromPS > hcNumberingPS_
std::unique_ptr< HcalNumberingScheme > hcNumberingScheme_
void beginRun(edm::EventSetup const &) override
std::vector< const G4LogicalVolume * > volEESD_
std::unique_ptr< EcalBarrelNumberingScheme > ebNumberingScheme_
std::tuple< const G4LogicalVolume *, uint32_t, int, int, double, double, double, double, double, double, double > PassiveData
static bool isGammaElectronPositron(int pdgCode)
std::unique_ptr< EcalEndcapNumberingScheme > eeNumberingScheme_
double getBirkL3(double dE, double step, double chg, double dens) const
std::vector< PassiveData > store_
const std::vector< std::string > nameHCSD_
Log< level::Warning, false > LogWarning
void setSize(const int &size)
double curve_LY(double crystalLength, double crystalDepth) const
~CaloSteppingAction() override