Skip to content

Commit

Permalink
Merge pull request #3187 from kpedro88/Phase2-CT4
Browse files Browse the repository at this point in the history
Update CaloTowers for hcal flexible segmentation in Phase 2
  • Loading branch information
cmsbuild committed Apr 4, 2014
2 parents 9760756 + 00829c8 commit a558508
Show file tree
Hide file tree
Showing 54 changed files with 1,554 additions and 557 deletions.
154 changes: 154 additions & 0 deletions CondTools/Geometry/plugins/calowriters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,160 @@ CaloGeometryDBEP<HcalGeometry, CaloGeometryDBWriter>::produceAligned( const type

return ptr ;
}

template<>
CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter>::PtrType
CaloGeometryDBEP<CaloTowerGeometry, CaloGeometryDBWriter>::produceAligned( const typename CaloTowerGeometry::AlignedRecord& iRecord ) {

const Alignments* alignPtr ( 0 ) ;
const Alignments* globalPtr ( 0 ) ;
if( m_applyAlignment ) { // get ptr if necessary
edm::ESHandle< Alignments > alignments ;
iRecord.getRecord< typename CaloTowerGeometry::AlignmentRecord >().get( alignments ) ;

assert( alignments.isValid() && // require valid alignments and expected sizet
( alignments->m_align.size() == CaloTowerGeometry::numberOfAlignments() ) ) ;
alignPtr = alignments.product() ;

edm::ESHandle< Alignments > globals ;
iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;

assert( globals.isValid() ) ;
globalPtr = globals.product() ;
}

TrVec tvec ;
DimVec dvec ;
IVec ivec ;
IVec dins ;

if( CaloGeometryDBWriter::writeFlag() ) {
edm::ESHandle<CaloSubdetectorGeometry> pG ;
iRecord.get( CaloTowerGeometry::producerTag() + std::string("_master"), pG ) ;

const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;

pGptr->getSummary( tvec, ivec, dvec, dins ) ;

CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, CaloTowerGeometry::dbString() ) ;
} else {
edm::ESHandle<PCaloGeometry> pG ;
iRecord.getRecord<typename CaloTowerGeometry::PGeometryRecord >().get( pG ) ;

tvec = pG->getTranslation() ;
dvec = pG->getDimension() ;
ivec = pG->getIndexes() ;
dins = pG->getDenseIndices();
}
//*********************************************************************************************

edm::ESHandle<CaloTowerTopology> caloTopology;
iRecord.getRecord<HcalRecNumberingRecord>().get( caloTopology );


CaloTowerGeometry* ctg=new CaloTowerGeometry( &*caloTopology );

const unsigned int nTrParm ( tvec.size()/ctg->numberOfCellsForCorners() ) ;

assert( dvec.size() == ctg->numberOfShapes() * CaloTowerGeometry::k_NumberOfParametersPerShape ) ;


PtrType ptr ( ctg ) ;

ptr->fillDefaultNamedParameters() ;

ptr->allocateCorners( ctg->numberOfCellsForCorners() ) ;

ptr->allocatePar( dvec.size() ,
CaloTowerGeometry::k_NumberOfParametersPerShape ) ;

for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
const unsigned int nPerShape ( ctg->numberOfParametersPerShape() ) ;
DimVec dims ;
dims.reserve( nPerShape ) ;

const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;

DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;

for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
dims.push_back( *dsrc ) ;
++dsrc ;
}

const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
ptr->parMgr(),
ptr->parVecVec() ));


const DetId id ( caloTopology->detIdFromDenseIndex(dins[i]) ) ;

const unsigned int iGlob ( 0 == globalPtr ? 0 :
ctg->alignmentTransformIndexGlobal( id ) ) ;

assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;

const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;

