Skip to content

Commit 996ebdd

Browse files
Merge pull request #885 from SBNSoftware/feature/TriggerWorkNikki-PR
Trigger Emulation Bug Fix and smaller updates
2 parents ced6c2c + d7f3a51 commit 996ebdd

8 files changed

Lines changed: 111 additions & 119 deletions

sbndcode/Decoders/PMT/SBNDPMTDecoder_module.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ sbndaq::SBNDPMTDecoder::SBNDPMTDecoder(fhicl::ParameterSet const& p)
195195

196196
produces< std::vector<int> >("MonPulses");
197197
produces< std::vector<int> >("MonPulseSizes");
198+
produces<int>("pairsOverThreshold");
198199
}
199200

200201
void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
@@ -278,6 +279,9 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
278279
auto sizesPtr = std::make_unique<std::vector<int>>();
279280
evt.put(std::move(flatPtr), "MonPulses");
280281
evt.put(std::move(sizesPtr), "MonPulseSizes");
282+
283+
auto pairFlag = std::make_unique<int>(-1);
284+
evt.put(std::move(pairFlag), "pairsOverThreshold");
281285
return;
282286
}
283287

@@ -623,30 +627,27 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
623627
std::vector<int> pulseSizes;
624628
MonPulsesFlat.clear();
625629
pulseSizes.clear();
626-
int TotalFlash = pmtwvfmVec->size()/((int)fn_caenboards*PMTPerBoard); // pmtwvfmVec = waveHandle ???
630+
int pmt_caenboards = (int)fn_caenboards-1;
631+
int TotalFlash = pmtwvfmVec->size()/(pmt_caenboards*PMTPerBoard);
632+
633+
int numPairsOverThreshold = 0;
627634
for (int FlashCounter=0; FlashCounter<TotalFlash; FlashCounter++)
628635
{
629636
int WaveIndex = FlashCounter*PMTPerBoard;
630637
int WaveformSize = (*pmtwvfmVec)[WaveIndex].size();
638+
int pairThisFlash = 0;
631639
std::vector<int> *MonPulse = new std::vector<int>(WaveformSize);
632-
fTriggerService->ConstructMonPulse(*pmtwvfmVec, fmon_threshold, MonPulse, FlashCounter);
640+
fTriggerService->ConstructMonPulse(*pmtwvfmVec, fmon_threshold, MonPulse, FlashCounter, &pairThisFlash);
633641
//MonPulsesAll.push_back(std::move(MonPulse));
634642
MonPulsesFlat.insert(MonPulsesFlat.end(), (*MonPulse).begin(), (*MonPulse).end());
635643
pulseSizes.push_back(MonPulse->size());
644+
numPairsOverThreshold = numPairsOverThreshold + pairThisFlash;
636645
delete MonPulse;
637646
}
638647
// make ptrs
639648
auto flatPtr = std::make_unique<std::vector<int>>(std::move(MonPulsesFlat));
640649
auto sizesPtr = std::make_unique<std::vector<int>>(std::move(pulseSizes));
641-
642-
/*std::unique_ptr< std::vector< std::vector<int> > > MonPulsesPtr(std::make_unique< std::vector< std::vector<int> > > ());
643-
for (auto &pulse : MonPulsesAll) {
644-
MonPulsesPtr->reserve(MonPulsesPtr->size() + pulse.size());
645-
std::move(pulse.begin(), pulse.end(), std::back_inserter(*MonPulsesPtr));
646-
}
647-
// clean up the vector
648-
for (unsigned i = 0; i < MonPulsesAll.size(); i++) MonPulsesAll[i] = std::vector<int>();
649-
*/
650+
auto pairFlag = std::make_unique<int>(numPairsOverThreshold);
650651

651652
board_frag_v.clear();
652653

@@ -663,6 +664,7 @@ void sbndaq::SBNDPMTDecoder::produce(art::Event& evt)
663664

664665
evt.put(std::move(flatPtr), "MonPulses");
665666
evt.put(std::move(sizesPtr), "MonPulseSizes");
667+
evt.put(std::move(pairFlag), "pairsOverThreshold");
666668
}
667669

668670
void sbndaq::SBNDPMTDecoder::get_fragments(artdaq::Fragment & frag, std::vector<std::vector<artdaq::Fragment>> & board_frag_v){

sbndcode/Decoders/PMT/run_pmtdecoder.fcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services: {
1111
MonWidth: 12
1212
TotalCAENBoards: 8
1313
PMTPerBoard: 15
14-
Baseline: 14250
14+
Baseline: 14250 #Run 1: 14250, Run 2: 14257
1515
MC: false
1616
}
1717
}

