Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from ianna/calotowers-and-hcal-geometry-test
CaloTowers and Hcal geometry test
- Loading branch information
Showing
5 changed files
with
247 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
219 changes: 219 additions & 0 deletions
219
Geometry/HcalTowerAlgo/test/CaloTowerGeometryAnalyzer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
#include "FWCore/Framework/interface/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
|
||
#include "Geometry/CaloGeometry/interface/CaloGeometry.h" | ||
#include "Geometry/Records/interface/CaloGeometryRecord.h" | ||
#include "Geometry/CaloGeometry/interface/CaloGenericDetId.h" | ||
#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" | ||
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" | ||
#include "DataFormats/HcalDetId/interface/HcalDetId.h" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
namespace | ||
{ | ||
bool | ||
AreSame( double a, double b, double epsilon ) | ||
{ | ||
return std::fabs( a - b ) < epsilon; | ||
} | ||
|
||
double | ||
round( double n, int digits ) | ||
{ | ||
double mult = pow( 10, digits ); | ||
return floor( n * mult ) / mult; | ||
} | ||
|
||
std::map<int, std::string> hcalmapping = {{1, "HB"}, | ||
{2, "HE"}, | ||
{3, "HO"}, | ||
{4, "HF"}, | ||
{5, "HT"}, | ||
{6, "ZDC"}, | ||
{0, "Empty"} | ||
}; | ||
} | ||
|
||
class CaloTowerGeometryAnalyzer : public edm::EDAnalyzer | ||
{ | ||
public: | ||
explicit CaloTowerGeometryAnalyzer( const edm::ParameterSet& ); | ||
~CaloTowerGeometryAnalyzer( void ); | ||
|
||
virtual void analyze( const edm::Event&, const edm::EventSetup& ); | ||
|
||
private: | ||
std::string m_fname; | ||
double m_epsilon; | ||
}; | ||
|
||
CaloTowerGeometryAnalyzer::CaloTowerGeometryAnalyzer( const edm::ParameterSet& iConfig ) | ||
: m_fname( "CaloTower.cells" ), | ||
m_epsilon( 0.004 ) | ||
{ | ||
m_fname = iConfig.getParameter<std::string>( "FileName" ); | ||
m_epsilon = iConfig.getParameter<double>( "Epsilon" ); | ||
} | ||
|
||
CaloTowerGeometryAnalyzer::~CaloTowerGeometryAnalyzer( void ) | ||
{ | ||
} | ||
|
||
void | ||
CaloTowerGeometryAnalyzer::analyze( const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup ) | ||
{ | ||
std::fstream fAll( std::string( m_fname + ".all" ).c_str(), std::ios_base::out ); | ||
std::fstream f( std::string( m_fname + ".diff" ).c_str(), std::ios_base::out ); | ||
|
||
edm::ESHandle<CaloGeometry> caloGeom; | ||
iSetup.get<CaloGeometryRecord>().get( caloGeom ); | ||
|
||
const std::vector<DetId>& dha( caloGeom->getSubdetectorGeometry( DetId::Hcal, 1 )->getValidDetIds()); | ||
|
||
const std::vector< DetId >& ids (caloGeom->getValidDetIds()); | ||
|
||
fAll << std::setw( 4 ) << "iEta" | ||
<< std::setw( 4 ) << "iPhi" | ||
<< std::setw( 4 ) << "Z" | ||
<< std::setw( 10 ) << "Sub:Depth" | ||
<< std::setw( 6 ) << "Eta" | ||
<< std::setw( 13 ) << "Phi" | ||
<< std::setw( 18 ) << "Corners in Eta\n"; | ||
|
||
f << std::setw( 4 ) << "iEta" | ||
<< std::setw( 4 ) << "iPhi" | ||
<< std::setw( 4 ) << "Z" | ||
<< std::setw( 10 ) << "Sub:Depth" | ||
<< std::setw( 6 ) << "Eta" | ||
<< std::setw( 13 ) << "Phi" | ||
<< std::setw( 18 ) << "Corners in Eta\n"; | ||
|
||
for( std::vector<DetId>::const_iterator i( ids.begin()), iEnd( ids.end()) ; i != iEnd; ++i ) | ||
{ | ||
const CaloGenericDetId cgid( *i ); | ||
if( cgid.isCaloTower()) | ||
{ | ||
const CaloTowerDetId cid( *i ); | ||
const int ie( cid.ieta()); | ||
const int ip( cid.iphi()); | ||
const int iz( cid.zside()); | ||
|
||
fAll << std::setw( 4 ) << ie | ||
<< std::setw( 4 ) << ip | ||
<< std::setw( 4 ) << iz | ||
<< std::setw( 6 ) << "-"; | ||
|
||
const CaloCellGeometry *cell = caloGeom->getGeometry( *i ); | ||
assert( cell ); | ||
const GlobalPoint& pos = cell->getPosition(); | ||
double eta = pos.eta(); | ||
double phi = pos.phi(); | ||
fAll << std::setw( 10 ) << eta << std::setw( 13 ) << phi; | ||
|
||
const CaloCellGeometry::CornersVec& corners(cell->getCorners()); | ||
for( unsigned int i( 0 ); i != corners.size() ; ++i ) | ||
{ | ||
const GlobalPoint& cpos = corners[ i ]; | ||
double ceta = cpos.eta(); | ||
|
||
fAll << std::setw( 13 ) << ceta; | ||
} | ||
fAll << "\n"; | ||
|
||
for( std::vector<DetId>::const_iterator ii( dha.begin()), iiEnd( dha.end()); ii != iiEnd; ++ii ) | ||
{ | ||
const HcalDetId hid( *ii ); | ||
const int iie( hid.ieta()); | ||
const int iip( hid.iphi()); | ||
const int iiz( hid.zside()); | ||
const int iid( hid.depth()); | ||
|
||
if( ie == iie && ip == iip && iz == iiz ) | ||
{ | ||
fAll << std::setw( 4 ) << iie | ||
<< std::setw( 4 ) << iip | ||
<< std::setw( 4 ) << iiz; | ||
|
||
std::map<int, std::string>::const_iterator iter = hcalmapping.find( hid.subdet()); | ||
if( iter != hcalmapping.end()) | ||
{ | ||
fAll << std::setw( 4 ) << iter->second.c_str() << ":" << iid; | ||
} | ||
|
||
const CaloCellGeometry *hcell = caloGeom->getGeometry( *ii ); | ||
assert( hcell ); | ||
const GlobalPoint& hpos = hcell->getPosition(); | ||
double heta = hpos.eta(); | ||
double hphi = hpos.phi(); | ||
|
||
fAll << std::setw( 10 ) << heta << std::setw( 13 ) << hphi; | ||
|
||
const CaloCellGeometry::CornersVec& hcorners(hcell->getCorners()); | ||
for( unsigned int i( 0 ) ; i != hcorners.size() ; ++i ) | ||
{ | ||
const GlobalPoint& hcpos = hcorners[ i ]; | ||
double hceta = hcpos.eta(); | ||
|
||
fAll << std::setw( 13 ) << hceta; | ||
} | ||
|
||
if( !AreSame( eta, heta, m_epsilon )) | ||
{ | ||
|
||
fAll << "*DIFFER in Eta*"; | ||
|
||
f << std::setw( 4 ) << ie | ||
<< std::setw( 4 ) << ip | ||
<< std::setw( 4 ) << iz | ||
<< std::setw( 6 ) << "-"; | ||
|
||
f << std::setw( 10 ) << eta << std::setw( 13 ) << phi; | ||
|
||
for( unsigned int i( 0 ) ; i != corners.size() ; ++i ) | ||
{ | ||
const GlobalPoint& cpos = corners[ i ]; | ||
double ceta = cpos.eta(); | ||
|
||
f << std::setw( 9 ) << ceta; | ||
} | ||
f << "\n"; | ||
|
||
f << std::setw( 4 ) << iie | ||
<< std::setw( 4 ) << iip | ||
<< std::setw( 4 ) << iiz; | ||
|
||
if( iter != hcalmapping.end()) | ||
{ | ||
f << std::setw( 4 ) << iter->second.c_str() << ":" << iid; | ||
} | ||
|
||
f << std::setw( 10 ) << heta << std::setw( 13 ) << hphi; | ||
|
||
for( unsigned int i( 0 ) ; i != hcorners.size() ; ++i ) | ||
{ | ||
const GlobalPoint& hcpos = hcorners[ i ]; | ||
double hceta = hcpos.eta(); | ||
|
||
f << std::setw( 9 ) << hceta; | ||
} | ||
f << "\n\n"; | ||
} | ||
|
||
if( !AreSame( phi, hphi, m_epsilon )) | ||
fAll << " *DIFFER in Phi*"; | ||
fAll << "\n"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
fAll.close(); | ||
f.close(); | ||
} | ||
|
||
DEFINE_FWK_MODULE(CaloTowerGeometryAnalyzer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Geometry/HcalTowerAlgo/test/runCaloTowerGeometryAnalyzer_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
from Geometry.HcalEventSetup.HcalRelabel_cfi import HcalReLabel | ||
|
||
process = cms.Process("CaloTowerGeometryTest") | ||
|
||
process.load("Configuration.StandardSequences.GeometryDB_cff") | ||
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") | ||
from Configuration.AlCa.autoCond import autoCond | ||
process.GlobalTag.globaltag = autoCond['mc'] | ||
|
||
process.source = cms.Source("EmptySource") | ||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(1) | ||
) | ||
|
||
process.ctga = cms.EDAnalyzer("CaloTowerGeometryAnalyzer", | ||
Epsilon = cms.double(0.004), | ||
FileName = cms.string("CaloTower.cells")) | ||
|
||
|
||
process.Timing = cms.Service("Timing") | ||
process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck") | ||
|
||
process.p1 = cms.Path(process.ctga) |