assert( 0 == gt || iGlob == ctg->alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;

const unsigned int iLoc ( 0 == alignPtr ? 0 :
ctg->alignmentTransformIndexLocal( id ) ) ;

assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;

const AlignTransform* at ( 0 == alignPtr ? 0 :
&alignPtr->m_align[ iLoc ] ) ;

assert( 0 == at || ( ctg->alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;

const CaloGenericDetId gId ( id ) ;

Pt3D lRef ;
Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
ctg->localCorners( lc, &dims.front(), dins[i], lRef ) ;

const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
const Pt3D lCor ( lc[0] ) ;

//----------------------------------- create transform from 6 numbers ---
const unsigned int jj ( i*nTrParm ) ;
Tr3D tr ;
const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
const ROOT::Math::EulerAngles ea (
6==nTrParm ?
ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
ROOT::Math::EulerAngles() ) ;
const ROOT::Math::Transform3D rt ( ea, tl ) ;
double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
yx, yy, yz,
zx, zy, zz ),
CLHEP::Hep3Vector(dx,dy,dz) );

// now prepend alignment(s) for final transform
const Tr3D atr ( 0 == at ? tr :
( 0 == gt ? at->transform()*tr :
at->transform()*gt->transform()*tr ) ) ;
//--------------------------------- done making transform ---------------

const Pt3D gRef ( atr*lRef ) ;
const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
const Pt3D gBck ( atr*lBck ) ;
const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
const Pt3D gCor ( atr*lCor ) ;
const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;

assert( caloTopology->denseIndex(id) == dins[i] );

ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
}

ptr->initializeParms() ; // initializations; must happen after cells filled

return ptr ;
}

