Skip to content

Commit

Permalink
Merge pull request #26696 from cms-sw/code-format-simulation-23f813
Browse files Browse the repository at this point in the history
Running code-format for simulation
  • Loading branch information
cmsbuild committed May 8, 2019
2 parents 7a8d8c0 + 60c8d88 commit 9a33fb1
Show file tree
Hide file tree
Showing 133 changed files with 4,091 additions and 5,766 deletions.
42 changes: 18 additions & 24 deletions SimCalorimetry/CastorSim/plugins/CastorDigiAnalyzer.cc
Expand Up @@ -4,42 +4,36 @@
#include <iostream>

CastorDigiAnalyzer::CastorDigiAnalyzer(edm::ParameterSet const &conf)
: hitReadoutName_("CastorHits"), simParameterMap_(),
: hitReadoutName_("CastorHits"),
simParameterMap_(),
castorHitAnalyzer_("CASTORDigi", 1., &simParameterMap_, &castorFilter_),
castorDigiStatistics_("CASTORDigi", 3, 10., 6., 0.1, 0.5,
castorHitAnalyzer_),
castorDigiCollectionTag_(
conf.getParameter<edm::InputTag>("castorDigiCollectionTag")) {}
castorDigiStatistics_("CASTORDigi", 3, 10., 6., 0.1, 0.5, castorHitAnalyzer_),
castorDigiCollectionTag_(conf.getParameter<edm::InputTag>("castorDigiCollectionTag")) {}

