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" 53 #include "G4UnitsTable.hh" 54 #include "G4UserSteppingAction.hh" 55 #include "G4VPhysicalVolume.hh" 56 #include "G4VTouchable.hh" 58 #include <CLHEP/Units/SystemOfUnits.h> 70 public Observer<const BeginOfEvent*>,
90 void NaNTrap(
const G4Step*)
const;
92 void fillHit(uint32_t
id,
double dE,
double time,
int primID, uint16_t
depth,
double em,
int flag);
93 uint16_t
getDepth(
bool flag,
double crystalDepth,
double radl)
const;
94 double curve_LY(
double crystalLength,
double crystalDepth)
const;
103 #ifdef HcalNumberingTest 105 std::unique_ptr<HcalNumberingFromDDD> hcNumbering_;
115 std::map<const G4LogicalVolume*, std::string>
mapLV_;
122 typedef std::tuple<const G4LogicalVolume*, uint32_t, int, int, double, double, double, double, double, double, double>
133 allSteps_(iC_.getParameter<
int>(
"AllSteps")),
134 slopeLY_(iC_.getParameter<double>(
"SlopeLightYield")),
135 birkC1EC_(iC_.getParameter<double>(
"BirkC1EC")),
136 birkSlopeEC_(iC_.getParameter<double>(
"BirkSlopeEC")),
137 birkCutEC_(iC_.getParameter<double>(
"BirkCutEC")),
138 birkC1HC_(iC_.getParameter<double>(
"BirkC1HC")),
139 birkC2HC_(iC_.getParameter<double>(
"BirkC2HC")),
140 birkC3HC_(iC_.getParameter<double>(
"BirkC3HC")),
141 timeSliceUnit_(iC_.getUntrackedParameter<double>(
"TimeSliceUnit", 1.0)),
167 #ifdef HcalNumberingTest 168 hcNumbering_.reset(
nullptr);
172 produces<edm::PCaloHitContainer>(
nameHitC_[
k]);
175 produces<edm::PassiveHitContainer>(
"AllPassiveHits");
180 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: --------> Total number of " 181 <<
"selected entries : " <<
count_;
185 #ifdef HcalNumberingTest 187 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::Initialize ESGetToken for HcalDDDSimConstants";
194 auto product = std::make_unique<edm::PCaloHitContainer>();
207 <<
slave_[
type].get()->hits().size() <<
" hits";
214 for (
const auto& element :
store_) {
215 auto lv = std::get<0>(element);
219 std::get<1>(element),
220 std::get<5>(element),
221 std::get<6>(element),
222 std::get<4>(element),
223 std::get<2>(element),
224 std::get<3>(element),
225 std::get<7>(element),
226 std::get<8>(element),
227 std::get<9>(element),
228 std::get<10>(element));
229 cc.emplace_back(
hit);
237 #ifdef HcalNumberingTest 241 <<
"HcalNumberingFromDDD";
242 hcNumbering_ = std::make_unique<HcalNumberingFromDDD>(hcons_);
248 int irun = (*run)()->GetRunID();
251 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
253 std::map<const std::string, const G4LogicalVolume*> nameMap;
254 std::map<const std::string, const G4LogicalVolume*>::const_iterator itr;
255 for (
auto lvi = lvs->begin(), lve = lvs->end(); lvi != lve; ++lvi) {
256 nameMap.emplace((*lvi)->GetName(), *lvi);
258 mapLV_[*lvi] = (*lvi)->GetName();
262 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
264 if (lvname.find(
name) != std::string::npos) {
266 int type = (lvname.find(
"refl") == std::string::npos) ? -1 : 1;
267 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
268 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
269 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second,
dz *
type));
271 mapLV_[itr->second] = itr->first;
276 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
278 if (lvname.find(
name) != std::string::npos) {
280 int type = (lvname.find(
"refl") == std::string::npos) ? 1 : -1;
281 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
282 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
283 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second,
dz *
type));
285 mapLV_[itr->second] = itr->first;
291 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
293 if (lvname.find(
name) != std::string::npos) {
296 mapLV_[itr->second] = itr->first;
313 for (
auto itr =
mapLV_.begin(); itr !=
mapLV_.end(); ++itr) {
314 edm::LogVerbatim(
"Step") <<
"[" <<
k <<
"] " << itr->second <<
":" << itr->first;
336 auto lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
341 if (hc || eb || ee) {
342 double dEStep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
343 auto const theTrack = aStep->GetTrack();
344 double time = theTrack->GetGlobalTime() / CLHEP::nanosecond;
345 int primID = theTrack->GetTrackID();
347 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
348 auto const& hitPoint = aStep->GetPreStepPoint()->GetPosition();
350 int depth = (touch->GetReplicaNumber(0)) % 10 + 1;
351 int lay = (touch->GetReplicaNumber(0) / 10) % 100 + 1;
352 int det = (touch->GetReplicaNumber(1)) / 1000;
354 if (unitID > 0 && dEStep > 0.0) {
356 (aStep->GetStepLength() / CLHEP::cm),
357 aStep->GetPreStepPoint()->GetCharge(),
358 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3)));
363 int size = touch->GetHistoryDepth() + 1;
369 theBaseNumber.
addLevel(touch->GetVolume(
ii)->GetName(), touch->GetReplicaNumber(
ii));
373 if (unitID > 0 && dEStep > 0.0) {
374 auto local = touch->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
376 double crystalLength = ((ite ==
xtalMap_.end()) ? 230.0 :
std::abs(ite->second));
377 double crystalDepth =
379 double radl = aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() / CLHEP::mm;
380 bool flag = ((ite ==
xtalMap_.end()) ?
true : (((ite->second) >= 0) ?
true :
false));
383 (aStep->GetStepLength() / CLHEP::cm),
384 aStep->GetPreStepPoint()->GetCharge(),
385 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3))) *
386 curve_LY(crystalLength, crystalDepth));
395 double energy = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
396 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
397 double time = aStep->GetTrack()->GetGlobalTime() / CLHEP::nanosecond;
398 int trackId = aStep->GetTrack()->GetTrackID();
399 int pdg = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
400 double stepl = (aStep->GetStepLength() / CLHEP::cm);
401 double xp = aStep->GetPreStepPoint()->GetPosition().x() / CLHEP::cm;
402 double yp = aStep->GetPreStepPoint()->GetPosition().y() / CLHEP::cm;
403 double zp = aStep->GetPreStepPoint()->GetPosition().z() / CLHEP::cm;
405 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: Volume " << lv->GetName() <<
" History " 406 << touch->GetHistoryDepth() <<
" Pointers " << aStep->GetPostStepPoint() <<
":" 407 << aStep->GetTrack()->GetNextVolume() <<
":" << aStep->IsLastStepInVolume() <<
" E " 408 <<
energy <<
" T " <<
time <<
" PDG " <<
pdg <<
" step " << stepl <<
" Position (" << xp
409 <<
", " << yp <<
", " << zp <<
")";
412 if (((aStep->GetPostStepPoint() ==
nullptr) || (aStep->GetTrack()->GetNextVolume() ==
nullptr)) &&
413 (aStep->IsLastStepInVolume())) {
414 energy += (aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::MeV);
416 time = aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::nanosecond;
418 copy = (touch->GetHistoryDepth() < 1)
419 ? static_cast<uint32_t>(touch->GetReplicaNumber(0))
420 : static_cast<uint32_t>(touch->GetReplicaNumber(0) + 1000 * touch->GetReplicaNumber(1));
422 PassiveData key(std::make_tuple(lv,
copy, trackId,
pdg,
time,
energy,
energy, stepl, xp, yp, zp));
432 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: EndOfEvent " << (*evt)()->GetEventID();
436 auto currentPos = aStep->GetTrack()->GetPosition();
437 double xyz = currentPos.x() + currentPos.y() + currentPos.z();
438 auto currentMom = aStep->GetTrack()->GetMomentum();
439 xyz += currentMom.x() + currentMom.y() + currentMom.z();
442 auto pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
443 auto& nameOfVol = pCurrentVol->GetName();
445 <<
" Corrupted Event - NaN detected in volume " << nameOfVol <<
"\n";
451 #ifdef HcalNumberingTest 463 double edepEM = (em ? dE : 0);
464 double edepHAD = (em ? 0 : dE);
465 std::pair<int, CaloHitID> evID = std::make_pair(
eventID_, currentID);
468 (
it->second).addEnergyDeposit(edepEM, edepHAD);
472 aHit.
setID(currentID);
480 uint16_t depth2 = (uint16_t)floor(crystalDepth / radl);
483 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getDepth radl " << radl <<
":" << crystalDepth <<
" depth " <<
depth;
490 double dapd = crystalLength - crystalDepth;
491 if (dapd >= -0.1 || dapd <= crystalLength + 0.1) {
495 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::curve_LY " << crystalDepth <<
":" << crystalLength <<
":" << dapd
499 edm::LogWarning(
"Step") <<
"CaloSteppingAction: light coll curve : wrong " 500 <<
"distance to APD " << dapd <<
" crlength = " << crystalLength
501 <<
" crystal Depth = " << crystalDepth <<
" weight = " <<
weight;
509 double dedx = dEStep /
step;
519 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkL3 Charge " <<
charge <<
" dE/dx " << dedx <<
" Birk Const " 520 << rkb <<
" Weight = " <<
weight <<
" dE " << dEStep <<
" step " <<
step;
529 double dedx = dEStep /
step;
534 weight = 1. / (1. + rkb * dedx +
c * dedx * dedx);
536 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkHC Charge " <<
charge <<
" dE/dx " << dedx <<
" Birk Const " 537 << rkb <<
", " <<
c <<
" Weight = " <<
weight <<
" dE " << dEStep;
549 0.001 *
hit.second.getEM(),
550 0.001 *
hit.second.getHadr(),
551 hit.second.getTimeSlice(),
552 hit.second.getTrackID(),
553 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)
key
prepare the HTCondor submission files and eventually submit them
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