Skip to content

Commit

Permalink
Merge pull request #677 from ianna/calotowers-and-hcal-geometry-test
Browse files Browse the repository at this point in the history
CaloTowers and Hcal geometry test
  • Loading branch information
nclopezo committed Sep 4, 2013
2 parents a561d0b + b80f001 commit 182a6ff
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 4 deletions.
1 change: 0 additions & 1 deletion Geometry/HcalTowerAlgo/interface/CaloTowerGeometry.h
Expand Up @@ -4,7 +4,6 @@
#include "Geometry/CaloGeometry/interface/IdealObliquePrism.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
//#include "CondFormats/AlignmentRecord/interface/CaloTowerAlignmentRcd.h"
#include "Geometry/Records/interface/CaloTowerGeometryRecord.h"

/** \class CaloTowerGeometry
Expand Down
3 changes: 3 additions & 0 deletions Geometry/HcalTowerAlgo/test/BuildFile.xml
Expand Up @@ -7,6 +7,9 @@
<use name="Geometry/Records"/>
<bin file="HcalGeometryTest.cpp">
</bin>
<library file="CaloTowerGeometryAnalyzer.cc" name="testCaloTowerGeometryESProducer">
<flags EDM_PLUGIN="1"/>
</library>
<library file="HcalGeometryAnalyzer.cc" name="testHcalGeometryESProducer">
<flags EDM_PLUGIN="1"/>
</library>
Expand Down
219 changes: 219 additions & 0 deletions Geometry/HcalTowerAlgo/test/CaloTowerGeometryAnalyzer.cc
@@ -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);
4 changes: 1 addition & 3 deletions Geometry/HcalTowerAlgo/test/HcalGeometryAnalyzer.cc
Expand Up @@ -18,13 +18,11 @@ class HcalGeometryAnalyzer : public edm::EDAnalyzer
virtual void analyze( const edm::Event&, const edm::EventSetup& );

private:
const HcalFlexiHardcodeGeometryLoader& m_loader;
std::string m_label;
};

HcalGeometryAnalyzer::HcalGeometryAnalyzer( const edm::ParameterSet& iConfig )
: m_loader( iConfig ),
m_label("_master")
: m_label("_master")
{
m_label = iConfig.getParameter<std::string>( "HCALGeometryLabel" );
}
Expand Down
24 changes: 24 additions & 0 deletions Geometry/HcalTowerAlgo/test/runCaloTowerGeometryAnalyzer_cfg.py
@@ -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)

0 comments on commit 182a6ff

Please sign in to comment.