namespace CastorDigiAnalyzerImpl {
template <class Collection>
void analyze(edm::Event const &e, CastorDigiStatistics &statistics,
edm::InputTag &tag) {
edm::Handle<Collection> digis;
e.getByLabel(tag, digis);
if (!digis.isValid()) {
edm::LogError("CastorDigiAnalyzer")
<< "Could not find Castor Digi Container ";
} else {
for (unsigned i = 0; i < digis->size(); ++i) {
statistics.analyze((*digis)[i]);
template <class Collection>
void analyze(edm::Event const &e, CastorDigiStatistics &statistics, edm::InputTag &tag) {
edm::Handle<Collection> digis;
e.getByLabel(tag, digis);
if (!digis.isValid()) {
edm::LogError("CastorDigiAnalyzer") << "Could not find Castor Digi Container ";
} else {
for (unsigned i = 0; i < digis->size(); ++i) {
statistics.analyze((*digis)[i]);
}
}
}
}
} // namespace CastorDigiAnalyzerImpl
} // namespace CastorDigiAnalyzerImpl

void CastorDigiAnalyzer::analyze(edm::Event const &e,
edm::EventSetup const &c) {
void CastorDigiAnalyzer::analyze(edm::Event const &e, edm::EventSetup const &c) {
// edm::Handle<edm::PCaloHitContainer> hits;
edm::Handle<CrossingFrame<PCaloHit>> castorcf;

e.getByLabel("mix", "g4SimHitsCastorFI", castorcf);

// access to SimHits
std::unique_ptr<MixCollection<PCaloHit>> hits(
new MixCollection<PCaloHit>(castorcf.product()));
std::unique_ptr<MixCollection<PCaloHit>> hits(new MixCollection<PCaloHit>(castorcf.product()));
// if (hits.isValid()) {
castorHitAnalyzer_.fillHits(*hits);
CastorDigiAnalyzerImpl::analyze<CastorDigiCollection>(
e, castorDigiStatistics_, castorDigiCollectionTag_);
CastorDigiAnalyzerImpl::analyze<CastorDigiCollection>(e, castorDigiStatistics_, castorDigiCollectionTag_);
}
56 changes: 23 additions & 33 deletions SimCalorimetry/CastorSim/plugins/CastorDigiProducer.cc
Expand Up @@ -25,11 +25,13 @@ CastorDigiProducer::CastorDigiProducer(const edm::ParameterSet &ps,
: theParameterMap(new CastorSimParameterMap(ps)),
theCastorShape(new CastorShape()),
theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
theCastorResponse(
new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
theAmplifier(nullptr), theCoderFactory(nullptr),
theElectronicsSim(nullptr), theHitCorrection(nullptr),
theCastorDigitizer(nullptr), theCastorHits() {
theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
theAmplifier(nullptr),
theCoderFactory(nullptr),
theElectronicsSim(nullptr),
theHitCorrection(nullptr),
theCastorDigitizer(nullptr),
theCastorHits() {
theHitsProducerTag = ps.getParameter<edm::InputTag>("hitsProducer");
iC.consumes<std::vector<PCaloHit>>(theHitsProducerTag);

Expand All @@ -48,16 +50,14 @@ CastorDigiProducer::CastorDigiProducer(const edm::ParameterSet &ps,
theCoderFactory = new CastorCoderFactory(CastorCoderFactory::DB);
theElectronicsSim = new CastorElectronicsSim(theAmplifier, theCoderFactory);

theCastorDigitizer =
new CastorDigitizer(theCastorResponse, theElectronicsSim, doNoise);
theCastorDigitizer = new CastorDigitizer(theCastorResponse, theElectronicsSim, doNoise);

edm::Service<edm::RandomNumberGenerator> rng;
if (!rng.isAvailable()) {
throw cms::Exception("Configuration")
<< "CastorDigiProducer requires the RandomNumberGeneratorService\n"
"which is not present in the configuration file. You must add the "
"service\n"
"in the configuration file or remove the modules that require it.";
throw cms::Exception("Configuration") << "CastorDigiProducer requires the RandomNumberGeneratorService\n"
"which is not present in the configuration file. You must add the "
"service\n"
"in the configuration file or remove the modules that require it.";
}
}

Expand All @@ -73,8 +73,7 @@ CastorDigiProducer::~CastorDigiProducer() {
delete theHitCorrection;
}

void CastorDigiProducer::initializeEvent(edm::Event const &event,
edm::EventSetup const &eventSetup) {
void CastorDigiProducer::initializeEvent(edm::Event const &event, edm::EventSetup const &eventSetup) {
// get the appropriate gains, noises, & widths for this event
edm::ESHandle<CastorDbService> conditions;
eventSetup.get<CastorDbRecord>().get(conditions);
Expand All @@ -96,8 +95,7 @@ void CastorDigiProducer::initializeEvent(edm::Event const &event,
theCastorDigitizer->initializeHits();
}

void CastorDigiProducer::accumulateCaloHits(
std::vector<PCaloHit> const &hcalHits, int bunchCrossing) {
void CastorDigiProducer::accumulateCaloHits(std::vector<PCaloHit> const &hcalHits, int bunchCrossing) {
// fillFakeHits();

if (theHitCorrection != nullptr) {
Expand All @@ -106,8 +104,7 @@ void CastorDigiProducer::accumulateCaloHits(
theCastorDigitizer->add(hcalHits, bunchCrossing, randomEngine_);
}

void CastorDigiProducer::accumulate(edm::Event const &e,
edm::EventSetup const &) {
void CastorDigiProducer::accumulate(edm::Event const &e, edm::EventSetup const &) {
// Step A: Get and accumulate digitized hits
edm::Handle<std::vector<PCaloHit>> castorHandle;
e.getByLabel(theHitsProducerTag, castorHandle);
Expand All @@ -125,35 +122,29 @@ void CastorDigiProducer::accumulate(PileUpEventPrincipal const &e,
accumulateCaloHits(*castorHandle.product(), e.bunchCrossing());
}

void CastorDigiProducer::finalizeEvent(edm::Event &e,
const edm::EventSetup &eventSetup) {
void CastorDigiProducer::finalizeEvent(edm::Event &e, const edm::EventSetup &eventSetup) {
// Step B: Create empty output

std::unique_ptr<CastorDigiCollection> castorResult(
new CastorDigiCollection());
std::unique_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection());

// Step C: Invoke the algorithm, getting back outputs.
theCastorDigitizer->run(*castorResult, randomEngine_);

edm::LogInfo("CastorDigiProducer")
<< "HCAL/Castor digis : " << castorResult->size();
edm::LogInfo("CastorDigiProducer") << "HCAL/Castor digis : " << castorResult->size();

// Step D: Put outputs into event
e.put(std::move(castorResult));

randomEngine_ = nullptr; // to prevent access outside event
randomEngine_ = nullptr; // to prevent access outside event
}

void CastorDigiProducer::sortHits(const edm::PCaloHitContainer &hits) {
for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
hitItr != hits.end(); ++hitItr) {
for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
DetId detId = hitItr->id();
if (detId.det() == DetId::Calo &&
detId.subdetId() == HcalCastorDetId::SubdetectorId) {
if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId) {
theCastorHits.push_back(*hitItr);
} else {
edm::LogError("CastorDigiProducer")
<< "Bad Hit subdetector " << detId.subdetId();
edm::LogError("CastorDigiProducer") << "Bad Hit subdetector " << detId.subdetId();
}
}
}
Expand All @@ -170,8 +161,7 @@ void CastorDigiProducer::checkGeometry(const edm::EventSetup &eventSetup) {
eventSetup.get<CaloGeometryRecord>().get(geometry);
theCastorResponse->setGeometry(&*geometry);

const std::vector<DetId> &castorCells =
geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);

// std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
// "<<castorCells.size()<<std::endl;
Expand Down
15 changes: 6 additions & 9 deletions SimCalorimetry/CastorSim/plugins/CastorDigiProducer.h
Expand Up @@ -21,28 +21,25 @@
#include <vector>

namespace edm {
class StreamID;
class ConsumesCollector;
} // namespace edm
class StreamID;
class ConsumesCollector;
} // namespace edm

namespace CLHEP {
class HepRandomEngine;
class HepRandomEngine;
}

class PCaloHit;
class PileUpEventPrincipal;

class CastorDigiProducer : public DigiAccumulatorMixMod {
public:
explicit CastorDigiProducer(const edm::ParameterSet &ps,
edm::ProducerBase &mixMod,
edm::ConsumesCollector &iC);
explicit CastorDigiProducer(const edm::ParameterSet &ps, edm::ProducerBase &mixMod, edm::ConsumesCollector &iC);
~CastorDigiProducer() override;

void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override;
void accumulate(edm::Event const &e, edm::EventSetup const &c) override;
void accumulate(PileUpEventPrincipal const &e, edm::EventSetup const &c,
edm::StreamID const &) override;
void accumulate(PileUpEventPrincipal const &e, edm::EventSetup const &c, edm::StreamID const &) override;
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override;

private:
Expand Down
26 changes: 14 additions & 12 deletions SimCalorimetry/CastorSim/plugins/CastorDigiStatistics.h
Expand Up @@ -8,17 +8,22 @@

class CastorDigiStatistics {
public:
CastorDigiStatistics(std::string name, int maxBin, float amplitudeThreshold,
float expectedPedestal, float binPrevToBinMax,
CastorDigiStatistics(std::string name,
int maxBin,
float amplitudeThreshold,
float expectedPedestal,
float binPrevToBinMax,
float binNextToBinMax,
CaloHitAnalyzer &amplitudeAnalyzer)
: maxBin_(maxBin), amplitudeThreshold_(amplitudeThreshold),
: maxBin_(maxBin),
amplitudeThreshold_(amplitudeThreshold),
pedestal_(name + " pedestal", expectedPedestal, 0.),
binPrevToBinMax_(name + " binPrevToBinMax", binPrevToBinMax, 0.),
binNextToBinMax_(name + " binNextToBinMax", binNextToBinMax, 0.),
amplitudeAnalyzer_(amplitudeAnalyzer) {}

template <class Digi> void analyze(const Digi &digi);
template <class Digi>
void analyze(const Digi &digi);

private:
int maxBin_;
Expand All @@ -29,7 +34,8 @@ class CastorDigiStatistics {
CaloHitAnalyzer &amplitudeAnalyzer_;
};

template <class Digi> void CastorDigiStatistics::analyze(const Digi &digi) {
template <class Digi>
void CastorDigiStatistics::analyze(const Digi &digi) {
pedestal_.addEntry(digi[0].adc());
pedestal_.addEntry(digi[1].adc());

Expand All @@ -38,17 +44,13 @@ template <class Digi> void CastorDigiStatistics::analyze(const Digi &digi) {
double maxAmplitude = digi[maxBin_].nominal_fC() - pedestal_fC;

if (maxAmplitude > amplitudeThreshold_) {

double binPrevToBinMax =
(digi[maxBin_ - 1].nominal_fC() - pedestal_fC) / maxAmplitude;
double binPrevToBinMax = (digi[maxBin_ - 1].nominal_fC() - pedestal_fC) / maxAmplitude;
binPrevToBinMax_.addEntry(binPrevToBinMax);

double binNextToBinMax =
(digi[maxBin_ + 1].nominal_fC() - pedestal_fC) / maxAmplitude;
double binNextToBinMax = (digi[maxBin_ + 1].nominal_fC() - pedestal_fC) / maxAmplitude;
binNextToBinMax_.addEntry(binNextToBinMax);

double amplitude = digi[maxBin_].nominal_fC() +
digi[maxBin_ + 1].nominal_fC() - 2 * pedestal_fC;
double amplitude = digi[maxBin_].nominal_fC() + digi[maxBin_ + 1].nominal_fC() - 2 * pedestal_fC;

amplitudeAnalyzer_.analyze(digi.id().rawId(), amplitude);
}
Expand Down
37 changes: 17 additions & 20 deletions SimCalorimetry/CastorSim/plugins/CastorHitAnalyzer.cc
Expand Up @@ -4,36 +4,33 @@
#include <iostream>

CastorHitAnalyzer::CastorHitAnalyzer(edm::ParameterSet const &conf)
: hitReadoutName_("CastorHits"), simParameterMap_(), castorFilter_(),
: hitReadoutName_("CastorHits"),
simParameterMap_(),
castorFilter_(),
castorAnalyzer_("CASTOR", 1., &simParameterMap_, &castorFilter_),
castorRecHitCollectionTag_(
conf.getParameter<edm::InputTag>("castorRecHitCollectionTag")) {}
castorRecHitCollectionTag_(conf.getParameter<edm::InputTag>("castorRecHitCollectionTag")) {}

namespace CastorHitAnalyzerImpl {
template <class Collection>
void analyze(edm::Event const &e, CaloHitAnalyzer &analyzer,
edm::InputTag &tag) {
edm::Handle<Collection> recHits;
e.getByLabel(tag, recHits);
if (!recHits.isValid()) {
edm::LogError("CastorHitAnalyzer")
<< "Could not find Castor RecHitContainer ";
} else {
for (unsigned i = 0; i < recHits->size(); ++i) {
analyzer.analyze((*recHits)[i].id().rawId(), (*recHits)[i].energy());
template <class Collection>
void analyze(edm::Event const &e, CaloHitAnalyzer &analyzer, edm::InputTag &tag) {
edm::Handle<Collection> recHits;
e.getByLabel(tag, recHits);
if (!recHits.isValid()) {
edm::LogError("CastorHitAnalyzer") << "Could not find Castor RecHitContainer ";
} else {
for (unsigned i = 0; i < recHits->size(); ++i) {
analyzer.analyze((*recHits)[i].id().rawId(), (*recHits)[i].energy());
}
}
}
}
} // namespace CastorHitAnalyzerImpl
} // namespace CastorHitAnalyzerImpl

void CastorHitAnalyzer::analyze(edm::Event const &e, edm::EventSetup const &c) {
edm::Handle<CrossingFrame<PCaloHit>> castorcf;
e.getByLabel("mix", "g4SimHitsCastorFI", castorcf);

// access to SimHits
std::unique_ptr<MixCollection<PCaloHit>> hits(
new MixCollection<PCaloHit>(castorcf.product()));
std::unique_ptr<MixCollection<PCaloHit>> hits(new MixCollection<PCaloHit>(castorcf.product()));
castorAnalyzer_.fillHits(*hits);
CastorHitAnalyzerImpl::analyze<CastorRecHitCollection>(
e, castorAnalyzer_, castorRecHitCollectionTag_);
CastorHitAnalyzerImpl::analyze<CastorRecHitCollection>(e, castorAnalyzer_, castorRecHitCollectionTag_);
}
20 changes: 7 additions & 13 deletions SimCalorimetry/CastorSim/src/CastorAmplifier.cc
Expand Up @@ -13,26 +13,20 @@

#include <iostream>

CastorAmplifier::CastorAmplifier(const CastorSimParameterMap *parameters,
bool addNoise)
: theDbService(nullptr), theParameterMap(parameters), theStartingCapId(0),
addNoise_(addNoise) {}
CastorAmplifier::CastorAmplifier(const CastorSimParameterMap *parameters, bool addNoise)
: theDbService(nullptr), theParameterMap(parameters), theStartingCapId(0), addNoise_(addNoise) {}

void CastorAmplifier::amplify(CaloSamples &frame,
CLHEP::HepRandomEngine *engine) const {
void CastorAmplifier::amplify(CaloSamples &frame, CLHEP::HepRandomEngine *engine) const {
const CastorSimParameters &parameters = theParameterMap->castorParameters();
assert(theDbService != nullptr);
HcalGenericDetId hcalGenDetId(frame.id());
const CastorPedestal *peds = theDbService->getPedestal(hcalGenDetId);
const CastorPedestalWidth *pwidths =
theDbService->getPedestalWidth(hcalGenDetId);
const CastorPedestalWidth *pwidths = theDbService->getPedestalWidth(hcalGenDetId);
if (!peds || !pwidths) {
edm::LogError("CastorAmplifier")
<< "Could not fetch HCAL/CASTOR conditions for channel "
<< hcalGenDetId;
edm::LogError("CastorAmplifier") << "Could not fetch HCAL/CASTOR conditions for channel " << hcalGenDetId;
} else {
double gauss[32]; // big enough
double noise[32]; // big enough
double gauss[32]; // big enough
double noise[32]; // big enough
double fCperPE = parameters.photoelectronsToAnalog(frame.id());
double nominalfCperPE = parameters.getNominalfCperPE();

Expand Down
5 changes: 2 additions & 3 deletions SimCalorimetry/CastorSim/src/CastorAmplifier.h
Expand Up @@ -7,7 +7,7 @@
class CastorDbService;

namespace CLHEP {
class HepRandomEngine;
class HepRandomEngine;
}

class CastorAmplifier {
Expand All @@ -18,8 +18,7 @@ class CastorAmplifier {
/// the Producer will probably update this every event
void setDbService(const CastorDbService *service) { theDbService = service; }

virtual void amplify(CaloSamples &linearFrame,
CLHEP::HepRandomEngine *) const;
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const;

void setStartingCapId(int capId) { theStartingCapId = capId; }

Expand Down
3 changes: 1 addition & 2 deletions SimCalorimetry/CastorSim/src/CastorCoderFactory.cc
Expand Up @@ -2,8 +2,7 @@
#include "CalibFormats/CastorObjects/interface/CastorNominalCoder.h"
#include "SimCalorimetry/CastorSim/src/CastorCoderFactory.h"

CastorCoderFactory::CastorCoderFactory(CoderType coderType)
: theCoderType(coderType), theDbService(nullptr) {}
CastorCoderFactory::CastorCoderFactory(CoderType coderType) : theCoderType(coderType), theDbService(nullptr) {}

std::unique_ptr<CastorCoder> CastorCoderFactory::coder(const DetId &id) const {
CastorCoder *result = nullptr;
Expand Down

0 comments on commit 9a33fb1

Please sign in to comment.