48 #include "TProfile2D.h" 69 template<
class T1>
void analyzeDigi(
int type,
const T1& detId, uint16_t
adc);
127 usesResource(
"TFileService");
151 std::cout <<
"HGCalTBAnalyzer:: SimHits = " << doSimHits_ <<
" Digis = " 152 << doDigis_ <<
":" << sampleIndex_ <<
" RecHits = " << doRecHits_
153 <<
" useDets " << ifEE_ <<
":" << ifFH_ <<
":" << ifBH_ <<
":" 154 << ifBeam_ <<
" zFront " << zFrontEE_ <<
":" << zFrontFH_ <<
":" 155 << zFrontBH_ <<
" IdBeam " << idBeams_.size() <<
":";
159 if (idBeams_.empty()) idBeams_.push_back(1001);
162 tok_hepMC_ = consumes<edm::HepMCProduct>(tmp0);
165 std::cout <<
"HGCalTBAnalyzer:: GeneratorSource = " << tmp0 << std::endl;
178 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
189 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorFH_ <<
" with tags " 190 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
215 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBH_ <<
" with tags " 216 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
223 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBeam_
224 <<
" with tags " << tmp1 << std::endl;
235 desc.
add<
bool>(
"UseEE",
true);
236 desc.
add<
double>(
"ZFrontEE",0.0);
241 desc.
add<
bool>(
"UseFH",
false);
242 desc.
add<
double>(
"ZFrontFH",0.0);
247 desc.
add<
bool>(
"UseBH",
false);
248 desc.
add<
double>(
"ZFrontBH",0.0);
253 desc.
add<
bool>(
"UseBeam",
false);
255 std::vector<int>
ids = {1000,1001,1002,1003,1004,1005,1006,1007,1008,1011,1012,1013,1014,2001,2002,2003,2004,2005};
256 desc.
add<std::vector<int>>(
"IDBeams",
ids);
263 desc.
add<
bool>(
"DoSimHits",
true);
264 desc.
add<
bool>(
"DoDigis",
true);
265 desc.
add<
bool>(
"DoRecHits",
true);
266 desc.
add<
int>(
"SampleIndex",0);
271 descriptions.
add(
"HGCalTBAnalyzer",desc);
277 hBeam_ =
fs_->
make<TH1D>(
"BeamP",
"Beam Momentum", 1000, 0, 1000.0);
278 for (
int i=0;
i<3; ++
i) {
290 sprintf (name,
"SimHitEn%s", det.c_str());
291 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
293 sprintf (name,
"SimHitEnX%s", det.c_str());
294 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
296 sprintf (name,
"SimHitTm%s", det.c_str());
297 sprintf (title,
"Sim Hit Timing for %s", det.c_str());
299 sprintf (name,
"SimHitLat%s", det.c_str());
300 sprintf (title,
"Lateral Shower profile (Sim Hit) for %s", det.c_str());
302 sprintf (name,
"SimHitLng%s", det.c_str());
303 sprintf (title,
"Longitudinal Shower profile (Sim Hit) for %s",det.c_str());
305 sprintf (name,
"SimHitLng1%s", det.c_str());
306 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
308 sprintf (name,
"SimHitLng2%s", det.c_str());
309 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
314 sprintf (name,
"DigiADC%s", det.c_str());
315 sprintf (title,
"ADC at Digi level for %s", det.c_str());
317 sprintf (name,
"DigiOcc%s", det.c_str());
318 sprintf (title,
"Occupancy (Digi)for %s", det.c_str());
320 sprintf (name,
"DigiLng%s", det.c_str());
321 sprintf (title,
"Longitudinal Shower profile (Digi) for %s",det.c_str());
326 sprintf (name,
"RecHitEn%s", det.c_str());
327 sprintf (title,
"Rec Hit Energy for %s", det.c_str());
329 sprintf (name,
"RecHitOcc%s", det.c_str());
330 sprintf (title,
"Occupancy (Rec Hit)for %s", det.c_str());
332 sprintf (name,
"RecHitLat%s", det.c_str());
333 sprintf (title,
"Lateral Shower profile (Rec Hit) for %s", det.c_str());
335 sprintf (name,
"RecHitLng%s", det.c_str());
336 sprintf (title,
"Longitudinal Shower profile (Rec Hit) for %s",det.c_str());
338 sprintf (name,
"RecHitLng1%s", det.c_str());
339 sprintf (title,
"Longitudinal Shower profile vs Layer for %s",det.c_str());
345 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
348 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
351 sprintf (title,
"Sim Hit Timing for %s",
detectorBeam_.c_str());
409 sprintf (name,
"SimHitEnA%d%s",
l,
detectorEE_.c_str());
410 sprintf (title,
"Sim Hit Energy in SIM layer %d for %s",
l+1,
414 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorEE_.c_str());
415 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
441 sprintf (name,
"SimHitEnA%d%s",
l,
detectorFH_.c_str());
442 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
446 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorFH_.c_str());
447 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
463 sprintf (name,
"SimHitEnA%d%s",
l,
detectorBH_.c_str());
464 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
467 sprintf (name,
"SimHitEnB%d%s",
l,
detectorBH_.c_str());
468 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
477 sprintf (title,
"Sim Hit Energy in type %d for %s",
idBeams_[
l],
493 const HepMC::GenEvent * myGenEvent = evtMC->
GetEvent();
495 for (HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
496 p != myGenEvent->particles_end(); ++
p, ++
k) {
497 if (k == 0)
hBeam_->Fill((*p)->momentum().rho());
499 std::cout <<
"Particle[" << k <<
"] with p " << (*p)->momentum().rho()
500 <<
" theta " << (*p)->momentum().theta() <<
" phi " 501 << (*p)->momentum().phi() << std::endl;
523 std::vector<PCaloHit> caloHits;
528 if (theCaloHitContainers.
isValid()) {
531 << theCaloHitContainers->size() <<
" hits" << std::endl;
534 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
535 theCaloHitContainers->end());
540 <<
" !!!" << std::endl;
548 if (theCaloHitContainers.
isValid()) {
551 << theCaloHitContainers->size() <<
" hits" << std::endl;
554 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
555 theCaloHitContainers->end());
560 <<
" !!!" << std::endl;
568 if (theCaloHitContainers.
isValid()) {
571 << theCaloHitContainers->size() <<
" hits" << std::endl;
574 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
575 theCaloHitContainers->end());
580 <<
" !!!" << std::endl;
587 if (theCaloHitContainers.
isValid()) {
590 << theCaloHitContainers->size() <<
" hits" << std::endl;
593 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
594 theCaloHitContainers->end());
599 <<
" !!!" << std::endl;
643 if (theDigiContainers.
isValid()) {
646 << theDigiContainers->
size() <<
" element(s)" << std::endl;
648 for (
auto it : *theDigiContainers) {
651 uint16_t
adc = hgcSample.
data();
659 if (theDigiContainers.
isValid()) {
662 << theDigiContainers->
size() <<
" element(s)" << std::endl;
664 for (
auto it : *theDigiContainers) {
667 uint16_t
adc = hgcSample.
data();
679 if (theCaloHitContainers.
isValid()) {
682 << theCaloHitContainers->
size() <<
" hits" << std::endl;
688 <<
" !!!" << std::endl;
694 if (theCaloHitContainers.
isValid()) {
697 << theCaloHitContainers->
size() <<
" hits" << std::endl;
703 <<
" !!!" << std::endl;
714 std::map<uint32_t,double> map_hits, map_hitn;
715 std::map<int,double> map_hitDepth;
716 std::map<int,std::pair<uint32_t,double> > map_hitLayer, map_hitCell;
718 for (
unsigned int i=0;
i<hits.size();
i++) {
719 double energy = hits[
i].energy();
720 double time = hits[
i].time();
721 uint32_t
id = hits[
i].id();
723 int subdet,
zside, layer, sector, subsector(0), cell,
depth(0),
idx(0);
733 }
else if (type == 3) {
735 depth = layer; zside = 1;
736 idx = subdet*1000 + layer;
742 idx = sector*1000+cell;
745 std::cout <<
"SimHit:Hit[" <<
i <<
"] Id " << subdet <<
":" << zside <<
":" 746 << layer <<
":" << sector <<
":" << subsector <<
":" << cell
747 <<
":" <<
depth <<
" Energy " << energy <<
" Time " << time
750 if (map_hits.count(
id) != 0) {
751 map_hits[
id] += energy;
753 map_hits[
id] = energy;
755 if (map_hitLayer.count(layer) != 0) {
756 double ee = energy + map_hitLayer[layer].second;
757 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,ee);
759 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,energy);
762 if (map_hitCell.count(idx) != 0) {
763 double ee = energy + map_hitCell[
idx].second;
764 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,ee);
766 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,energy);
768 if (map_hitDepth.count(
depth) != 0) {
769 map_hitDepth[
depth] += energy;
771 map_hitDepth[
depth] = energy;
773 uint32_t idn = (type >= 2) ?
id :
776 if (map_hitn.count(idn) != 0) {
777 map_hitn[idn] += energy;
779 map_hitn[idn] = energy;
786 for (
auto itr : map_hits) {
790 for (
auto itr : map_hitLayer) {
791 int layer = itr.first - 1;
792 double energy = (itr.second).
second;
797 std::cout <<
"SimHit:Layer " << layer+1 <<
" Z " << zp <<
":" << zp-zFront
798 <<
" E " << energy << std::endl;
809 }
else if (type == 1) {
814 }
else if (type == 2) {
829 for (
auto itr : map_hitDepth) {
830 int layer = itr.first - 1;
831 double energy = itr.second;
833 std::cout <<
"SimHit:Layer " << layer+1 <<
" " << energy << std::endl;
841 }
else if (type == 1) {
846 }
else if (type == 2) {
855 for (
auto itr : map_hitCell) {
856 uint32_t
id = ((itr.second).
first);
857 double energy = ((itr.second).
second);
858 std::pair<float,float>
xy(0,0);
864 int subdet,
zside, layer, sector, subsector, cell;
869 xx = (zp < 0) ? -xy.first : xy.first;
875 for (
auto itr : map_hitn) {
876 uint32_t
id = itr.first;
877 double energy = itr.second;
880 }
else if (type == 1) {
882 }
else if (type == 2) {
884 }
else if (type == 3) {
895 for (
auto simTrkItr : *SimTk) {
897 std::cout <<
"Track " << simTrkItr.trackId() <<
" Vertex " 898 << simTrkItr.vertIndex() <<
" Type " << simTrkItr.type()
899 <<
" Charge " << simTrkItr.charge() <<
" momentum " 900 << simTrkItr.momentum() <<
" " << simTrkItr.momentum().P()
903 if (vertIndex == -1) {
904 vertIndex = simTrkItr.vertIndex();
905 pBeam_ = simTrkItr.momentum().P();
908 if (vertIndex != -1 && vertIndex < (
int)SimVtx->size()) {
909 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
910 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
912 std::cout <<
"Vertex " << vertIndex <<
" position " 913 << simVtxItr->position() << std::endl;
915 xBeam_ = simVtxItr->position().X();
916 yBeam_ = simVtxItr->position().Y();
917 zBeam_ = simVtxItr->position().Z();
935 std::map<int,double> map_hitLayer;
936 std::map<int,std::pair<DetId,double> > map_hitCell;
937 for (
auto it : *hits) {
938 DetId detId = it.id();
940 double energy = it.energy();
945 if (map_hitLayer.count(layer) != 0) {
946 map_hitLayer[layer] += energy;
948 map_hitLayer[layer] = energy;
950 if (map_hitCell.count(cell) != 0) {
951 double ee = energy + map_hitCell[cell].second;
952 map_hitCell[cell] = std::pair<uint32_t,double>(detId,ee);
954 map_hitCell[cell] = std::pair<uint32_t,double>(detId,energy);
957 std::cout <<
"RecHit: " << layer <<
" " << global.
x() <<
" " << global.
y()
958 <<
" " << global.
z() <<
" " << energy << std::endl;
962 for (
auto itr : map_hitLayer) {
963 int layer = itr.first;
964 double energy = itr.second;
967 std::cout <<
"SimHit:Layer " << layer <<
" " << zp <<
" " << energy
974 for (
auto itr : map_hitCell) {
976 double energy = ((itr.second).
second);
984 for (
auto v : *hgcPH) {
985 double energy =
v.energy();
987 unsigned int id =
v.id();
989 double time =
v.time();
990 std::cout <<
"HGCalTBAnalyzer::analyzePassiveHits:Energy:Time:Name:Id : " 991 << energy <<
":" << time <<
":" << name <<
":" <<
id 999 }
else if (subdet==2) {
1003 }
else if (subdet==3) {
1007 }
else if (subdet==4) {
std::vector< TH1D * > hSimHitLayEn2EE_
int adc(sample_type sample)
get the ADC sample (12 bits)
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]
#define DEFINE_FWK_MODULE(type)
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
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_
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_