Skip to content

Commit

Permalink
Merge pull request #16 from PFCal-dev/hgcal_eol_pulse_update_112X_bis
Browse files Browse the repository at this point in the history
Addressing some comments by Kevin
  • Loading branch information
Giovanni Franzoni authored Jun 26, 2020
2 parents 9014602 + a06be40 commit 97f017e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
19 changes: 10 additions & 9 deletions SimCalorimetry/HGCalSimAlgos/interface/HGCalSiNoiseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define simcalorimetry_hgcalsimalgos_hgcalsinoisemap

#include "SimCalorimetry/HGCalSimAlgos/interface/HGCalRadiationMap.h"
#include "SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
#include <string>
Expand Down Expand Up @@ -55,7 +56,7 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {
void setDoseMap(const std::string &, const unsigned int &);

/**
@short overrides base class method which sets the geometry so that it can instantiate an operation
@short specialization of the base class method which sets the geometry so that it can instantiate an operation
cache the first time it is called - intrinsically related to the valid detIds in the geometry
the filling of the cache is ignored by configuration or if it has already been filled
*/
Expand All @@ -65,10 +66,10 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {
@short returns the charge collection efficiency and noise
if gain range is set to auto, it will find the most appropriate gain to put the mip peak close to 10 ADC counts
*/
SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did,
const SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did,
GainRange_t gain,
int aimMIPtoADC);
SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did) {
const SiCellOpCharacteristicsCore getSiCellOpCharacteristicsCore(const HGCSiliconDetId &did) {
return getSiCellOpCharacteristicsCore(did, defaultGain_, defaultAimMIPtoADC_);
}
SiCellOpCharacteristics getSiCellOpCharacteristics(const HGCSiliconDetId &did,
Expand All @@ -91,14 +92,14 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {
std::vector<double> &getIleakParam() { return ileakParam_; }
std::vector<std::vector<double> > &getENCsParam() { return encsParam_; }
std::vector<double> &getLSBPerGain() { return lsbPerGain_; }
void setDefaultADCPulseShape(const std::array<float, 6> &adcPulse) { defaultADCPulse_ = adcPulse; }
const std::array<float, 6> &getADCPulseForGain(GainRange_t gain) {
void setDefaultADCPulseShape(const hgc_digi::FEADCPulseShape &adcPulse) { defaultADCPulse_ = adcPulse; };
const hgc_digi::FEADCPulseShape &adcPulseForGain(GainRange_t gain) {
if (ignoreGainDependentPulse_)
return defaultADCPulse_;
return adcPulses_[gain];
}
};
std::vector<double> &getMaxADCPerGain() { return chargeAtFullScaleADCPerGain_; }
double getENCpad(const double &ileak);
double getENCpad(double ileak);
void setCachedOp(bool flag) { activateCachedOp_ = flag; }

inline void setENCCommonNoiseSubScale(double val) { encCommonNoiseSub_ = val; }
Expand All @@ -125,8 +126,8 @@ class HGCalSiNoiseMap : public HGCalRadiationMap {

//electronics noise (series+parallel) polynomial coeffs and ADC pulses;
std::vector<std::vector<double> > encsParam_;
std::array<float, 6> defaultADCPulse_;
std::vector<std::array<float, 6> > adcPulses_;
hgc_digi::FEADCPulseShape defaultADCPulse_;
std::vector<hgc_digi::FEADCPulseShape> adcPulses_;

//lsb
std::vector<double> lsbPerGain_, chargeAtFullScaleADCPerGain_;
Expand Down
32 changes: 7 additions & 25 deletions SimCalorimetry/HGCalSimAlgos/src/HGCalSiNoiseMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void HGCalSiNoiseMap::setDoseMap(const std::string &fullpath, const unsigned int
}

//
double HGCalSiNoiseMap::getENCpad(const double &ileak) {
double HGCalSiNoiseMap::getENCpad(double ileak) {
if (ileak > 45.40)
return 23.30 * ileak + 1410.04;
else if (ileak > 38.95)
Expand All @@ -91,6 +91,7 @@ double HGCalSiNoiseMap::getENCpad(const double &ileak) {

//
void HGCalSiNoiseMap::setGeometry(const CaloSubdetectorGeometry *hgcGeom, GainRange_t gain, int aimMIPtoADC) {

//call base class method
HGCalRadiationMap::setGeometry(hgcGeom);

Expand All @@ -105,7 +106,7 @@ void HGCalSiNoiseMap::setGeometry(const CaloSubdetectorGeometry *hgcGeom, GainRa
if (!siopCache_.empty())
return;

const std::vector<DetId> &validDetIds = geom()->getValidDetIds();
const auto &validDetIds = geom()->getValidDetIds();
for (auto &did : validDetIds) {
//use only positive side detIds
unsigned int rawId(did.rawId());
Expand All @@ -114,14 +115,12 @@ void HGCalSiNoiseMap::setGeometry(const CaloSubdetectorGeometry *hgcGeom, GainRa
continue;

//compute and store in cache
SiCellOpCharacteristicsCore siop = getSiCellOpCharacteristicsCore(hgcDetId);
std::pair<uint32_t, SiCellOpCharacteristicsCore> toAdd(rawId, siop);
siopCache_.insert(toAdd);
siopCache_.emplace( rawId, getSiCellOpCharacteristicsCore(hgcDetId) );
}
}

//
HGCalSiNoiseMap::SiCellOpCharacteristicsCore HGCalSiNoiseMap::getSiCellOpCharacteristicsCore(
const HGCalSiNoiseMap::SiCellOpCharacteristicsCore HGCalSiNoiseMap::getSiCellOpCharacteristicsCore(
const HGCSiliconDetId &cellId, GainRange_t gain, int aimMIPtoADC) {
//re-compute
if (!activateCachedOp_)
Expand Down Expand Up @@ -154,8 +153,8 @@ HGCalSiNoiseMap::SiCellOpCharacteristics HGCalSiNoiseMap::getSiCellOpCharacteris
//location of the cell
int subdet(cellId.subdet());
std::vector<double> &cceParam = cceParam_[cellThick];
auto xy(
ddd()->locateCell(cellId.layer(), cellId.waferU(), cellId.waferV(), cellId.cellU(), cellId.cellV(), true, true));
const auto &xy(
ddd()->locateCell(cellId.layer(), cellId.waferU(), cellId.waferV(), cellId.cellU(), cellId.cellV(), true, true));
double radius = sqrt(std::pow(xy.first, 2) + std::pow(xy.second, 2)); //in cm

//call baseline method and add to cache
Expand Down Expand Up @@ -216,30 +215,13 @@ HGCalSiNoiseMap::SiCellOpCharacteristics HGCalSiNoiseMap::getSiCellOpCharacteris
double S(siop.core.cce * mipEqfC);
if (gain == GainRange_t::AUTO) {
gain = GainRange_t::q320fC;

//@franzoni: i think the order needs to be this one (i.e. take the first according to preference) - tbc
std::vector<GainRange_t> orderedGainChoice = {GainRange_t::q160fC, GainRange_t::q80fC};
for (const auto &igain : orderedGainChoice) {
double mipPeakADC(S / lsbPerGain_[igain]);
if (mipPeakADC > 16)
break;
gain = igain;
}

//previous algo (kept commented for the moment)
// double S(siop.core.cce * mipEqfC);
// if (gain == GainRange_t::AUTO) {
// double desiredLSB(S / aimMIPtoADC);
// std::vector<double> diffToPhysLSB = {fabs(desiredLSB - lsbPerGain_[GainRange_t::q80fC]),
// fabs(desiredLSB - lsbPerGain_[GainRange_t::q160fC]),
// fabs(desiredLSB - lsbPerGain_[GainRange_t::q320fC])};
// size_t gainIdx = std::min_element(diffToPhysLSB.begin(), diffToPhysLSB.end()) - diffToPhysLSB.begin();
// gain = HGCalSiNoiseMap::q80fC;
// if (gainIdx == 1)
// gain = HGCalSiNoiseMap::q160fC;
// if (gainIdx == 2)
// gain = HGCalSiNoiseMap::q320fC;
// }
}

//fill in the parameters of the struct
Expand Down
14 changes: 9 additions & 5 deletions SimCalorimetry/HGCalSimProducers/interface/HGCFEElectronics.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

namespace hgc = hgc_digi;

namespace hgc_digi{
typedef std::array<float, 6> FEADCPulseShape;
}

template <class DFr>
class HGCFEElectronics {
public:
Expand All @@ -33,7 +37,7 @@ class HGCFEElectronics {
inline void runShaper(DFr& dataFrame,
hgc::HGCSimHitData& chargeColl,
hgc::HGCSimHitData& toa,
const std::array<float, 6>& adcPulse,
const hgc_digi::FEADCPulseShape& adcPulse,
CLHEP::HepRandomEngine* engine,
uint32_t thrADC = 0,
float lsbADC = -1,
Expand Down Expand Up @@ -105,7 +109,7 @@ class HGCFEElectronics {
float lsbADC,
uint32_t gainIdx,
float maxADC,
const std::array<float, 6>& adcPulse);
const hgc_digi::FEADCPulseShape& adcPulse);
void runSimpleShaper(
DFr& dataFrame, hgc::HGCSimHitData& chargeColl, uint32_t thrADC, float lsbADC, uint32_t gainIdx, float maxADC) {
runSimpleShaper(dataFrame, chargeColl, thrADC, lsbADC, gainIdx, maxADC, adcPulse_);
Expand All @@ -123,7 +127,7 @@ class HGCFEElectronics {
uint32_t gainIdx,
float maxADC,
int thickness,
const std::array<float, 6>& adcPulse);
const hgc_digi::FEADCPulseShape& adcPulse);
void runShaperWithToT(DFr& dataFrame,
hgc::HGCSimHitData& chargeColl,
hgc::HGCSimHitData& toa,
Expand All @@ -144,7 +148,7 @@ class HGCFEElectronics {
/**
@short getter for the default ADC pulse configured by python
*/
std::array<float, 6>& getDefaultADCPulse() { return adcPulse_; }
hgc_digi::FEADCPulseShape& getDefaultADCPulse() { return adcPulse_; }

/**
@short DTOR
Expand All @@ -154,7 +158,7 @@ class HGCFEElectronics {
private:
//private members
uint32_t fwVersion_;
std::array<float, 6> adcPulse_, pulseAvgT_;
hgc_digi::FEADCPulseShape adcPulse_, pulseAvgT_;
std::array<float, 3> tdcForToAOnset_fC_;
std::vector<float> tdcChargeDrainParameterisation_;
float adcSaturation_fC_, adcLSB_fC_, tdcLSB_fC_, tdcSaturation_fC_, adcThreshold_fC_, tdcOnset_fC_, toaLSB_ns_,
Expand Down
2 changes: 1 addition & 1 deletion SimCalorimetry/HGCalSimProducers/src/HGCDigitizerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>&
HGCalSiNoiseMap::GainRange_t gain((HGCalSiNoiseMap::GainRange_t)siop.gain);
lsbADC = scal_.getLSBPerGain()[gain];
maxADC = scal_.getMaxADCPerGain()[gain];
adcPulse = scal_.getADCPulseForGain(gain);
adcPulse = scal_.adcPulseForGain(gain);
gainIdx = siop.gain;
if (thresholdFollowsMIP_)
thrADC = siop.thrADC;
Expand Down
4 changes: 2 additions & 2 deletions SimCalorimetry/HGCalSimProducers/src/HGCFEElectronics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void HGCFEElectronics<DFr>::runSimpleShaper(DFr& dataFrame,
float lsbADC,
uint32_t gainIdx,
float maxADC,
const std::array<float, 6>& adcPulse) {
const hgc_digi::FEADCPulseShape& adcPulse) {
//convolute with pulse shape to compute new ADCs
newCharge.fill(0.f);
bool debug(false);
Expand Down Expand Up @@ -213,7 +213,7 @@ void HGCFEElectronics<DFr>::runShaperWithToT(DFr& dataFrame,
uint32_t gainIdx,
float maxADC,
int thickness,
const std::array<float, 6>& adcPulse) {
const hgc_digi::FEADCPulseShape& adcPulse) {
busyFlags.fill(false);
totFlags.fill(false);
toaFlags.fill(false);
Expand Down

0 comments on commit 97f017e

Please sign in to comment.