sbndcode/OpDetSim/TriggerEmulationService.cc

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace calib {
1717
: fMonWidth(pset.get<int>("MonWidth", 12)),
1818
fTotalCAENBoards(pset.get<int>("TotalCAENBoards", 8)),
1919
PMTPerBoard(pset.get<int>("PMTPerBoard", 15)),
20-
Baseline(pset.get<int>("Baseline", 14250)),
20+
Baseline(pset.get<int>("Baseline")),
2121
fMC(pset.get<bool>("MC", true))
2222
{}
2323

@@ -29,9 +29,11 @@ namespace calib {
2929
int MonThreshold,
3030
std::vector<int> *MonPulse,
3131
int FlashCounter,
32-
int *numPairsOverThreshold
32+
int *numPairsOverThreshold,
33+
std::vector<int> PMT_Channels
3334
)
3435
{
36+
3537
// Loop over the entries in our waveform vector
3638
// We care about getting the pairing correct
3739

@@ -44,22 +46,37 @@ namespace calib {
4446
}
4547

4648
std::map<int, const raw::OpDetWaveform*> channel_to_waveform;
47-
for (const auto& wvf : fWaveforms)
49+
for (const auto& wvf : fWaveforms) {
4850
channel_to_waveform[wvf.ChannelNumber()] = &wvf;
51+
}
4952

5053
std::vector<int> Pair2 = { 6, 8, 10, 12, 14, 16, 36, 38, 40, 60, 62, 66, 68, 70, 84, 86, 88, 90, 92, 94, 114, 116, 118, 138, 140, 144, 146, 148, 162, 164, 168, 170, 172, 192, 194, 196, 216, 218, 220, 222, 224, 226, 240, 242, 246, 248, 250, 270, 272, 274, 294, 296, 298, 300, 302, 304};
5154
std::vector<int> Pair1 = { 7, 9, 11, 13, 15, 17, 37, 39, 41, 61, 63, 67, 69, 71, 85, 87, 89, 91, 93, 95, 115, 117, 119, 139, 141, 145, 147, 149, 163, 165, 169, 171, 173, 193, 195, 197, 217, 219, 221, 223, 225, 227, 241, 243, 247, 249, 251, 271, 273, 275, 295, 297, 299, 301, 303, 305};
5255
std::vector<int> Unpaired = {65, 64, 143, 142, 167, 166, 245, 244};
5356
std::set<int> used_channels;
5457

5558
// resize
56-
int ReadoutSize = fWaveforms[0].size();
59+
int ReadoutSize;
60+
if (PMT_Channels.empty()) { std::cout<<"Warning: Please provide PMT channels list."<<std::endl; ReadoutSize = fWaveforms[Pair1[0]].size(); }
61+
else ReadoutSize = fWaveforms[PMT_Channels[0]].size();
5762
MonPulse->assign(ReadoutSize, 0);
5863

5964
for (size_t i = 0; i < Pair1.size(); ++i) {
6065
int ch1 = Pair1[i];
6166
int ch2 = Pair2[i];
6267

68+
// check that ch1 and ch2 show up in PMT_Channels
69+
if (PMT_Channels.empty()) std::cout<<"Warning: Please provide PMT channels list to check if channels are PMT channels."<<std::endl;
70+
else {
71+
if (!(std::find(PMT_Channels.begin(), PMT_Channels.end(), ch1) != PMT_Channels.end())) {
72+
throw cet::exception("TriggerEmulationService") << "Paired channel " << ch1 << " is not PMT channel. Check Pairs list. Skipping..." << std::endl;
73+
continue;
74+
} if (!(std::find(PMT_Channels.begin(), PMT_Channels.end(), ch2) != PMT_Channels.end())) {
75+
throw cet::exception("TriggerEmulationService") << "Paired channel " << ch2 << " is not PMT channel. Check Pairs list. Skipping..." << std::endl;
76+
continue;
77+
}
78+
}
79+
6380
// skip if either waveform is missing
6481
if (channel_to_waveform.count(ch1) == 0 || channel_to_waveform.count(ch2) == 0) continue;
6582
// skip if already processed
@@ -82,6 +99,16 @@ namespace calib {
8299
}
83100

84101
for (int ch : Unpaired) { // Unpaired channels
102+
103+
// check that ch1 and ch2 show up in PMT_Channels
104+
if (PMT_Channels.empty()) std::cout<<"Warning: Please provide PMT channels list to check if channels are PMT channels."<<std::endl;
105+
else {
106+
if (!(std::find(PMT_Channels.begin(), PMT_Channels.end(), ch) != PMT_Channels.end())) {
107+
throw cet::exception("TriggerEmulationService") << "Unpaired channel " << ch << " is not PMT channel. Check list. Skipping..." << std::endl;
108+
continue;
109+
}
110+
}
111+
85112
if (used_channels.count(ch)) continue;
86113
if (channel_to_waveform.count(ch) == 0) continue;
87114

@@ -143,6 +170,9 @@ namespace calib {
143170
CAENChannel=CAENChannel+ChannelStep;
144171
} //loop over channels
145172
} //loop over boards
173+
174+
if (numPairsOverThreshold) *numPairsOverThreshold = *std::max_element(MonPulse->begin(), MonPulse->end());
175+
146176
} // data
147177
} // ConstructMonPulse
148178

sbndcode/OpDetSim/TriggerEmulationService.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
int MonThreshold,
3838
std::vector<int> *MonPulse,
3939
int FlashCounter,
40-
int *numPairsOverThreshold = nullptr
40+
int *numPairsOverThreshold = nullptr,
41+
std::vector<int> PMT_Channels={}
4142
);
4243

4344
int getTotalCAENBoards() const { return fTotalCAENBoards; }

0 commit comments

Comments
 (0)