Skip to content

Conversation

@fengyvoid
Copy link
Contributor

@fengyvoid fengyvoid commented Jan 20, 2025

EBPMT Tool in EventBuildingV2 tool set.

This is splitted from PR #307, I agree that it's definitely easier to submit tools one by one and not necessary to submit by a whole tool chain. I will also list the changes based on your comments in #307.

Changes based on your comments:

· Can we translate EBPMT.cpp line 386 to english please?
Yes, now it's at 396 - 398

@marc1uk
Copy link
Collaborator

marc1uk commented Feb 24, 2025

RWMRawWaveforms and BRFRawWaveforms (lines 29,30) are both immediately leaked by lines 46,47.
It would be sensible to either check the return of the corresponding Get calls. It may also be worth checking the corresponding pointers are not null before de-referencing them in the following log lines.

Is it worth moving the check on line 76 to line 44; is this just doing needless work if those checks are both false?

i think line 122 should be enclosed with line 121 in { } for line 120 to prevent spurious printouts.

It seems like it may not be intended that the printout in line 125 may result in the insertion of an element into the AlmostCompletedWavefroms map via operator[].
Same for line 137. Note that .at calls will throw in the event that the element doesn't exist - there may be more logic required to avoid that. I'm getting a bit lost with the different potential if conditions. May be better to check & access the map just once and re-use the result.

Would suggest using references on lines 152, 154, 284, 290, 295, 297, 446, 447, 450-453 to avoid copies.

Not sure if the logic prohibits it but would suggest for good practice the use of emplace rather than operator[] and checking the return value second to avoid potentially clobbering previous entries on lines 325, 326, 327.

1. I move the get and check of `RWMRawWaveforms` and `BRFRawWaveforms` to line 75 to 85.
2. I move the check and return to line 44-49.
3. The line 122 was still at 122, but only print after the `[]`
4. For line 125 and 137, I change the usage of `[]` to a int AlmostCompleteWaveforms_CountHere, initialized to be zero.
5. I would want to use that but may want to leave this to future optimization... since everything is working right now. (not perfectly because I do see zero PMT waveform from some timestamps, but they can be removed in later steps no matter where they are from)
6. Now at line 339 to 341, changed to emplace as you suggest.
@fengyvoid
Copy link
Contributor Author

Appreciate for all the very useful comments and suggestions! I definitely need to learn more about pointers...

  1. I move the get and check of RWMRawWaveforms and BRFRawWaveforms to line 75 to 85.
  2. I move the check and return to line 44-49.
  3. The line 122 was still at 122, but only print after the []
  4. For line 125 and 137, I change the usage of [] to a int AlmostCompleteWaveforms_CountHere, initialized to be zero.
  5. I would want to use that but may want to leave this to future optimization... since everything is working right now. (not perfectly because I do see zero PMT waveform from some timestamps, but they can be removed in later steps no matter where they are from)
  6. Now at line 339 to 341, changed to emplace as you suggest.

Previously, if NumWavesInCompleteSet was set to 140 and there are only ~133 PMT waveforms exist in data, the AlmostCompleteWaveforms[PMTCounterTimeNs] won't be created. But the usage of AlmostCompleteWaveforms[PMTCounterTimeNs] in Log will create an entry there. This won't affect the later code because there are checks to require AlmostCompleteWaveforms[PMTCounterTimeNs] > 5.

Now the Log was removed and the tolerance for PMT number is changed to 10 at:
ChannelKey.size() >= (NumWavesInCompleteSet - 10)
@S81D S81D self-assigned this Aug 22, 2025
@S81D
Copy link
Collaborator

S81D commented Aug 25, 2025

It looks like Marcus' points were addressed in the new changes. As this is a standalone tool and is in the event building workflow currently in use, I say it's good to go.




if (exeNum % 80 == 0 && exeNum != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a bit confusing and seems a bit hand wavey. I don't really follow the comment, but am not a great fan of "do the VME offset correction once every X number of executes because that seems to be about right probably".
Is there not a more definitive way of determining when it needs to be done?

vector<uint64_t> RWMEmplacedTimes;
vector<uint64_t> BRFEmplacedTimes;

for (std::pair<uint64_t, std::map<unsigned long, std::vector<Hit>> *> p : *InProgressHits)
Copy link
Collaborator

Choose a reason for hiding this comment

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

would prefer using a reference in range-based for loops, but since value is a pointer i suppose this isn't too critical.

{
uint64_t PMTCounterTimeNs = p.first;
std::map<unsigned long, std::vector<Hit>> *hitMap = p.second;
vector<unsigned long> ChannelKey = InProgressChkey->at(PMTCounterTimeNs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

again making copies of vectors isn't great efficiency, using a reference would be better.

if (ChannelKey.size() >= (NumWavesInCompleteSet - 10))
{
Log("EBPMT: ChannelKey.size() == (NumWavesInCompleteSet - 1), ChannelKey.size() = " + std::to_string(ChannelKey.size()) + " == NumWavesInCompleteSet - 1 = " + std::to_string(NumWavesInCompleteSet - 1), v_debug, verbosityEBPMT);
if (AlmostCompleteWaveforms.find(PMTCounterTimeNs) != AlmostCompleteWaveforms.end())
Copy link
Collaborator

Choose a reason for hiding this comment

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

AlmostCompleteWaveforms is a std::map - no need to use .find() != .end(), just use .count()

// cout<<ch<<", ";
// }
// cout<<endl;
auto it_acw = AlmostCompleteWaveforms.find(PMTCounterTimeNs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

again shouldn't be using find with std::map

// loop all the grouped triggers, if the value is target trigger, then calculate the time difference
for (int i = 0; i < groupedTriggers.size(); i++)
{
map<uint64_t, uint32_t> groupedTrigger = groupedTriggers.at(i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use reference

if (saveRWMWaveforms)
{
// check does RWMRawWaveforms have key PMTCounterTimeNs, if not, print a log waring and skip
if (RWMRawWaveforms->find(PMTCounterTimeNs) == RWMRawWaveforms->end())
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::map.count() instead of .find()

if (saveBRFWaveforms)
{
// check does BRFRawWaveforms have key PMTCounterTimeNs, if not, print a log waring and skip
if (BRFRawWaveforms->find(PMTCounterTimeNs) == BRFRawWaveforms->end())
Copy link
Collaborator

Choose a reason for hiding this comment

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

count instead of find


Log("EBPMT: Found " + std::to_string(timestamps.size()) + " timestamps", v_message, verbosityEBPMT);

// loop timestamps,对于每一个时间戳,检查它与它之前的时间戳的差值是否是8或者16
Copy link
Collaborator

Choose a reason for hiding this comment

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

english translation please

#include "AssignBunchTimingMC.h"
#include "FitRWMWaveform.h"
#include "EBPMT.h"
#include "EBPMT.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate entry

@marc1uk
Copy link
Collaborator

marc1uk commented Oct 22, 2025

I'm inclined to merge this to avoid holding things off any longer. The requested changes are very minimal - both with regards to time/effort to implement, but also in terms of severity. In light of this, I'm going to merge, but as per #333 I would appreciate if someone can make (and validate) the requested changes in a new PR.

@marc1uk marc1uk merged commit 4130676 into ANNIEsoft:Application Oct 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants