Skip to content

Commit

Permalink
Fixed bad condition for time sample position in vector in HGCDigitize…
Browse files Browse the repository at this point in the history
…r.cc

Moved data members to unique_ptr which are instantiated only if the digitizer is in charge of a sub-detector
(previously they where all being instantiated even if only one would be used)
  • Loading branch information
pfs committed Jul 11, 2014
1 parent 5f9a722 commit ba6bb59
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
17 changes: 8 additions & 9 deletions SimCalorimetry/HGCSimProducers/interface/HGCDigitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ class HGCDigitizer
{
public:

explicit HGCDigitizer(const edm::ParameterSet& ps);
virtual ~HGCDigitizer();

HGCDigitizer(const edm::ParameterSet& ps);
~HGCDigitizer() { }

/**
@short handle SimHit accumulation
Expand All @@ -45,9 +44,9 @@ class HGCDigitizer

/**
*/
bool producesEEDigis() { return (hitCollection_.find("HitsEE")!=std::string::npos); }
bool producesHEfrontDigis() { return (hitCollection_.find("HitsHEfront")!=std::string::npos); }
bool producesHEbackDigis() { return (hitCollection_.find("HitsHEback")!=std::string::npos); }
bool producesEEDigis() { return (mySubDet_==ForwardSubdetector::HGCEE); }
bool producesHEfrontDigis() { return (mySubDet_==ForwardSubdetector::HGCHEF); }
bool producesHEbackDigis() { return (mySubDet_==ForwardSubdetector::HGCHEB); }
std::string digiCollection() { return digiCollection_; }

/**
Expand All @@ -74,9 +73,9 @@ private :
void resetSimHitDataAccumulator();

//digitizers
HGCEEDigitizer theHGCEEDigitizer_;
HGCHEbackDigitizer theHGCHEbackDigitizer_;
HGCHEfrontDigitizer theHGCHEfrontDigitizer_;
std::unique_ptr<HGCEEDigitizer> theHGCEEDigitizer_;
std::unique_ptr<HGCHEbackDigitizer> theHGCHEbackDigitizer_;
std::unique_ptr<HGCHEfrontDigitizer> theHGCHEfrontDigitizer_;

//subdetector id
ForwardSubdetector mySubDet_;
Expand Down
31 changes: 20 additions & 11 deletions SimCalorimetry/HGCSimProducers/plugins/HGCDigiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,57 @@
//
HGCDigiProducer::HGCDigiProducer(edm::ParameterSet const& pset, edm::EDProducer& mixMod) :
DigiAccumulatorMixMod(),
theDigitizer_(pset)
theDigitizer_(new HGCDigitizer(pset) )
{
if( theDigitizer_->producesEEDigis() )
mixMod.produces<HGCEEDigiCollection>(theDigitizer_->digiCollection());
if( theDigitizer_->producesHEfrontDigis() || theDigitizer_->producesHEbackDigis() )
mixMod.produces<HGCHEDigiCollection>(theDigitizer_->digiCollection());
}

//
HGCDigiProducer::~HGCDigiProducer()
{
if( theDigitizer_.producesEEDigis() )
mixMod.produces<HGCEEDigiCollection>(theDigitizer_.digiCollection());
if( theDigitizer_.producesHEfrontDigis() || theDigitizer_.producesHEbackDigis() )
mixMod.produces<HGCHEDigiCollection>(theDigitizer_.digiCollection());
}

//
void HGCDigiProducer::initializeEvent(edm::Event const& event, edm::EventSetup const& es)
{
theDigitizer_.initializeEvent(event, es);
theDigitizer_->initializeEvent(event, es);
}

//
void HGCDigiProducer::finalizeEvent(edm::Event& event, edm::EventSetup const& es)
{
theDigitizer_.finalizeEvent(event, es);
theDigitizer_->finalizeEvent(event, es);
}

//
void HGCDigiProducer::accumulate(edm::Event const& event, edm::EventSetup const& es)
{
theDigitizer_.accumulate(event, es);
theDigitizer_->accumulate(event, es);
}

void HGCDigiProducer::accumulate(PileUpEventPrincipal const& event, edm::EventSetup const& es)
{
theDigitizer_.accumulate(event, es);
theDigitizer_->accumulate(event, es);
}

//
void HGCDigiProducer::beginRun(edm::Run const&, edm::EventSetup const& es)
{
theDigitizer_.beginRun(es);
theDigitizer_->beginRun(es);
}

//
void HGCDigiProducer::endRun(edm::Run const&, edm::EventSetup const&)
{
theDigitizer_.endRun();
theDigitizer_->endRun();
}

//
//HGCDigiProducer::~HGCDigiProducer()
//{
//}

DEFINE_DIGI_ACCUMULATOR(HGCDigiProducer);
8 changes: 5 additions & 3 deletions SimCalorimetry/HGCSimProducers/plugins/HGCDigiProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "SimGeneral/MixingModule/interface/DigiAccumulatorMixMod.h"
#include "SimCalorimetry/HGCSimProducers/interface/HGCDigitizer.h"

#include <memory>

namespace edm {
class EDProducer;
class ParameterSet;
Expand All @@ -18,10 +20,10 @@ class HGCDigiProducer : public DigiAccumulatorMixMod {
virtual void accumulate(PileUpEventPrincipal const&, edm::EventSetup const&) override;
virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
~HGCDigiProducer();
private:


HGCDigitizer theDigitizer_;
//the digitizer
std::unique_ptr<HGCDigitizer> theDigitizer_;
};

#endif
42 changes: 23 additions & 19 deletions SimCalorimetry/HGCSimProducers/src/HGCDigitizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
HGCDigitizer::HGCDigitizer(const edm::ParameterSet& ps) :
checkValidDetIds_(true),
simHitAccumulator_( new HGCSimHitDataAccumulator ),
theHGCEEDigitizer_(ps),
theHGCHEbackDigitizer_(ps),
theHGCHEfrontDigitizer_(ps),
mySubDet_(ForwardSubdetector::ForwardEmpty)
{
//configure from cfg
Expand All @@ -35,15 +32,25 @@ HGCDigitizer::HGCDigitizer(const edm::ParameterSet& ps) :
if ( ! rng.isAvailable()) {
throw cms::Exception("Configuration") << "HGCDigitizer requires the RandomNumberGeneratorService - please add this service or remove the modules that require it";
}

CLHEP::HepRandomEngine& engine = rng->getEngine();
theHGCEEDigitizer_.setRandomNumberEngine(engine);
theHGCHEbackDigitizer_.setRandomNumberEngine(engine);
theHGCHEfrontDigitizer_.setRandomNumberEngine(engine);

//subdetector
if( producesEEDigis() ) mySubDet_=ForwardSubdetector::HGCEE;
if( producesHEfrontDigis() ) mySubDet_=ForwardSubdetector::HGCHEF;
if( producesHEbackDigis() ) mySubDet_=ForwardSubdetector::HGCHEB;
if(hitCollection_.find("HitsEE")!=std::string::npos) {
mySubDet_=ForwardSubdetector::HGCEE;
theHGCEEDigitizer_=std::unique_ptr<HGCEEDigitizer>(new HGCEEDigitizer(ps) );
theHGCEEDigitizer_->setRandomNumberEngine(engine);
}
if(hitCollection_.find("HitsHEfront")!=std::string::npos)
{
mySubDet_=ForwardSubdetector::HGCHEF;
theHGCHEfrontDigitizer_=std::unique_ptr<HGCHEfrontDigitizer>(new HGCHEfrontDigitizer(ps) );
theHGCHEfrontDigitizer_->setRandomNumberEngine(engine);
}
if(hitCollection_.find("HitsHEback")!=std::string::npos)
{
mySubDet_=ForwardSubdetector::HGCHEB;
theHGCHEbackDigitizer_=std::unique_ptr<HGCHEbackDigitizer>(new HGCHEbackDigitizer(ps) );
theHGCHEbackDigitizer_->setRandomNumberEngine(engine);
}
}

//
Expand All @@ -58,21 +65,21 @@ void HGCDigitizer::finalizeEvent(edm::Event& e, edm::EventSetup const& es)
if( producesEEDigis() )
{
std::auto_ptr<HGCEEDigiCollection> digiResult(new HGCEEDigiCollection() );
theHGCEEDigitizer_.run(digiResult,*simHitAccumulator_,digitizationType_);
theHGCEEDigitizer_->run(digiResult,*simHitAccumulator_,digitizationType_);
edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " EE hits";
e.put(digiResult,digiCollection());
}
if( producesHEfrontDigis())
{
std::auto_ptr<HGCHEDigiCollection> digiResult(new HGCHEDigiCollection() );
theHGCHEfrontDigitizer_.run(digiResult,*simHitAccumulator_,digitizationType_);
theHGCHEfrontDigitizer_->run(digiResult,*simHitAccumulator_,digitizationType_);
edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " HE front hits";
e.put(digiResult,digiCollection());
}
if( producesHEbackDigis() )
{
std::auto_ptr<HGCHEDigiCollection> digiResult(new HGCHEDigiCollection() );
theHGCHEbackDigitizer_.run(digiResult,*simHitAccumulator_,digitizationType_);
theHGCHEbackDigitizer_->run(digiResult,*simHitAccumulator_,digitizationType_);
edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " HE back hits";
e.put(digiResult,digiCollection());
}
Expand Down Expand Up @@ -165,7 +172,7 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits, i
}

//check if time is ok
if( itime > (int)(simHitIt->second.size()) ) continue;
if( itime >= (int)(simHitIt->second.size()) ) continue;

(simHitIt->second)[itime] += ien;
}
Expand Down Expand Up @@ -211,9 +218,6 @@ void HGCDigitizer::resetSimHitDataAccumulator()
}


//
HGCDigitizer::~HGCDigitizer()
{
}



0 comments on commit ba6bb59

Please sign in to comment.