Skip to content

Feature/ascarpel timing pmt crt#440

Merged
mmrosenberg merged 39 commits intodevelopfrom
feature/ascarpel_timing_pmt_crt
Nov 1, 2022
Merged

Feature/ascarpel timing pmt crt#440
mmrosenberg merged 39 commits intodevelopfrom
feature/ascarpel_timing_pmt_crt

Conversation

@ascarpel
Copy link
Copy Markdown
Contributor

@ascarpel ascarpel commented Sep 7, 2022

This PR introduces several changes related to the PMT system and the way timing is corrected and calculated:

  1. In Decode/ChannelMapping: modified the PMTChannelMapping to include the laser optical channel in preparation of a future PR including the code for the laser calibration. It should be harmless
  2. In PMT/ICARUSFlashAssAna_module.cc new variable are added to the TTree holding the OpFlash information. The new variables group together OpHit-level information related to the same PMT, in order to have a more intuitive overview of the components of each single OpFlash . It should be harmless although it would be good to verify the final data size of the calibration ntuples after this modification and verify if compatible with the space allocated
  3. Files Timing/PMTTimingCorrectionService_service.cc , Timing/PMTTimingCorrectionsProvider.* are added to include a new LArSoft service that interface with the PostgreSQL calibration database and load the database entries given a run number. It should be verified the robustness of the code proposed and if there is room to improve its speed and performance.
  4. A new data product Timing/DataProducts/PMTWaveformTimeCorrection.* with the corresponding extractor PMTWaveformTimeCorrectionExtractor.* is designed to calculate and hold the time correction coming from the sampled reference signal on the spare channel of the CAEN1730V digitizers. This would allow dropping the corresponding waveform (the ones that now are saved with the instances “trigprm”, “BNB”, “NuMI”). The data product is saved following the same convention followed for the waveforms
  5. A module called Timing/OpHitTimingCorrection_module.cc which takes the OpHit data products vector and generates a new OpHit data product list with PeakTimeAbs() and PeakTime()corrected for the delays calculated using the laser and muon calibration. The choice to apply that correction to the OpHit was made to preserve the representation of the OpWaveform::TimeStamp()
  6. Changes to DaqDecoderICARUSPMT_module.cc to implement the correction of the first two bullet point above and produces the PMTWaveformTimeCorrection data-products. It also recalculates the OpWaveform::TimeStamp() recalculating the offset starting from the sample of the "trgprim" labelled waveform. It should be verified if this approach is valid and consistent with the remaining part of the decoder logic.

There should be backward compatibility with data collected previously, however, since most of the changes apply to the stage0 step of the production. Older samples must be reprocessed to include the changes here introduced

@mmrosenberg
Copy link
Copy Markdown
Contributor

trigger build

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for c7:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for e20:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

⚠️ CI build for ICARUS Warning at phase ci_tests ICARUS on slf7 for c7:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the warning phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

⚠️ CI build for ICARUS Warning at phase ci_tests ICARUS on slf7 for e20:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the warning phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

* the update with a new run was already removed from the interface
* map access replaced with read-only one
* default values for missing entries explicitly implemented
* algorithms use `icarusDB::PMTTimingCorrections` interface (can store it in a constant reference data member)
* art modules provide them the object with that interface via the `icarusDB::IPMTTimingCorrectionService` service interface:
  `lar::providerFrom<icarusDB::IPMTTimingCorrectionService>()` or equivalent returns the pointer the algorithms need
