16 std::vector<raw::ExternalTrigger>
19 std::vector<raw::ExternalTrigger> ExternTrigs;
21 std::vector<lbne::PennMicroSlice::Payload_Trigger::trigger_type_t> trigger_types = {lbne::PennMicroSlice::Payload_Trigger::TA,
22 lbne::PennMicroSlice::Payload_Trigger::TB,
23 lbne::PennMicroSlice::Payload_Trigger::TC,
24 lbne::PennMicroSlice::Payload_Trigger::TD};
25 std::vector<lbne::PennMicroSlice::Payload_Trigger::trigger_type_t> calib_types = {lbne::PennMicroSlice::Payload_Trigger::C1,
26 lbne::PennMicroSlice::Payload_Trigger::C2,
27 lbne::PennMicroSlice::Payload_Trigger::C3,
28 lbne::PennMicroSlice::Payload_Trigger::C4};
29 std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fCounterTimes;
30 std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fMuonTriggerTimes;
31 std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fSSPTriggerTimes;
33 std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> fCalibrationTriggerTimes;
35 std::vector<lbne::PennMicroSlice::Payload_Counter> fCounterWords;
36 std::vector<lbne::PennMicroSlice::Payload_Trigger> fMuonTriggers;
37 std::vector<lbne::PennMicroSlice::Payload_Trigger> fSSPTriggers;
39 std::vector<lbne::PennMicroSlice::Payload_Trigger> fCalibrationTriggers;
42 for (
size_t idx = 0; idx < Fragments.size(); ++idx ) {
43 const auto& frag(Fragments[idx]);
46 lbne::PennMilliSliceFragment msf(frag);
48 lbne::PennMicroSlice::Payload_Header *word_header =
nullptr;
49 lbne::PennMicroSlice::Payload_Counter *word_p_counter =
nullptr;
50 lbne::PennMicroSlice::Payload_Trigger *word_p_trigger =
nullptr;
51 lbne::PennMicroSlice::Payload_Timestamp *previous_timestamp =
nullptr;
52 lbne::PennMicroSlice::Payload_Header *future_timestamp_header =
nullptr;
53 lbne::PennMicroSlice::Payload_Timestamp *future_timestamp =
nullptr;
54 uint8_t* payload_data =
nullptr;
58 payloadCount = msf.payloadCount(counter, trigger, timestamp);
62 while (payload_index <
uint32_t(payloadCount-1) ) {
63 payload_data = msf.get_next_payload(payload_index,word_header);
65 if (payload_data ==
nullptr)
67 switch(word_header->data_packet_type) {
69 case lbne::PennMicroSlice::DataTypeCounter:
70 word_p_counter =
reinterpret_cast<lbne::PennMicroSlice::Payload_Counter*
>(payload_data);
71 fCounterWords.push_back(*word_p_counter);
72 GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fCounterTimes );
76 case lbne::PennMicroSlice::DataTypeTrigger:
77 word_p_trigger =
reinterpret_cast<lbne::PennMicroSlice::Payload_Trigger*
>(payload_data);
79 if (word_p_trigger->has_muon_trigger()) {
80 fMuonTriggers.push_back(*word_p_trigger);
81 GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fMuonTriggerTimes );
84 if (word_p_trigger->has_ssp_trigger()) {
85 fSSPTriggers.push_back(*word_p_trigger);
86 GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fSSPTriggerTimes );
96 if (word_p_trigger->has_calibration()) {
97 fCalibrationTriggers.push_back(*word_p_trigger);
98 GetTimestamp( msf, word_header, previous_timestamp, future_timestamp, future_timestamp_header, fCalibrationTriggerTimes );
104 case lbne::PennMicroSlice::DataTypeTimestamp:
105 previous_timestamp =
reinterpret_cast<lbne::PennMicroSlice::Payload_Timestamp*
>(payload_data);
106 if (FirstPTBTimestamp ==
nullptr) FirstPTBTimestamp = previous_timestamp;
118 for (
int counter_index=0; counter_index<98; ++counter_index ) {
119 bool counter_previously_on =
true;
121 bool counter_currently_on = fCounterWords.at(
pos).get_counter_status(counter_index);
124 bool MakeNewExtCount =
MakeNewExtTrig(
pos, counter_previously_on, counter_currently_on);
125 if (MakeNewExtCount) {
127 ExternTrigs.push_back(
counter);
135 bool trigA_previously_on =
false, trigB_previously_on =
false, trigC_previously_on =
false, trigD_previously_on =
false;
137 bool trigA_currently_on = fMuonTriggers.at(
pos).has_muon_TA();
138 bool trigB_currently_on = fMuonTriggers.at(
pos).has_muon_TB();
139 bool trigC_currently_on = fMuonTriggers.at(
pos).has_muon_TC();
140 bool trigD_currently_on = fMuonTriggers.at(
pos).has_muon_TD();
141 lbne::PennMicroSlice::Payload_Timestamp::timestamp_t current_trigger_time = fMuonTriggerTimes.at(
pos);
142 bool MakeNewExtTrigA, MakeNewExtTrigB, MakeNewExtTrigC, MakeNewExtTrigD;
144 MakeNewExtTrigA = trigA_previously_on = trigA_currently_on;
145 MakeNewExtTrigB = trigA_previously_on = trigB_currently_on;
146 MakeNewExtTrigC = trigA_previously_on = trigC_currently_on;
147 MakeNewExtTrigD = trigA_previously_on = trigD_currently_on;
149 MakeNewExtTrigA =
MakeNewExtTrig(
pos, trigA_previously_on, trigA_currently_on );
150 MakeNewExtTrigB =
MakeNewExtTrig(
pos, trigB_previously_on, trigB_currently_on );
151 MakeNewExtTrigC =
MakeNewExtTrig(
pos, trigC_previously_on, trigC_currently_on );
152 MakeNewExtTrigD =
MakeNewExtTrig(
pos, trigD_previously_on, trigD_currently_on );
158 if (MakeNewExtTrigA) {
161 ExternTrigs.push_back(counter);
163 if (MakeNewExtTrigB) {
166 ExternTrigs.push_back(counter);
168 if (MakeNewExtTrigC) {
171 ExternTrigs.push_back(counter);
173 if (MakeNewExtTrigD) {
176 ExternTrigs.push_back(counter);
183 lbne::PennMicroSlice::Payload_Timestamp::timestamp_t current_trigger_time = fSSPTriggerTimes.at(
pos);
205 lbne::PennMicroSlice::Payload_Header*& word_header,
206 lbne::PennMicroSlice::Payload_Timestamp*
const& previous_timestamp,
207 lbne::PennMicroSlice::Payload_Timestamp*& future_timestamp,
208 lbne::PennMicroSlice::Payload_Header*& future_timestamp_header,
209 std::vector<lbne::PennMicroSlice::Payload_Timestamp::timestamp_t> &TimeVector ) {
211 if (previous_timestamp !=
nullptr) {
212 TimeVector.push_back(word_header->get_full_timestamp_post(previous_timestamp->nova_timestamp));
214 if (future_timestamp ==
nullptr) {
215 future_timestamp =
reinterpret_cast<lbne::PennMicroSlice::Payload_Timestamp*
>(msf.get_next_timestamp(future_timestamp_header));
216 if (future_timestamp ==
nullptr) {
217 std::cerr <<
"CAN'T FIND PTB TIMESTAMP WORDS IN MILLISLICE FRAGMENT!!! Logic will fail." <<
std::endl;
221 TimeVector.push_back(word_header->get_full_timestamp_pre(future_timestamp->nova_timestamp));
227 if (pos == 0 && NowOn )
229 else if (PrevOn && NowOn )
231 else if (PrevOn && !NowOn) {
234 }
else if (!PrevOn && !NowOn )
236 else if (!PrevOn && NowOn) {
240 std::cout<<
"ERROR IN PTBFORMATTER'S LOGIC IN COUNTER ANALYSIS"<<
std::endl;
252 std::ostringstream LocStream;
253 LocStream << MapDir << MapFile;
258 if (sp.
find_file(MapFile, FileLoc)) fullname = FileLoc;
260 if (fullname.empty())
261 mf::LogWarning(
"DAQToOffline") <<
"Input PTB channel map file " << MapFile <<
" not found in FW_SEARCH_PATH, or in location " << LocStream.str() <<
". Using online channel numbers!" <<
std::endl;
264 mf::LogVerbatim(
"DAQToOffline") <<
"Build PTB Online->Offline channel Map from " << fullname;
265 std::ifstream
infile(fullname);
266 if (!infile.good()) std::cout <<
"Not finding " << fullname <<
std::endl;
267 while (infile.good()) {
268 infile >> onlineChannel >> offlineChannel;
269 channelMap.insert(std::make_pair(onlineChannel,offlineChannel));
270 mf::LogVerbatim(
"DAQToOffline") <<
" " << onlineChannel <<
" -> " << offlineChannel;
272 mf::LogVerbatim(
"DAQToOffline")<<
"channelMap has size " << channelMap.size();
278 if ( fExtendCountersY == 0 ) fExtendCountersY = fExtendCountersX;
279 if ( fExtendCountersZ == 0 ) fExtendCountersZ = fExtendCountersX;
296 CounterPositionMap.clear();
298 auto fGeom = lar::providerFrom<geo::Geometry>();
300 std::ostringstream CountStream;
301 CountStream << CounterDir << CounterFile;
306 if (sp.
find_file(CounterFile, CountLoc)) CountPath = CountLoc;
308 if (CountPath.empty()) {
309 mf::LogWarning(
"DAQToOffline") <<
"ERROR::Cannot find the counter position map file " << CounterFile <<
" in FW_SEARCH_PATH or " << CounterDir <<
std::endl;
312 std::cout <<
"Loading the counter position map from " << CountPath <<
std::endl;
313 std::ifstream
infile(CountPath);
314 while (infile.good()) {
316 double CentreX, CentreY, CentreZ;
317 char Type, Side, Orientation;
318 infile >> CountInd >> CentreX >> CentreY >> CentreZ >> Type >> Side >> Orientation;
324 TVector3 Centre( CentreX, CentreY, CentreZ );
325 TVector3 TL, TR, BL, BR;
328 double HalfLength = 0.5 * auxDet.
Length();
333 MakeCounterCorners( CountInd, HalfLength, HalfWidth1, HalfWidth2, Centre, TL, TR, BL, BR, fExtendCountersX, fExtendCountersY, fExtendCountersZ );
336 std::vector<TVector3> Corners;
337 Corners.push_back( TL );
338 Corners.push_back( TR );
339 Corners.push_back( BL );
340 Corners.push_back( BR );
343 CounterPositionMap.insert( std::make_pair( CountInd, std::make_pair( Centre, Corners ) ) );
348 void DAQToOffline::MakeCounterCorners(
int CountInd,
double HalfLength,
double HalfWidth1,
double HalfWidth2, TVector3 Centre, TVector3& TL, TVector3& TR, TVector3& BL, TVector3& BR,
double fExtendCountersX,
double fExtendCountersY,
double fExtendCountersZ ) {
353 if ( fExtendCountersY == 0 ) fExtendCountersY = fExtendCountersX;
354 if ( fExtendCountersZ == 0 ) fExtendCountersZ = fExtendCountersX;
357 if ( CountInd < 44 ) {
358 if ( (CountInd >=6 && CountInd <=15) || (CountInd >=28 && CountInd <=37) ) {
361 TL[0] = Centre[0] - fExtendCountersX - HalfWidth1;
362 TL[1] = Centre[1] + fExtendCountersY + HalfLength;
365 TR[0] = Centre[0] + fExtendCountersX + HalfWidth1;
366 TR[1] = Centre[1] + fExtendCountersY + HalfLength;
369 BL[0] = Centre[0] - fExtendCountersX - HalfWidth1;
370 BL[1] = Centre[1] - fExtendCountersY - HalfLength;
373 BR[0] = Centre[0] + fExtendCountersX + HalfWidth1;
374 BR[1] = Centre[1] - fExtendCountersY - HalfLength;
380 TL[1] = Centre[1] + fExtendCountersY + HalfLength;
381 TL[2] = Centre[2] - fExtendCountersZ - HalfWidth1;
384 TR[1] = Centre[1] + fExtendCountersY + HalfLength;
385 TR[2] = Centre[2] + fExtendCountersZ + HalfWidth1;
388 BL[1] = Centre[1] - fExtendCountersY - HalfLength;
389 BL[2] = Centre[2] - fExtendCountersZ - HalfWidth1;
392 BR[1] = Centre[1] - fExtendCountersY - HalfLength;
393 BR[2] = Centre[2] + fExtendCountersZ + HalfWidth1;
396 if ( (CountInd >= 44 && CountInd <= 56) || (CountInd >= 67 && CountInd <= 82) ) {
398 for (
int ww=0; ww<3; ++ww )
399 TL[ww] = TR[ww] = BL[ww] = BR[ww] = Centre[ww];
402 for (
int ww=0; ww<3; ++ww )
403 TL[ww] = TR[ww] = BL[ww] = BR[ww] = Centre[ww];
void MakeCounterCorners(int CountInd, double HalfLength, double HalfWidth1, double HalfWidth2, TVector3 Centre, TVector3 &TL, TVector3 &TR, TVector3 &BL, TVector3 &BR, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void BuildPTBChannelMap(std::string MapDir, std::string MapFile, std::map< int, int > &channelMap)
void GetTimestamp(lbne::PennMilliSliceFragment msf, lbne::PennMicroSlice::Payload_Header *&word_header, lbne::PennMicroSlice::Payload_Timestamp *const &previous_timestamp, lbne::PennMicroSlice::Payload_Timestamp *&future_timestamp, lbne::PennMicroSlice::Payload_Header *&future_timestamp_header, std::vector< lbne::PennMicroSlice::Payload_Timestamp::timestamp_t > &TimeVector)
bool MakeNewExtTrig(uint32_t pos, bool &PrevOn, bool NowOn)
double HalfWidth2() const
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string find_file(std::string const &filename) const
void MakeCounterPositionMap(std::string CounterDir, std::string CounterFile, std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > &CounterPositionMap, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
double HalfWidth1() const
std::vector< raw::ExternalTrigger > PennFragmentToExternalTrigger(artdaq::Fragments const &Fragments, std::map< int, int > &channelMap, lbne::PennMicroSlice::Payload_Timestamp *&FirstPTBTimestamp)
QTextStream & endl(QTextStream &s)