Skip to content

Commit

Permalink
Merge pull request #8003 from lgray/topic_fix_pandora_pointers
Browse files Browse the repository at this point in the history
Remove static pointer holding Pandora
  • Loading branch information
cmsbuild committed Mar 2, 2015
2 parents b3b8dd8 + c832d38 commit bcf9923
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 46 deletions.
2 changes: 2 additions & 0 deletions RecoParticleFlow/PandoraTranslator/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<use name="pandora"/>
<use name="FWCore/Utilities"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="DataFormats/ForwardDetId"/>

<export>
<lib name="1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file RecoParticleFlow/PandoraTranslator/interface/CMSGlobalHadronCompensationPlugin.h"
*
* @brief Header file for hit-based shower compensation
*
* $Log: $
*/
#ifndef CMS_GLOBAL_HADRON_COMPENSATION_PLUGINS_H
#define CMS_GLOBAL_HADRON_COMPENSATION_PLUGINS_H 1

#include "Plugins/EnergyCorrectionsPlugin.h"

namespace cms_content
{

/**
* @brief GlobalHadronCompensation class. Correct cluster energy by looking at number of hits above 10 MIPs compared to the average energy density in HEF in MIPs
*/
class GlobalHadronCompensation : public pandora::EnergyCorrectionPlugin
{
public:
/**
* @brief Default constructor
*/
GlobalHadronCompensation();

pandora::StatusCode MakeEnergyCorrections(const pandora::Cluster *const pCluster, float &correctedEnergy) const;

private:
/**
* @brief Get the sum of the hadronic energies of all calo hits in a specified layer of an ordered calo hit list
*
* @param orderedCaloHitList the ordered calo hit list
* @param pseudoLayer the specified pseudolayer
*/
float GetHadronicEnergyInLayer(const pandora::OrderedCaloHitList &orderedCaloHitList, const unsigned int pseudoLayer) const;

pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle);

float m_nMIPsCut; ///< Min calo energy in MIPs to consider a hit for correction the

};

} //cms_content

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "LCContent.h"
#include "LCContentFast.h"
#include "RecoParticleFlow/PandoraTranslator/interface/CMSTemplateAlgorithm.h"
#include "RecoParticleFlow/PandoraTranslator/interface/CMSGlobalHadronCompensationPlugin.h"
//#include "PandoraMonitoringApi.h"

#include "FWCore/Framework/interface/ESHandle.h"
Expand Down Expand Up @@ -87,14 +88,16 @@ namespace cms_content {
LC_ENERGY_CORRECTION_LIST(PANDORA_REGISTER_ENERGY_CORRECTION);
LC_PARTICLE_ID_LIST(PANDORA_REGISTER_PARTICLE_ID);

PANDORA_REGISTER_ENERGY_CORRECTION("CMSGlobalHadronCompensation", pandora::HADRONIC, cms_content::GlobalHadronCompensation);

PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetPseudoLayerPlugin(pandora, new cms_content::CMSPseudoLayerPlugin));
PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetShowerProfilePlugin(pandora, new lc_content::LCShowerProfilePlugin));

return pandora::STATUS_CODE_SUCCESS;
}
}