* configuration must include the service `IPMTTimingCorrectionService` and specify its implementation
  (currently only `PMTTimingCorrectionService` is provided
Previously, the corrections were in ophitcorr, which was then used for creating flashes.
@PetrilloAtWork
Copy link
Copy Markdown
Member

PetrilloAtWork commented Sep 25, 2022

The last commit is a fix triggered by a report by @francescopoppi and @aheggest who did not see the time correction on the hits in some output trees. The branch was creating the ophitcorr data product from ophit, and using the former for reconstructing the flashes, which is all well and good as long as you use the flashes. But some trees (simpleLightAna and probably any CAF tree) used to pick ophit which still did not have the correction.
Now ophit is corrected, and the uncorrected... ophituncorrected is just an accident of the workflow. We can even drop it if it bothers (edit: in fact, that's what the Stage0 configuration does). The corrections are saved in their own data product, in case one wanted to attempt to change or undo them.

Copy link
Copy Markdown
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

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

The main requests were addressed. I have become part of the solution, so my review is not fair any more.
Thus, I hereby approve.

// Get the laserChannelNumber
char laserChannelBuffer[10];
getStringValue(tuple, 7, laserChannelBuffer, sizeof(laserChannelBuffer), &error);
if (error) throw std::runtime_error("Encountered error when trying to recover the PMT laser channel label");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to know which error that was. e.g.:

Suggested change
if (error) throw std::runtime_error("Encountered error when trying to recover the PMT laser channel label");
if (error) throw std::runtime_error("Encountered error (code: " + std::to_string(error) + ") when trying to recover the PMT laser channel label");

This of course is a general comment for the class (and of course I don't expect you to change this all the way in this context).

getStringValue(tuple, 7, laserChannelBuffer, sizeof(laserChannelBuffer), &error);
if (error) throw std::runtime_error("Encountered error when trying to recover the PMT laser channel label");
std::string laserChannelLabel(laserChannelBuffer, 2, sizeof(laserChannelBuffer)); //sizeof(digitizerBuffer));
unsigned int laserChannel = std::stol(laserChannelLabel); // try-catch syntax for stol or not necessary ?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Necessary if we want meaningful error messages (remember the error from the trigger decoder? the entirety of the message was: stoi).

Suggested change
unsigned int laserChannel = std::stol(laserChannelLabel); // try-catch syntax for stol or not necessary ?
unsigned int laserChannel;
try {
laserChannel = std::stol(laserChannelLabel);
}
catch(std::logic_error const& e) {
throw std::runtime_error("Invalid laser channel number from digitizer " + digitizerLabel + ": " + laserChannelLabel + " (\"" + e.what() + "\")";
}


// Read the laser channel
std::string laserChannelLabel = argv[7]; // format is L-<number> . <number> is int from [1-41]
unsigned int laserChannel = std::stol(laserChannelLabel.substr(2,4)); // try-catch syntax for stol or not necessary ?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Necessary if we want meaningful error messages (remember my last comment? yes, this is C&P).

Suggested change
unsigned int laserChannel = std::stol(laserChannelLabel.substr(2,4)); // try-catch syntax for stol or not necessary ?
unsigned int laserChannel;
try {
laserChannel = std::stol(laserChannelLabel.substr(2,4));
}
catch(std::logic_error const& e) {
throw std::runtime_error("Invalid laser channel number for fragment " + std::to_string(fragmentID) + " channel " std::to_string(digitizerChannelNo) + ": " + laserChannelLabel + " (\"" + e.what() + "\")";
}

* Then define the function interface to fill these data structures
*/
using DigitizerChannelChannelIDPair = std::pair<size_t,size_t>;
using DigitizerChannelChannelIDPair = std::tuple<size_t,size_t,size_t>; // std::tuple<DigitizerChannel, ChannelID, LaserChannel>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lui, lei te... un paio in tre. 😉

bool const fRequireBoardConfig;

/// String of the instance to use for the time corrections
std::string fCorrectionInstance;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To follow the pattern in the module:

Suggested change
std::string fCorrectionInstance;
std::string const fCorrectionInstance;

(not a bit deal, but it prevents "accidental" modifications)

Comment on lines +1403 to +1405
for (std::string const& instanceName: getAllInstanceNames()){
if( instanceName.empty() ) continue;
produces<std::vector<icarus::timing::PMTWaveformTimeCorrection>>(instanceName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there is a merge issue here.

Suggested change
for (std::string const& instanceName: getAllInstanceNames()){
if( instanceName.empty() ) continue;
produces<std::vector<icarus::timing::PMTWaveformTimeCorrection>>(instanceName);
if (!fSkipWaveforms) {
for (std::string const& instanceName: getAllInstanceNames())
produces<std::vector<raw::OpDetWaveform>>(instanceName);
}
for (std::string const& instanceName: getAllInstanceNames()){
if( instanceName.empty() ) continue;
produces<std::vector<icarus::timing::PMTWaveformTimeCorrection>>(instanceName);

My suggestion here honours fSkipWaveforms in writing the waveforms only if requested, but it always writes the correction. In alternative, the corrections may be written only when the waveforms are.
I don't believe there is one rightful solution here, since the SkipWaveforms option is there just for debug.

Comment on lines +1407 to +1408

produces<std::vector<raw::OpDetWaveform>>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tail of the merge issue above.

Suggested change
produces<std::vector<raw::OpDetWaveform>>();

= [&digitizerChannelVec](unsigned short int channelNumber) -> raw::Channel_t
{
for (auto const [ chNo, chID ]: digitizerChannelVec)
for (auto const [ chNo, chID, _ ]: digitizerChannelVec) // too pythonic?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have seen that (rarely) in C++ too. Maybe from people used to Python...

Copy link
Copy Markdown
Contributor

@SFBayLaser SFBayLaser left a comment

Choose a reason for hiding this comment

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

I am not entirely sure why I was selected as a reviewer here since I am not familiar with the details of this code. I see that Gianluca has done a comprehensive review and given his long track record of careful work if he has approved then it is fine for me.

@rennney
Copy link
Copy Markdown
Contributor

rennney commented Sep 26, 2022

trigger build

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for c7:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for e20:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

❌ CI build for ICARUS Failed at phase ci_tests ICARUS on slf7 for c7:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the failed phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

❌ CI build for ICARUS Failed at phase ci_tests ICARUS on slf7 for e20:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the failed phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@PetrilloAtWork
Copy link
Copy Markdown
Member

I am not entirely sure why I was selected as a reviewer here since I am not familiar with the details of this code. I see that Gianluca has done a comprehensive review and given his long track record of careful work if he has approved then it is fine for me.

AKA: "if the branch messes up anything, it's his fault."

@rennney rennney mentioned this pull request Sep 30, 2022
@ascarpel
Copy link
Copy Markdown
Contributor Author

ascarpel commented Oct 5, 2022

After a quick investigation, the CI test failure is related to the change of the Optical Hit reconstruction process name. the former ophit is now ophituncorrected while since this PR the ophit relates to the OpHit corrected including timing. The new names should be appropriately homogenized across the framework, in particular for Monte Carlo configuration files.

@ascarpel
Copy link
Copy Markdown
Contributor Author

ascarpel commented Oct 5, 2022

commit 60121d3 should fix the above

@rennney
Copy link
Copy Markdown
Contributor

rennney commented Oct 5, 2022

trigger build

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for c7:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for e20:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

❌ CI build for ICARUS Failed at phase ci_tests ICARUS on slf7 for c7:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the failed phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

❌ CI build for ICARUS Failed at phase ci_tests ICARUS on slf7 for e20:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the failed phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@mmrosenberg
Copy link
Copy Markdown
Contributor

trigger build

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for e20:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

✔️ CI build for LArSoft Succeeded on slf7 for c7:prof -- details available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

⚠️ CI build for ICARUS Warning at phase ci_tests ICARUS on slf7 for c7:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the warning phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@FNALbuild
Copy link
Copy Markdown
Collaborator

⚠️ CI build for ICARUS Warning at phase ci_tests ICARUS on slf7 for e20:prof - ignored warnings for build -- details available through the CI dashboard

🚨 For more details about the warning phase, check the ci_tests ICARUS phase logs

parent CI build details are available through the CI dashboard

@rennney
Copy link
Copy Markdown
Contributor

rennney commented Oct 12, 2022

@PetrilloAtWork Hi, we got a merge conflict with recent restructuring of icarus config files. Please have a look

SFBayLaser added a commit that referenced this pull request Oct 15, 2022
… (feature/ascarpel_timing_pmt_crt, see Pull Request #440) with updates to fhicl files to include the CRT hits in stage 0. This became a bit complicated by the base of Andrea's feature branch being before the restructuring of fhicl files so I've had to reconcile that. As well, I moved the new PMT data product to the IcarusObj folder so we can be sure of where are data objects are. Note that I did not reconcile the fhicl files directly related to production running so some of the special case PMT fhicl files still need reconciliation.
mmrosenberg added a commit that referenced this pull request Nov 1, 2022
…d_crt_stage0

Reconcile PR #440 with new fhicl file format, include CRT in stage 0
@mmrosenberg mmrosenberg merged commit 5987b73 into develop Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants