26 #include "G4SDManager.hh" 29 #include "G4VProcess.hh" 30 #include "G4HCofThisEvent.hh" 32 #include <CLHEP/Random/Randomize.h> 33 #include <CLHEP/Units/SystemOfUnits.h> 34 #include <CLHEP/Units/PhysicalConstants.h> 51 public Observer<const BeginOfEvent*>,
83 std::unique_ptr<HcalTestHistoClass>
tuples_;
89 const std::vector<std::string>
names_;
97 std::unique_ptr<HcalTestNumberingScheme>
org_;
114 eta0_(m_Anal.getParameter<double>(
"Eta0")),
115 phi0_(m_Anal.getParameter<double>(
"Phi0")),
116 laygroup_(m_Anal.getParameter<
int>(
"LayerGrouping")),
117 centralTower_(m_Anal.getParameter<
int>(
"CentralTower")),
119 fileName_(m_Anal.getParameter<
std::
string>(
"FileName")),
125 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events" 131 for (
unsigned int i = 0;
i <
group_.size();
i++)
141 myqie_ = std::make_unique<HcalQie>(
p);
143 produces<HcalTestHistoClass>();
147 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of selected entries : " <<
count_;
153 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Initialize ESGetToken for HcalDDDSimConstants";
162 std::vector<int>
temp(19);
164 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
165 for (
int i = 0;
i < 19;
i++)
167 }
else if (
group == 2) {
168 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
169 for (
int i = 0;
i < 19;
i++)
171 }
else if (
group == 3) {
172 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
173 for (
int i = 0;
i < 19;
i++)
175 }
else if (
group == 4) {
176 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
177 for (
int i = 0;
i < 19;
i++)
180 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
181 for (
int i = 0;
i < 19;
i++)
186 for (
int i = 0;
i < 19;
i++)
192 int etac = (centre / 100) % 100;
193 int phic = (centre % 100);
212 std::vector<int>
temp(2 * nbuf);
221 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for Central " << centre <<
" and " << nadd
222 <<
" on either side";
223 for (
int i = 0;
i < nbuf;
i++)
238 org_ = std::make_unique<HcalTestNumberingScheme>(
false);
243 int irun = (*run)()->GetRunID();
244 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
266 }
else if (idet == static_cast<int>(
HcalBarrel)) {
268 }
else if (idet == static_cast<int>(
HcalEndcap)) {
276 <<
" corresponds to eta0 = " <<
eta0_ <<
" phi0 = " <<
phi0_;
279 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
281 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
282 if (aSD ==
nullptr) {
283 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with " 284 <<
"name " << sdname <<
" in this Setup";
287 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
291 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new numbering scheme";
295 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get" 303 tuples_ = std::make_unique<HcalTestHistoClass>();
309 for (
i = 0;
i < 20;
i++)
311 for (
i = 0;
i < 20;
i++)
314 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
319 if (aStep !=
nullptr) {
320 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
321 G4String
name = curPV->GetName();
323 double edeposit = aStep->GetTotalEnergyDeposit();
327 }
else if (
name ==
"EFR") {
329 }
else if (
name ==
"HBS") {
330 layer = (curPV->GetCopyNo() / 10) % 100;
334 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
337 }
else if (
name ==
"HES") {
338 layer = (curPV->GetCopyNo() / 10) % 100;
342 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
345 }
else if (
name ==
"HTS") {
346 layer = (curPV->GetCopyNo() / 10) % 100;
350 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
358 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
361 aStep->GetPreStepPoint()->GetPosition().y(),
362 aStep->GetPreStepPoint()->GetPosition().z());
373 <<
" Edep " << std::setw(6) << edeposit / MeV <<
" MeV";
388 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
394 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
399 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
402 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
404 int nhc = 0, neb = 0, nef = 0,
j = 0;
408 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[0]);
410 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[0] <<
" of ID " << HCHCid
411 <<
" is obtained at " << theHCHC;
412 int hchc_entries = theHCHC->entries();
413 if (HCHCid >= 0 && theHCHC !=
nullptr) {
414 for (
j = 0;
j < hchc_entries;
j++) {
426 int subdet,
zside,
layer, etaIndex, phiIndex, lay;
427 org_->unpackHcalIndex(unitID, subdet,
zside,
layer, etaIndex, phiIndex, lay);
438 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
439 if (etaIndex <= 20) {
447 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 448 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
455 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[1]);
457 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[1] <<
" of ID " << EBHCid
458 <<
" is obtained at " << theEBHC;
459 int ebhc_entries = theEBHC->entries();
460 if (EBHCid >= 0 && theEBHC !=
nullptr) {
461 for (
j = 0;
j < ebhc_entries;
j++) {
474 uint32_t unitID =
org_->getUnitID(
id);
484 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 485 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
492 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[2]);
494 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[2] <<
" of ID " << EEHCid
495 <<
" is obtained at " << theEEHC;
496 int eehc_entries = theEEHC->entries();
497 if (EEHCid >= 0 && theEEHC !=
nullptr) {
498 for (
j = 0;
j < eehc_entries;
j++) {
511 uint32_t unitID =
org_->getUnitID(
id);
521 << std::setw(6) <<
time <<
" theta " << std::setw(8) <<
theta <<
" eta " 522 << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8)
537 uint32_t unitID =
org_->getUnitID(
id);
545 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
550 << laymax <<
" Hits " << hittot;
552 if (laymax > 0 && hittot > 0) {
553 std::vector<CaloHit>
hits(hittot);
554 std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
555 std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
559 for (
int layr = 0; layr <
nGroup_; layr++) {
577 for (
int k1 = 0; k1 < hittot; k1++) {
579 int subdetc =
hit.det();
584 if (subdetc == subdet &&
group == layr + 1) {
585 int zsidec, ietac, iphic,
idx;
587 org_->unpackHcalIndex(unitID, subdetc, zsidec,
layer, ietac, iphic, lay);
588 if (etac > 0 && phic > 0) {
589 idx = ietac * 100 + iphic;
590 }
else if (etac > 0) {
592 }
else if (phic > 0) {
606 std::vector<int>
cd =
myqie_->getCode(nhit,
hits, engine);
607 double eqie =
myqie_->getEnergy(
cd);
609 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " << layr <<
" Sim " << esim
610 <<
" After QIE " << eqie;
611 for (
int i = 0;
i < 4;
i++) {
615 esimlay[20 *
i + layr] += esim;
616 eqielay[20 *
i + layr] += eqie;
617 esimtow[50 *
i +
it] += esim;
618 eqietow[50 *
i +
it] += eqie;
623 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3] <<
" (SimHit) " << eqietot[3]
626 std::vector<double> latphi(10);
630 for (
int i = 0;
i < 4;
i++) {
631 double scals = 1, scalq = 1;
632 std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
634 scals = 1. / esimtot[
i];
636 scalq = 1. / eqietot[
i];
639 latfs[phib] += scals * esimtow[50 *
i +
it];
640 latfq[phib] += scalq * eqietow[50 *
i +
it];
642 for (
int layr = 0; layr <=
nGroup_; layr++) {
643 longs[layr] = scals * esimlay[20 *
i + layr];
644 longq[layr] = scalq * eqielay[20 *
i + layr];
646 tuples_->fillQie(
i, esimtot[
i], eqietot[
i],
nGroup_, longs, longq,
nt, latphi, latfs, latfq);
654 edm::LogVerbatim(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit " 655 <<
"\n at EB : " << std::setw(6) <<
edepEB_ / MeV <<
"\n at EE : " << std::setw(6)
656 <<
edepEE_ / MeV <<
"\n at HB : " << std::setw(6) <<
edepHB_ / MeV
657 <<
"\n at HE : " << std::setw(6) <<
edepHE_ / MeV <<
"\n at HO : " << std::setw(6)
658 <<
edepHO_ / MeV <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
659 for (
i = 0;
i < 20;
i++)
660 edm::LogVerbatim(
"HcalSim") <<
" Layer " << std::setw(2) <<
i <<
" E " << std::setw(8) <<
edepl_[
i] / MeV <<
" MeV";
670 const double rLay[19] = {1836.0,
692 const double zLay[19] = {4034.0,
714 double tmp = dist / c_light / ns;
716 <<
" 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
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_