Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 25, 2024
1 parent 0271fb5 commit e3e6796
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 88 deletions.
108 changes: 59 additions & 49 deletions Hcal/src/Hcal/HcalDigiProducer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
*/

#include "Hcal/HcalDigiProducer.h"
#include "Tools/PulseRecord.h"

#include <fstream>

#include "Framework/RandomNumberSeedService.h"
#include "Tools/PulseRecord.h"

namespace hcal {

Expand Down Expand Up @@ -131,7 +133,7 @@ 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
// For plotting purposes
std::vector<std::tuple<double, int, int>> DigiToPlot;
DigiToPlot.clear();

Expand Down Expand Up @@ -219,8 +221,9 @@ void HcalDigiProducer::produce(framework::Event& event) {
iContrib++) {
double voltage = simHit.getContrib(iContrib).edep * MeV_;

std::cout << " Energy deposited: " << simHit.getContrib(iContrib).edep << std::endl;

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) /
Expand Down Expand Up @@ -255,36 +258,39 @@ void HcalDigiProducer::produce(framework::Event& event) {
hcalDigis.addDigi(posendID.raw(), digiToAddPosend);
hcalDigis.addDigi(negendID.raw(), digiToAddNegend);

//for(const auto& digi: hcalDigis){
//std::cout << " DEBUG PRINT 2: " << digi.at(2) << std::endl;
//}
}
// Recording digitized pulses in PulseRecord
// 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();
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());
}
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();
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());
}
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";
for (const auto& entry : DigiToPlot) {
dataFile << std::get<0>(entry) << " " << std::get<1>(entry) << " "
<< std::get<2>(entry) << "\n";
}
dataFile.close();

Expand All @@ -304,50 +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();
// 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());
}
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();
// 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();

} 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();
// 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());
}
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();
// 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();
}
}
}

/******************************************************************************************
* Noise Simulation on Empty Channels
*****************************************************************************************/
//bool noise_ = false;
//std::cout << " noise: " << noise_ << std::endl;
// bool noise_ = false;
// std::cout << " noise: " << noise_ << std::endl;
if (noise_) {
int numChannels = 0;
for (int section = 0; section < hcalGeometry.getNumSections(); section++) {
Expand Down Expand Up @@ -424,7 +434,7 @@ void HcalDigiProducer::produce(framework::Event& event) {
}
} // loop over noise amplitudes

} // if we should add noise
} // if we should add noise

event.add(digiCollName_, hcalDigis);

Expand Down
10 changes: 6 additions & 4 deletions Tools/include/Tools/HgcrocEmulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,13 @@ class HgcrocEmulator {
*/
mutable TF1 pulseFunc_;

mutable std::vector<ldmx::PulseRecord> pulseRecord_ ;
mutable std::vector<ldmx::PulseRecord> pulseRecord_;

//Getter to access pulseRecord_
public:
const std::vector<ldmx::PulseRecord>& getPulseRecord() const { return pulseRecord_;}
// Getter to access pulseRecord_
public:
const std::vector<ldmx::PulseRecord>& getPulseRecord() const {
return pulseRecord_;
}

}; // HgcrocEmulator

Expand Down
32 changes: 16 additions & 16 deletions Tools/include/Tools/PulseRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

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) {}
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_; }
// 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_;
};
}
private:
double volts_;
int adc_;
int tot_;
};
} // namespace ldmx

#endif
#endif
37 changes: 18 additions & 19 deletions Tools/src/Tools/HgcrocEmulator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +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
pulseRecord_.clear(); // clear pulseRecord
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");
Expand Down Expand Up @@ -104,18 +104,18 @@ bool HgcrocEmulator::digitize(
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;
// 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){
// startTOT = true;
// if (toverTOT < hit.second)
// toverTOT = hit.second; // use the latest time in the window
//}

if (bxvolts > totThreshold){
if (bxvolts > totThreshold) {
startTOT = true;
if (toverTOT < hit.second)
toverTOT = hit.second; // use the latest time in the window
Expand Down Expand Up @@ -199,13 +199,12 @@ bool HgcrocEmulator::digitize(
// Now just kill everything...
while (digiToAdd.size() < nADCs_) {
digiToAdd.emplace_back(true, false, // flags to mark type of sample
0x3FF, 0x3FF, 0);
0x3FF, 0x3FF, 0);
}

for(const auto& digi: digiToAdd)
return true; // always readout
for (const auto &digi : digiToAdd) return true; // always readout

} else {
} else {
// determine the voltage at the sampling time
double bxvolts = pulse((iADC - iSOI_) * clockCycle_);
// add noise if requested
Expand All @@ -216,9 +215,9 @@ bool HgcrocEmulator::digitize(
if (adc > 1023) adc = 1023;

// Record in PulseRecord
if(adc >= readoutThreshold){
//pulseRecord_.clear();
pulseRecord_.emplace_back(bxvolts, adc, 0);
if (adc >= readoutThreshold) {
// pulseRecord_.clear();
pulseRecord_.emplace_back(bxvolts, adc, 0);
}

// check for TOA
Expand All @@ -241,7 +240,7 @@ bool HgcrocEmulator::digitize(
adc, // ADC[t] is the second field
toa // TOA is third measurement
);

} // TOT or ADC Mode
} // sampling baskets

Expand Down

0 comments on commit e3e6796

Please sign in to comment.