template class CaloGeometryDBEP< EcalBarrelGeometry , CaloGeometryDBWriter> ;
template class CaloGeometryDBEP< EcalEndcapGeometry , CaloGeometryDBWriter> ;
Expand Down
27 changes: 21 additions & 6 deletions DataFormats/CaloTowers/interface/CaloTower.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class CaloTower : public reco::LeafCandidate {
void addConstituents( const std::vector<DetId>& ids );
void setEcalTime(int t) { ecalTime_ = t; };
void setHcalTime(int t) { hcalTime_ = t; };
void setHcalLimits(int firstHB, int lastHB,
int firstHE, int lastHE,
int firstHF, int lastHF,
int firstHO, int lastHO) {
firstHBRing_ = firstHB; lastHBRing_ = lastHB;
firstHERing_ = firstHE; lastHERing_ = lastHE;
firstHFRing_ = firstHF; lastHFRing_ = lastHF;
firstHORing_ = firstHO; lastHORing_ = lastHO;
}

// set CaloTower status based on the number of
// bad/recovered/problematic cells in ECAL and HCAL
Expand All @@ -78,12 +87,12 @@ class CaloTower : public reco::LeafCandidate {
// energy in HO ("outerEnergy")is not included in "hadEnergy"
double emEnergy() const { return emE_ ; }
double hadEnergy() const { return hadE_ ; }
double outerEnergy() const { return (id_.ietaAbs()<16)? outerE_ : 0.0; }
double outerEnergy() const { return (id_.ietaAbs()<=lastHORing_)? outerE_ : 0.0; }

// transverse energies wrt to vtx (0,0,0)
double emEt() const { return emE_ * sin( theta() ); }
double hadEt() const { return hadE_ * sin( theta() ); }
double outerEt() const { return (id_.ietaAbs()<16)? outerE_ * sin( theta() ) : 0.0; }
double outerEt() const { return (id_.ietaAbs()<=lastHORing_)? outerE_ * sin( theta() ) : 0.0; }


// preserve the inherited default accessors where applicable
Expand All @@ -102,7 +111,7 @@ class CaloTower : public reco::LeafCandidate {

double emEt(double vtxZ) const { return emE_ * sin(p4(vtxZ).theta()); }
double hadEt(double vtxZ) const { return hadE_ * sin(p4(vtxZ).theta()); }
double outerEt(double vtxZ) const { return (id_.ietaAbs()<16)? outerE_ * sin(p4(vtxZ).theta()) : 0.0; }
double outerEt(double vtxZ) const { return (id_.ietaAbs()<=lastHORing_)? outerE_ * sin(p4(vtxZ).theta()) : 0.0; }

// recalculated wrt vertex provided as 3D point

Expand All @@ -112,7 +121,7 @@ class CaloTower : public reco::LeafCandidate {

double emEt(Point v) const { return emE_ * sin(p4(v).theta()); }
double hadEt(Point v) const { return hadE_ * sin(p4(v).theta()); }
double outerEt(Point v) const { return (id_.ietaAbs()<16)? outerE_ * sin(p4(v).theta()) : 0.0; }
double outerEt(Point v) const { return (id_.ietaAbs()<=lastHORing_)? outerE_ * sin(p4(v).theta()) : 0.0; }

double hottestCellE() const { return hottestCellE_; }

Expand All @@ -133,8 +142,8 @@ class CaloTower : public reco::LeafCandidate {
int hadLv11() const { return hadLvl1_; }

// energy contained in depths>1 in the HE for 18<|iEta|<29
double hadEnergyHeOuterLayer() const { return (id_.ietaAbs()<18 || id_.ietaAbs()>29)? 0 : outerE_; }
double hadEnergyHeInnerLayer() const { return (id_.ietaAbs()<18 || id_.ietaAbs()>29)? 0 : hadE_ - outerE_; }
double hadEnergyHeOuterLayer() const { return (id_.ietaAbs()<=firstHERing_ || id_.ietaAbs()>lastHERing_)? 0 : outerE_; }
double hadEnergyHeInnerLayer() const { return (id_.ietaAbs()<=firstHERing_ || id_.ietaAbs()>lastHERing_)? 0 : hadE_ - outerE_; }

// energy in the tower by HCAL subdetector
// This is trivial except for tower 16
Expand Down Expand Up @@ -183,6 +192,12 @@ class CaloTower : public reco::LeafCandidate {
GlobalPoint emPosition_;
GlobalPoint hadPosition_;

//hcal limits in CT continuous ieta (from CaloTowerTopology)
int firstHBRing_, lastHBRing_;
int firstHERing_, lastHERing_;
int firstHFRing_, lastHFRing_;
int firstHORing_, lastHORing_;

// time
int ecalTime_;
int hcalTime_;
Expand Down
27 changes: 0 additions & 27 deletions DataFormats/CaloTowers/interface/CaloTowerDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,6 @@ class CaloTowerDetId : public DetId {

static const int SubdetId = 1;

static bool validDetId( int ie , int ip ) ;

uint32_t denseIndex() const ;

static CaloTowerDetId detIdFromDenseIndex( uint32_t din ) ;

static bool validDenseIndex( uint32_t din ) { return ( din < kSizeForDenseIndexing ) ; }

enum { kMaxIEta = 41 ,
kMaxIPhi = 72 ,
kBarNPhi = kMaxIPhi ,
kEndNPhi = kMaxIPhi/2 ,
kForNPhi = kMaxIPhi/4 ,
kBarIEta = 20 ,
kEndIEta = 39 ,
kForIEta = kMaxIEta ,
kBarNEta = kBarIEta ,
kEndNEta = kEndIEta - kBarNEta ,
kForNEta = kForIEta - kEndIEta ,
kBarNTot = kBarNPhi*kBarNEta ,
kEndNTot = kEndNPhi*kEndNEta ,
kForNTot = kForNPhi*kForNEta ,
kAllNTot = kBarNTot + kEndNTot + kForNTot ,
kNIndex = 2*kAllNTot } ;

enum { kSizeForDenseIndexing = kNIndex } ;

};

std::ostream& operator<<(std::ostream&, const CaloTowerDetId& id);
Expand Down
26 changes: 13 additions & 13 deletions DataFormats/CaloTowers/src/CaloTower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ math::PtEtaPhiMLorentzVector CaloTower::hadP4(double vtxZ) const {
// note: for now we use the same position for HO as for the other detectors

double hcalTot;
if (abs(ieta())<16) hcalTot = (energy() - emE_);
if (abs(ieta())<=lastHORing_) hcalTot = (energy() - emE_);
else hcalTot = hadE_;

if (hcalTot>0) {
Expand Down Expand Up @@ -78,7 +78,7 @@ math::PtEtaPhiMLorentzVector CaloTower::hadP4(Point v) const {
// note: for now we use the same position for HO as for the other detectors

double hcalTot;
if (abs(ieta())<16) hcalTot = (energy() - emE_);
if (abs(ieta())<lastHORing_) hcalTot = (energy() - emE_);
else hcalTot = hadE_;

if (hcalTot>0) {
Expand All @@ -104,7 +104,7 @@ math::PtEtaPhiMLorentzVector CaloTower::emP4(Point v) const {

math::PtEtaPhiMLorentzVector CaloTower::p4(double vtxZ) const {

if (abs(ieta())<=29) {
if (abs(ieta())<=lastHERing_) {
return (emP4(vtxZ)+hadP4(vtxZ));
}
// em and had energy in HF are defined in a special way
Expand All @@ -117,7 +117,7 @@ math::PtEtaPhiMLorentzVector CaloTower::p4(double vtxZ) const {

math::PtEtaPhiMLorentzVector CaloTower::p4(Point v) const {

if (abs(ieta())<=29) {
if (abs(ieta())<=lastHERing_) {
return emP4(v)+hadP4(v);
}
// em and had energy in HF are defined in a special way
Expand All @@ -131,7 +131,7 @@ math::PtEtaPhiMLorentzVector CaloTower::p4(Point v) const {

math::PtEtaPhiMLorentzVector CaloTower::p4_HO(Point v) const {

if (ietaAbs()>15 || outerE_<0) return math::PtEtaPhiMLorentzVector(0,0,0,0);
if (ietaAbs()>lastHORing_ || outerE_<0) return math::PtEtaPhiMLorentzVector(0,0,0,0);

GlobalPoint p(v.x(), v.y(), v.z());
math::XYZVector dir = math::XYZVector(hadPosition_ - p);
Expand All @@ -145,7 +145,7 @@ math::PtEtaPhiMLorentzVector CaloTower::p4_HO(double vtxZ) const {

math::PtEtaPhiMLorentzVector CaloTower::p4_HO() const {

if (ietaAbs()>15 || outerE_<0) return math::PtEtaPhiMLorentzVector(0.0,0.0,0.0,0.0);
if (ietaAbs()>lastHORing_ || outerE_<0) return math::PtEtaPhiMLorentzVector(0.0,0.0,0.0,0.0);
return math::PtEtaPhiMLorentzVector(outerE_ * sin(hadPosition_.theta()), hadPosition_.eta(), hadPosition_.phi(), 0.0);
}

Expand All @@ -156,7 +156,7 @@ void CaloTower::addConstituents( const std::vector<DetId>& ids ) {
}

int CaloTower::numCrystals() const {
if (id_.ietaAbs()>29) return 0;
if (id_.ietaAbs()>lastHERing_) return 0;

int nC = 0;
std::vector<DetId>::const_iterator it = constituents_.begin();
Expand Down Expand Up @@ -196,19 +196,19 @@ void CaloTower::setCaloTowerStatus(unsigned int numBadHcalChan,unsigned int numB
// needed by JetMET cleanup in AOD.

double CaloTower::energyInHB() const {
if (id_.ietaAbs()<16) return hadE_;
else if (id_.ietaAbs()==16) return hadE_-outerE_;
if (id_.ietaAbs()<lastHBRing_) return hadE_;
else if (id_.ietaAbs()==lastHBRing_) return hadE_-outerE_;
else return 0.0;
}

double CaloTower::energyInHE() const {
if (id_.ietaAbs()>16 && id_.ietaAbs()<30) return hadE_;
else if (id_.ietaAbs()==16) return outerE_;
if (id_.ietaAbs()>firstHERing_ && id_.ietaAbs()<=lastHERing_) return hadE_;
else if (id_.ietaAbs()==firstHERing_) return outerE_;
else return 0.0;
}

double CaloTower::energyInHF() const {
if (id_.ietaAbs()>29) return energy();
if (id_.ietaAbs()>=firstHFRing_) return energy();
else return 0.0;
}

Expand All @@ -218,7 +218,7 @@ double CaloTower::energyInHF() const {
// when HO was not used

double CaloTower::energyInHO() const {
if (id_.ietaAbs()>15) return 0.0;
if (id_.ietaAbs()>lastHORing_) return 0.0;
else return (energy() - hadE_ -emE_);
}

Expand Down
Loading

0 comments on commit a558508

Please sign in to comment.