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;
94 double getBirkL3(
double dE,
double step,
double chg,
double dens)
const;
95 double getBirkHC(
double dE,
double step,
double chg,
double dens)
const;
102 #ifdef HcalNumberingTest
104 std::unique_ptr<HcalNumberingFromDDD> hcNumbering_;
113 std::map<const G4LogicalVolume*, std::string>
mapLV_;
119 typedef std::tuple<const G4LogicalVolume*, uint32_t, int, int, double, double, double, double, double, double, double>
140 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction:: " << nameEBSD_.size() <<
" names for EB SD's";
141 for (
unsigned int k = 0;
k < nameEBSD_.size(); ++
k)
143 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction:: " << nameEESD_.size() <<
" names for EE SD's";
144 for (
unsigned int k = 0;
k < nameEESD_.size(); ++
k)
146 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction:: " << nameHCSD_.size() <<
" names for HC SD's";
147 for (
unsigned int k = 0;
k < nameHCSD_.size(); ++
k)
149 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::Constants for ECAL: slope " << slopeLY_ <<
" Birk constants "
150 << birkC1EC_ <<
":" << birkSlopeEC_ <<
":" <<
birkCutEC_;
152 <<
"constants " << birkC1HC_ <<
":" << birkC2HC_ <<
":" <<
birkC3HC_;
154 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction:: " << nameHitC_.size() <<
" hit collections";
155 for (
unsigned int k = 0;
k < nameHitC_.size(); ++
k)
162 #ifdef HcalNumberingTest
163 hcNumbering_.reset(
nullptr);
166 slave_[
k] = std::make_unique<CaloSlaveSD>(nameHitC_[
k]);
167 produces<edm::PCaloHitContainer>(nameHitC_[
k]);
170 produces<edm::PassiveHitContainer>(
"AllPassiveHits");
171 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction:: All Steps Flag " << allSteps_ <<
" for passive hits";
175 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: --------> Total number of "
176 <<
"selected entries : " <<
count_;
180 #ifdef HcalNumberingTest
182 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::Initialize ESGetToken for HcalDDDSimConstants";
189 auto product = std::make_unique<edm::PCaloHitContainer>();
201 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::fillHits for type " << type <<
" with "
202 <<
slave_[
type].get()->hits().size() <<
" hits";
209 for (
const auto& element :
store_) {
210 auto lv = std::get<0>(element);
211 auto it =
mapLV_.find(lv);
214 std::get<1>(element),
215 std::get<5>(element),
216 std::get<6>(element),
217 std::get<4>(element),
218 std::get<2>(element),
219 std::get<3>(element),
220 std::get<7>(element),
221 std::get<8>(element),
222 std::get<9>(element),
223 std::get<10>(element));
224 cc.emplace_back(hit);
232 #ifdef HcalNumberingTest
236 <<
"HcalNumberingFromDDD";
237 hcNumbering_ = std::make_unique<HcalNumberingFromDDD>(hcons_);
243 int irun = (*run)()->GetRunID();
246 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
248 std::map<const std::string, const G4LogicalVolume*> nameMap;
249 std::map<const std::string, const G4LogicalVolume*>::const_iterator itr;
250 for (
auto lvi = lvs->begin(), lve = lvs->end(); lvi != lve; ++lvi) {
251 nameMap.emplace((*lvi)->GetName(), *lvi);
253 mapLV_[*lvi] = (*lvi)->GetName();
257 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
259 if (lvname.find(
name) != std::string::npos) {
261 int type = (lvname.find(
"refl") == std::string::npos) ? -1 : 1;
262 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
263 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
264 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second, dz * type));
266 mapLV_[itr->second] = itr->first;
271 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
273 if (lvname.find(
name) != std::string::npos) {
275 int type = (lvname.find(
"refl") == std::string::npos) ? 1 : -1;
276 G4Trap* solid =
static_cast<G4Trap*
>(itr->second->GetSolid());
277 double dz = 2 * solid->GetZHalfLength() / CLHEP::mm;
278 xtalMap_.insert(std::pair<const G4LogicalVolume*, double>(itr->second, dz * type));
280 mapLV_[itr->second] = itr->first;
286 for (itr = nameMap.begin(); itr != nameMap.end(); ++itr) {
288 if (lvname.find(
name) != std::string::npos) {
291 mapLV_[itr->second] = itr->first;
308 for (
auto itr =
mapLV_.begin(); itr !=
mapLV_.end(); ++itr) {
309 edm::LogVerbatim(
"Step") <<
"[" << k <<
"] " << itr->second <<
":" << itr->first;
331 auto lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
336 if (hc || eb || ee) {
337 double dEStep = aStep->GetTotalEnergyDeposit() /
CLHEP::MeV;
338 auto const theTrack = aStep->GetTrack();
339 double time = theTrack->GetGlobalTime() / CLHEP::nanosecond;
340 int primID = theTrack->GetTrackID();
342 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
343 auto const& hitPoint = aStep->GetPreStepPoint()->GetPosition();
345 int depth = (touch->GetReplicaNumber(0)) % 10 + 1;
346 int lay = (touch->GetReplicaNumber(0) / 10) % 100 + 1;
347 int det = (touch->GetReplicaNumber(1)) / 1000;
349 if (unitID > 0 && dEStep > 0.0) {
351 (aStep->GetStepLength() / CLHEP::cm),
352 aStep->GetPreStepPoint()->GetCharge(),
353 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3)));
354 fillHit(unitID, dEStep, time, primID, 0, em, 2);
358 int size = touch->GetHistoryDepth() + 1;
364 theBaseNumber.
addLevel(touch->GetVolume(
ii)->GetName(), touch->GetReplicaNumber(
ii));
368 if (unitID > 0 && dEStep > 0.0) {
369 auto local = touch->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
371 double crystalLength = ((ite ==
xtalMap_.end()) ? 230.0 :
std::abs(ite->second));
372 double crystalDepth =
373 ((ite ==
xtalMap_.end()) ? 0.0 : (
std::abs(0.5 * (ite->second) + (local.z() / CLHEP::mm))));
374 double radl = aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() / CLHEP::mm;
375 bool flag = ((ite ==
xtalMap_.end()) ?
true : (((ite->second) >= 0) ?
true :
false));
378 (aStep->GetStepLength() / CLHEP::cm),
379 aStep->GetPreStepPoint()->GetCharge(),
380 (aStep->GetPreStepPoint()->GetMaterial()->GetDensity() / (
CLHEP::g / CLHEP::cm3))) *
381 curve_LY(crystalLength, crystalDepth));
382 fillHit(unitID, dEStep, time, primID,
depth, em, (eb ? 0 : 1));
388 auto it =
mapLV_.find(lv);
391 auto const touch = aStep->GetPreStepPoint()->GetTouchable();
392 double time = aStep->GetTrack()->GetGlobalTime() / CLHEP::nanosecond;
393 int trackId = aStep->GetTrack()->GetTrackID();
394 int pdg = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
395 double stepl = (aStep->GetStepLength() / CLHEP::cm);
396 double xp = aStep->GetPreStepPoint()->GetPosition().x() / CLHEP::cm;
397 double yp = aStep->GetPreStepPoint()->GetPosition().y() / CLHEP::cm;
398 double zp = aStep->GetPreStepPoint()->GetPosition().z() / CLHEP::cm;
400 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: Volume " << lv->GetName() <<
" History "
401 << touch->GetHistoryDepth() <<
" Pointers " << aStep->GetPostStepPoint() <<
":"
402 << aStep->GetTrack()->GetNextVolume() <<
":" << aStep->IsLastStepInVolume() <<
" E "
403 << energy <<
" T " << time <<
" PDG " << pdg <<
" step " << stepl <<
" Position (" << xp
404 <<
", " << yp <<
", " << zp <<
")";
407 if (((aStep->GetPostStepPoint() ==
nullptr) || (aStep->GetTrack()->GetNextVolume() ==
nullptr)) &&
408 (aStep->IsLastStepInVolume())) {
409 energy += (aStep->GetPreStepPoint()->GetKineticEnergy() /
CLHEP::MeV);
411 time = aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::nanosecond;
413 copy = (touch->GetHistoryDepth() < 1)
414 ? static_cast<uint32_t>(touch->GetReplicaNumber(0))
415 : static_cast<uint32_t>(touch->GetReplicaNumber(0) + 1000 * touch->GetReplicaNumber(1));
417 PassiveData key(std::make_tuple(lv, copy, trackId, pdg, time, energy, energy, stepl, xp, yp, zp));
427 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction: EndOfEvent " << (*evt)()->GetEventID();
431 auto currentPos = aStep->GetTrack()->GetPosition();
432 double xyz = currentPos.x() + currentPos.y() + currentPos.z();
433 auto currentMom = aStep->GetTrack()->GetMomentum();
434 xyz += currentMom.x() + currentMom.y() + currentMom.z();
437 auto pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
438 auto& nameOfVol = pCurrentVol->GetName();
440 <<
" Corrupted Event - NaN detected in volume " << nameOfVol <<
"\n";
446 #ifdef HcalNumberingTest
458 double edepEM = (em ? dE : 0);
459 double edepHAD = (em ? 0 : dE);
460 std::pair<int, CaloHitID> evID = std::make_pair(
eventID_, currentID);
461 auto it =
hitMap_[flag].find(evID);
463 (it->second).addEnergyDeposit(edepEM, edepHAD);
467 aHit.
setID(currentID);
475 uint16_t depth2 = (uint16_t)floor(crystalDepth / radl);
478 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getDepth radl " << radl <<
":" << crystalDepth <<
" depth " <<
depth;
485 double dapd = crystalLength - crystalDepth;
486 if (dapd >= -0.1 || dapd <= crystalLength + 0.1) {
490 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::curve_LY " << crystalDepth <<
":" << crystalLength <<
":" << dapd
494 edm::LogWarning(
"Step") <<
"CaloSteppingAction: light coll curve : wrong "
495 <<
"distance to APD " << dapd <<
" crlength = " << crystalLength
496 <<
" crystal Depth = " << crystalDepth <<
" weight = " <<
weight;
503 if (charge != 0. && step > 0.) {
504 double dedx = dEStep /
step;
510 else if (weight > 1.)
514 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkL3 Charge " << charge <<
" dE/dx " << dedx <<
" Birk Const "
515 << rkb <<
" Weight = " << weight <<
" dE " << dEStep <<
" step " <<
step;
523 if (charge != 0. && step > 0.) {
524 double dedx = dEStep /
step;
529 weight = 1. / (1. + rkb * dedx + c * dedx * dedx);
531 edm::LogVerbatim(
"Step") <<
"CaloSteppingAction::getBirkHC Charge " << charge <<
" dE/dx " << dedx <<
" Birk Const "
532 << rkb <<
", " << c <<
" Weight = " << weight <<
" dE " << dEStep;
544 0.001 *
hit.second.getEM(),
545 0.001 *
hit.second.getHadr(),
546 hit.second.getTimeSlice(),
547 hit.second.getTrackID(),
548 hit.second.getDepth());
std::map< std::pair< int, CaloHitID >, CaloGVHit > hitMap_[nSD_]
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
#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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static std::vector< std::string > checklist log
const edm::EventSetup & c
double getBirkL3(double dE, double step, double chg, double dens) const
static const int kEcalDepthRefz
constexpr bool isNotFinite(T x)
void produce(edm::Event &, const edm::EventSetup &) override
void registerConsumes(edm::ConsumesCollector) override
uint32_t getDetIDHC(int det, int lay, int depth, const math::XYZVectorD &pos) const
std::map< const G4LogicalVolume *, double > xtalMap_
std::vector< const G4LogicalVolume * > volHCSD_
double getBirkHC(double dE, double step, double chg, double dens) const
double curve_LY(double crystalLength, double crystalDepth) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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
bool getData(T &iHolder) const
void fillHits(edm::PCaloHitContainer &cc, int type)
void addLevel(const std::string &name, const int ©Number)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
std::vector< std::string > nameHitC_
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
std::vector< std::string > nameHCSD_
tuple key
prepare the HTCondor submission files and eventually submit them
Abs< T >::type abs(const T &t)
static const int kEcalDepthOffset
std::map< const G4LogicalVolume *, std::string > mapLV_
void fillPassiveHits(edm::PassiveHitContainer &cc)
std::vector< PassiveHit > PassiveHitContainer
void addEnergyDeposit(double em, double hd)
std::unique_ptr< CaloSlaveSD > slave_[nSD_]
std::vector< std::string > nameEBSD_
void fillHit(uint32_t id, double dE, double time, int primID, uint16_t depth, double em, int flag)
void NaNTrap(const G4Step *) const
std::unique_ptr< HcalNumberingFromPS > hcNumberingPS_
std::unique_ptr< HcalNumberingScheme > hcNumberingScheme_
T getParameter(std::string const &) const
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_
std::vector< std::string > nameEESD_
std::vector< PassiveData > store_
Log< level::Warning, false > LogWarning
void setSize(const int &size)
uint16_t getDepth(bool flag, double crystalDepth, double radl) const
tuple size
Write out results.
~CaloSteppingAction() override