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

[WIP] Updated version of tripple coincidences code, accoring to Pawel remarks - left for reference #24

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

dominikpanek
Copy link

No description provided.

Copy link
Member

@BlurredChoise BlurredChoise left a comment

Choose a reason for hiding this comment

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

Well done, but there are a lot of places that need to be tweaked to make things work better now and in the future.

You should modify the code as in the comments provided. Correct not only new code changes but also old ones, because the current code is suboptimal, has a lot of error prone sites and is difficult to read.

Also add descriptions of the functions.

And finally, I dont see the declarations of functions in the file EventAnalysis.h

@@ -232,6 +232,56 @@ EventType verify_type_of_coincidence_castor(const Hit &h1, const Hit &h2) {
return kUnspecified;
}

EventType verify_type_of_triple_coincidence(const Hit &h1, const Hit &h2, const Hit &h3) {
Copy link
Member

Choose a reason for hiding this comment

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

Too many if{}else{} plus this implantation is easy to cause some potential errors.

In my opinion you should replace this function with following set of functions:

bool all_same_event(const vector<Hit>& hits) {
 unsigned int nhits = hits.size();
 if ( nhits == 0 ) {
  return false;
 }
 const int ref_id = hits.at(0).eventID;
 return std::all_of(hits.cbegin(), hits.cend(), [ref_id](Hit& hit){ return hit.eventID == ref_id; });
}

bool not_phantom_compton(const vector<Hit>& hits) {
 return std::all_of(hits.cbegin(), hits.cend(), [](Hit& hit){ return hit.nPhantomCompton == 0; });
}

bool all_crystal_compton(const vector<Hit>& hits) {
 return std::all_of(hits.cbegin(), hits.cend(), [](Hit& hit){ return hit.nCrystalCompton == 1; });
}

EventType verify_type_of_triple_coincidence(const std::vector<Hit>& hits) {
 if ( all_same_event(hits) ) {
  //true, phantom-scattered and detector-scattered
  if ( not_phantom_compton(hits) ) {
   if ( all_crystal_compton(hits) ) {
    return kTrue;
   }
   return kDetectorScattered;
  }
  return kPhantomScattered;
 }
 //otherwise --> accidental
 return kAccidental;
}

You should use these 3 new function in other part of code too.
For example, function EventType verify_type_of_coincidence(const Hit &h1, const Hit &h2)
can be replaced by EventType verify_type_of_coincidence(const vector<Hit>& hits)

//================================================================================
// MAIN ANALYSIS FUNCTION
//================================================================================

void analyze_event(vector<Hit> &hits, bool hits_are_singles)
void analyze_event(vector<Hit> &hits, bool hits_are_singles, bool triple_coincidence)
Copy link
Member

Choose a reason for hiding this comment

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

As I understand these variables are not modified by by function, hence:
void analyze_event(const vector<Hit> &hits, const bool hits_are_singles, const bool triple_coincidence)

@@ -326,6 +430,13 @@ void analyze_event(vector<Hit> &hits, bool hits_are_singles)
if (N==MAX_N and N0<=MAX_N0) print_coincidences(selected_hits);
//if (N>=2 and N<=MAX_N and N0<=MAX_N0) print_coincidences(selected_hits);

if (triple_coincidences) {
if (N==MAX_N and N0<=MAX_N0) print_coincidences(selected_hits);
Copy link
Member

Choose a reason for hiding this comment

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

This is error fragile usage of the if().
You should use brackets: if (N==MAX_N and N0<=MAX_N0) {print_coincidences(selected_hits);}

@@ -399,5 +510,4 @@ void RunTests()
assert(single4.eventID == 10); // 10 is a value set manually
assert(single4.volumeID == 9); // 9 is a value set manually
assert(std::abs(single4.edep - 140) < epsilon); // Energy of single == sum of energies of hits: 10+80+50 = 140
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing end of line

…hanges were applied in the EventAnalysis.cpp and the declarations

of new functions were added in th EventAnalysis.h
@@ -51,7 +63,9 @@ Hit merge_hits(const std::vector<Hit> &hits, const AveragingMethod winner);

void print_coincidence(const Hit& h1, const Hit& h2);
void print_coincidences(const std::vector<Hit>& hits);
void print_triple_coincidences(const std::vector<Hit>& hits, PROMPT_E_TH);
Copy link
Member

Choose a reason for hiding this comment

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

incorrectly declared method, causes compilation errors.
Please make sure that code compiles correctly before you send changes to github.

@@ -41,8 +41,20 @@ Hit merge_hits(const std::vector<Hit> &hits, const AveragingMethod winner);
/// returns number of singles above noise energy threshold, number of singles above Compton energy threshold, and selected singles
std::tuple<int, int, std::vector<Hit>> select_coincident_singles(const std::vector<Hit> &hits, double compton_energy_threshold);

/// returns the event ID of the hit
Copy link
Member

Choose a reason for hiding this comment

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

I guess this not the description of function all_same_event(...)

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

/// returns the event ID of the hit
bool all_same_event(const std::vector<Hit>& hits);

/// returns 0 if the hit was not scattered in phantom
Copy link
Member

Choose a reason for hiding this comment

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

incorrect description

Copy link
Author

Choose a reason for hiding this comment

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

Comments were corrected. As for the comments in the code they concern the functions below them.

/// returns 0 if the hit was not scattered in phantom
bool not_phantom_compton(const std::vector<Hit>& hits);

/// returns 1 if there was not any scattering in the detector
Copy link
Member

Choose a reason for hiding this comment

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

incorrect description

Copy link
Member

Choose a reason for hiding this comment

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

it returns bool not int so a good desciption in:

Checks if none of hits is from the Compton scattering in the phantom
@param: hits - list of hits from the event
@return: if at least one photon scattered in the phantom it returns false, otherwise true

// Below function contains simple definition of coincidence that does not take into account Rayleigh scatterings
EventType verify_type_of_coincidence(const Hit &h1, const Hit &h2);
EventType verify_type_of_coincidence(const std::vector<Hit>& hits);
Copy link
Member

Choose a reason for hiding this comment

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

maybe I'm picking on, but the function name is misleading: this method returns type of event but name suggests that this function returns bool value. So maybe good idea is to replace "verify" with "get".

Copy link
Author

Choose a reason for hiding this comment

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

That is true, but these functions were already declared a long time ago and we didn't want to change it.

Copy link
Member

@BlurredChoise BlurredChoise left a comment

Choose a reason for hiding this comment

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

Please make sure this code compiles correctly ( -c++ compiler does not return errors) at this moments github shows a lot of errors which means you send a code which does not work. If you need help let me know - we can discuss how to fix some errors, but I think you can do it by yourself.

/// returns 0 if the hit was not scattered in phantom
bool not_phantom_compton(const std::vector<Hit>& hits);

/// returns 1 if there was not any scattering in the detector
Copy link
Member

Choose a reason for hiding this comment

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

it returns bool not int so a good desciption in:

Checks if none of hits is from the Compton scattering in the phantom
@param: hits - list of hits from the event
@return: if at least one photon scattered in the phantom it returns false, otherwise true

@@ -63,7 +63,7 @@ Hit merge_hits(const std::vector<Hit> &hits, const AveragingMethod winner);

void print_coincidence(const Hit& h1, const Hit& h2);
void print_coincidences(const std::vector<Hit>& hits);
void print_triple_coincidences(const std::vector<Hit>& hits, PROMPT_E_TH);
void print_triple_coincidences(const std::vector<Hit>& hits, double PROMPT_E_TH);
Copy link
Member

Choose a reason for hiding this comment

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

please use lowercase when you add an argument to function. Uppercase is dedicated for the GLOBAL variables.
but global variables are generally bad - you should not create global variable, instead you should create a namespace with some constant variables).

So if you want to have a set of some physical constants you should create a dedicated namespace for that i.e.:

namespace MyConstants {
 const int kMy_int_const = 123;
 const double kMy_double_const = 123.0;
};

and when you want to use such constant you just call:

//...some code
funnyFunction(MyConstants::kMy_double_const)

Moreover, you corrected the function declaration but you didnt corrected the usage of this function - there are missing variables.

@wkrzemien wkrzemien changed the title Updated version of tripple coincidences code, accoring to Pawel remarks [WIP] Updated version of tripple coincidences code, accoring to Pawel remarks - left for reference Jan 11, 2023
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.

3 participants