Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to HGC-BH Digitization + Code cleanup. #12584

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SimCalorimetry/HGCalSimProducers/interface/HGCDigitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private :
//handle sim hits
int maxSimHitsAccTime_;
double bxTime_;
std::unique_ptr<HGCSimHitDataAccumulator> simHitAccumulator_;
std::unique_ptr<hgc::HGCSimHitDataAccumulator> simHitAccumulator_;
void resetSimHitDataAccumulator();

//digitizers
Expand Down
48 changes: 22 additions & 26 deletions SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h"

typedef float HGCSimData_t;
#include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerTypes.h"

//15 time samples: 9 pre-samples, 1 in-time, 5 post-samples
typedef std::array<HGCSimData_t,15> HGCSimHitData;
#include "SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h"

//1st array=energy, 2nd array=energy weighted time-of-flight
typedef std::unordered_map<uint32_t, std::array<HGCSimHitData,2> > HGCSimHitDataAccumulator;
namespace hgc = hgc_digi;

template <class DFr>
class HGCDigitizerBase {
public:

typedef edm::SortedCollection<DFr> DColl;

/**
@short CTOR
*/
HGCDigitizerBase(const edm::ParameterSet &ps) {
*/
HGCDigitizerBase(const edm::ParameterSet &ps) {
bxTime_ = ps.getParameter<double>("bxTime");
myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
doTimeSamples_ = myCfg_.getParameter< bool >("doTimeSamples");
Expand All @@ -43,39 +39,39 @@ class HGCDigitizerBase {
myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr> >( new HGCFEElectronics<DFr>(feCfg) );
}

/**
@short steer digitization mode
*/
void run(std::auto_ptr<DColl> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType,CLHEP::HepRandomEngine* engine);

/**
@short steer digitization mode
*/
void run(std::auto_ptr<DColl> &digiColl, hgc::HGCSimHitDataAccumulator &simData, uint32_t digitizationType,CLHEP::HepRandomEngine* engine);
/**
@short getters
*/
*/
float keV2fC() const { return keV2fC_; }
bool toaModeByEnergy() const { return (myFEelectronics_->toaMode()==HGCFEElectronics<DFr>::WEIGHTEDBYE); }
float tdcOnset() const { return myFEelectronics_->getTDCOnset(); }

/**
@short a trivial digitization: sum energies and digitize without noise
*/
void runSimple(std::auto_ptr<DColl> &coll,HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine);

void runSimple(std::auto_ptr<DColl> &coll, hgc::HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine);
/**
@short prepares the output according to the number of time samples to produce
*/
void updateOutput(std::auto_ptr<DColl> &coll,const DFr& rawDataFrame);

*/
void updateOutput(std::auto_ptr<DColl> &coll, const DFr& rawDataFrame);
/**
@short to be specialized by top class
*/
virtual void runDigitizer(std::auto_ptr<DColl> &coll,HGCSimHitDataAccumulator &simData,uint32_t digitizerType, CLHEP::HepRandomEngine* engine)
*/
virtual void runDigitizer(std::auto_ptr<DColl> &coll, hgc::HGCSimHitDataAccumulator &simData,uint32_t digitizerType, CLHEP::HepRandomEngine* engine)
{
throw cms::Exception("HGCDigitizerBaseException") << " Failed to find specialization of runDigitizer";
}

/**
@short DTOR
*/
*/
~HGCDigitizerBase()
{ };

Expand Down
20 changes: 20 additions & 0 deletions SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __SimCalorimetry_HGCCalSimProducers_HGCDigitizerTypes_h__
#define __SimCalorimetry_HGCCalSimProducers_HGCDigitizerTypes_h__

#include <unordered_map>
#include <array>

namespace hgc_digi {

//15 time samples: 9 pre-samples, 1 in-time, 5 post-samples
constexpr size_t nSamples = 15;

typedef float HGCSimData_t;

typedef std::array<HGCSimData_t,nSamples> HGCSimHitData;

//1st array=energy, 2nd array=energy weighted time-of-flight
typedef std::unordered_map<uint32_t, std::array<HGCSimHitData,2> > HGCSimHitDataAccumulator;

}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HGCEEDigitizer : public HGCDigitizerBase<HGCEEDataFrame> {

public:
HGCEEDigitizer(const edm::ParameterSet& ps);
void runDigitizer(std::auto_ptr<HGCEEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
void runDigitizer(std::auto_ptr<HGCEEDigiCollection> &digiColl,hgc::HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
~HGCEEDigitizer();
private:

Expand Down
22 changes: 13 additions & 9 deletions SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
#include "CLHEP/Random/RandGauss.h"
#include "CLHEP/Random/RandGaussQ.h"

#include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerTypes.h"

/**
@class HGCFEElectronics
@short models the behavior of the front-end electronics
*/

namespace hgc = hgc_digi;

template <class DFr>
class HGCFEElectronics
{
public:

enum HGCFEElectronicsFirmwareVersion { TRIVIAL, SIMPLE, WITHTOT };
enum HGCFEElectronicsTOTMode { WEIGHTEDBYE, SIMPLETHRESHOLD };

Expand All @@ -28,7 +32,8 @@ class HGCFEElectronics
/**
@short switches according to the firmware version
*/
inline void runShaper(DFr &dataFrame,std::vector<float> &chargeColl,std::vector<float> &toa, CLHEP::HepRandomEngine* engine)
inline void runShaper(DFr &dataFrame, hgc::HGCSimHitData& chargeColl,
hgc::HGCSimHitData& toa, CLHEP::HepRandomEngine* engine)
{
switch(fwVersion_)
{
Expand All @@ -50,25 +55,24 @@ class HGCFEElectronics
/**
@short converts charge to digis without pulse shape
*/
void runTrivialShaper(DFr &dataFrame,std::vector<float> &chargeColl);
void runTrivialShaper(DFr &dataFrame, hgc::HGCSimHitData& chargeColl);

/**
@short applies a shape to each time sample and propagates the tails to the subsequent time samples
*/
void runSimpleShaper(DFr &dataFrame,std::vector<float> &chargeColl);
void runSimpleShaper(DFr &dataFrame, hgc::HGCSimHitData& chargeColl);

/**
@short implements pulse shape and switch to time over threshold including deadtime
*/
void runShaperWithToT(DFr &dataFrame,std::vector<float> &chargeColl,std::vector<float> &toa, CLHEP::HepRandomEngine* engine);
void runShaperWithToT(DFr &dataFrame, hgc::HGCSimHitData& chargeColl,
hgc::HGCSimHitData& toa, CLHEP::HepRandomEngine* engine);

/**
@short returns how ToT will be computed
*/
uint32_t toaMode() const { return toaMode_; }

void resetCaches();

/**
@short DTOR
*/
Expand All @@ -83,8 +87,8 @@ class HGCFEElectronics
adcThreshold_fC_, tdcOnset_fC_, toaLSB_ns_, tdcResolutionInNs_;
uint32_t toaMode_;
//caches
std::vector<bool> busyFlags, totFlags;
std::vector<float> newCharge, toaFromToT;
std::array<bool,hgc::nSamples> busyFlags, totFlags;
hgc::HGCSimHitData newCharge, toaFromToT;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
#include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerBase.h"
#include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"


class HGCHEbackDigitizer : public HGCDigitizerBase<HGCHEDataFrame>
{
public:

HGCHEbackDigitizer(const edm::ParameterSet& ps);
void runDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
void runDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,hgc::HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
~HGCHEbackDigitizer();

private:

//calice-like digitization parameters
float keV2MIP_, noise_MIP_;
float nPEperMIP_, nTotalPE_, xTalk_, sdPixels_;
void runCaliceLikeDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine);
void runCaliceLikeDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,hgc::HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HGCHEfrontDigitizer : public HGCDigitizerBase<HGCHEDataFrame> {

public:
HGCHEfrontDigitizer(const edm::ParameterSet& ps);
void runDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
void runDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl, hgc::HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine);
~HGCHEfrontDigitizer();
private:

Expand Down
4 changes: 2 additions & 2 deletions SimCalorimetry/HGCalSimProducers/python/hgcalDigitizer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
noise_MIP = cms.double(0.20),
doTimeSamples = cms.bool(False),
nPEperMIP = cms.double(11.0),
nTotalPE = cms.double(11560), #1156 pixels => saturation ~600MIP
nTotalPE = cms.double(1156), #1156 pixels => saturation ~600MIP
xTalk = cms.double(0.25),
sdPixels = cms.double(3.0),
feCfg = cms.PSet(
Expand All @@ -129,7 +129,7 @@
# n bits for the ADC
adcNbits = cms.uint32(12),
# ADC saturation : in this case we use the same variable but fC=MIP
adcSaturation_fC = cms.double(2048),
adcSaturation_fC = cms.double(1024),
# threshold for digi production : in this case we use the same variable but fC=MIP
adcThreshold_fC = cms.double(1.0)
)
Expand Down
32 changes: 19 additions & 13 deletions SimCalorimetry/HGCalSimProducers/src/HGCDigitizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <algorithm>
#include <boost/foreach.hpp>

using namespace hgc_digi;

//
HGCDigitizer::HGCDigitizer(const edm::ParameterSet& ps,
edm::ConsumesCollector& iC) :
Expand Down Expand Up @@ -155,6 +157,11 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits,
tdcOnset = theHGCHEfrontDigitizer_->tdcOnset();
keV2fC = theHGCHEfrontDigitizer_->keV2fC();
break;
case ForwardSubdetector::HGCHEB:
weightToAbyEnergy = theHGCHEbackDigitizer_->toaModeByEnergy();
tdcOnset = std::numeric_limits<float>::max();//theHGCHEbackDigitizer_->tdcOnset();
keV2fC = theHGCHEbackDigitizer_->keV2fC();
break;
default:
break;
}
Expand Down Expand Up @@ -196,34 +203,33 @@ void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits,
std::sort(hitRefs.begin(),hitRefs.end(),this->orderByDetIdThenTime);

//loop over sorted hits
for(int i=0; i<nchits; i++)
for(int i=0; i<nchits; ++i)
{
int hitidx = std::get<0>(hitRefs[i]);
uint32_t id = std::get<1>(hitRefs[i]);
const int hitidx = std::get<0>(hitRefs[i]);
const uint32_t id = std::get<1>(hitRefs[i]);
if(id==0) continue; // to be ignored at RECO level

float toa = std::get<2>(hitRefs[i]);
const float toa = std::get<2>(hitRefs[i]);
const PCaloHit &hit=hits->at( hitidx );
float charge = hit.energy()*1e6*keV2fC;


const float charge = hit.energy()*1e6*keV2fC;

//distance to the center of the detector
float dist2center( geom->getPosition(id).mag() );
const float dist2center( geom->getPosition(id).mag() );

//hit time: [time()]=ns [centerDist]=cm [refSpeed_]=cm/ns + delay by 1ns
//accumulate in 15 buckets of 25ns (9 pre-samples, 1 in-time, 5 post-samples)
float tof(toa-dist2center/refSpeed_+tofDelay_);
int itime=floor( tof/bxTime_ ) ;
const float tof = toa-dist2center/refSpeed_+tofDelay_ ;
const int itime= std::floor( tof/bxTime_ ) + 9;

//no need to add bx crossing - tof comes already corrected from the mixing module
//itime += bxCrossing;
itime += 9;
//itime += 9;

if(itime<0 || itime>14) continue;

//check if already existing (perhaps could remove this in the future - 2nd event should have all defined)
HGCSimHitDataAccumulator::iterator simHitIt=simHitAccumulator_->find(id);
if(simHitIt == simHitAccumulator_->end()) {
HGCSimHitDataAccumulator::iterator simHitIt = simHitAccumulator_->find(id);
if( simHitIt == simHitAccumulator_->end() ) {
simHitIt = simHitAccumulator_->insert( std::make_pair(id,baseData) ).first;
}

Expand Down
12 changes: 6 additions & 6 deletions SimCalorimetry/HGCalSimProducers/src/HGCDigitizerBase.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerBase.h"

using namespace hgc_digi;

template<class DFr>
void HGCDigitizerBase<DFr>::run( std::auto_ptr<HGCDigitizerBase::DColl> &digiColl,
HGCSimHitDataAccumulator &simData,
Expand All @@ -13,12 +15,12 @@ template<class DFr>
void HGCDigitizerBase<DFr>::runSimple(std::auto_ptr<HGCDigitizerBase::DColl> &coll,
HGCSimHitDataAccumulator &simData,
CLHEP::HepRandomEngine* engine) {
std::vector<float> chargeColl,toa;
HGCSimHitData chargeColl,toa;
for(HGCSimHitDataAccumulator::iterator it=simData.begin();
it!=simData.end();
it++) {
chargeColl.resize(it->second[0].size());
toa.resize(it->second[0].size());
chargeColl.fill(0.f);
toa.fill(0.f);
for(size_t i=0; i<it->second[0].size(); i++) {
double rawCharge((it->second)[0][i]);

Expand All @@ -45,9 +47,7 @@ void HGCDigitizerBase<DFr>::runSimple(std::auto_ptr<HGCDigitizerBase::DColl> &co

//update the output according to the final shape
updateOutput(coll,rawDataFrame);
}

myFEelectronics_->resetCaches();
}
}

template<class DFr>
Expand Down
2 changes: 2 additions & 0 deletions SimCalorimetry/HGCalSimProducers/src/HGCEEDigitizer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "SimCalorimetry/HGCalSimProducers/interface/HGCEEDigitizer.h"

using namespace hgc_digi;

//
HGCEEDigitizer::HGCEEDigitizer(const edm::ParameterSet& ps) : HGCDigitizerBase(ps) { }

Expand Down
Loading