-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleC.cpp
More file actions
154 lines (126 loc) · 5.81 KB
/
ModuleC.cpp
File metadata and controls
154 lines (126 loc) · 5.81 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
/**
* @copyright Copyright 2016 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 ModuleC.cpp
*/
#include <iostream>
#include <JPetWriter/JPetWriter.h>
#include "ModuleC.h"
using namespace std;
ModuleC::ModuleC(const char * name, const char * description):JPetTask(name, description){}
ModuleC::~ModuleC(){}
void ModuleC::init(const JPetTaskInterface::Options& opts){
}
void ModuleC::exec(){
//getting the data from event in propriate format
if(auto currSignal = dynamic_cast<const JPetRawSignal*const>(getEvent())){
getStatistics().getCounter("No. initial signals")++;
if (fSignals.empty()) {
fSignals.push_back(*currSignal);
}
else {
if (fSignals[0].getTimeWindowIndex() == currSignal->getTimeWindowIndex()) {
fSignals.push_back(*currSignal);
}
else {
saveHits(createHits(fSignals));
fSignals.clear();
fSignals.push_back(*currSignal);
}
}
}
}
vector<JPetHit> ModuleC::createHits(const vector<JPetRawSignal>&signals){
vector<JPetHit> hits;
for (auto i = signals.begin(); i != signals.end(); ++i) {
for (auto j = i; ++j != signals.end();) {
if (i->getPM().getScin() == j->getPM().getScin()) {
// found 2 signals from the same scintillator
// wrap the RawSignal objects into RecoSignal and PhysSignal
// for now this is just wrapping opne object into another
// in the future analyses it will involve more logic like
// reconstructing the signal's shape, charge, amplitude etc.
JPetRecoSignal recoSignalA;
JPetRecoSignal recoSignalB;
JPetPhysSignal physSignalA;
JPetPhysSignal physSignalB;
// assign sides A and B properly
if( i -> getNumberOfTrailingEdgePoints() == 4 and j -> getNumberOfTrailingEdgePoints() == 4
and i -> getNumberOfLeadingEdgePoints() == 4 and j -> getNumberOfLeadingEdgePoints() == 4){
if(
(i->getPM().getSide() == JPetPM::SideA)
&&(j->getPM().getSide() == JPetPM::SideB)
){
recoSignalA.setRawSignal(*i);
recoSignalB.setRawSignal(*j);
}
else if(
(j->getPM().getSide() == JPetPM::SideA)
&&(i->getPM().getSide() == JPetPM::SideB)
){
recoSignalA.setRawSignal(*j);
recoSignalB.setRawSignal(*i);
}
else {
// if two hits on the same side, ignore
WARNING("TWO hits on the same scintillator side we ignore it");
continue;
}
physSignalA.setRecoSignal(recoSignalA);
physSignalB.setRecoSignal(recoSignalB);
auto leadTimesA = recoSignalA.getRawSignal().getTimesVsThresholdNumber(JPetSigCh::Leading);
auto leadTimesB = recoSignalB.getRawSignal().getTimesVsThresholdNumber(JPetSigCh::Leading);
double timesSumA = 0;
double timesSumB = 0;
for(int itr = 1; itr <= 4; itr++){
timesSumA += leadTimesA[itr];
timesSumB += leadTimesB[itr];
}
physSignalA.setTime(timesSumA/4);
physSignalB.setTime(timesSumB/4);
if ( (physSignalA.getTime() - physSignalB.getTime()) < 10000 /*ps*/){
JPetHit hit;
hit.setSignalA(physSignalA);
hit.setSignalB(physSignalB);
hit.setTime( (physSignalB.getTime() + physSignalB.getTime())/2 );
hit.setScintillator(i->getPM().getScin());
hit.setBarrelSlot(i->getPM().getScin().getBarrelSlot());
// cout << recoSignalA.getRawSignal().getTOTsVsThresholdNumber().at(3) - recoSignalA.getRawSignal().getTOTsVsThresholdNumber().at(4) << endl;
hits.push_back(hit);
}
}
getStatistics().getCounter("No. found hits")++;
}
}
}
return hits;
}
void ModuleC::terminate(){
saveHits(createHits(fSignals)); //if there is something left
INFO( Form("From %d initial signals %d hits were paired.",
static_cast<int>(getStatistics().getCounter("No. initial signals")),
static_cast<int>(getStatistics().getCounter("No. found hits")) )
);
}
void ModuleC::saveHits(const vector<JPetHit>&hits){
assert(fWriter);
auto sorted = hits;
sort(sorted.begin(), sorted.end(), [](const JPetHit & hit1, const JPetHit & hit2){return hit1.getTime() < hit2.getTime();});
for (auto hit : sorted){
// here one can impose any conditions on hits that should be
// saved or skipped
// for now, all hits are written to the output file
// without checking anything
fWriter->write(hit);
}
}
void ModuleC::setWriter(JPetWriter* writer){fWriter =writer;}