pandora::Pandora * PandoraCMSPFCandProducer::m_pPandora = NULL;
//pandora::Pandora * PandoraCMSPFCandProducer::m_pPandora = NULL;
//
// constructors and destructor
//
Expand All @@ -113,9 +116,6 @@ PandoraCMSPFCandProducer::PandoraCMSPFCandProducer(const edm::ParameterSet& iCon
// produces<reco::PFCandidateElectronExtraCollection>(electronExtraOutputCol_);
// produces<reco::PFCandidatePhotonExtraCollection>(photonExtraOutputCol_);

//now do what ever initialization is needed
m_pPandora = new pandora::Pandora();

inputTagHGCrechit_ = iConfig.getParameter<InputTag>("HGCrechitCollection");
inputTagGeneralTracks_ = iConfig.getParameter<InputTag>("generaltracks");
inputTagtPRecoTrackAsssociation_ = iConfig.getParameter<InputTag>("tPRecoTrackAsssociation");
Expand All @@ -133,19 +133,6 @@ PandoraCMSPFCandProducer::PandoraCMSPFCandProducer(const edm::ParameterSet& iCon
stm = new steerManager(m_energyWeightingFilename.fullPath().c_str());

speedoflight = (CLHEP::c_light/CLHEP::cm)/CLHEP::ns;

// NS // SHOWER PROFILE CALCULATOR

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, LCContent::RegisterAlgorithms(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, LCContentFast::RegisterAlgorithms(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, cms_content::RegisterBasicPlugins(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetBFieldPlugin(*m_pPandora, new CMSBFieldPlugin()));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::RegisterAlgorithmFactory(*m_pPandora, "Template", new CMSTemplateAlgorithm::Factory));

}

PandoraCMSPFCandProducer::~PandoraCMSPFCandProducer()
Expand Down Expand Up @@ -1841,14 +1828,40 @@ PandoraCMSPFCandProducer::beginLuminosityBlock(edm::LuminosityBlock const& iLumi
//get the magnetic field
iSetup.get<IdealMagneticFieldRecord>().get(magneticField);

//prepare geom at the beginning of each lumi block
prepareGeometry() ;
// reset the pandora instance
m_pPandora.reset( new pandora::Pandora() );

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, LCContent::RegisterAlgorithms(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, LCContentFast::RegisterAlgorithms(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, cms_content::RegisterBasicPlugins(*m_pPandora));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetBFieldPlugin(*m_pPandora, new CMSBFieldPlugin()));

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::RegisterAlgorithmFactory(*m_pPandora, "Template", new CMSTemplateAlgorithm::Factory));

// reset all the calibration info since it depends on the geometry
m_calibEE = CalibHGC(ForwardSubdetector::HGCEE,"EE",debugPrint);
m_calibHEF = CalibHGC(ForwardSubdetector::HGCHEF,"HEF",debugPrint);
m_calibHEB = CalibHGC(ForwardSubdetector::HGCHEB,"HEB",debugPrint);
// read in calibration parameters
m_calibEE.m_energyCorrMethod = m_calibHEF.m_energyCorrMethod = m_calibHEB.m_energyCorrMethod = m_energyCorrMethod;
m_calibEE.m_stm = m_calibHEF.m_stm = m_calibHEB.m_stm = stm;
initPandoraCalibrParameters();
readCalibrParameterFile();
if (m_energyCorrMethod == "WEIGHTING")
readEnergyWeight();
calibInitialized = false;

//rebuild pandora
// prepare the geometry
prepareGeometry();

//rebuild pandora
if( pandora::STATUS_CODE_SUCCESS != PandoraApi::ReadSettings(*m_pPandora, m_pandoraSettingsXmlFile.fullPath()) ) {
throw cms::Exception("InvalidXMLConfig")
<< "Unable to parse pandora configuration file";
}
}
//PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::ReadSettings(*m_pPandora, m_pandoraSettingsXmlFile.fullPath()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
// -*- C++ -*-
//
// Package: PFCal/runPandora
// Class: runPandora
//
/**\class runPandora runPandora.cc PFCal/runPandora/plugins/runPandora.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Andreas Psallidas
// Created: Mon, 11 Nov 2013 15:11:14 GMT
//
//


// system include files
#include <memory>
#include <vector>
Expand Down Expand Up @@ -229,7 +210,7 @@ class PandoraCMSPFCandProducer : public edm::EDProducer {

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

static pandora::Pandora *m_pPandora;
std::unique_ptr<pandora::Pandora> m_pPandora;

void prepareTrack(edm::Event& iEvent);
void prepareHits(edm::Event& iEvent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @file RecoParticleFlow/PandoraTranslator/src/CMSGlobalHadronCompensationPlugin.cc
*
* @brief Implementation of the Global Hadronic Energy Compensation strategy
*
* $Log: $
*/

#include "Pandora/AlgorithmHeaders.h"

#include "LCHelpers/ReclusterHelper.h"

#include "RecoParticleFlow/PandoraTranslator/interface/CMSGlobalHadronCompensationPlugin.h"

#include <DataFormats/ForwardDetId/interface/ForwardSubdetector.h>
#include <DataFormats/ParticleFlowReco/interface/PFRecHit.h>

using namespace pandora;
using namespace cms_content;

//------------------------------------------------------------------------------------------------------------------------------------------

GlobalHadronCompensation::GlobalHadronCompensation() :
m_nMIPsCut(10.0f)
{
}

//------------------------------------------------------------------------------------------------------------------------------------------

StatusCode GlobalHadronCompensation::MakeEnergyCorrections(const Cluster *const pCluster, float &correctedHadronicEnergy) const
{

//const unsigned int firstPseudoLayer(this->GetPandora().GetPlugins()->GetPseudoLayerPlugin()->GetPseudoLayerAtIp());

const OrderedCaloHitList& orderedCaloHitList = pCluster->GetOrderedCaloHitList();

OrderedCaloHitList::const_iterator layer = orderedCaloHitList.begin();
OrderedCaloHitList::const_iterator hits_end = orderedCaloHitList.end();

float en_avg(0.f), nHits(0.f);

for( ; layer != hits_end; ++ layer ) {
const CaloHitList& hits_in_layer = *(layer->second);
for( const auto& hit : hits_in_layer ) {
// hack so that we can know if we are in the HEF or not (go back to cmssw det id)
const void* void_hit_ptr = hit->GetParentCaloHitAddress();
const reco::PFRecHit* original_hit_ptr = static_cast<const reco::PFRecHit*>(void_hit_ptr);
const uint32_t rawid = original_hit_ptr->detId();
const int subDetId = (rawid>>25)&0x7;
if( subDetId != ForwardSubdetector::HGCHEF ) continue;

const float en_mip = hit->GetMipEquivalentEnergy();
en_avg += en_mip;
nHits += 1.f;
}
}

if( nHits == 0.f ) {
correctedHadronicEnergy *= 1.f;
return STATUS_CODE_SUCCESS;
}

en_avg /= nHits;

float nHits_avg(0.f), nHits_elim(0.f);
for( ; layer != hits_end; ++ layer ) {
const CaloHitList& hits_in_layer = *(layer->second);
for( const auto& hit : hits_in_layer ) {
// hack so that we can know if we are in the HEF or not (go back to cmssw det id)
const void* void_hit_ptr = hit->GetParentCaloHitAddress();
const reco::PFRecHit* original_hit_ptr = static_cast<const reco::PFRecHit*>(void_hit_ptr);
const uint32_t rawid = original_hit_ptr->detId();
const int subDetId = (rawid>>25)&0x7;
if( subDetId != ForwardSubdetector::HGCHEF ) continue;

const float en_mip = hit->GetMipEquivalentEnergy();
if( en_mip > en_avg ) {
nHits_avg += 1.f;
} else {
nHits_elim += 1.f;
}
}
}

correctedHadronicEnergy *= (nHits-nHits_elim)/(nHits-nHits_avg);

return STATUS_CODE_SUCCESS;
}

//------------------------------------------------------------------------------------------------------------------------------------------

float GlobalHadronCompensation::GetHadronicEnergyInLayer(const OrderedCaloHitList &orderedCaloHitList, const unsigned int pseudoLayer) const
{
OrderedCaloHitList::const_iterator iter = orderedCaloHitList.find(pseudoLayer);

float hadronicEnergy(0.f);

if (iter != orderedCaloHitList.end())
{
for (CaloHitList::const_iterator hitIter = iter->second->begin(), hitIterEnd = iter->second->end(); hitIter != hitIterEnd; ++hitIter)
{
hadronicEnergy += (*hitIter)->GetHadronicEnergy();
}
}

return hadronicEnergy;
}

//------------------------------------------------------------------------------------------------------------------------------------------

StatusCode GlobalHadronCompensation::ReadSettings(const TiXmlHandle xmlHandle)
{
PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"MipEnergyThreshold", m_nMIPsCut));

