Skip to content

Commit 7dafc12

Browse files
authored
Fix PMTWaveformSim event skipping (#366)
* Remove skipping of events Instead, we can fill one of the dead PMTs with a "minimal" waveform to pass to the hit finding tool * Remove event skipping for hit finder tool * Fix skip event * Add files via upload * Add files via upload * Add files via upload * Update PMTWaveformSim.cpp forgot to set the channel ID to a dead PMT * Update README.md Quick disclaimer about the dummy channel
1 parent 22e6afc commit 7dafc12

File tree

7 files changed

+50
-68
lines changed

7 files changed

+50
-68
lines changed

UserTools/AssignBunchTimingMC/AssignBunchTimingMC.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ bool AssignBunchTimingMC::Execute()
9999
std::cout << "AssignBunchTimingMC: Executing tool..." << std::endl;
100100
}
101101

102-
// An upstream tool may opt to skip this execution stage
103-
// For example the PMTWaveformSim tool will skip events with no MCHits or if
104-
// no waveforms are produced.
105-
bool skip = false;
106-
bool got_skip_status = m_data->Stores["ANNIEEvent"]->Get("SkipExecute", skip);
107-
if (got_skip_status && skip) {
108-
Log("AssignBunchTimingMC: An upstream tool told me to skip this event.",v_warning,verbosity);
109-
return true;
110-
}
111-
112102
if (!LoadStores()) // Load info from store
113103
return false;
114104
if (verbosity >= v_debug) {

UserTools/ClusterClassifiers/ClusterClassifiers.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ bool ClusterClassifiers::Initialise(std::string configfile, DataModel &data){
3535

3636
bool ClusterClassifiers::Execute(){
3737

38-
//We're gonna make ourselves a couple cluster classifier maps boyeeee
39-
bool skip = false;
40-
bool goodSkipStatus = m_data->Stores.at("ANNIEEvent")->Get("SkipExecute", skip);
41-
if (goodSkipStatus && skip) {
42-
logmessage = "ClusterClassifier: An upstream tool told me to skip this event.";
43-
Log(logmessage, v_warning, verbosity);
44-
return true;
45-
}
46-
4738
if(verbosity>4) std::cout << "ClusterClassifiers tool: Accessing cluster map in CStore" << std::endl;
4839
bool get_clusters = false;
4940
m_data->CStore.Get("ClusterMap",m_all_clusters);

UserTools/ClusterFinder/ClusterFinder.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,6 @@ bool ClusterFinder::Execute(){
165165
//----------------------------------------------------------------------------
166166
//---------------get the members of the ANNIEEvent----------------------------
167167
//----------------------------------------------------------------------------
168-
169-
// An upstream tool may opt to skip this execution stage
170-
// For example the PMTWaveformSim tool will skip events with no MCHits or if
171-
// no waveforms are produced.
172-
bool skip = false;
173-
bool got_skip_status = m_data->Stores["ANNIEEvent"]->Get("SkipExecute", skip);
174-
if (got_skip_status && skip) {
175-
Log("ClusterFinder: An upstream tool told me to skip this event.",v_warning,verbose);
176-
return true;
177-
}
178168

179169
m_data->Stores["ANNIEEvent"]->Get("EventNumber", evnum);
180170
//m_data->Stores["ANNIEEvent"]->Get("BeamStatus", BeamStatus);

UserTools/PMTWaveformSim/PMTWaveformSim.cpp

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,51 @@ bool PMTWaveformSim::Execute()
9797
{
9898
int load_status = LoadFromStores();
9999

100-
100+
if (load_status == 0) return false;
101+
101102
// The container for the data that we'll put into the ANNIEEvent
102103
std::map<unsigned long, std::vector<Waveform<uint16_t>> > RawADCDataMC;
103104
std::map<unsigned long, std::vector<CalibratedADCWaveform<double>> > CalADCDataMC;
104105

106+
107+
// If MCHits is empty (load_status == 2), create one minimal baseline waveform so that the hit finder doesn't freak out
108+
// while keeping the rest of the machinery the same
109+
if (load_status == 2) {
110+
logmessage = "PMTWaveformSim: Creating single minimal baseline waveform (No MCHits)...";
111+
Log(logmessage, v_message, verbosity);
112+
113+
// we can put the dummy baseline in a dead PMT channel so it won't be integrated
114+
unsigned long dummy_chankey = 333; // PMT ID 333 is dead
115+
116+
// create a short baseline waveform (~50ns) so that the hit finder will be satisfied
117+
int num_samples = 25; // 50ns
118+
double noiseSigma = fRandom.Gaus(1, 0.01); // set the noise to basically 0
119+
int baseline = fRandom.Uniform(300, 350);
120+
121+
std::vector<uint16_t> rawSamples;
122+
std::vector<double> calSamples;
123+
124+
for (int i = 0; i < num_samples; i++) {
125+
double noise = fRandom.Gaus(0, noiseSigma);
126+
int sample = std::round(noise + baseline);
127+
sample = (sample > 4095) ? 4095 : ((sample < 0) ? 0 : sample); // shouldn't matter
128+
129+
rawSamples.push_back(sample);
130+
calSamples.push_back((sample - baseline) * ADC_TO_VOLT);
131+
}
132+
133+
std::vector<Waveform<uint16_t>> rawWaveforms;
134+
std::vector<CalibratedADCWaveform<double>> calWaveforms;
135+
136+
rawWaveforms.emplace_back(0, rawSamples);
137+
calWaveforms.emplace_back(0, calSamples, baseline, noiseSigma);
138+
139+
RawADCDataMC.emplace(dummy_chankey, rawWaveforms);
140+
CalADCDataMC.emplace(dummy_chankey, calWaveforms);
141+
142+
}
143+
144+
// normal use case (no blank MCHits)
105145
for (auto mcHitsIt : *fMCHits) { // Loop over the hit PMTs
106146
int PMTID = mcHitsIt.first;
107147

@@ -177,22 +217,14 @@ bool PMTWaveformSim::Execute()
177217
CalADCDataMC.emplace(PMTID, calWaveforms);
178218
}// end loop over PMTs
179219

220+
180221
// Publish the waveforms to the ANNIEEvent store if we have them
181-
if (RawADCDataMC.size()) {
182-
m_data->Stores.at("ANNIEEvent")->Set("RawADCDataMC", RawADCDataMC);
183-
m_data->Stores.at("ANNIEEvent")->Set("CalibratedADCData", CalADCDataMC);
184-
} else {
185-
logmessage = "PMTWaveformSim: No waveforms produced. Skipping!";
186-
Log(logmessage, v_warning, verbosity);
187-
m_data->Stores.at("ANNIEEvent")->Set("SkipExecute", true);
188-
return true;
189-
}
190-
222+
m_data->Stores.at("ANNIEEvent")->Set("RawADCDataMC", RawADCDataMC);
223+
m_data->Stores.at("ANNIEEvent")->Set("CalibratedADCData", CalADCDataMC);
191224

192225
if (fDebug)
193226
FillDebugGraphs(RawADCDataMC);
194227

195-
m_data->Stores.at("ANNIEEvent")->Set("SkipExecute", false);
196228
return true;
197229
}
198230

@@ -460,7 +492,7 @@ int PMTWaveformSim::LoadFromStores()
460492
}
461493

462494
if (fMCHits->empty()) {
463-
logmessage = "PMTWaveformSim: The MCHits map is empty! Skipping!";
495+
logmessage = "PMTWaveformSim: The MCHits map is empty! Will fill a single PMT with a minimal waveform.";
464496
Log(logmessage, v_warning, verbosity);
465497
return 2;
466498
}

UserTools/PMTWaveformSim/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ MakeDebugFile 0 # Produce a root file containing all the simulated waveforms
3535

3636
## Other notes
3737
#### CAUTION: In line 90, the RNG seed is set in Initialization based on the clock time. If any other downstream tools are also setting a random seed, there may be unexpected behavior as a result of this tool.
38+
39+
For events with no MCHits (and hence no waveforms to simulate) a "dummy" waveform is simulated in one of the dead PMT channels (333). The dummy waveform is very short (50ns) and samples from a noise distribution lower than normal, as to not have any hits register in the hit finder (the hit finder will skip dead PMTs anyways). Passing at least one waveform to the hit finding tools prevents crashing. **IF** that PMT is ever repaired or comes back online, please move this dummy channel to a different offline channel.
40+

UserTools/PhaseIIADCHitFinder/PhaseIIADCHitFinder.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,6 @@ bool PhaseIIADCHitFinder::Execute() {
140140

141141
if (mc_waveforms) {
142142
got_raw_data = annie_event->Get("RawADCDataMC", raw_waveform_map);
143-
144-
// Some executes are skipped if there are no MCHits or waveforms produced
145-
// Put the cleared maps into the ANNIEEvent to ensure that a downstream
146-
// tool doesn't grab a map from a previous event
147-
bool skip = false;
148-
bool got_skip_status = annie_event->Get("SkipExecute", skip);
149-
if (got_skip_status && skip) {
150-
Log("PhaseIIADCHitFinder: An upstream tool told me to skip this event.",v_warning,verbosity);
151-
152-
m_data->Stores.at("ANNIEEvent")->Set("RecoADCHits", pulse_map);
153-
m_data->Stores.at("ANNIEEvent")->Set("RecoADCAuxHits", aux_pulse_map);
154-
155-
return true;
156-
}
157143
}// end if mc_waveforms
158144

159145
}
@@ -168,7 +154,7 @@ bool PhaseIIADCHitFinder::Execute() {
168154
verbosity);
169155
return false;
170156
}
171-
else if ( raw_waveform_map.empty() ) {
157+
else if ( raw_waveform_map.empty() && !mc_waveforms ) {
172158
Log("Error: The PhaseIIADCHitFinder tool found an empty RawADCData entry", v_error,
173159
verbosity);
174160
return false;
@@ -197,7 +183,7 @@ bool PhaseIIADCHitFinder::Execute() {
197183
" entry", v_error, verbosity);
198184
return false;
199185
}
200-
else if ( calibrated_waveform_map.empty() ) {
186+
else if ( calibrated_waveform_map.empty() && !mc_waveforms ) {
201187
Log("Error: The PhaseIIADCHitFinder tool found an empty CalibratedADCData entry",
202188
v_error, verbosity);
203189
return false;

UserTools/PhaseIITreeMaker/PhaseIITreeMaker.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,6 @@ bool PhaseIITreeMaker::Execute(){
526526
// Reset variables
527527
this->ResetVariables();
528528
// Get a pointer to the ANNIEEvent Store
529-
530-
// An upstream tool may opt to skip this execution stage
531-
// For example the PMTWaveformSim tool will skip events with no MCHits or if
532-
// no waveforms are produced.
533-
bool skip = false;
534-
bool got_skip_status = m_data->Stores["ANNIEEvent"]->Get("SkipExecute", skip);
535-
if (got_skip_status && skip) {
536-
Log("PhaseIITreeMaker: An upstream tool told me to skip this event.",v_warning,verbosity);
537-
return true;
538-
}
539529

540530
// If only clean events are built, return true for dirty events
541531
if(fillCleanEventsOnly){

0 commit comments

Comments
 (0)