-
Notifications
You must be signed in to change notification settings - Fork 17
Implementing NN into Strip Pairing #183
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
base: develop/em
Are you sure you want to change the base?
Changes from all commits
ec76532
fc91b21
fe0a54e
d73b58b
1edeef3
87c75ae
a1ab750
6097e47
2879859
d96b0ec
633cf5d
a872494
cc35e5e
14bce2e
6a721e8
a9fb662
e0c430e
ae7d555
14330c2
83a0cc1
b5243d3
25551a4
9f7b813
dc40418
1fd176a
0dc4d82
293e36e
8adf152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,13 @@ class MModuleStripPairingMultiRoundChiSquare : public MModule | |
| float ChargeTrappingCorrection(unsigned int d, const vector<vector<MStripHit*>>& StripHits); | ||
|
|
||
| //! Divide an event's strip hits by detector and LV/HV side | ||
| vector<vector<vector<MStripHit*>>> CollectStripHits(MReadOutAssembly* Event); | ||
| tuple<vector<vector<vector<MStripHit*>>>, bool> CollectStripHits(MReadOutAssembly* Event); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these now only triggered strip hits? Maybe make that clear in the comment?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I see below these are only the triggered strip hits. You should update the comment to reflect this change. "//! Divide an event's triggered strip hits by detector and LV/HV side" |
||
|
|
||
| //! Divide an event's nearest neighbor strip hits by detector and LV/HV side | ||
| vector<vector<vector<MStripHit*>>> CollectNearestNeighborStripHits(MReadOutAssembly* Event); | ||
|
|
||
| //! Assign nearest neighbor strip hits to their associated hits | ||
| void AssignNearestNeighbors(MReadOutAssembly* Event); | ||
|
|
||
| //! Read in strip hits on each side for each detector and perform quality selections | ||
| bool EventSelection(MReadOutAssembly* Event, const vector<vector<vector<MStripHit*>>>& StripHits); | ||
|
|
@@ -97,6 +103,7 @@ class MModuleStripPairingMultiRoundChiSquare : public MModule | |
|
|
||
| //! Evaluate the reduced chi square for all possible strip pairings | ||
| tuple<vector<vector<unsigned int>>, vector<vector<unsigned int>>, double> EvaluateAllCombinations(unsigned int d, const vector<vector<vector<vector<vector<unsigned int>>>>>& Combinations, const vector<vector<vector<MStripHit*>>>& StripHits); | ||
|
|
||
| //! Create hits | ||
| bool CreateHits(unsigned int d, MReadOutAssembly* Event, const vector<vector<vector<MStripHit*>>>& StripHits, const vector<vector<unsigned int>>& BestLVSideCombo, const vector<vector<unsigned int>>& BestHVSideCombo); | ||
| //! Return the order of indices resulting from sorting a vector | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,40 +234,93 @@ float MModuleStripPairingMultiRoundChiSquare::ChargeTrappingCorrection(unsigned | |
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| //! Divide an event's strip hits by detector and LV/HV side | ||
| vector<vector<vector<MStripHit*>>> MModuleStripPairingMultiRoundChiSquare::CollectStripHits(MReadOutAssembly* Event) | ||
| tuple<vector<vector<vector<MStripHit*>>>, bool> MModuleStripPairingMultiRoundChiSquare::CollectStripHits(MReadOutAssembly* Event) | ||
| { | ||
|
|
||
| // Split hits by detector ID | ||
| vector<unsigned int> DetectorIDs; // List of detector IDs | ||
| vector<vector<vector<MStripHit*>>> StripHits; // list of detector IDs, list of sides (LV and HV), list of strip hits | ||
| bool IncludingNearestNeighbors = false; | ||
|
|
||
| for (unsigned int sh = 0; sh < Event->GetNStripHits(); ++sh) { // Populate StripHits with this event's strip hits | ||
| MStripHit* SH = Event->GetStripHit(sh); | ||
| unsigned int Side = (SH->IsLowVoltageStrip() == true) ? 0 : 1; | ||
|
|
||
| // Check if detector is on list | ||
| bool DetectorFound = false; | ||
| unsigned int DetectorPos = 0; | ||
| for (unsigned int d = 0; d < DetectorIDs.size(); ++d) { | ||
| if (DetectorIDs[d] == SH->GetDetectorID()) { | ||
| DetectorFound = true; | ||
| DetectorPos = d; | ||
|
|
||
| // Separate out the triggered and NN strip hits | ||
| if (SH->IsNearestNeighbor() == false) { | ||
|
|
||
| unsigned int Side = (SH->IsLowVoltageStrip() == true) ? 0 : 1; | ||
|
|
||
| // Check if detector is on list | ||
| bool DetectorFound = false; | ||
| unsigned int DetectorPos = 0; | ||
| for (unsigned int d = 0; d < DetectorIDs.size(); ++d) { | ||
| if (DetectorIDs[d] == SH->GetDetectorID()) { | ||
| DetectorFound = true; | ||
| DetectorPos = d; | ||
| } | ||
| } | ||
|
|
||
| // Once the correct detector is found, add strip hit to StripHits | ||
| if (DetectorFound == true) { | ||
| StripHits[DetectorPos][Side].push_back(SH); | ||
| } else { // If encountering a new detector, initialize list of sides/hits corresponding to that detector | ||
| vector<vector<MStripHit*>> List; // list of sides, list of hits | ||
| List.push_back(vector<MStripHit*>()); // LV | ||
| List.push_back(vector<MStripHit*>()); // HV | ||
| List[Side].push_back(SH); | ||
| StripHits.push_back(List); | ||
| DetectorIDs.push_back(SH->GetDetectorID()); | ||
| } | ||
| } | ||
| else { | ||
| IncludingNearestNeighbors = true; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a moment to understand what you're trying to do with this boolean. Maybe add a comment for this else statement: "If nearest neighbor strips are found in the event, set flag to properly account for them when strip pairing" We have the boolean Get/SetIncludeNearestNeighbors in the MModuleLeaderMeasurementHDF module, which theoretically should be the same as this boolean here, except you're deriving it from the data, and not the GUI. I'm wondering if it will be less confusing (an potentially less prone to mistakes) to instead use that user-defined variable. |
||
| } | ||
| } | ||
| return {StripHits, IncludingNearestNeighbors}; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| // Once the correct detector is found, add strip hit to StripHits | ||
| if (DetectorFound == true) { | ||
| StripHits[DetectorPos][Side].push_back(SH); | ||
| } else { // If encountering a new detector, initialize list of sides/hits corresponding to that detector | ||
| vector<vector<MStripHit*>> List; // list of sides, list of hits | ||
| List.push_back(vector<MStripHit*>()); // LV | ||
| List.push_back(vector<MStripHit*>()); // HV | ||
| List[Side].push_back(SH); | ||
| StripHits.push_back(List); | ||
| DetectorIDs.push_back(SH->GetDetectorID()); | ||
| //! Divide an event's nearest neighbor strip hits by detector and LV/HV side | ||
| vector<vector<vector<MStripHit*>>> MModuleStripPairingMultiRoundChiSquare::CollectNearestNeighborStripHits(MReadOutAssembly* Event) | ||
| { | ||
|
|
||
| // Split hits by detector ID | ||
| vector<unsigned int> DetectorIDs; // List of detector IDs | ||
| vector<vector<vector<MStripHit*>>> NNStripHits; // list of detector IDs, list of sides (LV and HV), list of strip hits | ||
|
|
||
| for (unsigned int sh = 0; sh < Event->GetNStripHits(); ++sh) { // Populate StripHits with this event's NN strip hits | ||
| MStripHit* SH = Event->GetStripHit(sh); | ||
|
|
||
| // Separate out the triggered and NN strip hits | ||
| if (SH->IsNearestNeighbor() == true) { | ||
|
|
||
| unsigned int Side = (SH->IsLowVoltageStrip() == true) ? 0 : 1; | ||
|
|
||
| // Check if detector is on list | ||
| bool DetectorFound = false; | ||
| unsigned int DetectorPos = 0; | ||
| for (unsigned int d = 0; d < DetectorIDs.size(); ++d) { | ||
| if (DetectorIDs[d] == SH->GetDetectorID()) { | ||
| DetectorFound = true; | ||
| DetectorPos = d; | ||
| } | ||
| } | ||
|
|
||
| // Once the correct detector is found, add strip hit to NNStripHits | ||
| if (DetectorFound == true) { | ||
| NNStripHits[DetectorPos][Side].push_back(SH); | ||
| } else { // If encountering a new detector, initialize list of sides/hits corresponding to that detector | ||
| vector<vector<MStripHit*>> List; // list of sides, list of hits | ||
| List.push_back(vector<MStripHit*>()); // LV | ||
| List.push_back(vector<MStripHit*>()); // HV | ||
| List[Side].push_back(SH); | ||
| NNStripHits.push_back(List); | ||
| DetectorIDs.push_back(SH->GetDetectorID()); | ||
| } | ||
| } | ||
| } | ||
| return StripHits; | ||
| return NNStripHits; | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
@@ -276,7 +329,7 @@ vector<vector<vector<MStripHit*>>> MModuleStripPairingMultiRoundChiSquare::Colle | |
| bool MModuleStripPairingMultiRoundChiSquare::EventSelection(MReadOutAssembly* Event, const vector<vector<vector<MStripHit*>>>& StripHits) | ||
| { | ||
|
|
||
| // Limit the number of strip hits on each side | ||
| // Limit the number of (triggered) strip hits on each side | ||
| for (unsigned int d = 0; d < StripHits.size(); ++d) { // Detector loop | ||
| for (unsigned int side = 0; side <= 1; ++side) { // Side loop | ||
| if (StripHits[d][side].size() > m_MaximumStrips) { | ||
|
|
@@ -711,6 +764,74 @@ bool MModuleStripPairingMultiRoundChiSquare::CreateHits(unsigned int d, MReadOut | |
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| //! Assign nearest neighbor strip hits to their appropriate hit | ||
| void MModuleStripPairingMultiRoundChiSquare::AssignNearestNeighbors(MReadOutAssembly* Event) { | ||
|
|
||
| vector<vector<vector<MStripHit*>>> NNStripHits = CollectNearestNeighborStripHits(Event); // List of detectors, list of sides, list of strip hits | ||
|
|
||
| vector<MStripHit*> AssignedNeighbors; // List of all the assigned NN strip hits, in order to check if NNs are double counted | ||
|
|
||
| for (unsigned int h = 0; h < Event->GetNHits(); h++) { | ||
| vector<vector<int>> StripIDs; // list of sides, list of strips | ||
| StripIDs.push_back(vector<int>()); // LV | ||
| StripIDs.push_back(vector<int>()); // HV | ||
| bool AssignedDetector = false; | ||
| int DetectorID; // Define detector ID where hit took place | ||
| for (unsigned int sh = 0; sh < Event->GetHit(h)->GetNStripHits(); sh++) { | ||
| // Collect all the strip hits in a hit and split them by side | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that whenever this function is called, the Hit only has triggered strips assigned to it. So this GetNStripHits will only return the number of triggered strip hits. Make that clear in the comment? Once you assign Nearest Neighbor strip hits to the event, do you expect GetNStripHits to count all associated strip hits, or only triggered strips? |
||
| MStripHit* SH = Event->GetHit(h)->GetStripHit(sh); | ||
| unsigned int Side = (SH->IsLowVoltageStrip() == true) ? 0 : 1; | ||
| StripIDs[Side].push_back(SH->GetStripID()); | ||
|
|
||
| if (AssignedDetector == false) { | ||
| DetectorID = SH->GetDetectorID(); | ||
| AssignedDetector = true; | ||
| } | ||
| } | ||
| // For each side, find the edge strip hit. i.e if there's charge sharing between strips 4, 5, and 6, the edges will be 4 and 6 | ||
| int LeftEdgeLV = *min_element(StripIDs[0].begin(), StripIDs[0].end()); | ||
| int RightEdgeLV = *max_element(StripIDs[0].begin(), StripIDs[0].end()); | ||
| int LeftEdgeHV = *min_element(StripIDs[1].begin(), StripIDs[1].end()); | ||
| int RightEdgeHV = *max_element(StripIDs[1].begin(), StripIDs[1].end()); | ||
|
|
||
| // If there are two hits that are one strip hit apart, then the NN strip hit will be added to both hits | ||
|
|
||
| // Define the LV neighbors | ||
| for (unsigned int sh = 0; sh < NNStripHits[DetectorID][0].size(); sh++) { | ||
| MStripHit* NNSH = NNStripHits[DetectorID][0][sh]; | ||
| if ((NNSH->GetStripID() == LeftEdgeLV - 1) or (NNSH->GetStripID() == RightEdgeLV + 1)) { | ||
| Event->GetHit(h)->AddNearestNeighborStripHit(NNSH); | ||
| // If NN strip hit is not yet assigned to a hit, then add it to the list of assigned neighbors | ||
| if (find(AssignedNeighbors.begin(), AssignedNeighbors.end(), NNSH) == AssignedNeighbors.end()) { | ||
| AssignedNeighbors.push_back(NNSH); | ||
| } | ||
| // If it has already been assigned to a hit, then flag that strip hit as an ambiguous nearest neighbor | ||
| else { | ||
| NNSH->IsAmbiguousNearestNeighbor(true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Define the HV neighbors | ||
| for (unsigned int sh = 0; sh < NNStripHits[DetectorID][1].size(); sh++) { | ||
| MStripHit* NNSH = NNStripHits[DetectorID][1][sh]; | ||
| if ((NNSH->GetStripID() == LeftEdgeHV - 1) or (NNSH->GetStripID() == RightEdgeHV + 1)) { | ||
| Event->GetHit(h)->AddNearestNeighborStripHit(NNSH); | ||
| } | ||
| // If NN strip hit is not yet assigned to a hit, then add it to the list of assigned neighbors | ||
| if (find(AssignedNeighbors.begin(), AssignedNeighbors.end(), NNSH) == AssignedNeighbors.end()) { | ||
| AssignedNeighbors.push_back(NNSH); | ||
| } | ||
| // If it has already been assigned to a hit, then flag that strip hit as an ambiguous nearest neighbor | ||
| else { | ||
| NNSH->IsAmbiguousNearestNeighbor(true); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| //! Main data analysis routine, which updates the event to a new level | ||
| bool MModuleStripPairingMultiRoundChiSquare::AnalyzeEvent(MReadOutAssembly* Event) | ||
| { | ||
|
|
@@ -722,7 +843,7 @@ bool MModuleStripPairingMultiRoundChiSquare::AnalyzeEvent(MReadOutAssembly* Even | |
| } | ||
|
|
||
| // Collect strip hits from input event | ||
| vector<vector<vector<MStripHit*>>> StripHits = CollectStripHits(Event); // List of detectors, list of sides, list of strip hits | ||
| auto [StripHits, IncludingNearestNeighbors] = CollectStripHits(Event); // List of detectors, list of sides, list of strip hits (and bool saying if running with nearest neighbors or not | ||
|
|
||
| // Perform some event selections | ||
| bool CheckStripHits = EventSelection(Event, StripHits); | ||
|
|
@@ -840,6 +961,11 @@ bool MModuleStripPairingMultiRoundChiSquare::AnalyzeEvent(MReadOutAssembly* Even | |
|
|
||
| } // End Detector loop | ||
|
|
||
| // If there are NN strips, assign them to their appropriate hits | ||
| if (IncludingNearestNeighbors == true) { | ||
| AssignNearestNeighbors(Event); | ||
| } | ||
|
|
||
| Event->SetAnalysisProgress(MAssembly::c_StripPairing); | ||
|
|
||
| return true; | ||
|
|
||
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'm wondering about any potential confusion/overlap with NN strip hits listed here vs in the StripHit list that then have the IsNearestNeightbor flag. Do we expect NN strip hits to also be listed in the standard GetStripHit list or is that now exclusively for triggered strips? If so, let's make that clear.