-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleA.cpp
More file actions
128 lines (98 loc) · 4.56 KB
/
ModuleA.cpp
File metadata and controls
128 lines (98 loc) · 4.56 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
/**
* @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 ModuleA.cpp
*/
#include <JPetUnpacker/Unpacker2/EventIII.h>
#include <JPetWriter/JPetWriter.h>
#include "ModuleA.h"
ModuleA::ModuleA(const char * name, const char * description)
:JPetTask(name, description),fCurrEventNumber(0){}
void ModuleA::init(const JPetTaskInterface::Options& opts){
getStatistics().createHistogram( new TH1F("HitsPerEvtCh","Hits per channel in one event",50,-0.5,49.5) );
getStatistics().createHistogram( new TH1F("ChannelsPerEvt","Channels fired in one event",200,-0.5,199.5) );
}
ModuleA::~ModuleA(){}
void ModuleA::exec(){
if(auto evt = reinterpret_cast</*const*/ EventIII*const>(getEvent())){
int ntdc = evt->GetTotalNTDCChannels();
getStatistics().getHisto1D("ChannelsPerEvt").Fill( ntdc );
JPetTimeWindow tslot;
tslot.setIndex(fCurrEventNumber);
auto tdcHits = evt->GetTDCChannelsArray();
for (int i = 0; i < ntdc; ++i) {
//const is commented because this class has inproper architecture:
// all get-methods aren't tagged with const modifier
auto tdcChannel = dynamic_cast</*const*/ TDCChannel*const>(tdcHits->At(i));
auto tomb_number = tdcChannel->GetChannel();
if (tomb_number % 65 == 0) { // skip trigger signals from TRB
continue;
}
if( getParamBank().getTOMBChannels().count(tomb_number) == 0 ) {
WARNING(Form("DAQ Channel %d appears in data but does not exist in the setup from DB.", tomb_number));
continue;
}
JPetTOMBChannel& tomb_channel = getParamBank().getTOMBChannel(tomb_number);
// one TDC channel may record multiple signals in one TSlot
// iterate over all signals from one TDC channel
// analyze number of hits per channel
getStatistics().getHisto1D("HitsPerEvtCh").Fill( tdcChannel->GetHitsNum() );
const int kNumHits = tdcChannel->GetHitsNum();
for(int j = 0; j < kNumHits; ++j){
// check for unreasable times
// the times should be negative (measured w.r.t end of time window)
// and not smaller than -1*timeWindowWidth (which can vary for different)
// data but shoudl not exceed 1 ms, i.e. 1.e6 ns)
if( tdcChannel->GetLeadTime(j) > kMaxTime ||
tdcChannel->GetLeadTime(j) < kMinTime )continue;
if( tdcChannel->GetTrailTime(j) > kMaxTime ||
tdcChannel->GetTrailTime(j) < kMinTime )continue;
JPetSigCh sigChTmpLead = generateSigCh(tomb_channel, JPetSigCh::Leading);
JPetSigCh sigChTmpTrail = generateSigCh(tomb_channel, JPetSigCh::Trailing);
// finally, set the times in ps [raw times are in ns]
sigChTmpLead.setValue(tdcChannel->GetLeadTime(j) * 1000.);
sigChTmpTrail.setValue(tdcChannel->GetTrailTime(j) * 1000.);
tslot.addCh(sigChTmpLead);
tslot.addCh(sigChTmpTrail);
}
}
saveTimeWindow(tslot);
fCurrEventNumber++;
}
}
void ModuleA::terminate(){}
void ModuleA::saveTimeWindow( JPetTimeWindow slot){
assert(fWriter);
fWriter->write(slot);
}
void ModuleA::setWriter(JPetWriter* writer){
fWriter=writer;
}
void ModuleA::setParamManager(JPetParamManager* paramManager) {
fParamManager = paramManager;
}
const JPetParamBank& ModuleA::getParamBank()const{
assert(fParamManager);
return fParamManager->getParamBank();
}
JPetSigCh ModuleA::generateSigCh(const JPetTOMBChannel & channel, JPetSigCh::EdgeType edge) const{
JPetSigCh sigch;
sigch.setDAQch(channel.getChannel());
sigch.setType(edge);
sigch.setThresholdNumber(channel.getLocalChannelNumber());
sigch.setThreshold(channel.getThreshold());
sigch.setPM(channel.getPM());
sigch.setFEB(channel.getFEB());
sigch.setTRB(channel.getTRB());
sigch.setTOMBChannel(channel);
return sigch;
}