48 #include "TProfile2D.h" 69 template<
class T1>
void analyzeDigi(
int type,
const T1& detId, uint16_t
adc);
116 usesResource(
"TFileService");
138 std::cout <<
"HGCalTBAnalyzer:: SimHits = " << doSimHits_ <<
" Digis = " 139 << doDigis_ <<
":" << sampleIndex_ <<
" RecHits = " << doRecHits_
140 <<
" useDets " << ifEE_ <<
":" << ifFH_ <<
":" << ifBH_ <<
":" 141 << ifBeam_ <<
" zFront " << zFrontEE_ <<
":" << zFrontFH_ <<
":" 142 << zFrontBH_ <<
" IdBeam " << idBeams_.size() <<
":";
146 if (idBeams_.size() == 0) idBeams_.push_back(1001);
149 tok_hepMC_ = consumes<edm::HepMCProduct>(tmp0);
151 std::cout <<
"HGCalTBAnalyzer:: GeneratorSource = " << tmp0 << std::endl;
164 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
175 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorFH_ <<
" with tags " 176 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
187 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBH_ <<
" with tags " 188 << tmp1 <<
", " << tmp2 <<
", " << tmp3 << std::endl;
195 std::cout <<
"HGCalTBAnalyzer:: Detector " << detectorBeam_ <<
" with tags " 196 << tmp1 << std::endl;
207 desc.
add<
bool>(
"UseEE",
true);
208 desc.
add<
double>(
"ZFrontEE",0.0);
213 desc.
add<
bool>(
"UseFH",
false);
214 desc.
add<
double>(
"ZFrontFH",0.0);
219 desc.
add<
bool>(
"UseBH",
false);
220 desc.
add<
double>(
"ZFrontBH",0.0);
225 desc.
add<
bool>(
"UseBeam",
false);
227 std::vector<int> ids = {1000,1001,1002,1003,1004,1005,1006,1007,1008,1011,1012,1013,1014,2001,2002,2003,2004,2005};
228 desc.
add<std::vector<int>>(
"IDBeams",ids);
230 desc.
add<
bool>(
"DoSimHits",
true);
231 desc.
add<
bool>(
"DoDigis",
true);
232 desc.
add<
bool>(
"DoRecHits",
true);
233 desc.
add<
int>(
"SampleIndex",0);
236 descriptions.
add(
"HGCalTBAnalyzer",desc);
242 hBeam_ =
fs_->
make<TH1D>(
"BeamP",
"Beam Momentum", 1000, 0, 1000.0);
243 for (
int i=0;
i<3; ++
i) {
255 sprintf (name,
"SimHitEn%s", det.c_str());
256 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
258 sprintf (name,
"SimHitEnX%s", det.c_str());
259 sprintf (title,
"Sim Hit Energy for %s", det.c_str());
261 sprintf (name,
"SimHitTm%s", det.c_str());
262 sprintf (title,
"Sim Hit Timing for %s", det.c_str());
264 sprintf (name,
"SimHitLat%s", det.c_str());
265 sprintf (title,
"Lateral Shower profile (Sim Hit) for %s", det.c_str());
267 sprintf (name,
"SimHitLng%s", det.c_str());
268 sprintf (title,
"Longitudinal Shower profile (Sim Hit) for %s",det.c_str());
270 sprintf (name,
"SimHitLng1%s", det.c_str());
271 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
273 sprintf (name,
"SimHitLng2%s", det.c_str());
274 sprintf (title,
"Longitudinal Shower profile (Layer) for %s",det.c_str());
279 sprintf (name,
"DigiADC%s", det.c_str());
280 sprintf (title,
"ADC at Digi level for %s", det.c_str());
282 sprintf (name,
"DigiOcc%s", det.c_str());
283 sprintf (title,
"Occupancy (Digi)for %s", det.c_str());
285 sprintf (name,
"DigiLng%s", det.c_str());
286 sprintf (title,
"Longitudinal Shower profile (Digi) for %s",det.c_str());
291 sprintf (name,
"RecHitEn%s", det.c_str());
292 sprintf (title,
"Rec Hit Energy for %s", det.c_str());
294 sprintf (name,
"RecHitOcc%s", det.c_str());
295 sprintf (title,
"Occupancy (Rec Hit)for %s", det.c_str());
297 sprintf (name,
"RecHitLat%s", det.c_str());
298 sprintf (title,
"Lateral Shower profile (Rec Hit) for %s", det.c_str());
300 sprintf (name,
"RecHitLng%s", det.c_str());
301 sprintf (title,
"Longitudinal Shower profile (Rec Hit) for %s",det.c_str());
303 sprintf (name,
"RecHitLng1%s", det.c_str());
304 sprintf (title,
"Longitudinal Shower profile vs Layer for %s",det.c_str());
310 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
313 sprintf (title,
"Sim Hit Energy for %s",
detectorBeam_.c_str());
316 sprintf (title,
"Sim Hit Timing for %s",
detectorBeam_.c_str());
359 sprintf (name,
"SimHitEnA%d%s",
l,
detectorEE_.c_str());
360 sprintf (title,
"Sim Hit Energy in SIM layer %d for %s",
l+1,
364 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorEE_.c_str());
365 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
391 sprintf (name,
"SimHitEnA%d%s",
l,
detectorFH_.c_str());
392 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
396 sprintf (name,
"SimHitEnB%d%s", (
l/3+1),
detectorFH_.c_str());
397 sprintf (title,
"Sim Hit Energy in layer %d for %s",(
l/3+1),
413 sprintf (name,
"SimHitEnA%d%s",
l,
detectorBH_.c_str());
414 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
417 sprintf (name,
"SimHitEnB%d%s",
l,
detectorBH_.c_str());
418 sprintf (title,
"Sim Hit Energy in layer %d for %s",
l+1,
427 sprintf (title,
"Sim Hit Energy in type %d for %s",
idBeams_[
l],
443 const HepMC::GenEvent * myGenEvent = evtMC->
GetEvent();
445 for (HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
446 p != myGenEvent->particles_end(); ++
p, ++
k) {
447 if (k == 0)
hBeam_->Fill((*p)->momentum().rho());
449 std::cout <<
"Particle[" << k <<
"] with p " << (*p)->momentum().rho()
450 <<
" theta " << (*p)->momentum().theta() <<
" phi " 451 << (*p)->momentum().phi() << std::endl;
473 std::vector<PCaloHit> caloHits;
478 if (theCaloHitContainers.
isValid()) {
481 << theCaloHitContainers->size() <<
" hits" << std::endl;
484 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
485 theCaloHitContainers->end());
490 <<
" !!!" << std::endl;
498 if (theCaloHitContainers.
isValid()) {
501 << theCaloHitContainers->size() <<
" hits" << std::endl;
504 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
505 theCaloHitContainers->end());
510 <<
" !!!" << std::endl;
518 if (theCaloHitContainers.
isValid()) {
521 << theCaloHitContainers->size() <<
" hits" << std::endl;
524 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
525 theCaloHitContainers->end());
530 <<
" !!!" << std::endl;
537 if (theCaloHitContainers.
isValid()) {
540 << theCaloHitContainers->size() <<
" hits" << std::endl;
543 caloHits.insert(caloHits.end(), theCaloHitContainers->begin(),
544 theCaloHitContainers->end());
549 <<
" !!!" << std::endl;
561 if (theDigiContainers.
isValid()) {
564 << theDigiContainers->
size() <<
" element(s)" << std::endl;
567 it !=theDigiContainers->
end(); ++it) {
570 uint16_t
adc = hgcSample.
data();
578 if (theDigiContainers.
isValid()) {
581 << theDigiContainers->
size() <<
" element(s)" << std::endl;
584 it !=theDigiContainers->
end(); ++it) {
587 uint16_t
adc = hgcSample.
data();
599 if (theCaloHitContainers.
isValid()) {
602 << theCaloHitContainers->
size() <<
" hits" << std::endl;
608 <<
" !!!" << std::endl;
614 if (theCaloHitContainers.
isValid()) {
617 << theCaloHitContainers->
size() <<
" hits" << std::endl;
623 <<
" !!!" << std::endl;
633 std::map<uint32_t,double> map_hits, map_hitn;
634 std::map<int,double> map_hitDepth;
635 std::map<int,std::pair<uint32_t,double> > map_hitLayer, map_hitCell;
637 for (
unsigned int i=0;
i<hits.size();
i++) {
638 double energy = hits[
i].energy();
639 double time = hits[
i].time();
640 uint32_t
id = hits[
i].id();
642 int subdet,
zside, layer, sector, subsector(0), cell,
depth(0),
idx(0);
652 }
else if (type == 3) {
654 depth = layer; zside = 1;
655 idx = subdet*1000 + layer;
661 idx = sector*1000+cell;
664 std::cout <<
"SimHit:Hit[" <<
i <<
"] Id " << subdet <<
":" << zside <<
":" 665 << layer <<
":" << sector <<
":" << subsector <<
":" << cell
666 <<
":" <<
depth <<
" Energy " << energy <<
" Time " << time
669 if (map_hits.count(
id) != 0) {
670 map_hits[
id] += energy;
672 map_hits[
id] = energy;
674 if (map_hitLayer.count(layer) != 0) {
675 double ee = energy + map_hitLayer[layer].second;
676 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,ee);
678 map_hitLayer[layer] = std::pair<uint32_t,double>(
id,energy);
681 if (map_hitCell.count(idx) != 0) {
682 double ee = energy + map_hitCell[
idx].second;
683 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,ee);
685 map_hitCell[
idx] = std::pair<uint32_t,double>(
id,energy);
687 if (map_hitDepth.count(
depth) != 0) {
688 map_hitDepth[
depth] += energy;
690 map_hitDepth[
depth] = energy;
692 uint32_t idn = (type >= 2) ?
id :
695 if (map_hitn.count(idn) != 0) {
696 map_hitn[idn] += energy;
698 map_hitn[idn] = energy;
705 for (std::map<uint32_t,double>::iterator itr = map_hits.begin() ;
706 itr != map_hits.end(); ++itr) {
710 for (
std::map<
int,std::pair<uint32_t,double> >::iterator itr = map_hitLayer.begin();
711 itr != map_hitLayer.end(); ++itr) {
712 int layer = itr->first - 1;
713 double energy = (itr->second).
second;
718 std::cout <<
"SimHit:Layer " << layer+1 <<
" Z " << zp <<
":" << zp-zFront
719 <<
" E " << energy << std::endl;
730 }
else if (type == 1) {
735 }
else if (type == 2) {
750 for (std::map<int,double>::iterator itr = map_hitDepth.begin();
751 itr != map_hitDepth.end(); ++itr) {
752 int layer = itr->first - 1;
753 double energy = itr->second;
755 std::cout <<
"SimHit:Layer " << layer+1 <<
" " << energy << std::endl;
763 }
else if (type == 1) {
768 }
else if (type == 2) {
777 for (
std::map<
int,std::pair<uint32_t,double> >::iterator itr = map_hitCell.begin();
778 itr != map_hitCell.end(); ++itr) {
779 uint32_t
id = ((itr->second).
first);
780 double energy = ((itr->second).
second);
781 std::pair<float,float>
xy(0,0);
787 int subdet,
zside, layer, sector, subsector, cell;
792 xx = (zp < 0) ? -xy.first : xy.first;
798 for (std::map<uint32_t,double>::iterator itr = map_hitn.begin();
799 itr != map_hitn.end(); ++itr) {
800 uint32_t
id = itr->first;
801 double energy = itr->second;
804 }
else if (type == 1) {
806 }
else if (type == 2) {
808 }
else if (type == 3) {
819 for (edm::SimTrackContainer::const_iterator simTrkItr = SimTk->begin();
820 simTrkItr!= SimTk->end(); simTrkItr++) {
822 std::cout <<
"Track " << simTrkItr->trackId() <<
" Vertex " 823 << simTrkItr->vertIndex() <<
" Type " << simTrkItr->type()
824 <<
" Charge " << simTrkItr->charge() <<
" momentum " 825 << simTrkItr->momentum() <<
" " << simTrkItr->momentum().P()
828 if (vertIndex == -1) {
829 vertIndex = simTrkItr->vertIndex();
830 pBeam = simTrkItr->momentum().P();
833 if (vertIndex != -1 && vertIndex < (
int)SimVtx->size()) {
834 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
835 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
837 std::cout <<
"Vertex " << vertIndex <<
" position " 838 << simVtxItr->position() << std::endl;
840 xBeam = simVtxItr->position().X();
841 yBeam = simVtxItr->position().Y();
842 zBeam = simVtxItr->position().Z();
860 std::map<int,double> map_hitLayer;
861 std::map<int,std::pair<DetId,double> > map_hitCell;
863 it != hits->
end(); ++it) {
864 DetId detId = it->id();
866 double energy = it->energy();
871 if (map_hitLayer.count(layer) != 0) {
872 map_hitLayer[layer] += energy;
874 map_hitLayer[layer] = energy;
876 if (map_hitCell.count(cell) != 0) {
877 double ee = energy + map_hitCell[cell].second;
878 map_hitCell[cell] = std::pair<uint32_t,double>(detId,ee);
880 map_hitCell[cell] = std::pair<uint32_t,double>(detId,energy);
883 std::cout <<
"RecHit: " << layer <<
" " << global.
x() <<
" " << global.
y()
884 <<
" " << global.
z() <<
" " << energy << std::endl;
888 for (std::map<int,double>::iterator itr = map_hitLayer.begin();
889 itr != map_hitLayer.end(); ++itr) {
890 int layer = itr->first;
891 double energy = itr->second;
894 std::cout <<
"SimHit:Layer " << layer <<
" " << zp <<
" " << energy
901 for (
std::map<
int,std::pair<DetId,double> >::iterator itr = map_hitCell.begin();
902 itr != map_hitCell.end(); ++itr) {
904 double energy = ((itr->second).
second);
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)
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< HGCEEDataFrame >::const_iterator const_iterator
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)
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_
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
const_iterator end() const
TProfile2D * hRecHitLat_[3]
const HepMC::GenEvent * GetEvent() const
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
std::vector< float > simHitLayEn1FH
std::vector< float > simHitCellEnBH
std::string detectorBeam_
void analyzeDigi(int type, const T1 &detId, uint16_t adc)
std::vector< float > simHitLayEn2EE
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)
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 #
const_iterator begin() const
TProfile * hRecHitLng1_[3]
std::vector< TH1D * > hSimHitLayEn2FH_
virtual void beginJob() override
edm::EDGetToken tok_digiEE_
std::vector< float > simHitLayEn2FH