Skip to content
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

TRestDetectorSingleChannelAnalysisProcess fixes #29

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/TRestDetectorSingleChannelAnalysisProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TRestDetectorSingleChannelAnalysisProcess : public TRestEventProcess {
any GetOutputEvent() { return fSignalEvent; }

void FitChannelGain();
// See comments on CXX
void SaveGainMetadata(string filename);
void InitProcess();
TRestEvent* ProcessEvent(TRestEvent* eventInput);
Expand Down
34 changes: 21 additions & 13 deletions src/TRestDetectorSingleChannelAnalysisProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ void TRestDetectorSingleChannelAnalysisProcess::InitProcess() {
fCalib = GetMetadata<TRestDetectorGainMap>();
if (fReadout == NULL) {
} else {
auto readout = *fReadout;
for (int i = 0; i < readout.GetNumberOfReadoutPlanes(); i++) {
auto plane = readout[i];
for (int j = 0; j < plane.GetNumberOfModules(); j++) {
auto mod = plane[j];
for (int k = 0; k < mod.GetNumberOfChannels(); k++) {
auto channel = mod[k];
fChannelGain[channel.GetDaqID()] = 1; // default correction factor is 1
fChannelGainError[channel.GetDaqID()] = 1; // relative error
fChannelThrIntegral[channel.GetDaqID()] =
new TH1D(Form("h%i", channel.GetDaqID()), Form("h%i", channel.GetDaqID()), 100, 0,
for (int i = 0; i < fReadout->GetNumberOfReadoutPlanes(); i++) {
auto plane = fReadout->GetReadoutPlane(i);
for (int j = 0; j < plane->GetNumberOfModules(); j++) {
auto mod = plane->GetModule(j);
for (int k = 0; k < mod->GetNumberOfChannels(); k++) {
auto channel = mod->GetChannel(k);
fChannelGain[channel->GetDaqID()] = 1; // default correction factor is 1
fChannelGainError[channel->GetDaqID()] = 1; // relative error
fChannelThrIntegral[channel->GetDaqID()] =
new TH1D(Form("h%i", channel->GetDaqID()), Form("h%i", channel->GetDaqID()), 100, 0,
fSpecFitRange.Y() * 1.5);
}
}
Expand Down Expand Up @@ -169,7 +168,7 @@ TRestEvent* TRestDetectorSingleChannelAnalysisProcess::ProcessEvent(TRestEvent*
void TRestDetectorSingleChannelAnalysisProcess::EndProcess() {
if (fCreateGainMap) {
FitChannelGain();
SaveGainMetadata(fCalibSave);
// SaveGainMetadata(fCalibSave);
}
}

Expand Down Expand Up @@ -240,6 +239,13 @@ void TRestDetectorSingleChannelAnalysisProcess::FitChannelGain() {
}
}

/*** This should not be done. The framework saves any metadata structure inside of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am exporting a calibration file containing TRestDetectorGainMap metadata object. I think a calibration file should not contain observables. Yes, newing a TRestRun object is bad. I can use TRestRun of the process to store calibration data.

* common TRestRun during processing. If TRestRun does not know a particular metadata
* instance, then it should be added to the run, and it will be written to disk with it.
* If we want just to have a method to export data, in principe it is possible. But
* better without using a new TRestRun instance. TRestRun should only be created for
* writting the standard processing scheme.
***/
void TRestDetectorSingleChannelAnalysisProcess::SaveGainMetadata(string filename) {
cout << "TRestDetectorSingleChannelAnalysisProcess: saving result..." << endl;

Expand All @@ -251,16 +257,18 @@ void TRestDetectorSingleChannelAnalysisProcess::SaveGainMetadata(string filename
fCalib->fChannelGain = fChannelGain;
fCalib->SetName("ChannelCalibration");

TRestRun* r = new TRestRun();
TRestRun* r = (TRestRun*)fRunInfo->Clone();
r->SetOutputFileName(filename);
r->AddMetadata(fCalib);
r->AddMetadata(fReadout);
r->AddMetadata(this);
r->FormOutputFile();

PrintChannelSpectrums(filename);
delete r;
}


TH1D* TRestDetectorSingleChannelAnalysisProcess::GetChannelSpectrum(int id) {
if (fChannelThrIntegral.count(id) != 0) return fChannelThrIntegral[id];
return NULL;
Expand Down