-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeWindowCreatorTools.cpp
More file actions
163 lines (157 loc) · 6.28 KB
/
Copy pathTimeWindowCreatorTools.cpp
File metadata and controls
163 lines (157 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @copyright Copyright 2020 The J-PET Framework Authors. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may find a copy of the License in the LICENCE file.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @file TimeWindowCreatorTools.cpp
*/
#include "TimeWindowCreatorTools.h"
#include "UniversalFileLoader.h"
using namespace std;
/**
* Sorting method for Signal Channels by time value
*/
void TimeWindowCreatorTools::sortByValue(vector<JPetSigCh>& input)
{
std::sort(input.begin(), input.end(),
[] (JPetSigCh sigCh1, JPetSigCh sigCh2) {
return sigCh1.getValue() < sigCh2.getValue();
}
);
}
/**
* Building all Signal Chnnels from one TDC
*/
vector<JPetSigCh> TimeWindowCreatorTools::buildSigChs(
TDCChannel* tdcChannel, const JPetTOMBChannel& tombChannel,
map<unsigned int, vector<double>>& timeCalibrationMap,
map<unsigned int, vector<double>>& thresholdsMap,
double maxTime, double minTime, bool setTHRValuesFromChannels,
JPetStatistics& stats, bool saveHistos
){
vector<JPetSigCh> allTDCSigChs;
// Loop over all entries on leading edge in current TOMBChannel and create SigCh
for (int j = 0; j < tdcChannel->GetLeadHitsNum(); j++) {
auto leadTime = tdcChannel->GetLeadTime(j);
if (leadTime > maxTime || leadTime < minTime ) { continue; }
auto leadSigCh = generateSigCh(
leadTime, tombChannel, timeCalibrationMap, thresholdsMap,
JPetSigCh::Leading, setTHRValuesFromChannels
);
allTDCSigChs.push_back(leadSigCh);
if (saveHistos){
stats.fillHistogram(Form("pm_occupation_thr%d", tombChannel.getLocalChannelNumber()),
tombChannel.getPM().getID());
}
}
// Loop over all entries on trailing edge in current TOMBChannel and create SigCh
for (int j = 0; j < tdcChannel->GetTrailHitsNum(); j++) {
auto trailTime = tdcChannel->GetTrailTime(j);
if (trailTime > maxTime || trailTime < minTime ) { continue; }
auto trailSigCh = generateSigCh(
trailTime, tombChannel, timeCalibrationMap, thresholdsMap,
JPetSigCh::Trailing, setTHRValuesFromChannels
);
allTDCSigChs.push_back(trailSigCh);
if (saveHistos){
stats.fillHistogram(Form("pm_occupation_thr%d", tombChannel.getLocalChannelNumber()),
tombChannel.getPM().getID());
}
}
return allTDCSigChs;
}
/**
* Method for investigation of repetated edges - setting RecoFlag for each SigCh.
* SigChs are flagged as GOOD if they appear in the sequence LTLTLTLT ->
* in other words, each found LT pair is marked as GOOD. If sequence of one type of
* the edge is encountered, repeated ones are flagged CORRUPTED. Examples:
* edge type -> LTLTLT LLT LLTT LLLLTTTT LLTTLTLTTTLLLLTT
* flag -> GGGGGG CGG CGGC CCCGGCCC CGGCGGGGCCCCCGGC
*/
void TimeWindowCreatorTools::flagSigChs(
vector<JPetSigCh>& inputSigChs, JPetStatistics& stats, bool saveHistos
) {
for(unsigned int i=0; i<inputSigChs.size(); i++) {
if(i == inputSigChs.size()-1) {
inputSigChs.at(i).setRecoFlag(JPetSigCh::Good);
if(saveHistos){ stats.fillHistogram("good_vs_bad_sigch", 1); }
break;
}
auto& sigCh1 = inputSigChs.at(i);
auto& sigCh2 = inputSigChs.at(i+1);
// Explicit check for repeated edges
if((sigCh1.getType() == JPetSigCh::Leading && sigCh2.getType() == JPetSigCh::Trailing)){
sigCh1.setRecoFlag(JPetSigCh::Good);
sigCh2.setRecoFlag(JPetSigCh::Good);
if(saveHistos){
stats.fillHistogram("LT_time_diff", sigCh2.getValue()-sigCh1.getValue());
stats.fillHistogram("good_vs_bad_sigch", 1, 2);
}
} else if (sigCh1.getType() == JPetSigCh::Trailing && sigCh2.getType() == JPetSigCh::Leading) {
if(sigCh1.getRecoFlag() == JPetSigCh::Unknown){
sigCh1.setRecoFlag(JPetSigCh::Good);
if(saveHistos){
stats.fillHistogram("good_vs_bad_sigch", 1);
}
}
} else if (sigCh1.getType() == JPetSigCh::Leading && sigCh2.getType() == JPetSigCh::Leading) {
sigCh1.setRecoFlag(JPetSigCh::Corrupted);
if(saveHistos){
stats.fillHistogram("good_vs_bad_sigch", 2);
stats.fillHistogram("LL_per_PM", sigCh1.getPM().getID());
stats.fillHistogram("LL_per_THR", sigCh1.getThresholdNumber());
stats.fillHistogram("LL_time_diff", sigCh2.getValue()-sigCh1.getValue());
}
} else if (sigCh1.getType() == JPetSigCh::Trailing && sigCh2.getType() == JPetSigCh::Trailing){
if(sigCh1.getRecoFlag() == JPetSigCh::Unknown) {
sigCh1.setRecoFlag(JPetSigCh::Corrupted);
}
sigCh2.setRecoFlag(JPetSigCh::Corrupted);
if(saveHistos){
stats.fillHistogram("good_vs_bad_sigch", 2);
stats.fillHistogram("TT_per_PM", sigCh1.getPM().getID());
stats.fillHistogram("TT_per_THR", sigCh1.getThresholdNumber());
stats.fillHistogram("TT_time_diff", sigCh2.getValue()-sigCh1.getValue());
}
}
if(sigCh1.getRecoFlag() == JPetSigCh::Unknown && saveHistos){
stats.fillHistogram("good_vs_bad_sigch", 3);
}
}
}
/**
* Sets up Signal Channel fields
*/
JPetSigCh TimeWindowCreatorTools::generateSigCh(
double tdcChannelTime, const JPetTOMBChannel& channel,
map<unsigned int, vector<double>>& timeCalibrationMap,
map<unsigned int, vector<double>>& thresholdsMap,
JPetSigCh::EdgeType edge, bool setTHRValuesFromChannels
) {
JPetSigCh sigCh;
sigCh.setValue(1000.*(tdcChannelTime
+ UniversalFileLoader::getConfigurationParameter(timeCalibrationMap, channel.getChannel())
));
sigCh.setType(edge);
sigCh.setTOMBChannel(channel);
sigCh.setPM(channel.getPM());
sigCh.setFEB(channel.getFEB());
sigCh.setTRB(channel.getTRB());
sigCh.setDAQch(channel.getChannel());
sigCh.setThresholdNumber(channel.getLocalChannelNumber());
if(setTHRValuesFromChannels) {
sigCh.setThreshold(channel.getThreshold());
} else {
sigCh.setThreshold(
UniversalFileLoader::getConfigurationParameter(thresholdsMap, channel.getChannel())
);
}
return sigCh;
}