-
Notifications
You must be signed in to change notification settings - Fork 35
Feature/howard spillquality #390
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
Feature/howard spillquality #390
Conversation
…he spill quality for the spill that goes with a given event, and code supporting that.
…wants to use this spill. The other checks not just for the first event but the first event OF A GIVEN STREAM for the numi case.
|
One other thing to check is that we probably want some way to directly check in the CAFs |
|
Per @PetrilloAtWork request to make things less confusing (even if we still have to figure out about the differences between this and develop) I've changed the base branch to be |
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.
Looks ok, comments left mostly for C++ improval plus an error that I would prefer to be fatal.
Becomes approval if you think it's ok as is.
Ok, it's already approval because I messed up. But it's ok.
sbncode/CAFMaker/CAFMaker_module.cc
Outdated
| if ( fBNBInfoEventMap.find(info.event)==fBNBInfoEventMap.end() ) { | ||
| fBNBInfoEventMap[info.event] = info; | ||
| } | ||
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > |
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.
Can you put this into a function, like:
namespace {
template <typename SpillInfo>
double spillInfoToTimestamp(SpillInfo const& info) {
return static_cast<double>(info.spill_time_s)
+ static_cast<double>(info.spill_time_ns)*1e-9;
}
}Even better would be to add a timestamp() member function to caf::SRBNBSpillInfo and sister.
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.
Good idea! Is the namespace { } enclosure here just a generic template of such a function or do you prefer it live in a specific namespace? Otherwise, I was thinking to just put it in caf namespace in the code.
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.
The unnamed namespace has a specific meaning, in that its content is not visible outside the translation unit C++ source file where it is defined. For example, if I wrote a header file cheater.h like:
template <typename SpillInfo>
double spillInfoToTimestamp(SpillInfo const& info);and I included it in another source file:
#include "cheater.h"
double const timeStamp = spillInfoToTimestamp(SpillInfo{});this would fail linking because spillInfoToTimestamp would not be found anywhere.
[example faults: (1) for a template this should not be done in such way anyway (pretend it's not a template) and (2) the header where SpillInfo is declared needs to be included somewhere]
sbncode/CAFMaker/CAFMaker_module.cc
Outdated
| if ( fBNBInfoEventMap.find(info.event)==fBNBInfoEventMap.end() ) { | ||
| fBNBInfoEventMap[info.event] = info; | ||
| } | ||
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > | ||
| (fBNBInfoEventMap[info.event].spill_time_s+(fBNBInfoEventMap[info.event].spill_time_ns/1.0e9)) ) { | ||
| fBNBInfoEventMap[info.event] = info; | ||
| } |
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.
Minor point: optimisation to reduce lookups in the map:
| if ( fBNBInfoEventMap.find(info.event)==fBNBInfoEventMap.end() ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > | |
| (fBNBInfoEventMap[info.event].spill_time_s+(fBNBInfoEventMap[info.event].spill_time_ns/1.0e9)) ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| auto const iInfo = fBNBInfoEventMap.find(info.event); | |
| if ( iInfo==fBNBInfoEventMap.end() ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > | |
| (iInfo->spill_time_s+(iInfo->spill_time_ns/1.0e9)) ) { | |
| *iInfo = info; | |
| } |
Another approach is a bit more convoluted:
| if ( fBNBInfoEventMap.find(info.event)==fBNBInfoEventMap.end() ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > | |
| (fBNBInfoEventMap[info.event].spill_time_s+(fBNBInfoEventMap[info.event].spill_time_ns/1.0e9)) ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| auto& storedInfo = fBNBInfoEventMap[info.event]; | |
| if (storedInfo.event == UINT_MAX) { // no info | |
| storedInfo = info; | |
| } | |
| else if ( (info.spill_time_s+info.spill_time_ns/1.0e9) > | |
| (storedInfo.spill_time_s+storedInfo.spill_time_ns/1.0e9)) ) { | |
| storedInfo = info; | |
| } |
which relies on the fact that a default-constructed SpillInfo object has an event number UINT_MAX; or, merging with the other suggestion:
| if ( fBNBInfoEventMap.find(info.event)==fBNBInfoEventMap.end() ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| else if ( (info.spill_time_s+(info.spill_time_ns/1.0e9)) > | |
| (fBNBInfoEventMap[info.event].spill_time_s+(fBNBInfoEventMap[info.event].spill_time_ns/1.0e9)) ) { | |
| fBNBInfoEventMap[info.event] = info; | |
| } | |
| auto& storedInfo = fBNBInfoEventMap[info.event]; // creates if needed | |
| if ((storedInfo.event == UINT_MAX) // no info | |
| || spillInfoToTimestamp(info) > spillInfoToTimestamp(storedInfo) // newer | |
| { | |
| storedInfo = std::move(info); | |
| } |
sbncode/CAFMaker/CAFMaker_module.cc
Outdated
| std::cout << "Found > 0 BNBInfo size and NuMIInfo size, which seems strange. Will not fill event-specific spill quality info for this event..." << std::endl; | ||
| } | ||
| else if ( fHasBNBInfo ) { | ||
| if ( fBNBInfoEventMap.find(evt.id().event()) == fBNBInfoEventMap.end() ) |
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.
Or, more intelligible:
| if ( fBNBInfoEventMap.find(evt.id().event()) == fBNBInfoEventMap.end() ) | |
| unsigned int const eventNo = evt.id().event(); | |
| if ( fBNBInfoEventMap.count(eventNo) == 0 ) |
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.
Wait shouldn't count > 0 if fHasBNBInfo ?
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.
That count "counts" the number of entries in the map for eventNo: there may be some information (in which case presumably fHasBNBInfo is true), but the one for eventNo might be missing, in which case that count(eventNo) returns 0.
I would call that situation a problem, but technically it is possible.
sbncode/CAFMaker/CAFMaker_module.cc
Outdated
| else rec.hdr.spillbnbinfo = makeSRBNBInfo(fBNBInfoEventMap.at(evt.id().event())); | ||
| } | ||
| else if ( fHasNuMIInfo ) { | ||
| if ( fNuMIInfoEventMap.find(evt.id().event()) == fNuMIInfoEventMap.end() ) |
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.
Ditto.
|
@PetrilloAtWork does what I just pushed address your idea with the Tried to address other points as well, let me know if something misses the mark. Thanks for the suggestions! (Will be running a test to see that I get the same POT values or something else as with my previous test.) |
| auto const & raw_data = (*raw_data_ptr); | ||
|
|
||
| // NOTE: Really we should skip the first event of each trigger type, so let's make this look at that too... | ||
| if ( raw_data.size()==0 ) return; |
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.
I can't believe I missed one of my favourite pet peeves!
| if ( raw_data.size()==0 ) return; | |
| if ( raw_data.empty() ) return; |
PetrilloAtWork
left a comment
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.
I confirm the approval.
|
@brucehoward-physics @PetrilloAtWork Is this still needed for the " current ICARUS production" or as been discussed can go into develop and into the soon coming new production release? |
I hereby summon @SFBayLaser since I definitely don't have knowledge current enough to answer. |
|
I'm seeing something slightly strange in my last test so probably best to not merge just yet... I'll try to figure out what's going on (or re-do the test?)... |
|
I don't know what happened with my initial attempted retest where things didn't seem to add up but I am getting the same output POT I got the first time, so I'm back to thinking this is okay... I even added the fix for @PetrilloAtWork 's preference to use |
|
Hi @brucehoward-physics , since I haven't heard anyone object and #407 got merged, I am closing this PR now. Many thanks! |
Putting together PR for a couple of spill info updates to try to get things into the CAFs and in a way that we can also start to do beam quality cuts. Some questions notes:
See some info in doc-33224 slides 5-13
IMPORTANT (!!) -- I'm not sure if I should be making this PR against develop or v09_72_00_05 e.g. There seem to be a lot of commits present in the latter but not in develop as my changes are only the last few commits...
Think some additional similar changes may be needed in BNB module(s) but probably would be a PR from their side — including Joseph and Jacob L in the conversation here.
What else do we need for validation? (See some info at doc-33224)
Do we want these parts
(info.spill_time_s+(info.spill_time_ns/1.0e9))to instead do something with more precision?We probably want to talk to NOvA to remember how they handle the POT sums within CAFAna and with spill quality cuts, but this PR is more about getting the info available for use rather than the internal workings. But it's possible that the way of saving them would preclude certain usage patterns.
Tagging some reviewers that I think make sense given this touches trigger info, spill accounting, CAFs, etc.