26 #include "G4SDManager.hh" 29 #include "G4VProcess.hh" 30 #include "G4HCofThisEvent.hh" 32 #include <CLHEP/Random/Randomize.h> 33 #include <CLHEP/Units/GlobalSystemOfUnits.h> 34 #include <CLHEP/Units/GlobalPhysicalConstants.h> 44 public Observer<const BeginOfEvent*>,
76 std::unique_ptr<HcalTestHistoClass>
tuples_;
82 const std::vector<std::string>
names_;
90 std::unique_ptr<HcalTestNumberingScheme>
org_;
107 eta0_(m_Anal.getParameter<double>(
"Eta0")),
108 phi0_(m_Anal.getParameter<double>(
"Phi0")),
109 laygroup_(m_Anal.getParameter<
int>(
"LayerGrouping")),
110 centralTower_(m_Anal.getParameter<
int>(
"CentralTower")),
112 fileName_(m_Anal.getParameter<
std::
string>(
"FileName")),
118 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events" 124 for (
unsigned int i = 0;
i <
group_.size();
i++)
134 myqie_ = std::make_unique<HcalQie>(
p);
136 produces<HcalTestHistoClass>();
140 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of selected entries : " <<
count_;
146 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Initialize ESGetToken for HcalDDDSimConstants";
155 std::vector<int>
temp(19);
157 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
158 for (
int i = 0;
i < 19;
i++)
160 }
else if (
group == 2) {
161 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
162 for (
int i = 0;
i < 19;
i++)
164 }
else if (
group == 3) {
165 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
166 for (
int i = 0;
i < 19;
i++)
168 }
else if (
group == 4) {
169 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
170 for (
int i = 0;
i < 19;
i++)
173 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
174 for (
int i = 0;
i < 19;
i++)
179 for (
int i = 0;
i < 19;
i++)
185 int etac = (centre / 100) % 100;
186 int phic = (centre % 100);
205 std::vector<int>
temp(2 * nbuf);
214 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for Central " << centre <<
" and " << nadd
215 <<
" on either side";
216 for (
int i = 0;
i < nbuf;
i++)
231 org_ = std::make_unique<HcalTestNumberingScheme>(
false);
236 int irun = (*run)()->GetRunID();
237 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
259 }
else if (idet == static_cast<int>(
HcalBarrel)) {
261 }
else if (idet == static_cast<int>(
HcalEndcap)) {
269 <<
" corresponds to eta0 = " <<
eta0_ <<
" phi0 = " <<
phi0_;
272 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
274 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
275 if (aSD ==
nullptr) {
276 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with " 277 <<
"name " << sdname <<
" in this Setup";
280 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
284 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new numbering scheme";
288 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get" 296 tuples_ = std::make_unique<HcalTestHistoClass>();
302 for (
i = 0;
i < 20;
i++)
304 for (
i = 0;
i < 20;
i++)
307 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
312 if (aStep !=
nullptr) {
313 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
314 G4String
name = curPV->GetName();
316 double edeposit = aStep->GetTotalEnergyDeposit();
320 }
else if (
name ==
"EFR") {
322 }
else if (
name ==
"HBS") {
323 layer = (curPV->GetCopyNo() / 10) % 100;
327 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
330 }
else if (
name ==
"HES") {
331 layer = (curPV->GetCopyNo() / 10) % 100;
335 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
338 }
else if (
name ==
"HTS") {
339 layer = (curPV->GetCopyNo() / 10) % 100;
343 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
351 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
354 aStep->GetPreStepPoint()->GetPosition().y(),
355 aStep->GetPreStepPoint()->GetPosition().z());
366 <<
" Edep " << std::setw(6) << edeposit / MeV <<
" MeV";
381 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
387 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
392 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
395 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
397 int nhc = 0, neb = 0, nef = 0,
j = 0;
401 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[0]);
403 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[0] <<
" of ID " << HCHCid
404 <<
" is obtained at " << theHCHC;
405 int hchc_entries = theHCHC->entries();
406 if (HCHCid >= 0 && theHCHC !=
nullptr) {
407 for (
j = 0;
j < hchc_entries;
j++) {
419 int subdet,
zside,
layer, etaIndex, phiIndex, lay;
420 org_->unpackHcalIndex(unitID, subdet,
zside,
layer, etaIndex, phiIndex, lay);
431 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
432 if (etaIndex <= 20) {
440 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 441 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
448 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[1]);
450 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[1] <<
" of ID " << EBHCid
451 <<
" is obtained at " << theEBHC;
452 int ebhc_entries = theEBHC->entries();
453 if (EBHCid >= 0 && theEBHC !=
nullptr) {
454 for (
j = 0;
j < ebhc_entries;
j++) {
467 uint32_t unitID =
org_->getUnitID(
id);
477 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 478 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
485 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[2]);
487 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[2] <<
" of ID " << EEHCid
488 <<
" is obtained at " << theEEHC;
489 int eehc_entries = theEEHC->entries();
490 if (EEHCid >= 0 && theEEHC !=
nullptr) {
491 for (
j = 0;
j < eehc_entries;
j++) {
504 uint32_t unitID =
org_->getUnitID(
id);
514 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 515 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
530 uint32_t unitID =
org_->getUnitID(
id);
538 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
543 << laymax <<
" Hits " << hittot;
545 if (laymax > 0 && hittot > 0) {
546 std::vector<CaloHit>
hits(hittot);
547 std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
548 std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
552 for (
int layr = 0; layr <
nGroup_; layr++) {
567 for (
int it = 0; it <
nTower_; it++) {
570 for (
int k1 = 0; k1 < hittot; k1++) {
572 int subdetc =
hit.det();
577 if (subdetc == subdet &&
group == layr + 1) {
578 int zsidec, ietac, iphic,
idx;
580 org_->unpackHcalIndex(unitID, subdetc, zsidec,
layer, ietac, iphic, lay);
581 if (etac > 0 && phic > 0) {
582 idx = ietac * 100 + iphic;
583 }
else if (etac > 0) {
585 }
else if (phic > 0) {
599 std::vector<int>
cd =
myqie_->getCode(nhit,
hits, engine);
600 double eqie =
myqie_->getEnergy(
cd);
602 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " << layr <<
" Sim " << esim
603 <<
" After QIE " << eqie;
604 for (
int i = 0;
i < 4;
i++) {
608 esimlay[20 *
i + layr] += esim;
609 eqielay[20 *
i + layr] += eqie;
610 esimtow[50 *
i + it] += esim;
611 eqietow[50 *
i + it] += eqie;
616 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3] <<
" (SimHit) " << eqietot[3]
619 std::vector<double> latphi(10);
621 for (
int it = 0; it <
nt; it++)
623 for (
int i = 0;
i < 4;
i++) {
624 double scals = 1, scalq = 1;
625 std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
627 scals = 1. / esimtot[
i];
629 scalq = 1. / eqietot[
i];
630 for (
int it = 0; it <
nTower_; it++) {
632 latfs[phib] += scals * esimtow[50 *
i + it];
633 latfq[phib] += scalq * eqietow[50 *
i + it];
635 for (
int layr = 0; layr <=
nGroup_; layr++) {
636 longs[layr] = scals * esimlay[20 *
i + layr];
637 longq[layr] = scalq * eqielay[20 *
i + layr];
639 tuples_->fillQie(
i, esimtot[
i], eqietot[
i],
nGroup_, longs, longq,
nt, latphi, latfs, latfq);
647 edm::LogVerbatim(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit " 648 <<
"\n at EB : " << std::setw(6) <<
edepEB_ / MeV <<
"\n at EE : " << std::setw(6)
649 <<
edepEE_ / MeV <<
"\n at HB : " << std::setw(6) <<
edepHB_ / MeV
650 <<
"\n at HE : " << std::setw(6) <<
edepHE_ / MeV <<
"\n at HO : " << std::setw(6)
651 <<
edepHO_ / MeV <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
652 for (
i = 0;
i < 20;
i++)
653 edm::LogVerbatim(
"HcalSim") <<
" Layer " << std::setw(2) <<
i <<
" E " << std::setw(8) <<
edepl_[
i] / MeV <<
" MeV";
663 const double rLay[19] = {1836.0,
685 const double zLay[19] = {4034.0,
707 double tmp = dist / c_light / ns;
709 <<
" eta/theta " <<
eta <<
" " <<
theta / deg <<
" dist " << dist;
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
const std::vector< std::string > names_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
std::unique_ptr< HcalTestHistoClass > tuples_
std::vector< int > layerGrouping(int)
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD_
uint32_t cc[maxCellsPerHit]
Sin< T >::type sin(const T &t)
const edm::ParameterSet m_Anal
void beginRun(edm::EventSetup const &) override
void setNumberingScheme(HcalNumberingScheme *)
std::vector< int > towersToAdd(int centre, int nadd)
void produce(edm::Event &, const edm::EventSetup &) override
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
double timeOfFlight(int det, int layer, double eta)
math::XYZPoint getPosition() const
const std::string fileName_
void fill(const EndOfEvent *ev)
std::vector< int > tower_
HcalTestAnalysis(const edm::ParameterSet &p)
const HcalDDDSimConstants * hcons_
Cos< T >::type cos(const T &t)
~HcalTestAnalysis() override
std::unique_ptr< HcalQie > myqie_
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
void registerConsumes(edm::ConsumesCollector) override
XYZPointD XYZPoint
point in space with cartesian internal representation
std::unique_ptr< HcalTestNumberingScheme > org_
double getEnergyDeposit() const
uint32_t getUnitID() const
std::vector< CaloHit > caloHitCache_
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
edm::ESGetToken< HcalDDDSimConstants, HcalSimNumberingRecord > ddconsToken_
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
void qieAnalysis(CLHEP::HepRandomEngine *)
Log< level::Warning, false > LogWarning
Geom::Theta< T > theta() const
std::vector< int > group_