return STATUS_CODE_SUCCESS;
}
11 changes: 6 additions & 5 deletions RecoParticleFlow/PandoraTranslator/test/runPandora_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#process.EveService = cms.Service("EveService")


from particleFileLists import Pho100
#from particleFileLists import Pho100

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
Expand All @@ -65,7 +65,8 @@
# Pho100 # all photon files, 100 GeV
#'file:/tmp/lgray/step3.root'
#'file:simple_jets.root'
'file:/tmp/lgray/6EC19337-A7AE-E411-999E-0025905A613C.root'
#'file:/tmp/lgray/6EC19337-A7AE-E411-999E-0025905A613C.root'
'/store/cmst3/group/hgcal/CMSSW/Single130-FixE_CMSSW_6_2_0_SLHC23_patch2/Events_130_20_1.root'
)
)

Expand All @@ -78,7 +79,7 @@
process.load("Configuration.StandardSequences.Reconstruction_cff")
process.load("RecoParticleFlow/PFClusterProducer/particleFlowRecHitHGCEE_cfi")

process.load('HGCal/PandoraTranslator/HGCALTrackCollection_cfi')
process.load('RecoParticleFlow/PandoraTranslator/HGCalTrackCollection_cfi')

process.ak4PFJetsPandora = process.ak4PFJets.clone(src = cms.InputTag('pandorapfanew'))

Expand All @@ -87,9 +88,9 @@
# cd ${CMSSW_BASE}/src
# git clone https://github.com/sethzenz/HGCanalysis.git --branch hacked-interactions-filter UserCode/HGCanalysis
# cd Usercode ; scram b -j 9
process.load('HGCal.PandoraTranslator.runPandora_cfi')
process.load('RecoParticleFlow.PandoraTranslator.runPandora_cfi')

process.load("UserCode/HGCanalysis/hgcTrackerInteractionsFilter_cfi")
#process.load("UserCode/HGCanalysis/hgcTrackerInteractionsFilter_cfi")

process.FEVTDEBUGHLToutput = cms.OutputModule("PoolOutputModule",
splitLevel = cms.untracked.int32(0),
Expand Down

0 comments on commit bcf9923

Please sign in to comment.