-
Notifications
You must be signed in to change notification settings - Fork 21
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
Hcal tot digitization #1475
base: trunk
Are you sure you want to change the base?
Hcal tot digitization #1475
Changes from all commits
1e9315e
f615908
5e1bf57
0271fb5
e3e6796
f138fdd
10681b1
be9bab3
513d34c
a8e8e62
f52fed6
9ad60c0
8b77d0d
c300260
986eb69
863a149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,10 @@ | |
|
||
#include "Hcal/HcalDigiProducer.h" | ||
|
||
#include <fstream> | ||
|
||
#include "Framework/RandomNumberSeedService.h" | ||
#include "Tools/PulseRecord.h" | ||
|
||
namespace hcal { | ||
|
||
|
@@ -39,6 +42,10 @@ void HcalDigiProducer::configure(framework::config::Parameters& ps) { | |
// and generate pedestal noise digis in every empty channel | ||
zeroSuppression_ = ps.getParameter<bool>("zeroSuppression"); | ||
|
||
// If true, save digis in a txt file | ||
digiEmulationDebug_ = ps.getParameter<bool>("digiEmulationDebug"); | ||
digiEmulationFile_ = ps.getParameter<std::string>("digiEmulationFile"); | ||
|
||
// collection names | ||
inputCollName_ = ps.getParameter<std::string>("inputCollName"); | ||
inputPassName_ = ps.getParameter<std::string>("inputPassName"); | ||
|
@@ -134,6 +141,10 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
std::vector<std::pair<double, double>> pulses_posend; | ||
std::vector<std::pair<double, double>> pulses_negend; | ||
|
||
// For plotting purposes | ||
std::vector<std::tuple<double, int, int>> DigiToPlot; | ||
DigiToPlot.clear(); | ||
|
||
for (auto psimHit : simBar.second) { | ||
const ldmx::SimCalorimeterHit& simHit = *psimHit; | ||
|
||
|
@@ -223,6 +234,10 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
for (int iContrib = 0; iContrib < simHit.getNumberOfContribs(); | ||
iContrib++) { | ||
double voltage = simHit.getContrib(iContrib).edep * MeV_; | ||
|
||
std::cout << " Energy deposited: " << simHit.getContrib(iContrib).edep | ||
<< std::endl; | ||
|
||
double time = | ||
simHit.getContrib(iContrib).time; // global time (t=0ns at target) | ||
time -= position.at(2) / | ||
|
@@ -255,8 +270,37 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
|
||
bool posEndActivity = | ||
hgcroc_->digitize(posendID.raw(), pulses_posend, digiToAddPosend); | ||
if (digiEmulationDebug_) { | ||
// Recording digitized pulses in PulseRecord | ||
const auto& pulseRecord = hgcroc_->getPulseRecord(); | ||
for (const auto& record : pulseRecord) { | ||
DigiToPlot.emplace_back(record.getVolts(), record.getADC(), | ||
record.getTOT()); | ||
} | ||
} | ||
|
||
bool negEndActivity = | ||
hgcroc_->digitize(negendID.raw(), pulses_negend, digiToAddNegend); | ||
if (digiEmulationDebug_) { | ||
// Recording digitized pulses in PulseRecord | ||
const auto& pulseRecord = hgcroc_->getPulseRecord(); | ||
for (const auto& record : pulseRecord) { | ||
DigiToPlot.emplace_back(record.getVolts(), record.getADC(), | ||
record.getTOT()); | ||
} | ||
} | ||
|
||
if (digiEmulationDebug_) { | ||
// Print Voltages, adc/tot values to the same txt file | ||
std::ofstream dataFile(digiEmulationFile_, std::ios::app); | ||
for (const auto& entry : DigiToPlot) { | ||
dataFile << std::get<0>(entry) << " " << std::get<1>(entry) << " " | ||
<< std::get<2>(entry) << "\n"; | ||
} | ||
// dataFile << "Section: " << section << " Layer: " << layer << " Strip: | ||
// " << strip << "\n"; | ||
dataFile.close(); | ||
} | ||
|
||
if (posEndActivity && negEndActivity && zeroSuppression_) { | ||
hcalDigis.addDigi(posendID.raw(), digiToAddPosend); | ||
|
@@ -280,7 +324,6 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
hcalDigis.addDigi(negendID.raw(), digi); | ||
} | ||
} | ||
|
||
} else { | ||
bool is_posend = false; | ||
std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAdd; | ||
|
@@ -300,6 +343,23 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
hgcroc_->noiseDigi(digiID.raw(), 0.0); | ||
hcalDigis.addDigi(digiID.raw(), digi); | ||
} | ||
// Recording digitized pulses in PulseRecord | ||
// Access PulseRecord | ||
const auto& pulseRecord = hgcroc_->getPulseRecord(); | ||
|
||
for (const auto& record : pulseRecord) { | ||
DigiToPlot.emplace_back(record.getVolts(), record.getADC(), | ||
record.getTOT()); | ||
} | ||
|
||
// Print Voltages, adc/tot values to the same txt file | ||
std::ofstream dataFile("Voltage_ADC_TOT.txt", std::ios::app); | ||
for (const auto& entry : DigiToPlot) { | ||
dataFile << std::get<0>(entry) << " " << std::get<1>(entry) << " " | ||
<< std::get<2>(entry) << "\n"; | ||
} | ||
dataFile.close(); | ||
|
||
Comment on lines
+346
to
+362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the code blocks that could be skipped if the user doesn't want to save the digi emulation detailed information. |
||
} else { | ||
ldmx::HcalDigiID digiID(section, layer, strip, 1); | ||
if (hgcroc_->digitize(digiID.raw(), pulses_negend, digiToAdd)) { | ||
|
@@ -309,13 +369,32 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
hgcroc_->noiseDigi(digiID.raw(), 0.0); | ||
hcalDigis.addDigi(digiID.raw(), digi); | ||
} | ||
|
||
// Recording digitized pulses in PulseRecord | ||
// Access PulseRecord | ||
const auto& pulseRecord = hgcroc_->getPulseRecord(); | ||
|
||
for (const auto& record : pulseRecord) { | ||
DigiToPlot.emplace_back(record.getVolts(), record.getADC(), | ||
record.getTOT()); | ||
} | ||
|
||
// Print Voltages, adc/tot values to the same txt file | ||
std::ofstream dataFile("Voltage_ADC_TOT.txt", std::ios::app); | ||
for (const auto& entry : DigiToPlot) { | ||
dataFile << std::get<0>(entry) << " " << std::get<1>(entry) << " " | ||
<< std::get<2>(entry) << "\n"; | ||
} | ||
dataFile.close(); | ||
Comment on lines
+372
to
+388
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the code blocks that could be skipped if the user doesn't want to save the digi emulation detailed information. |
||
} | ||
} | ||
} | ||
|
||
/****************************************************************************************** | ||
* Noise Simulation on Empty Channels | ||
*****************************************************************************************/ | ||
// bool noise_ = false; | ||
// std::cout << " noise: " << noise_ << std::endl; | ||
if (noise_) { | ||
std::vector<ldmx::HcalDigiID> channelMap; | ||
int numChannels = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef TOOLS_PULSERECORD_H_ | ||
#define TOOLS_PULSERECORD_H_ | ||
|
||
// new class PulseRecord for plotting purposes | ||
|
||
namespace ldmx { | ||
|
||
class PulseRecord { | ||
public: | ||
// Constructor to initialize Voltage, ADC, and TOT | ||
PulseRecord(double volts, int adc, int tot) | ||
: volts_(volts), adc_(adc), tot_(tot) {} | ||
|
||
// Getters for the recorded data | ||
double getVolts() const { return volts_; } | ||
int getADC() const { return adc_; } | ||
int getTOT() const { return tot_; } | ||
|
||
private: | ||
double volts_; | ||
int adc_; | ||
int tot_; | ||
}; | ||
} // namespace ldmx | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,8 @@ bool HgcrocEmulator::digitize( | |
std::vector<ldmx::HgcrocDigiCollection::Sample> &digiToAdd) const { | ||
// step 0: prepare ourselves for emulation | ||
|
||
digiToAdd.clear(); // make sure it is clean | ||
digiToAdd.clear(); // make sure it is clean | ||
pulseRecord_.clear(); // clear pulseRecord | ||
|
||
// Configure chip settings based off of table (that may have been passed) | ||
double totMax = getCondition(channelID, "TOT_MAX"); | ||
|
@@ -100,8 +101,20 @@ bool HgcrocEmulator::digitize( | |
continue; // if this hit wasn't in the current BX, continue... | ||
|
||
double vpeak = pulse(hit.second); | ||
double bxvolts = pulse((iADC - iSOI_) * clockCycle_); | ||
|
||
// std::cout << "DEBUG PRINT - COMPARE IN COMING VOLTAGE AND PULSE FUNC | ||
// VOLTAGE" << std::endl; std::cout << " Incoming peak Voltage: " << | ||
// vpeak << std::endl; std::cout << " Pulse func Voltage: " << bxvolts | ||
// << std::endl; std::cout << " " << std::endl; | ||
|
||
// if (vpeak > totThreshold){ | ||
// startTOT = true; | ||
// if (toverTOT < hit.second) | ||
// toverTOT = hit.second; // use the latest time in the window | ||
//} | ||
|
||
if (vpeak > totThreshold) { | ||
if (bxvolts > totThreshold) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the part that I am worried about effecting the ECal digi emulation as well. This is a substantial change and could affect things there and, while the change is well motivated, I would like to understand what the results are. |
||
startTOT = true; | ||
if (toverTOT < hit.second) | ||
toverTOT = hit.second; // use the latest time in the window | ||
|
@@ -133,6 +146,8 @@ bool HgcrocEmulator::digitize( | |
double charge_deposited = | ||
(pulse(toverTOT) - gain * pedestal) * padCapacitance; | ||
|
||
double voltaGe = (pulse(toverTOT) - gain * pedestal); | ||
|
||
// Measure Time Over Threshold (TOT) by using the drain rate. | ||
// 1. Use drain rate to see how long it takes for the charge to drain off | ||
// 2. Translate this into DIGI samples | ||
|
@@ -149,7 +164,7 @@ bool HgcrocEmulator::digitize( | |
// to measure a maximum of tot Max [ns] | ||
int tdc_counts = int(tot * 4096 / totMax) + pedestal; | ||
|
||
// were we already over TOA? TOT is reported in BX where TOA went over | ||
// were we already over TOnA? TOT is reported in BX where TOA went over | ||
// threshold... | ||
int toa{0}; | ||
if (wasTOA) { | ||
|
@@ -172,6 +187,10 @@ bool HgcrocEmulator::digitize( | |
toa // TOA is third measurement | ||
); | ||
|
||
// Record in PulseRecord | ||
pulseRecord_.clear(); | ||
pulseRecord_.emplace_back(voltaGe, 0, tdc_counts); | ||
|
||
// TODO: properly handle saturation and recovery, eventually. | ||
// Now just kill everything... | ||
while (digiToAdd.size() < nADCs_) { | ||
|
@@ -180,6 +199,7 @@ bool HgcrocEmulator::digitize( | |
} | ||
|
||
return true; // always readout | ||
|
||
} else { | ||
// determine the voltage at the sampling time | ||
double bxvolts = pulse((iADC - iSOI_) * clockCycle_); | ||
|
@@ -190,6 +210,12 @@ bool HgcrocEmulator::digitize( | |
if (adc < 0) adc = 0; | ||
if (adc > 1023) adc = 1023; | ||
|
||
// Record in PulseRecord | ||
if (adc >= readoutThreshold) { | ||
// pulseRecord_.clear(); | ||
pulseRecord_.emplace_back(bxvolts, adc, 0); | ||
} | ||
|
||
// check for TOA | ||
int toa(0); | ||
if (pulse(startBX) < toaThreshold && overTOA) { | ||
|
@@ -210,6 +236,7 @@ bool HgcrocEmulator::digitize( | |
adc, // ADC[t] is the second field | ||
toa // TOA is third measurement | ||
); | ||
|
||
} // TOT or ADC Mode | ||
} // sampling baskets | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the code blocks that could be skipped if the user doesn't want to save the digi emulation detailed information.