forked from dan131riley/strip-cluster-toy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrip-cluster.cc
109 lines (93 loc) · 3.3 KB
/
strip-cluster.cc
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
#include <fstream>
#include <iostream>
#include <algorithm>
#include "Clusterizer.h"
#include "FEDChannel.h"
#include "FEDZSChannelUnpacker.h"
class StripByStripAdder {
public:
typedef std::output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
StripByStripAdder(Clusterizer& clusterizer,
Clusterizer::State& state,
std::vector<SiStripCluster>& record)
: clusterizer_(clusterizer), state_(state), record_(record) {}
StripByStripAdder& operator= ( SiStripDigi digi )
{
clusterizer_.stripByStripAdd(state_, digi.strip(), digi.adc(), record_);
return *this;
}
StripByStripAdder& operator* () { return *this; }
StripByStripAdder& operator++ () { return *this; }
StripByStripAdder& operator++ (int) { return *this; }
private:
Clusterizer& clusterizer_;
Clusterizer::State& state_;
std::vector<SiStripCluster>& record_;
};
template<typename OUT>
OUT unpackZS(const FEDChannel& chan, uint16_t stripOffset, OUT out, detId_t idet)
{
auto unpacker = FEDZSChannelUnpacker::zeroSuppressedModeUnpacker(chan);
while (unpacker.hasData()) {
auto digi = SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc());
//std::cout << "unpackZS det " << idet << " digi " << digi.strip() << " sample " << (unsigned int) unpacker.sampleNumber() << " adc " << (unsigned int) unpacker.adc() << std::endl;
if (digi.strip() != 0) {
*out++ = digi;
}
unpacker++;
}
return out;
}
FEDSet fillFeds()
{
std::ifstream fedfile("stripdata.bin", std::ios::in | std::ios::binary);
FEDSet feds;
detId_t detid;
while (fedfile.read((char*)&detid, sizeof(detid)).gcount() == sizeof(detid)) {
FEDChannel fed(fedfile);
//std::cout << "Det " << detid << " fed " << fed.fedId() << " channel " << (int) fed.fedCh() << " length " << fed.length() << std::endl;
feds[detid].push_back(std::move(fed));
}
return feds;
}
std::vector<SiStripCluster>
fillClusters(detId_t idet, Clusterizer& clusterizer, Clusterizer::State& state, const std::vector<FEDChannel>& channels)
{
static bool first = true;
std::vector<SiStripCluster> out;
auto const & det = clusterizer.stripByStripBegin(idet);
state.reset(det);
for (auto const& chan : channels) {
//std::cout << "Processing channel for detid " << idet << " fed " << chan.fedId() << " channel " << (int) chan.fedCh() << " len:off " << chan.length() << ":" << chan.offset() << " ipair " << chan.iPair() << std::endl;
auto perStripAdder = StripByStripAdder(clusterizer, state, out);
unpackZS(chan, chan.iPair()*256, perStripAdder, idet);
}
clusterizer.stripByStripEnd(state, out);
if (first) {
first = false;
std::cout << "Printing clusters for detid " << idet << std::endl;
for (const auto& cluster : out) {
std::cout << "Cluster " << cluster.firstStrip() << ": ";
for (const auto& ampl : cluster.amplitudes()) {
std::cout << (int) ampl << " ";
}
std::cout << std::endl;
}
}
return out;
}
int main()
{
Clusterizer clusterizer;
Clusterizer::State state;
FEDSet feds(fillFeds());
for (auto idet : clusterizer.allDetIds()) {
if (feds.find(idet) != feds.end()) {
auto out = fillClusters(idet, clusterizer, state, feds[idet]);
}
}
}