-
Notifications
You must be signed in to change notification settings - Fork 20
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
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 { | ||
|
||
|
@@ -130,6 +133,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; | ||
|
||
|
@@ -213,6 +220,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) / | ||
|
@@ -246,7 +257,44 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
hgcroc_->digitize(negendID.raw(), pulses_negend, digiToAddNegend)) { | ||
hcalDigis.addDigi(posendID.raw(), digiToAddPosend); | ||
hcalDigis.addDigi(negendID.raw(), digiToAddNegend); | ||
} // Back Hcal needs to digitize both pulses or none | ||
|
||
// for(const auto& digi: hcalDigis){ | ||
// std::cout << " DEBUG PRINT 2: " << digi.at(2) << std::endl; | ||
// } | ||
} | ||
|
||
// Recording digitized pulses in PulseRecord | ||
// Since two pulses are digitized, using existing loop is bit untidy. | ||
// Access PulseRecord | ||
if (hgcroc_->digitize(posendID.raw(), pulses_posend, digiToAddPosend) && | ||
hgcroc_->digitize(negendID.raw(), pulses_negend, digiToAddNegend)) { | ||
const auto& pulseRecord = hgcroc_->getPulseRecord(); | ||
|
||
for (const auto& record : pulseRecord) { | ||
DigiToPlot.emplace_back(record.getVolts(), record.getADC(), | ||
record.getTOT()); | ||
} | ||
} | ||
|
||
if (hgcroc_->digitize(posendID.raw(), pulses_negend, digiToAddNegend) && | ||
hgcroc_->digitize(posendID.raw(), pulses_posend, digiToAddPosend)) { | ||
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
+289
to
+295
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 chunk of code (and the others like it) is incredibly helpful for you the developer when tuning the digitization parameters; however, most people running this producer will not be tuning the parameters and creating an extra txt file would at best be confusing and at worst cause extra issues. My request here is to put these code blocks behind a configuration parameter such that the user can choose whether to save the digitization information. Maybe a |
||
|
||
// Back Hcal needs to digitize both pulses or none | ||
} else { | ||
bool is_posend = false; | ||
std::vector<ldmx::HgcrocDigiCollection::Sample> digiToAdd; | ||
|
@@ -262,18 +310,54 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
if (hgcroc_->digitize(digiID.raw(), pulses_posend, digiToAdd)) { | ||
hcalDigis.addDigi(digiID.raw(), digiToAdd); | ||
} | ||
// 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
+313
to
+329
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)) { | ||
hcalDigis.addDigi(digiID.raw(), digiToAdd); | ||
} | ||
|
||
// 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
+335
to
+351
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_) { | ||
int numChannels = 0; | ||
for (int section = 0; section < hcalGeometry.getNumSections(); section++) { | ||
|
@@ -349,7 +433,8 @@ void HcalDigiProducer::produce(framework::Event& event) { | |
} | ||
} | ||
} // loop over noise amplitudes | ||
} // if we should add noise | ||
|
||
} // if we should add noise | ||
|
||
event.add(digiCollName_, hcalDigis); | ||
|
||
|
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"); | ||||||||
|
@@ -101,8 +102,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 | ||||||||
|
@@ -134,6 +147,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 | ||||||||
|
@@ -153,7 +168,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) { | ||||||||
|
@@ -176,14 +191,19 @@ 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_) { | ||||||||
digiToAdd.emplace_back(true, false, // flags to mark type of sample | ||||||||
0x3FF, 0x3FF, 0); | ||||||||
} | ||||||||
|
||||||||
return true; // always readout | ||||||||
for (const auto &digi : digiToAdd) return true; // always readout | ||||||||
|
||||||||
Comment on lines
-186
to
+206
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. You don't need the for loop. It will exit on the first entry in the for loop anyways.
Suggested change
|
||||||||
} else { | ||||||||
// determine the voltage at the sampling time | ||||||||
double bxvolts = pulse((iADC - iSOI_) * clockCycle_); | ||||||||
|
@@ -194,6 +214,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) { | ||||||||
|
@@ -214,6 +240,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.