47 #include "TProfile2D.h" 55 edm::one::SharedResources> {
131 usesResource(
"TFileService");
156 <<
"HGCalTBAnalyzer:: SimHits = " << doSimHits_ <<
" Digis = " << doDigis_
157 <<
":" << sampleIndex_ <<
" RecHits = " << doRecHits_ <<
" useDets " 158 << ifEE_ <<
":" << ifFH_ <<
":" << ifBH_ <<
":" << ifBeam_ <<
" zFront " 159 << zFrontEE_ <<
":" << zFrontFH_ <<
":" << zFrontBH_ <<
" IdBeam " 160 << idBeams_.size() <<
":";
161 for (
unsigned int k = 0;
k < idBeams_.size(); ++
k)
164 if (idBeams_.empty()) idBeams_.push_back(1001);
167 tok_hepMC_ = consumes<edm::HepMCProduct>(tmp0);
170 edm::LogVerbatim(
"HGCSim") <<
"HGCalTBAnalyzer:: GeneratorSource = " << tmp0;
174 consumes<edm::PCaloHitContainer>(
edm::InputTag(
"g4SimHits", tmp1));
184 <<
"HGCalTBAnalyzer:: Detector " <<
detectorEE_ <<
" with tags " << tmp1
185 <<
", " << tmp2 <<
", " << tmp3;
190 consumes<edm::PCaloHitContainer>(
edm::InputTag(
"g4SimHits", tmp1));
198 <<
"HGCalTBAnalyzer:: Detector " << detectorFH_ <<
" with tags " << tmp1
199 <<
", " << tmp2 <<
", " << tmp3;
204 consumes<edm::PCaloHitContainer>(
edm::InputTag(
"g4SimHits", tmp1));
226 <<
"HGCalTBAnalyzer:: Detector " << detectorBH_ <<
" with tags " << tmp1
227 <<
", " << tmp2 <<
", " << tmp3;
232 consumes<edm::PCaloHitContainer>(
edm::InputTag(
"g4SimHits", tmp1));
235 edm::LogVerbatim(
"HGCSim") <<
"HGCalTBAnalyzer:: Detector " << detectorBeam_
236 <<
" with tags " << tmp1;
248 desc.
add<
bool>(
"UseEE",
true);
249 desc.
add<
double>(
"ZFrontEE", 0.0);
255 desc.
add<
bool>(
"UseFH",
false);
256 desc.
add<
double>(
"ZFrontFH", 0.0);
262 desc.
add<
bool>(
"UseBH",
false);
263 desc.
add<
double>(
"ZFrontBH", 0.0);
269 desc.
add<
bool>(
"UseBeam",
false);
271 std::vector<int>
ids = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008,
272 1011, 1012, 1013, 1014, 2001, 2002, 2003, 2004, 2005};
273 desc.
add<std::vector<int>>(
"IDBeams",
ids);
284 desc.
add<
bool>(
"DoSimHits",
true);
285 desc.
add<
bool>(
"DoDigis",
true);
286 desc.
add<
bool>(
"DoRecHits",
true);
287 desc.
add<
int>(
"SampleIndex", 0);
292 descriptions.
add(
"HGCalTBAnalyzer", desc);
297 hBeam_ =
fs_->
make<TH1D>(
"BeamP",
"Beam Momentum", 1000, 0, 1000.0);
298 for (
int i = 0;
i < 3; ++
i) {
310 sprintf(name,
"SimHitEn%s", det.c_str());
311 sprintf(title,
"Sim Hit Energy for %s", det.c_str());
313 sprintf(name,
"SimHitEnX%s", det.c_str());
314 sprintf(title,
"Sim Hit Energy for %s", det.c_str());
316 sprintf(name,
"SimHitTm%s", det.c_str());
317 sprintf(title,
"Sim Hit Timing for %s", det.c_str());
319 sprintf(name,
"SimHitLat%s", det.c_str());
320 sprintf(title,
"Lateral Shower profile (Sim Hit) for %s", det.c_str());
323 sprintf(name,
"SimHitLng%s", det.c_str());
324 sprintf(title,
"Longitudinal Shower profile (Sim Hit) for %s",
327 sprintf(name,
"SimHitLng1%s", det.c_str());
328 sprintf(title,
"Longitudinal Shower profile (Layer) for %s", det.c_str());
330 sprintf(name,
"SimHitLng2%s", det.c_str());
331 sprintf(title,
"Longitudinal Shower profile (Layer) for %s", det.c_str());
336 sprintf(name,
"DigiADC%s", det.c_str());
337 sprintf(title,
"ADC at Digi level for %s", det.c_str());
339 sprintf(name,
"DigiOcc%s", det.c_str());
340 sprintf(title,
"Occupancy (Digi)for %s", det.c_str());
343 sprintf(name,
"DigiLng%s", det.c_str());
344 sprintf(title,
"Longitudinal Shower profile (Digi) for %s", det.c_str());
349 sprintf(name,
"RecHitEn%s", det.c_str());
350 sprintf(title,
"Rec Hit Energy for %s", det.c_str());
352 sprintf(name,
"RecHitOcc%s", det.c_str());
353 sprintf(title,
"Occupancy (Rec Hit)for %s", det.c_str());
356 sprintf(name,
"RecHitLat%s", det.c_str());
357 sprintf(title,
"Lateral Shower profile (Rec Hit) for %s", det.c_str());
360 sprintf(name,
"RecHitLng%s", det.c_str());
361 sprintf(title,
"Longitudinal Shower profile (Rec Hit) for %s",
364 sprintf(name,
"RecHitLng1%s", det.c_str());
365 sprintf(title,
"Longitudinal Shower profile vs Layer for %s",
372 sprintf(title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
375 sprintf(title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
378 sprintf(title,
"Sim Hit Timing for %s",
detectorBeam_.c_str());
436 sprintf(title,
"Sim Hit Energy in SIM layer %d for %s",
l + 1,
440 sprintf(name,
"SimHitEnB%d%s", (
l / 3 + 1),
detectorEE_.c_str());
441 sprintf(title,
"Sim Hit Energy in layer %d for %s", (
l / 3 + 1),
444 fs_->
make<TH1D>(name, title, 100000, 0., 0.2));
449 <<
"HGCalTBAnalyzer::" <<
detectorEE_ <<
" defined with " 470 sprintf(title,
"Sim Hit Energy in layer %d for %s",
l + 1,
474 sprintf(name,
"SimHitEnB%d%s", (
l / 3 + 1),
detectorFH_.c_str());
475 sprintf(title,
"Sim Hit Energy in layer %d for %s", (
l / 3 + 1),
478 fs_->
make<TH1D>(name, title, 100000, 0., 0.2));
483 <<
"HGCalTBAnalyzer::" <<
detectorFH_ <<
" defined with " 494 sprintf(title,
"Sim Hit Energy in layer %d for %s",
l + 1,
498 sprintf(title,
"Sim Hit Energy in layer %d for %s",
l + 1,
505 for (
unsigned int l = 0;
l <
idBeams_.size(); ++
l) {
507 sprintf(title,
"Sim Hit Energy in type %d for %s",
idBeams_[
l],
510 fs_->
make<TH1D>(name, title, 100000, 0., 0.2));
525 for (HepMC::GenEvent::particle_const_iterator
p =
526 myGenEvent->particles_begin();
527 p != myGenEvent->particles_end(); ++
p, ++
k) {
528 if (k == 0)
hBeam_->Fill((*p)->momentum().rho());
531 <<
"Particle[" << k <<
"] with p " << (*p)->momentum().rho()
532 <<
" theta " << (*p)->momentum().theta() <<
" phi " 533 << (*p)->momentum().phi();
562 std::vector<PCaloHit> caloHits;
567 if (theCaloHitContainers.
isValid()) {
570 <<
"PcalohitContainer for " <<
detectorEE_ <<
" has " 571 << theCaloHitContainers->size() <<
" hits";
574 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
575 theCaloHitContainers->end());
580 <<
"PCaloHitContainer does not exist for " <<
detectorEE_ <<
" !!!";
588 if (theCaloHitContainers.
isValid()) {
591 <<
"PcalohitContainer for " <<
detectorFH_ <<
" has " 592 << theCaloHitContainers->size() <<
" hits";
595 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
596 theCaloHitContainers->end());
601 <<
"PCaloHitContainer does not exist for " <<
detectorFH_ <<
" !!!";
609 if (theCaloHitContainers.
isValid()) {
612 <<
"PcalohitContainer for " <<
detectorBH_ <<
" has " 613 << theCaloHitContainers->size() <<
" hits";
616 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
617 theCaloHitContainers->end());
622 <<
"PCaloHitContainer does not exist for " <<
detectorBH_ <<
" !!!";
629 if (theCaloHitContainers.
isValid()) {
633 << theCaloHitContainers->size() <<
" hits";
636 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
637 theCaloHitContainers->end());
692 if (theDigiContainers.
isValid()) {
695 <<
"HGCDigiCintainer for " <<
detectorEE_ <<
" with " 696 << theDigiContainers->
size() <<
" element(s)";
698 for (
auto it : *theDigiContainers) {
701 uint16_t
adc = hgcSample.
data();
709 if (theDigiContainers.
isValid()) {
712 <<
"HGCDigiContainer for " <<
detectorFH_ <<
" with " 713 << theDigiContainers->
size() <<
" element(s)";
715 for (
auto it : *theDigiContainers) {
718 uint16_t
adc = hgcSample.
data();
730 if (theCaloHitContainers.
isValid()) {
733 <<
"HGCRecHitCollection for " <<
detectorEE_ <<
" has " 734 << theCaloHitContainers->
size() <<
" hits";
746 if (theCaloHitContainers.
isValid()) {
749 <<
"HGCRecHitCollection for " <<
detectorFH_ <<
" has " 750 << theCaloHitContainers->
size() <<
" hits";
766 std::map<uint32_t, double> map_hits, map_hitn;
767 std::map<int, double> map_hitDepth;
768 std::map<int, std::pair<uint32_t, double>> map_hitLayer, map_hitCell;
770 for (
unsigned int i = 0;
i < hits.size();
i++) {
771 double energy = hits[
i].energy();
772 double time = hits[
i].time();
773 uint32_t
id = hits[
i].id();
775 int subdet,
zside, layer, sector, subsector(0), cell,
depth(0),
idx(0);
785 }
else if (type == 3) {
789 idx = subdet * 1000 + layer;
795 idx = sector * 1000 + cell;
799 <<
"SimHit:Hit[" <<
i <<
"] Id " << subdet <<
":" << zside <<
":" 800 << layer <<
":" << sector <<
":" << subsector <<
":" << cell <<
":" 801 <<
depth <<
" Energy " << energy <<
" Time " <<
time;
803 if (map_hits.count(
id) != 0) {
808 if (map_hitLayer.count(layer) != 0) {
809 double ee = energy + map_hitLayer[layer].second;
810 map_hitLayer[layer] = std::pair<uint32_t, double>(
id, ee);
812 map_hitLayer[layer] = std::pair<uint32_t, double>(
id,
energy);
815 if (map_hitCell.count(idx) != 0) {
816 double ee = energy + map_hitCell[
idx].second;
817 map_hitCell[
idx] = std::pair<uint32_t, double>(
id, ee);
819 map_hitCell[
idx] = std::pair<uint32_t, double>(
id,
energy);
821 if (map_hitDepth.count(
depth) != 0) {
826 uint32_t idn = (type >= 2)
829 subdet, zside,
depth, sector, subsector, cell);
830 if (map_hitn.count(idn) != 0) {
840 for (
auto itr : map_hits) {
844 for (
auto itr : map_hitLayer) {
845 int layer = itr.first - 1;
854 <<
":" << zp - zFront <<
" E " <<
energy;
865 }
else if (type == 1) {
870 }
else if (type == 2) {
876 for (
unsigned int k = 0;
k <
idBeams_.size(); ++
k) {
885 for (
auto itr : map_hitDepth) {
886 int layer = itr.first - 1;
887 double energy = itr.second;
897 }
else if (type == 1) {
902 }
else if (type == 2) {
911 for (
auto itr : map_hitCell) {
912 uint32_t
id = ((itr.second).
first);
914 std::pair<float, float>
xy(0, 0);
920 int subdet,
zside, layer, sector, subsector, cell;
925 xx = (zp < 0) ? -xy.first : xy.first;
931 for (
auto itr : map_hitn) {
932 uint32_t
id = itr.first;
933 double energy = itr.second;
937 }
else if (type == 1) {
940 }
else if (type == 2) {
943 }
else if (type == 3) {
955 for (
auto simTrkItr : *SimTk) {
958 <<
"Track " << simTrkItr.trackId() <<
" Vertex " 959 << simTrkItr.vertIndex() <<
" Type " << simTrkItr.type() <<
" Charge " 960 << simTrkItr.charge() <<
" momentum " << simTrkItr.momentum() <<
" " 961 << simTrkItr.momentum().P();
963 if (vertIndex == -1) {
964 vertIndex = simTrkItr.vertIndex();
965 pBeam_ = simTrkItr.momentum().P();
968 if (vertIndex != -1 && vertIndex < (
int)SimVtx->size()) {
969 edm::SimVertexContainer::const_iterator simVtxItr = SimVtx->begin();
970 for (
int iv = 0; iv < vertIndex; iv++) simVtxItr++;
973 <<
"Vertex " << vertIndex <<
" position " << simVtxItr->position();
975 xBeam_ = simVtxItr->position().X();
976 yBeam_ = simVtxItr->position().Y();
977 zBeam_ = simVtxItr->position().Z();
992 std::map<int, double> map_hitLayer;
993 std::map<int, std::pair<DetId, double>> map_hitCell;
994 for (
auto it : *hits) {
995 DetId detId = it.id();
997 double energy = it.energy();
1002 if (map_hitLayer.count(layer) != 0) {
1003 map_hitLayer[layer] +=
energy;
1005 map_hitLayer[layer] =
energy;
1007 if (map_hitCell.count(cell) != 0) {
1008 double ee = energy + map_hitCell[cell].second;
1009 map_hitCell[cell] = std::pair<uint32_t, double>(detId, ee);
1011 map_hitCell[cell] = std::pair<uint32_t, double>(detId,
energy);
1015 <<
"RecHit: " << layer <<
" " << global.
x() <<
" " << global.
y() <<
" " 1016 << global.
z() <<
" " <<
energy;
1020 for (
auto itr : map_hitLayer) {
1021 int layer = itr.first;
1022 double energy = itr.second;
1026 <<
"SimHit:Layer " << layer <<
" " << zp <<
" " <<
energy;
1032 for (
auto itr : map_hitCell) {
1042 for (
auto v : *hgcPH) {
1045 unsigned int id =
v.id();
1047 double time =
v.time();
1048 edm::LogVerbatim(
"HGCSim") <<
"HGCalTBAnalyzer::analyzePassiveHits:Energy:" 1049 <<
"Time:Name:Id : " << energy <<
":" << time
1050 <<
":" << name <<
":" <<
id;
1057 }
else if (subdet == 2) {
1061 }
else if (subdet == 3) {
1065 }
else if (subdet == 4) {
std::vector< TH1D * > hSimHitLayEn2EE_
std::vector< float > simHitLayEn2EE_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< float > simHitLayEn2BH_
std::vector< uint32_t > simHitCellIdFH_
void analyzeSimTracks(edm::Handle< edm::SimTrackContainer > const &SimTk, edm::Handle< edm::SimVertexContainer > const &SimVtx)
HcalSubdetector subdet() const
get the subdetector
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
edm::EDGetToken tok_hitrBH_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
TProfile * hSimHitLng1_[3]
TProfile * hSimHitLng2_[3]
TProfile * hRecHitLng_[3]
std::vector< std::string > hgcPassiveFHName_
std::vector< float > simHitLayEn1EE_
std::vector< float > hgcPassiveBHEnergy_
static const int MaxDepth
get the layer number
static uint32_t packHexagonIndex(int subdet, int z, int lay, int wafer, int celltyp, int cell)
edm::Service< TFileService > fs_
HGCalTBAnalyzer(edm::ParameterSet const &)
void beginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetToken tok_digiFH_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsFH_
int irow() const
get the row number
T * make(const Args &...args) const
make new ROOT object
GlobalPoint getPosition(const DetId &id) const
std::vector< std::string > hgcPassiveBHName_
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::vector< float > hgcPassiveCMSEEnergy_
std::vector< int > hgcPassiveEEID_
std::vector< float > hgcPassiveEEEnergy_
std::vector< float > simHitCellEnFH_
TProfile2D * hSimHitLat_[3]
U second(std::pair< T, U > const &p)
std::vector< TH1D * > hSimHitLayEn1EE_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsBH_
void analyzeSimHits(int type, std::vector< PCaloHit > &hits, double zFront)
int icol() const
get the column number
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
#define DEFINE_FWK_MODULE(type)
std::vector< TH1D * > hSimHitLayEn2BH_
unsigned int layers(bool reco) const
std::vector< int > idBeams_
void analyzeRecHits(int type, edm::Handle< HGCRecHitCollection > &hits)
const HGCalGeometry * hgeom_[2]
std::vector< std::string > hgcPassiveCMSEName_
std::pair< double, double > getXY() const
get the local coordinate in the plane and along depth
~HGCalTBAnalyzer() override
edm::EDGetTokenT< edm::SimTrackContainer > tok_simTk_
void analyze(edm::Event const &, edm::EventSetup const &) override
std::vector< TH1D * > hSimHitLayEnBeam_
const HGCalDDDConstants * hgcons_[2]
edm::EDGetToken tok_hitrFH_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsBeam_
edm::EDGetTokenT< edm::HepMCProduct > tok_hepMC_
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< TH1D * > hSimHitLayEn1FH_
std::vector< uint32_t > simHitCellIdBH_
void analyzePassiveHits(edm::Handle< edm::PassiveHitContainer > const &hgcPh, int subdet)
double waferZ(int layer, bool reco) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< float > hgcPassiveFHEnergy_
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHEE_
std::vector< int > hgcPassiveCMSEID_
TProfile2D * hRecHitLat_[3]
const HepMC::GenEvent * GetEvent() const
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHBH_
int cell() const
get the absolute value of the cell #'s in x and y
std::vector< float > simHitCellEnBeam_
TProfile * hSimHitLng_[3]
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< std::string > hgcPassiveEEName_
void endRun(edm::Run const &, edm::EventSetup const &) override
std::string detectorBeam_
void analyzeDigi(int type, const T1 &detId, uint16_t adc)
std::vector< std::vector< double > > tmp
std::vector< int > hgcPassiveBHID_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsEE_
std::vector< float > simHitLayEn1FH_
edm::EDGetToken tok_digiBH_
std::vector< int > hgcPassiveFHID_
std::vector< float > simHitCellEnBH_
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHFH_
std::vector< float > simHitLayEn1BH_
std::vector< uint32_t > simHitCellIdEE_
std::vector< TH1D * > hSimHitLayEn1BH_
int zside() const
get the z-side of the cell (1/-1)
std::vector< float > simHitCellEnEE_
std::vector< uint32_t > simHitCellIdBeam_
T const * product() const
edm::EDGetToken tok_hitrEE_
std::vector< float > simHitLayEn2FH_
edm::EDGetTokenT< edm::SimVertexContainer > tok_simVtx_
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
int layer() const
get the layer #
TProfile * hRecHitLng1_[3]
std::vector< TH1D * > hSimHitLayEn2FH_
edm::EDGetToken tok_digiEE_
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHCMSE_
std::vector< float > simHitLayEnBeam_