50 #include "TProfile2D.h" 71 template<
class T1>
void analyzeDigi(
int type,
const T1& detId, uint16_t
adc);
129 usesResource(
"TFileService");
153 std::cout <<
"HGCalTBAnalyzer:: SimHits = " << doSimHits_ <<
" Digis = " 154 << doDigis_ <<
":" << sampleIndex_ <<
" RecHits = " << doRecHits_
155 <<
" useDets " << ifEE_ <<
":" << ifFH_ <<
":" << ifBH_ <<
":" 156 << ifBeam_ <<
" zFront " << zFrontEE_ <<
":" << zFrontFH_ <<
":" 157 << zFrontBH_ <<
" IdBeam " << idBeams_.size() <<
":";
161 if (idBeams_.empty()) idBeams_.push_back(1001);
164 tok_hepMC_ = consumes<edm::HepMCProduct>(tmp0);
167 std::cout <<
"HGCalTBAnalyzer:: GeneratorSource = " << tmp0 << std::endl;
180 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
191 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorFH_ <<
" with tags " 192 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
217 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBH_ <<
" with tags " 218 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
225 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBeam_
226 <<
" with tags " << tmp1 << std::endl;
237 desc.
add<
bool>(
"UseEE",
true);
238 desc.
add<
double>(
"ZFrontEE",0.0);
243 desc.
add<
bool>(
"UseFH",
false);
244 desc.
add<
double>(
"ZFrontFH",0.0);
249 desc.
add<
bool>(
"UseBH",
false);
250 desc.
add<
double>(
"ZFrontBH",0.0);
255 desc.
add<
bool>(
"UseBeam",
false);
257 std::vector<int>
ids = {1000,1001,1002,1003,1004,1005,1006,1007,1008,1011,1012,1013,1014,2001,2002,2003,2004,2005};
258 desc.
add<std::vector<int>>(
"IDBeams",
ids);
265 desc.
add<
bool>(
"DoSimHits",
true);
266 desc.
add<
bool>(
"DoDigis",
true);
267 desc.
add<
bool>(
"DoRecHits",
true);
268 desc.
add<
int>(
"SampleIndex",0);
273 descriptions.
add(
"HGCalTBAnalyzer",desc);
279 hBeam_ =
fs_->
make<TH1D>(
"BeamP",
"Beam Momentum", 1000, 0, 1000.0);
280 for (
int i=0;
i<3; ++
i) {
292 sprintf (name,
"SimHitEn%s", det.c_str());
293 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
295 sprintf (name,
"SimHitEnX%s", det.c_str());
296 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
298 sprintf (name,
"SimHitTm%s", det.c_str());
299 sprintf (title,
"Sim Hit Timing for %s", det.c_str());
301 sprintf (name,
"SimHitLat%s", det.c_str());
302 sprintf (title,
"Lateral Shower profile (Sim Hit) for %s", det.c_str());
304 sprintf (name,
"SimHitLng%s", det.c_str());
305 sprintf (title,
"Longitudinal Shower profile (Sim Hit) for %s",det.c_str());
307 sprintf (name,
"SimHitLng1%s", det.c_str());
308 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
310 sprintf (name,
"SimHitLng2%s", det.c_str());
311 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
316 sprintf (name,
"DigiADC%s", det.c_str());
317 sprintf (title,
"ADC at Digi level for %s", det.c_str());
319 sprintf (name,
"DigiOcc%s", det.c_str());
320 sprintf (title,
"Occupancy (Digi)for %s", det.c_str());
322 sprintf (name,
"DigiLng%s", det.c_str());
323 sprintf (title,
"Longitudinal Shower profile (Digi) for %s",det.c_str());
328 sprintf (name,
"RecHitEn%s", det.c_str());
329 sprintf (title,
"Rec Hit Energy for %s", det.c_str());
331 sprintf (name,
"RecHitOcc%s", det.c_str());
332 sprintf (title,
"Occupancy (Rec Hit)for %s", det.c_str());
334 sprintf (name,
"RecHitLat%s", det.c_str());
335 sprintf (title,
"Lateral Shower profile (Rec Hit) for %s", det.c_str());
337 sprintf (name,
"RecHitLng%s", det.c_str());
338 sprintf (title,
"Longitudinal Shower profile (Rec Hit) for %s",det.c_str());
340 sprintf (name,
"RecHitLng1%s", det.c_str());
341 sprintf (title,
"Longitudinal Shower profile vs Layer for %s",det.c_str());
347 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
350 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
353 sprintf (title,
"Sim Hit Timing for %s",
detectorBeam_.c_str());
411 sprintf (name,
"SimHitEnA%d%s",
l,
detectorEE_.c_str());
412 sprintf (title,
"Sim Hit Energy in SIM layer %d for %s",
l+1,
416 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorEE_.c_str());
417 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
443 sprintf (name,
"SimHitEnA%d%s",
l,
detectorFH_.c_str());
444 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
448 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorFH_.c_str());
449 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
465 sprintf (name,
"SimHitEnA%d%s",
l,
detectorBH_.c_str());
466 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
469 sprintf (name,
"SimHitEnB%d%s",
l,
detectorBH_.c_str());
470 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
479 sprintf (title,
"Sim Hit Energy in type %d for %s",
idBeams_[
l],
495 const HepMC::GenEvent * myGenEvent = evtMC->
GetEvent();
497 for (HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
498 p != myGenEvent->particles_end(); ++
p, ++
k) {
499 if (k == 0)
hBeam_->Fill((*p)->momentum().rho());
501 std::cout <<
"Particle[" << k <<
"] with p " << (*p)->momentum().rho()
502 <<
" theta " << (*p)->momentum().theta() <<
" phi " 503 << (*p)->momentum().phi() << std::endl;
525 std::vector<PCaloHit> caloHits;
530 if (theCaloHitContainers.
isValid()) {
533 << theCaloHitContainers->size() <<
" hits" << std::endl;
536 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
537 theCaloHitContainers->end());
542 <<
" !!!" << std::endl;
550 if (theCaloHitContainers.
isValid()) {
553 << theCaloHitContainers->size() <<
" hits" << std::endl;
556 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
557 theCaloHitContainers->end());
562 <<
" !!!" << std::endl;
570 if (theCaloHitContainers.
isValid()) {
573 << theCaloHitContainers->size() <<
" hits" << std::endl;
576 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
577 theCaloHitContainers->end());
582 <<
" !!!" << std::endl;
589 if (theCaloHitContainers.
isValid()) {
592 << theCaloHitContainers->size() <<
" hits" << std::endl;
595 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
596 theCaloHitContainers->end());
601 <<
" !!!" << std::endl;
645 if (theDigiContainers.
isValid()) {
648 << theDigiContainers->
size() <<
" element(s)" << std::endl;
650 for (
auto it : *theDigiContainers) {
653 uint16_t
adc = hgcSample.
data();
661 if (theDigiContainers.
isValid()) {
664 << theDigiContainers->
size() <<
" element(s)" << std::endl;
666 for (
auto it : *theDigiContainers) {
669 uint16_t
adc = hgcSample.
data();
681 if (theCaloHitContainers.
isValid()) {
684 << theCaloHitContainers->
size() <<
" hits" << std::endl;
690 <<
" !!!" << std::endl;
696 if (theCaloHitContainers.
isValid()) {
699 << theCaloHitContainers->
size() <<
" hits" << std::endl;
705 <<
" !!!" << std::endl;
716 std::map<uint32_t,double> map_hits, map_hitn;
717 std::map<int,double> map_hitDepth;
718 std::map<int,std::pair<uint32_t,double> > map_hitLayer, map_hitCell;
720 for (
unsigned int i=0;
i<hits.size();
i++) {
721 double energy = hits[
i].energy();
722 double time = hits[
i].time();
723 uint32_t
id = hits[
i].id();
725 int subdet,
zside, layer, sector, subsector(0), cell,
depth(0),
idx(0);
735 }
else if (type == 3) {
737 depth = layer; zside = 1;
738 idx = subdet*1000 + layer;
744 idx = sector*1000+cell;
747 std::cout <<
"SimHit:Hit[" <<
i <<
"] Id " << subdet <<
":" << zside <<
":" 748 << layer <<
":" << sector <<
":" << subsector <<
":" << cell
749 <<
":" <<
depth <<
" Energy " << energy <<
" Time " << time
752 if (map_hits.count(
id) != 0) {
753 map_hits[
id] += energy;
755 map_hits[
id] = energy;
757 if (map_hitLayer.count(layer) != 0) {
758 double ee = energy + map_hitLayer[layer].second;
759 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,ee);
761 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,energy);
764 if (map_hitCell.count(idx) != 0) {
765 double ee = energy + map_hitCell[
idx].second;
766 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,ee);
768 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,energy);
770 if (map_hitDepth.count(
depth) != 0) {
771 map_hitDepth[
depth] += energy;
773 map_hitDepth[
depth] = energy;
775 uint32_t idn = (type >= 2) ?
id :
778 if (map_hitn.count(idn) != 0) {
779 map_hitn[idn] += energy;
781 map_hitn[idn] = energy;
788 for (
auto itr : map_hits) {
792 for (
auto itr : map_hitLayer) {
793 int layer = itr.first - 1;
794 double energy = (itr.second).
second;
799 std::cout <<
"SimHit:Layer " << layer+1 <<
" Z " << zp <<
":" << zp-zFront
800 <<
" E " << energy << std::endl;
811 }
else if (type == 1) {
816 }
else if (type == 2) {
831 for (
auto itr : map_hitDepth) {
832 int layer = itr.first - 1;
833 double energy = itr.second;
835 std::cout <<
"SimHit:Layer " << layer+1 <<
" " << energy << std::endl;
843 }
else if (type == 1) {
848 }
else if (type == 2) {
857 for (
auto itr : map_hitCell) {
858 uint32_t
id = ((itr.second).
first);
859 double energy = ((itr.second).
second);
860 std::pair<float,float>
xy(0,0);
866 int subdet,
zside, layer, sector, subsector, cell;
871 xx = (zp < 0) ? -xy.first : xy.first;
877 for (
auto itr : map_hitn) {
878 uint32_t
id = itr.first;
879 double energy = itr.second;
882 }
else if (type == 1) {
884 }
else if (type == 2) {
886 }
else if (type == 3) {
897 for (
auto simTrkItr : *SimTk) {
899 std::cout <<
"Track " << simTrkItr.trackId() <<
" Vertex " 900 << simTrkItr.vertIndex() <<
" Type " << simTrkItr.type()
901 <<
" Charge " << simTrkItr.charge() <<
" momentum " 902 << simTrkItr.momentum() <<
" " << simTrkItr.momentum().P()
905 if (vertIndex == -1) {
906 vertIndex = simTrkItr.vertIndex();
907 pBeam_ = simTrkItr.momentum().P();
910 if (vertIndex != -1 && vertIndex < (
int)SimVtx->size()) {
911 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
912 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
914 std::cout <<
"Vertex " << vertIndex <<
" position " 915 << simVtxItr->position() << std::endl;
917 xBeam_ = simVtxItr->position().X();
918 yBeam_ = simVtxItr->position().Y();
919 zBeam_ = simVtxItr->position().Z();
937 std::map<int,double> map_hitLayer;
938 std::map<int,std::pair<DetId,double> > map_hitCell;
939 for (
auto it : *hits) {
940 DetId detId = it.id();
942 double energy = it.energy();
947 if (map_hitLayer.count(layer) != 0) {
948 map_hitLayer[layer] += energy;
950 map_hitLayer[layer] = energy;
952 if (map_hitCell.count(cell) != 0) {
953 double ee = energy + map_hitCell[cell].second;
954 map_hitCell[cell] = std::pair<uint32_t,double>(detId,ee);
956 map_hitCell[cell] = std::pair<uint32_t,double>(detId,energy);
959 std::cout <<
"RecHit: " << layer <<
" " << global.
x() <<
" " << global.
y()
960 <<
" " << global.
z() <<
" " << energy << std::endl;
964 for (
auto itr : map_hitLayer) {
965 int layer = itr.first;
966 double energy = itr.second;
969 std::cout <<
"SimHit:Layer " << layer <<
" " << zp <<
" " << energy
976 for (
auto itr : map_hitCell) {
978 double energy = ((itr.second).
second);
986 for (
auto v : *hgcPH) {
987 double energy =
v.energy();
989 unsigned int id =
v.id();
991 double time =
v.time();
992 std::cout <<
"HGCalTBAnalyzer::analyzePassiveHits:Energy:Time:Name:Id : " 993 << energy <<
":" << time <<
":" << name <<
":" <<
id 1001 }
else if (subdet==2) {
1005 }
else if (subdet==3) {
1009 }
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_