50 #include "TProfile2D.h" 71 template<
class T1>
void analyzeDigi(
int type,
const T1& detId, uint16_t
adc);
128 usesResource(
"TFileService");
155 std::cout <<
"HGCalTBAnalyzer:: SimHits = " << doSimHits_ <<
" Digis = " 156 << doDigis_ <<
":" << sampleIndex_ <<
" RecHits = " << doRecHits_
157 <<
" useDets " << ifEE_ <<
":" << ifFH_ <<
":" << ifBH_ <<
":" 158 << ifBeam_ <<
" zFront " << zFrontEE_ <<
":" << zFrontFH_ <<
":" 159 << zFrontBH_ <<
" IdBeam " << idBeams_.size() <<
":";
163 if (idBeams_.size() == 0) idBeams_.push_back(1001);
166 tok_hepMC_ = consumes<edm::HepMCProduct>(tmp0);
169 std::cout <<
"HGCalTBAnalyzer:: GeneratorSource = " << tmp0 << std::endl;
182 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
193 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorFH_ <<
" with tags " 194 << 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_ <<
" with tags " 226 << 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);
263 desc.
add<
bool>(
"DoSimHits",
true);
264 desc.
add<
bool>(
"DoDigis",
true);
265 desc.
add<
bool>(
"DoRecHits",
true);
266 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());
412 sprintf (name,
"SimHitEnA%d%s",
l,
detectorEE_.c_str());
413 sprintf (title,
"Sim Hit Energy in SIM layer %d for %s",
l+1,
417 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorEE_.c_str());
418 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
444 sprintf (name,
"SimHitEnA%d%s",
l,
detectorFH_.c_str());
445 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
449 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorFH_.c_str());
450 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
466 sprintf (name,
"SimHitEnA%d%s",
l,
detectorBH_.c_str());
467 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
470 sprintf (name,
"SimHitEnB%d%s",
l,
detectorBH_.c_str());
471 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
480 sprintf (title,
"Sim Hit Energy in type %d for %s",
idBeams_[
l],
496 const HepMC::GenEvent * myGenEvent = evtMC->
GetEvent();
498 for (HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
499 p != myGenEvent->particles_end(); ++
p, ++
k) {
500 if (k == 0)
hBeam_->Fill((*p)->momentum().rho());
502 std::cout <<
"Particle[" << k <<
"] with p " << (*p)->momentum().rho()
503 <<
" theta " << (*p)->momentum().theta() <<
" phi " 504 << (*p)->momentum().phi() << std::endl;
526 std::vector<PCaloHit> caloHits;
531 if (theCaloHitContainers.
isValid()) {
534 << theCaloHitContainers->size() <<
" hits" << std::endl;
537 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
538 theCaloHitContainers->end());
543 <<
" !!!" << std::endl;
551 if (theCaloHitContainers.
isValid()) {
554 << theCaloHitContainers->size() <<
" hits" << std::endl;
557 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
558 theCaloHitContainers->end());
563 <<
" !!!" << std::endl;
571 if (theCaloHitContainers.
isValid()) {
574 << theCaloHitContainers->size() <<
" hits" << std::endl;
577 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
578 theCaloHitContainers->end());
583 <<
" !!!" << std::endl;
590 if (theCaloHitContainers.
isValid()) {
593 << theCaloHitContainers->size() <<
" hits" << std::endl;
596 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
597 theCaloHitContainers->end());
602 <<
" !!!" << std::endl;
637 if (theDigiContainers.
isValid()) {
640 << theDigiContainers->
size() <<
" element(s)" << std::endl;
642 for (
auto it : *theDigiContainers) {
645 uint16_t
adc = hgcSample.
data();
653 if (theDigiContainers.
isValid()) {
656 << theDigiContainers->
size() <<
" element(s)" << std::endl;
658 for (
auto it : *theDigiContainers) {
661 uint16_t
adc = hgcSample.
data();
673 if (theCaloHitContainers.
isValid()) {
676 << theCaloHitContainers->
size() <<
" hits" << std::endl;
682 <<
" !!!" << std::endl;
688 if (theCaloHitContainers.
isValid()) {
691 << theCaloHitContainers->
size() <<
" hits" << std::endl;
697 <<
" !!!" << std::endl;
708 std::map<uint32_t,double> map_hits, map_hitn;
709 std::map<int,double> map_hitDepth;
710 std::map<int,std::pair<uint32_t,double> > map_hitLayer, map_hitCell;
712 for (
unsigned int i=0;
i<hits.size();
i++) {
713 double energy = hits[
i].energy();
714 double time = hits[
i].time();
715 uint32_t
id = hits[
i].id();
717 int subdet,
zside, layer, sector, subsector(0), cell,
depth(0),
idx(0);
727 }
else if (type == 3) {
729 depth = layer; zside = 1;
730 idx = subdet*1000 + layer;
736 idx = sector*1000+cell;
739 std::cout <<
"SimHit:Hit[" <<
i <<
"] Id " << subdet <<
":" << zside <<
":" 740 << layer <<
":" << sector <<
":" << subsector <<
":" << cell
741 <<
":" <<
depth <<
" Energy " << energy <<
" Time " << time
744 if (map_hits.count(
id) != 0) {
745 map_hits[
id] += energy;
747 map_hits[
id] = energy;
749 if (map_hitLayer.count(layer) != 0) {
750 double ee = energy + map_hitLayer[layer].second;
751 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,ee);
753 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,energy);
756 if (map_hitCell.count(idx) != 0) {
757 double ee = energy + map_hitCell[
idx].second;
758 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,ee);
760 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,energy);
762 if (map_hitDepth.count(
depth) != 0) {
763 map_hitDepth[
depth] += energy;
765 map_hitDepth[
depth] = energy;
767 uint32_t idn = (type >= 2) ?
id :
770 if (map_hitn.count(idn) != 0) {
771 map_hitn[idn] += energy;
773 map_hitn[idn] = energy;
780 for (
auto itr : map_hits) {
784 for (
auto itr : map_hitLayer) {
785 int layer = itr.first - 1;
786 double energy = (itr.second).
second;
791 std::cout <<
"SimHit:Layer " << layer+1 <<
" Z " << zp <<
":" << zp-zFront
792 <<
" E " << energy << std::endl;
803 }
else if (type == 1) {
808 }
else if (type == 2) {
823 for (
auto itr : map_hitDepth) {
824 int layer = itr.first - 1;
825 double energy = itr.second;
827 std::cout <<
"SimHit:Layer " << layer+1 <<
" " << energy << std::endl;
835 }
else if (type == 1) {
840 }
else if (type == 2) {
849 for (
auto itr : map_hitCell) {
850 uint32_t
id = ((itr.second).
first);
851 double energy = ((itr.second).
second);
852 std::pair<float,float>
xy(0,0);
858 int subdet,
zside, layer, sector, subsector, cell;
863 xx = (zp < 0) ? -xy.first : xy.first;
869 for (
auto itr : map_hitn) {
870 uint32_t
id = itr.first;
871 double energy = itr.second;
874 }
else if (type == 1) {
876 }
else if (type == 2) {
878 }
else if (type == 3) {
889 for (
auto simTrkItr : *SimTk) {
891 std::cout <<
"Track " << simTrkItr.trackId() <<
" Vertex " 892 << simTrkItr.vertIndex() <<
" Type " << simTrkItr.type()
893 <<
" Charge " << simTrkItr.charge() <<
" momentum " 894 << simTrkItr.momentum() <<
" " << simTrkItr.momentum().P()
897 if (vertIndex == -1) {
898 vertIndex = simTrkItr.vertIndex();
899 pBeam = simTrkItr.momentum().P();
902 if (vertIndex != -1 && vertIndex < (
int)SimVtx->size()) {
903 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
904 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
906 std::cout <<
"Vertex " << vertIndex <<
" position " 907 << simVtxItr->position() << std::endl;
909 xBeam = simVtxItr->position().X();
910 yBeam = simVtxItr->position().Y();
911 zBeam = simVtxItr->position().Z();
929 std::map<int,double> map_hitLayer;
930 std::map<int,std::pair<DetId,double> > map_hitCell;
931 for (
auto it : *hits) {
932 DetId detId = it.id();
934 double energy = it.energy();
939 if (map_hitLayer.count(layer) != 0) {
940 map_hitLayer[layer] += energy;
942 map_hitLayer[layer] = energy;
944 if (map_hitCell.count(cell) != 0) {
945 double ee = energy + map_hitCell[cell].second;
946 map_hitCell[cell] = std::pair<uint32_t,double>(detId,ee);
948 map_hitCell[cell] = std::pair<uint32_t,double>(detId,energy);
951 std::cout <<
"RecHit: " << layer <<
" " << global.
x() <<
" " << global.
y()
952 <<
" " << global.
z() <<
" " << energy << std::endl;
956 for (
auto itr : map_hitLayer) {
957 int layer = itr.first;
958 double energy = itr.second;
961 std::cout <<
"SimHit:Layer " << layer <<
" " << zp <<
" " << energy
968 for (
auto itr : map_hitCell) {
970 double energy = ((itr.second).
second);
978 for (
auto v : *hgcPH) {
979 double energy =
v.energy();
981 double time =
v.time();
984 unsigned int id =
v.id();
987 std::cout <<
"HGCalTBAnalyzer::analyzePassiveHits:Energy:Time:Name:Id : " 988 << energy <<
":" << time <<
":" << name <<
":" <<
id << std::endl;
994 }
else if (subdet==
"FH") {
998 }
else if (subdet==
"BH") {
std::vector< TH1D * > hSimHitLayEn2EE_
int adc(sample_type sample)
get the ADC sample (12 bits)
std::vector< float > simHitLayEn2BH
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< float > simHitCellEnBeam
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)
std::vector< int > hgcPassiveEEID
edm::EDGetToken tok_hitrBH_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
TProfile * hSimHitLng1_[3]
std::vector< float > simHitLayEn1BH
TProfile * hSimHitLng2_[3]
TProfile * hRecHitLng_[3]
#define DEFINE_FWK_MODULE(type)
std::vector< uint32_t > simHitCellIdFH
static const int MaxDepth
get the layer number
static uint32_t packHexagonIndex(int subdet, int z, int lay, int wafer, int celltyp, int cell)
std::vector< std::string > hgcPassiveEEName
edm::Service< TFileService > fs_
HGCalTBAnalyzer(edm::ParameterSet const &)
virtual 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
std::vector< float > simHitCellEnEE
T * make(const Args &...args) const
make new ROOT object
GlobalPoint getPosition(const DetId &id) const
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::vector< float > simHitLayEn1EE
TProfile2D * hSimHitLat_[3]
std::vector< float > simHitCellEnFH
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)
std::vector< float > hgcPassiveBHEnergy
std::vector< int > hgcPassiveFHID
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::pair< double, double > getXY() const
get the local coordinate in the plane and along depth
edm::EDGetTokenT< edm::SimTrackContainer > tok_simTk_
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
std::vector< TH1D * > hSimHitLayEnBeam_
std::vector< float > hgcPassiveFHEnergy
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_
double waferZ(int layer, bool reco) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< uint32_t > simHitCellIdBeam
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHEE_
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< uint32_t > simHitCellIdEE
TProfile * hSimHitLng_[3]
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< uint32_t > simHitCellIdBH
std::vector< float > simHitLayEnBeam
void analyzePassiveHits(edm::Handle< edm::PassiveHitContainer > &hgcPh, std::string subdet)
std::vector< float > simHitLayEn1FH
std::vector< float > simHitCellEnBH
std::string detectorBeam_
void analyzeDigi(int type, const T1 &detId, uint16_t adc)
std::vector< std::vector< double > > tmp
std::vector< float > simHitLayEn2EE
std::vector< std::string > hgcPassiveFHName
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hitsEE_
edm::EDGetToken tok_digiBH_
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
edm::EDGetTokenT< edm::PassiveHitContainer > tok_hgcPHFH_
std::vector< int > hgcPassiveBHID
std::vector< TH1D * > hSimHitLayEn1BH_
int zside() const
get the z-side of the cell (1/-1)
T const * product() const
edm::EDGetToken tok_hitrEE_
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_
virtual void beginJob() override
edm::EDGetToken tok_digiEE_
std::vector< float > hgcPassiveEEEnergy
std::vector< std::string > hgcPassiveBHName
std::vector< float > simHitLayEn2FH