Skip to content

Commit

Permalink
Merge pull request #778 from bonventre/elecprod
Browse files Browse the repository at this point in the history
Updated TrkPreampStraw script
  • Loading branch information
brownd1978 authored Apr 28, 2022
2 parents 19f57d3 + 28a1379 commit c0050b1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
1 change: 1 addition & 0 deletions TrackerConditions/fcl/prolog.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ StrawPhysics : {
StrawElectronics : {
verbose : 0
useDb : false
overrideDbTimeOffsets : false

defaultThresholddVdI : 8.43e6
thresholddVdI : []
Expand Down
6 changes: 5 additions & 1 deletion TrackerConditions/inc/StrawElectronics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace mu2e {
constexpr static const char* cxname = {"StrawElectronics"};

// construct with constants, then some values are computed and filled below
StrawElectronics( double tdeadAnalog, double tdeadDigital, double vsat,
StrawElectronics( bool overrideDbTimeOffsets, double tdeadAnalog, double tdeadDigital, double vsat,
double snoise, double ADCLSB, int maxADC, unsigned nADCPackets, unsigned nADCpre,
double ADCPeriod, double ADCOffset,
unsigned maxtsep,
Expand Down Expand Up @@ -79,6 +79,7 @@ namespace mu2e {
double triggerHysteresis,
double clusterLookbackTime) :
ProditionsEntity(cxname),
_overrideDbTimeOffsets(overrideDbTimeOffsets),
_tdeadAnalog(tdeadAnalog), _tdeadDigital(tdeadDigital), _vsat(vsat),
_snoise(snoise), _ADCLSB(ADCLSB), _maxADC(maxADC), _nADCPackets(nADCPackets),
_nADCpre(nADCpre), _ADCPeriod(ADCPeriod), _ADCOffset(ADCOffset),
Expand Down Expand Up @@ -210,7 +211,10 @@ namespace mu2e {
double getTimeOffsetStrawHV(size_t istraw) const { return _timeOffsetStrawHV[istraw]; }
double getTimeOffsetStrawCal(size_t istraw)const { return _timeOffsetStrawCal[istraw]; }

bool overrideDbTimeOffsets() const { return _overrideDbTimeOffsets; }

private:
bool _overrideDbTimeOffsets; // for digitization we override Db parameters and zero all time offsets

// generic waveform parameters
std::array<std::array<double, StrawId::_nustraws>,npaths> _dVdI; // scale factor between charge and voltage (milliVolts/picoCoulombs)
Expand Down
28 changes: 20 additions & 8 deletions TrackerConditions/src/StrawElectronicsMaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace mu2e {

// creat this at the beginning since it must be used,
// partially constructed, to complete the construction
auto ptr = std::make_shared<StrawElectronics>(_config.deadTimeAnalog(),
auto ptr = std::make_shared<StrawElectronics>(
_config.overrideDbTimeOffsets(), _config.deadTimeAnalog(),
_config.deadTimeDigital(), _config.saturationVoltage(), _config.strawNoise(),
_config.ADCLSB(), _config.maxADC(), _config.nADCPackets(), _config.nADCPresamples(),
_config.ADCPeriod(), _config.ADCOffset(),
Expand Down Expand Up @@ -273,13 +274,24 @@ namespace mu2e {
std::array<double, StrawId::_nupanels> timeOffsetPanel;
std::array<double, StrawId::_nustraws> timeOffsetStrawHV;
std::array<double, StrawId::_nustraws> timeOffsetStrawCal;
for(size_t i=0; i<StrawId::_nupanels; i++) {
timeOffsetPanel[i] = tdp->rowAt(i).delay();
}
for(size_t i=0; i<StrawId::_nustraws; i++) {
size_t istraw = i % StrawId::_nstraws;
timeOffsetStrawHV[i] = tdrs->rowAt(istraw).delayHv() + tps->rowAt(i).delayHv();
timeOffsetStrawCal[i] = tdrs->rowAt(istraw).delayCal() + tps->rowAt(i).delayCal();

if (ptr->overrideDbTimeOffsets()){
for(size_t i=0; i<StrawId::_nupanels; i++) {
timeOffsetPanel[i] = 0;
}
for(size_t i=0; i<StrawId::_nustraws; i++) {
timeOffsetStrawHV[i] = 0;
timeOffsetStrawCal[i] = 0;
}
}else{
for(size_t i=0; i<StrawId::_nupanels; i++) {
timeOffsetPanel[i] = tdp->rowAt(i).delay();
}
for(size_t i=0; i<StrawId::_nustraws; i++) {
size_t istraw = i % StrawId::_nstraws;
timeOffsetStrawHV[i] = tdrs->rowAt(istraw).delayHv() + tps->rowAt(i).delayHv();
timeOffsetStrawCal[i] = tdrs->rowAt(istraw).delayCal() + tps->rowAt(i).delayCal();
}
}

ptr->setOffsets( timeOffsetPanel,
Expand Down
50 changes: 35 additions & 15 deletions TrackerConditions/test/TrkPreampStrawRandomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,54 @@
import sys
import numpy as np

NPlanes = 36
NPanels = 6
NStraws = 96
NUStraws = NPlanes*NPanels*NStraws

if len(sys.argv) < 7:
print("Usage: python TrkPreampStrawRandomize.py <output filename> <time delay sigma (ns)> <mean threshold (mv)> <threshold sigma (mv)> <mean adc gain> <adc gain sigma>")
print("Usage: python TrkPreampStrawRandomize.py <output filename> <seed> <absolute time offset sigma (ns)> <deltat time offset sigma (ns)> <cal mean threshold (mv)> <mean hv-cal threshold (mv)> <cal threshold sigma (mv)> <hv threshold sigma (mv)> <mean adc gain> <adc gain sigma>")
sys.exit()

fn = sys.argv[1]

delay_sigma = float(sys.argv[2])
mean_threshold = float(sys.argv[3])
threshold_sigma = float(sys.argv[4])
mean_adc = float(sys.argv[5])
adc_sigma = float(sys.argv[6])
seed = int(sys.argv[2])
abs_delay_sigma = float(sys.argv[3])
dt_delay_sigma = float(sys.argv[4])
mean_threshold = float(sys.argv[5])
threshold_offset = float(sys.argv[6])
cal_threshold_sigma = float(sys.argv[7])
hv_threshold_sigma = float(sys.argv[8])
mean_adc = float(sys.argv[9])
adc_sigma = float(sys.argv[10])

fout = open(fn,"w")
fout.write("# Randomized calibration from TrkPreampStrawRandomize.py, parameters: delay sigma = %f, mean threshold = %f, threshold sigma = %f, mean adc gain = %f, adc gain sigma = %f\n" %
(delay_sigma, mean_threshold, threshold_sigma, mean_adc, adc_sigma))
fout.write("# Randomized calibration from TrkPreampStrawRandomize.py, parameters:\n")
fout.write("# absolute time offset sigma = %f ns\n" % (abs_delay_sigma))
fout.write("# deltat time offset sigma = %f ns\n" % (dt_delay_sigma))
fout.write("# cal mean threshold = %f mv\n" % (mean_threshold))
fout.write("# mean hv-cal threshold = %f mv\n" % (threshold_offset))
fout.write("# cal threshold sigma = %f mv\n" % (cal_threshold_sigma))
fout.write("# hv threshold sigma = %f mv\n" % (hv_threshold_sigma))
fout.write("# mean adc gain = %f\n" % (mean_adc))
fout.write("# adc gain sigma = %f %%\n" % (adc_sigma))
fout.write("# python ")
for i in range(len(sys.argv)):
fout.write(sys.argv[i] + " ")
fout.write("\n#\n#\n#\n")

rng = np.random.default_rng(seed)

fout.write("TABLE TrkPreampStraw\n")
fout.write("# index,delay_hv,delay_cal,threshold_hv,threshold_cal,gain\n")
for index in range(36*6*96):
delay_hv = np.random.normal(0,delay_sigma)
delay_cal = np.random.normal(0,delay_sigma)
threshold_hv = np.random.normal(mean_threshold,threshold_sigma)
threshold_cal = np.random.normal(mean_threshold,threshold_sigma)
gain = np.random.normal(mean_adc,adc_sigma)
fout.write("%d, %f, %f, %f, %f, %f\n" % (index, delay_hv, delay_cal, threshold_hv, threshold_cal, gain))
abs_delay = rng.normal(0,abs_delay_sigma,NUStraws)
dt_delay = rng.normal(0,dt_delay_sigma,NUStraws)
threshold_hv = rng.normal(mean_threshold+threshold_offset,hv_threshold_sigma,NUStraws)
threshold_cal = rng.normal(mean_threshold,cal_threshold_sigma,NUStraws)
gain = rng.normal(mean_adc,adc_sigma/100.*mean_adc,NUStraws)
for i in range(NUStraws):
delay_hv = abs_delay[i] + dt_delay[i]/2.
delay_cal = abs_delay[i] - dt_delay[i]/2.
fout.write("%d, %f, %f, %f, %f, %f\n" % (i, delay_hv, delay_cal, threshold_hv[i], threshold_cal[i], gain[i]))

fout.close()
2 changes: 2 additions & 0 deletions TrackerConfig/inc/StrawElectronicsConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace mu2e {
Name("verbose"), Comment("verbosity: 0 or 1")};
fhicl::Atom<bool> useDb{
Name("useDb"), Comment("use database or fcl")};
fhicl::Atom<bool> overrideDbTimeOffsets{
Name("overrideDbTimeOffsets"), Comment("Override Db time offsets and set to zero")};

fhicl::Atom<double> defaultThresholddVdI {
Name("defaultThresholddVdI"), Comment("defaultThresholddVdI")};
Expand Down

0 comments on commit c0050b1

Please sign in to comment.