Skip to content

Commit

Permalink
Merge pull request #12703 from bsunanda/Run2-hcx57
Browse files Browse the repository at this point in the history
bsunanda:Run2-hcx57 Utilize a test numbering scheme for HGCal in SIM step (as in #12572)
  • Loading branch information
cmsbuild committed Dec 8, 2015
2 parents 798f2ac + e887195 commit 9a0765e
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 60 deletions.
29 changes: 15 additions & 14 deletions DataFormats/ForwardDetId/interface/HGCalDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ class HGCalDetId : public DetId {

public:
static const int kHGCalCellOffset = 0;
static const int kHGCalCellMask = 0xFFFF;
static const int kHGCalSectorOffset = 16;
static const int kHGCalSectorMask = 0x7F;
static const int kHGCalSubSectorOffset = 23;
static const int kHGCalSubSectorMask = 0x1;
static const int kHGCalLayerOffset = 24;
static const int kHGCalLayerMask = 0x7F;
static const int kHGCalZsideOffset = 31;
static const int kHGCalCellMask = 0xFF;
static const int kHGCalWaferOffset = 8;
static const int kHGCalWaferMask = 0x3FF;
static const int kHGCalWaferTypeOffset = 18;
static const int kHGCalWaferTypeMask = 0x1;
static const int kHGCalLayerOffset = 19;
static const int kHGCalLayerMask = 0x1F;
static const int kHGCalZsideOffset = 24;
static const int kHGCalZsideMask = 0x1;

/** Create a null cellid*/
HGCalDetId();
/** Create cellid from raw id (0=invalid tower id) */
HGCalDetId(uint32_t rawid);
/** Constructor from subdetector, zplus, layer, module, cell numbers */
HGCalDetId(ForwardSubdetector subdet, int zp, int lay, int mod, int subsec, int cell);
HGCalDetId(ForwardSubdetector subdet, int zp, int lay, int wafertype, int wafer, int cell);
/** Constructor from a generic cell id */
HGCalDetId(const DetId& id);
/** Assignment from a generic cell id */
Expand All @@ -34,11 +34,11 @@ class HGCalDetId : public DetId {
/// get the absolute value of the cell #'s in x and y
int cell() const { return id_&kHGCalCellMask; }

/// get the sector #
int sector() const { return (id_>>kHGCalSectorOffset)&kHGCalSectorMask; }
/// get the wafer #
int wafer() const { return (id_>>kHGCalWaferOffset)&kHGCalWaferMask; }

/// get the degree subsector
int subsector() const { return ( (id_>>kHGCalSubSectorOffset)&kHGCalSubSectorMask ? 1 : -1); }
/// get the wafer type
int waferType() const { return (id_>>kHGCalWaferTypeOffset)&kHGCalWaferTypeMask; }

/// get the layer #
int layer() const { return (id_>>kHGCalLayerOffset)&kHGCalLayerMask; }
Expand All @@ -50,8 +50,9 @@ class HGCalDetId : public DetId {
bool isHGCal() const { return true; }
bool isForward() const { return true; }
static bool isValid(ForwardSubdetector subdet, int zp, int lay,
int mod, int subsec, int cell);
int wafertype, int wafer, int cell);

static const HGCalDetId Undefined;
};

std::ostream& operator<<(std::ostream&,const HGCalDetId& id);
Expand Down
46 changes: 21 additions & 25 deletions DataFormats/ForwardDetId/src/HGCalDetId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ HGCalDetId::HGCalDetId() : DetId() {
HGCalDetId::HGCalDetId(uint32_t rawid) : DetId(rawid) {
}

HGCalDetId::HGCalDetId(ForwardSubdetector subdet, int zp, int lay, int sec, int subsec, int cell) : DetId(Forward,subdet) {

if (cell > kHGCalCellMask || sec>kHGCalSectorMask ||
subsec > kHGCalSubSectorMask || lay>kHGCalLayerMask ) {
HGCalDetId::HGCalDetId(ForwardSubdetector subdet, int zp, int lay, int wafertype, int wafer, int cell) : DetId(Forward,subdet) {

if (cell>kHGCalCellMask || cell<0 || wafer>kHGCalWaferMask || wafer<0 || wafertype>kHGCalWaferTypeMask || wafertype<0 || lay>kHGCalLayerMask || lay<0) {
#ifdef DebugLog
std::cout << "[HGCalDetId] request for new id for layer=" << lay
<< " @ zp=" << zp
<< " sector=" << sec
<< " subsec=" << subsec
<< " wafer=" << wafer
<< " waferType=" << wafertype
<< " cell=" << cell
<< " for subdet=" << subdet
<< " has one or more fields out of bounds and will be reset"
<< std::endl;
#endif
cell=0; sec=0; subsec=0; lay=0;
zp = lay = wafertype = wafer = cell=0;
}
uint32_t rawid=0;
rawid |= ((cell & kHGCalCellMask) << kHGCalCellOffset);
rawid |= ((sec & kHGCalSectorMask) << kHGCalSectorOffset);
if (subsec<0) subsec=0;
rawid |= ((subsec & kHGCalSubSectorMask) << kHGCalSubSectorOffset);
rawid |= ((lay & kHGCalLayerMask) << kHGCalLayerOffset);
if (zp>0) rawid |= ((zp & kHGCalZsideMask) << kHGCalZsideOffset);
id_ = rawid;
id_ |= ((cell & kHGCalCellMask) << kHGCalCellOffset);
id_ |= ((wafer & kHGCalWaferMask) << kHGCalWaferOffset);
id_ |= ((wafertype & kHGCalWaferTypeMask) << kHGCalWaferTypeOffset);
id_ |= ((lay & kHGCalLayerMask) << kHGCalLayerOffset);
if (zp>0) id_ |= ((zp & kHGCalZsideMask) << kHGCalZsideOffset);
}

HGCalDetId::HGCalDetId(const DetId& gen) {
Expand All @@ -44,29 +40,29 @@ HGCalDetId& HGCalDetId::operator=(const DetId& gen) {
return (*this);
}

bool HGCalDetId::isValid(ForwardSubdetector subdet, int zp, int lay,
int mod, int subsec, int cell) {
bool HGCalDetId::isValid(ForwardSubdetector subdet, int zp, int lay, int wafertype, int wafer, int cell) {

bool ok = ((subdet == HGCEE || subdet == HGCHEF || subdet == HGCHEB) &&
(cell >= 0 && cell <= kHGCalCellMask) &&
(mod >= 1 && mod <= kHGCalSectorMask) &&
(subsec == 0 || subsec == 1) &&
(wafer >= 0 && wafer <= kHGCalWaferMask) &&
(wafertype >= 0 || wafertype <= kHGCalWaferTypeMask) &&
(lay >= 0 && lay <= kHGCalLayerMask) &&
(zp == -1 || zp == 1));
#ifdef DebugLog
if (!ok)
std::cout << "HGCalDetId: subdet " << subdet << ":"
<< (subdet == HGCEE || subdet == HGCHEF || subdet == HGCHEB)
<< " Cell " << cell << ":" << (cell >= 0 && cell <= 0xffff)
<< " Module " << mod << ":" << (mod >= 1 && mod <= 0x7f)
<< " SubSector " << subsec << ":" << (subsec == 0 || subsec == 1)
<< " Layer " << lay << ":" << (lay >= 0 && lay <= 0x7f)
<< " Cell " << cell << ":" << (cell >= 0 && cell <= kHGCalCellMask)
<< " Wafer " << wafer << ":" << (wafer >= 0 && wafer <= kHGCalWaferMask)
<< " WaferType " << wafertype << ":" << (wafertype >= 0 || wafertype <= kHGCalWaferTypeMask)
<< " Layer " << lay << ":" << (lay >= 0 && lay <= kHGCalLayerMask)
<< " zp " << zp << ":" << (zp == -1 || zp == 1) << std::endl;
#endif
return ok;
}

std::ostream& operator<<(std::ostream& s,const HGCalDetId& id) {
return s << "isHGCal=" << id.isHGCal() << " zpos=" << id.zside()
<< " layer=" << id.layer() << " phi subSector=" << id.subsector()
<< " sector=" << id.sector() << " cell=" << id.cell();
<< " layer=" << id.layer() << " wafer type=" << id.waferType()
<< " wafer=" << id.wafer() << " cell=" << id.cell();
}
1 change: 1 addition & 0 deletions SimCalorimetry/HGCalSimProducers/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="FWCore/Utilities"/>
<use name="SimGeneral/MixingModule"/>
<use name="DataFormats/ForwardDetId"/>
<use name="SimDataFormats/CaloTest"/>
<use name="Geometry/Records"/>
<use name="Geometry/HGCalGeometry"/>
<use name="hepmc"/>
Expand Down
32 changes: 16 additions & 16 deletions SimCalorimetry/HGCalSimProducers/src/HGCDigitizer.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCEEDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCHEDetId.h"
#include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
#include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizer.h"
#include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
Expand Down Expand Up @@ -171,29 +172,28 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits,
std::vector< HGCCaloHitTuple_t > hitRefs(nchits);
for(int i=0; i<nchits; i++)
{
HGCalDetId simId( hits->at(i).id() );

int layer, cell, sec, subsec, zp;
uint32_t simId = hits->at(i).id();
HGCalTestNumbering::unpackSquareIndex(simId, zp, layer, sec, subsec, cell);
//skip this hit if after ganging it is not valid
int layer(simId.layer()), cell(simId.cell());
std::pair<int,int> recoLayerCell=dddConst.simToReco(cell,layer,topo.detectorType());
cell = recoLayerCell.first;
layer = recoLayerCell.second;
if(layer<0 || cell<0)
{
hitRefs[i]=std::make_tuple( i, 0, 0.);
continue;
}
if (layer<0 || cell<0) {
hitRefs[i]=std::make_tuple( i, 0, 0.);
continue;
}

//assign the RECO DetId
DetId id( producesEEDigis() ?
(uint32_t)HGCEEDetId(mySubDet_,simId.zside(),layer,simId.sector(),simId.subsector(),cell):
(uint32_t)HGCHEDetId(mySubDet_,simId.zside(),layer,simId.sector(),simId.subsector(),cell) );
(uint32_t)HGCEEDetId(mySubDet_,zp,layer,sec,subsec,cell):
(uint32_t)HGCHEDetId(mySubDet_,zp,layer,sec,subsec,cell) );

if (verbosity_>0) {
if (producesEEDigis())
edm::LogInfo("HGCDigitizer") <<" i/p " << simId << " o/p " << HGCEEDetId(id) << std::endl;
edm::LogInfo("HGCDigitizer") <<" i/p " << std::hex << simId << std::dec << " o/p " << HGCEEDetId(id) << std::endl;
else
edm::LogInfo("HGCDigitizer") << " i/p " << simId << " o/p " << HGCHEDetId(id) << std::endl;
edm::LogInfo("HGCDigitizer") << " i/p " << std::hex << simId << std::dec << " o/p " << HGCHEDetId(id) << std::endl;
}

hitRefs[i]=std::make_tuple( i,
Expand Down Expand Up @@ -228,9 +228,9 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits,
if(itime<0 || itime>14) continue;

//check if already existing (perhaps could remove this in the future - 2nd event should have all defined)
HGCSimHitDataAccumulator::iterator simHitIt = simHitAccumulator_->find(id);
if( simHitIt == simHitAccumulator_->end() ) {
simHitIt = simHitAccumulator_->insert( std::make_pair(id,baseData) ).first;
HGCSimHitDataAccumulator::iterator simHitIt=simHitAccumulator_->find(id);
if(simHitIt == simHitAccumulator_->end()) {
simHitIt = simHitAccumulator_->insert( std::make_pair(id,baseData) ).first;
}

//check if time index is ok and store energy
Expand Down Expand Up @@ -261,7 +261,7 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits,
fireTDC = deltaT*(deltaQ2TDCOnset/deltaQ)+prev_tof;
}
}

(simHitIt->second)[1][itime]=fireTDC;
}
}
Expand Down
52 changes: 52 additions & 0 deletions SimDataFormats/CaloTest/interface/HGCalTestNumbering.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef SimDataFormats_HGCalTestNumbering_h
#define SimDataFormats_HGCalTestNumbering_h
///////////////////////////////////////////////////////////////////////////////
// File: HGCalTestNumbering.h
// Description: Numbering scheme for high granularity calorimeter (SIM step)
///////////////////////////////////////////////////////////////////////////////

#include <boost/cstdint.hpp>

class HGCalTestNumbering {

public:
static const int kHGCalCellSOffset = 0;
static const int kHGCalCellSMask = 0xFFFF;
static const int kHGCalSectorSOffset = 16;
static const int kHGCalSectorSMask = 0x7F;
static const int kHGCalSubSectorSOffset = 23;
static const int kHGCalSubSectorSMask = 0x1;
static const int kHGCalLayerSOffset = 24;
static const int kHGCalLayerSMask = 0x7F;
static const int kHGCalZsideSOffset = 31;
static const int kHGCalZsideSMask = 0x1;

static const int kHGCalCellHOffset = 0;
static const int kHGCalCellHMask = 0xFF;
static const int kHGCalCellTypHOffset = 8;
static const int kHGCalCellTypHMask = 0x1;
static const int kHGCalWaferHOffset = 9;
static const int kHGCalWaferHMask = 0x1FF;
static const int kHGCalLayerHOffset = 18;
static const int kHGCalLayerHMask = 0x7F;
static const int kHGCalZsideHOffset = 25;
static const int kHGCalZsideHMask = 0x1;
static const int kHGCalSubdetHOffset = 30;
static const int kHGCalSubdetHMask = 0x7;
HGCalTestNumbering() {}
virtual ~HGCalTestNumbering() {}
static uint32_t packSquareIndex(int z, int lay, int sec, int subsec,
int cell);
static uint32_t packHexagonIndex(int subdet, int z, int lay, int wafer,
int celltyp, int cell);
static void unpackSquareIndex(const uint32_t& idx, int& z, int& lay,
int& sec, int& subsec, int& cell);
static void unpackHexagonIndex(const uint32_t& idx, int& subdet, int& z,
int& lay, int& wafer, int& celltyp,
int& cell);
static bool isValidSquare(int z, int lay, int sec, int subsec, int cell);
static bool isValidHexagon(int subdet, int z, int lay, int wafer,
int celltyp, int cell);
};

#endif
124 changes: 124 additions & 0 deletions SimDataFormats/CaloTest/src/HGCalTestNumbering.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
#include <iostream>

//#define DebugLog

uint32_t HGCalTestNumbering::packSquareIndex(int zp, int lay, int sec,
int subsec, int cell) {

if (cell > kHGCalCellSMask || sec>kHGCalSectorSMask ||
subsec > kHGCalSubSectorSMask || lay>kHGCalLayerSMask ) {
#ifdef DebugLog
std::cout << "[HGCalTestNumbering] request for new id for layer=" << lay
<< " zp=" << zp
<< " sector=" << sec
<< " subsec=" << subsec
<< " cell=" << cell
<< " has one or more fields out of bounds and will be reset"
<< std::endl;
#endif
zp = lay = sec = subsec = cell = 0;
}

uint32_t rawid=0;
rawid |= ((cell & kHGCalCellSMask) << kHGCalCellSOffset);
rawid |= ((sec & kHGCalSectorSMask) << kHGCalSectorSOffset);
if (subsec<0) subsec=0;
rawid |= ((subsec & kHGCalSubSectorSMask) << kHGCalSubSectorSOffset);
rawid |= ((lay & kHGCalLayerSMask) << kHGCalLayerSOffset);
if (zp>0) rawid |= ((zp & kHGCalZsideSMask) << kHGCalZsideSOffset);
return rawid;
}

uint32_t HGCalTestNumbering::packHexagonIndex(int subdet, int zp, int lay,
int wafer, int celltyp,
int cell) {

if (cell > kHGCalCellHMask || celltyp>kHGCalCellTypHMask ||
wafer > kHGCalWaferHMask || lay>kHGCalLayerSMask ||
subdet > kHGCalSubdetHMask) {
#ifdef DebugLog
std::cout << "[HGCalTestNumbering] request for new id for layer=" << lay
<< " zp=" << zp
<< " wafer=" << wafer
<< " celltyp=" << celltyp
<< " cell=" << cell
<< " for subdet=" << subdet
<< " has one or more fields out of bounds and will be reset"
<< std::endl;
#endif
subdet = zp = lay = wafer = celltyp = cell = 0;
}

uint32_t rawid=0;
rawid |= ((cell & kHGCalCellHMask) << kHGCalCellHOffset);
rawid |= ((celltyp& kHGCalCellTypHMask) << kHGCalCellTypHOffset);
rawid |= ((wafer & kHGCalWaferHMask) << kHGCalWaferHOffset);
rawid |= ((lay & kHGCalLayerHMask) << kHGCalLayerHOffset);
if (zp>0) rawid |= ((zp & kHGCalZsideHMask) << kHGCalZsideHOffset);
rawid |= ((subdet & kHGCalSubdetHMask) << kHGCalSubdetHOffset);
return rawid;
}

void HGCalTestNumbering::unpackSquareIndex(const uint32_t& idx, int& zp,
int& lay, int& sec, int& subsec,
int& cell) {

cell = (idx>>kHGCalCellSOffset)&kHGCalCellSMask;
subsec = ((idx>>kHGCalSubSectorSOffset)&kHGCalSubSectorSMask ? 1 : -1);
sec = (idx>>kHGCalSectorSOffset)&kHGCalSectorSMask;
lay = (idx>>kHGCalLayerSOffset)&kHGCalLayerSMask;
zp = ((idx>>kHGCalZsideSOffset) & kHGCalZsideSMask ? 1 : -1);
}


void HGCalTestNumbering::unpackHexagonIndex(const uint32_t& idx, int& subdet,
int& zp, int& lay, int& wafer,
int& celltyp, int& cell) {
cell = (idx>>kHGCalCellHOffset)&kHGCalCellHMask;
celltyp= (idx>>kHGCalCellTypHOffset)&kHGCalCellTypHMask;
wafer = (idx>>kHGCalWaferHOffset)&kHGCalWaferHMask;
lay = (idx>>kHGCalLayerHOffset)&kHGCalLayerHMask;
zp = ((idx>>kHGCalZsideHOffset) & kHGCalZsideHMask ? 1 : -1);
subdet = (idx>>kHGCalSubdetHOffset)&kHGCalSubdetHMask;
}

bool HGCalTestNumbering::isValidSquare(int zp, int lay, int sec, int subsec,
int cell) {

if (cell > kHGCalCellSMask || sec>kHGCalSectorSMask ||
subsec > kHGCalSubSectorSMask || lay>kHGCalLayerSMask ) {
#ifdef DebugLog
std::cout << "[HGCalTestNumbering] request for new id for layer=" << lay
<< " zp=" << zp
<< " sector=" << sec
<< " subsec=" << subsec
<< " cell=" << cell
<< " has one or more fields out of bounds and will be reset"
<< std::endl;
#endif
return false;
}
return true;
}

bool HGCalTestNumbering::isValidHexagon(int subdet, int zp, int lay, int wafer,
int celltyp, int cell) {

if (cell > kHGCalCellHMask || celltyp>kHGCalCellTypHMask ||
wafer > kHGCalWaferHMask || lay>kHGCalLayerSMask ||
subdet > kHGCalSubdetHMask) {
#ifdef DebugLog
std::cout << "[HGCalTestNumbering] request for new id for layer=" << lay
<< " zp=" << zp
<< " wafer=" << wafer
<< " celltyp=" << celltyp
<< " cell=" << cell
<< " for subdet=" << subdet
<< " has one or more fields out of bounds and will be reset"
<< std::endl;
#endif
return false;
}
return true;
}
Loading

0 comments on commit 9a0765e

Please sign in to comment.