TemplateTrigger.cxx
Go to the documentation of this file.
1 // TemplateTrigger.cxx
2 //
3 // Karl Warburton --- karlwarb@iastate.edu
4 // May 2017
5 //
6 // A template trigger class for the DAQ trigger framework.
7 //
8 
9 #ifndef TemplateTrigger_CXX
10 #define TemplateTrigger_CXX
11 
12 // Framework includes
16 #include "fhiclcpp/ParameterSet.h"
18 
22 
23 // DUNETPC specific includes
25 
26 // C++ includes
27 #include <iomanip>
28 
29 //----------------------------------------------------------------------
30 //------------- The constructor for this trigger algorithm -------------
31 //----------------------------------------------------------------------
33 
34 //----------------------------------------------------------------------
35 //------------ The configuration for this trigger algorithm ------------
36 //----------------------------------------------------------------------
38  fMakeTrig = true;
39  fMyString = pset.get<std::string> ("AString");
40  fRawDigLabel = pset.get<std::string> ("RawDigitLabel");
41  fOpWaveLabel = pset.get<std::string> ("OpDetWaveLabel");
42 
43  // --- We have got all of the fcl parameters here too, lets check that they are what we expect...
44  std::cout << "\n------In my trigger class------\nThe fcl params have been set to :"
45  << "\n fMyString: " << fMyString
46  << "\n fRawDigLabel: " << fRawDigLabel
47  << "\n fOpWaveLabel: " << fOpWaveLabel
48  << "\n-------------------------------\n"
49  << std::endl;
50 } // Configure
51 
52 //----------------------------------------------------------------------
53 //------------ The trigger algorithm on the whole art event ------------
54 //----------------------------------------------------------------------
56  // --- If for some reason you changed your mind about making this trigger...
57  if (!fMakeTrig) return false;
58 
59  // --- Now do stuff...
60  fNumber = event.event();
61  std::cout << " I have just got into my template trigger for event " << event.event() << ", fMakeTrig is " << fMakeTrig << ", and fNumber is now " << fNumber << std::endl;
62 
63  // --- Lift out the TPC raw digits:
64  auto digits = event.getValidHandle<std::vector<raw::RawDigit> >(fRawDigLabel);
65  if ( digits.failedToGet() )
66  mf::LogError("TemplateTrigger_Algorithm") << "The raw::RawDigit you gave me " << fRawDigLabel << " is not in the event..." << std::endl;
67 
68  // --- Lift out the Photon Detector OpDetWaveforms:
69  auto waveforms = event.getValidHandle<std::vector<raw::OpDetWaveform> >(fOpWaveLabel);
70  if ( waveforms.failedToGet() )
71  mf::LogError("TemplateTrigger_Algorithm") << "The raw::OpDetWaveform you gave me " << fOpWaveLabel << " is not in the event..." << std::endl;
72 
73  // --- We have got the data products here too, look at the functions below to find out how to use them...
74  std::cout << " The size of digits is " << digits->size() << ", and the size of wave is " << waveforms->size() << std::endl;
75 
76  // --- Make a decision based on the event number...
77  if (event.event() < 3) {
78  fTrigDecision = true;
79  } else {
80  fTrigDecision = false;
81  }
82 
83  // --- Return the result of the trigger.
84  return fTrigDecision;
85 } // TriggerOnWholeEvent
86 
87 //----------------------------------------------------------------------
88 //----------- The trigger algorithm on just the TPC RawDigits ----------
89 //----------------------------------------------------------------------
90 bool triggersim::TemplateTrigger::TriggerOnTPC( std::vector< raw::RawDigit> rawTPC ) {
91  // --- If for some reason you changed your mind about making this trigger...
92  if (!fMakeTrig) return false;
93 
94  // --- It is often helpful to make a geometry service handle.
96 
97  // --- Now do stuff...
98  fNumber = rawTPC.size();
99  for (unsigned int Dig=0; Dig < rawTPC.size(); ++Dig) {
100  raw::RawDigit ThisDig = rawTPC[Dig]; // Can also use rawTPC.at(Dig);
101  int Chan = rawTPC[Dig].Channel(); // Alternatively can access stuff by doing rawTPC[Dig]->Channel()
102  if (Dig < 5) {
103  std::cout << " Looking at Dig " << Dig << " of " << rawTPC.size() << ", it has " << ThisDig.Samples() << " samples on Channel " << ThisDig.Channel() << " ("<<Chan<<")"
104  << ", and " << ThisDig.NADC() << " ADCs with a pedestal of " << ThisDig.GetPedestal()
105  << std::endl;
106  for (unsigned int ADCLoop=0; ADCLoop < ThisDig.NADC(); ++ADCLoop) {
107  if (ADCLoop < 5) {
108  std::cout << " Looking at ADC " << ADCLoop << " of " << ThisDig.NADC() << ", it was " << ThisDig.ADC(ADCLoop) << std::endl;
109  } // If ADCLoop < 5
110  } // Loop over ADCs
111  } // If Dig < 5
112 
113  // --- It can be useful to select only specific types of channels, normally you just continue for one of them.
114  if (geom->SignalType(ThisDig.Channel()) == geo::kCollection) {
115  // --- Something for collection plane wires...
116  } else if (geom->SignalType(ThisDig.Channel()) == geo::kInduction) {
117  // --- Something for induction plane wires...
118  }
119 
120  } // Loop over rawPD
121 
122  std::cout << " I have just got into my template TPC trigger , fMakeTrig is " << fMakeTrig << ", and (size) fNumber is now " << fNumber << std::endl;
123 
124  // --- For now just trigger on how many raw::RawDigits there are in this event...
125  // --- This number for triggering in the trigger has ABSOLUTELY NO PHYSICS CONSIDERATIONS
126  // --- - Do not read even the slightest bit into this. This just ensures that not every event is triggered.
127  if (fNumber > 3700) {
128  fTrigDecision = true;
129  } else {
130  fTrigDecision = false;
131  }
132 
133  // --- Return the result of the trigger.
134  return fTrigDecision;
135 } // TriggerOnTPC
136 
137 //----------------------------------------------------------------------
138 //-- The trigger algorithm on just the Photon Detector OpDetWaveforms --
139 //----------------------------------------------------------------------
140 bool triggersim::TemplateTrigger::TriggerOnPD( std::vector< raw::OpDetWaveform > rawPD) {
141  // --- If for some reason you changed your mind about making this trigger...
142  if (!fMakeTrig) return false;
143 
144  // --- Now do stuff...
145  fNumber = rawPD.size();
146  for (unsigned int Wave=0; Wave < rawPD.size(); ++Wave) {
147  if (Wave < 5) {
148  raw::OpDetWaveform ThisWaveform = rawPD[Wave]; // Also, rawPD.at(Wave);
149  std::cout << " Looking at Wave " << Wave << " of " << rawPD.size() << ", it was on channel " << ThisWaveform.ChannelNumber() << ", at time " << ThisWaveform.TimeStamp()
150  << ", there are " << ThisWaveform.Waveform().size() << " ADCs in this waveform " << std::endl;
151  std::vector< short > WaveformVec = ThisWaveform.Waveform();
152  for (unsigned int WaveformLoop=0; WaveformLoop < WaveformVec.size(); ++WaveformLoop) {
153  if (WaveformLoop < 5) {
154  std::cout << " Element " << WaveformLoop << " of " << WaveformVec.size() << " has ADC value " << WaveformVec.at(WaveformLoop) << std::endl;
155  } // If WaveformLoop < 5
156  } // Loop over the Waveform() data member
157  } // If Wave < 5
158  } // Loop over rawPD
159 
160  // --- If there are any OpDetWaveforms return true.
161  if (fNumber) {
162  fTrigDecision = true;
163  } else {
164  fTrigDecision = false;
165  }
166 
167  // --- Return the result of the trigger.
168  return fTrigDecision;
169 } // TriggerOnPD
170 
171 //----------------------------------------------------------------------
172 //----- The trigger algorithm on the RawDigits and OpDetWaveforms ------
173 //----------------------------------------------------------------------
174 bool triggersim::TemplateTrigger::TriggerOnTPC_PD( std::vector< raw::RawDigit > rawTPC, std::vector< raw::OpDetWaveform> rawPD) {
175  // --- If for some reason you changed your mind about making this trigger...
176  if (!fMakeTrig) return false;
177 
178  // --- Now do stuff...
179  std::cout << " The size of the RawDigits is " << rawTPC.size() << ", and the size of the OpDetWaveforms is " << rawPD.size() << std::endl;
180 
181  // --- Look at the above two function about how to access information out of either of these data products...
182 
183  // --- Just default the trigger to true.
184  fTrigDecision = true;
185 
186  // --- Return the result of the trigger.
187  return fTrigDecision;
188 } // TriggerOnTPC_PD
189 
190 //----------------------------------------------------------------------
191 //----- The trigger algorithm on the RawDigits and OpDetWaveforms ------
192 //----------------------------------------------------------------------
193 bool triggersim::TemplateTrigger::TriggerOnTriggers( std::vector<triggersim::BasicTrigger> triggerVec) {
194 
195  std::cout << " Looking at TriggerOnTriggers...I currently have " << triggerVec.size() << " triggers." << std::endl;
196  for (unsigned int TrigVecLoop=0; TrigVecLoop < triggerVec.size(); ++TrigVecLoop) {
197  //triggersim::BasicTrigger ThisTrig = triggerVec.at(TrigVecLoop);
198  //std::cout << " Looking at Trigger " << TrigVecLoop << ", TrigDecision " << ThisTrig.TrigDecision() << ", TrigType " << ThisTrig.TrigType()
199  // << ", TrigSubtype " << ThisTrig.TrigSubType()
200  std::cout << " Looking at Trigger " << TrigVecLoop << ", TrigDecision " << triggerVec[TrigVecLoop].TrigDecision() << ", TrigType " << triggerVec[TrigVecLoop].TrigType()
201  << ", TrigSubtype " << triggerVec[TrigVecLoop].TrigSubType()
202 
203  << std::endl;
204  }
205 
206 
207  // --- Just default the trigger to true.
208  fTrigDecision = true;
209 
210  // --- Return the result of the trigger.
211  return fTrigDecision;
212 } // TriggerOnTriggers
213 
214 
215 //----------------------------------------------------------------------
216 #endif
217 //----------------------------------------------------------------------
float GetPedestal() const
Definition: RawDigit.h:214
EventNumber_t event() const
Definition: DataViewImpl.cc:85
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
bool TriggerOnTPC(std::vector< raw::RawDigit > rawTPC)
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:65
short ADC(int i) const
ADC vector element number i; no decompression is applied.
Definition: RawDigit.h:208
TimeStamp_t TimeStamp() const
Definition: OpDetWaveform.h:66
std::string string
Definition: nybbler.cc:12
bool TriggerOnTriggers(std::vector< triggersim::BasicTrigger > triggerVec)
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::vector< ADC_Count_t > & Waveform()
Definition: OpDetWaveform.h:59
art framework interface to geometry description
bool fTrigDecision
did the trigger algorithm decide to keep this event?
unsigned int fNumber
Some random number to change.
Signal from induction planes.
Definition: geo_types.h:145
T get(std::string const &key) const
Definition: ParameterSet.h:271
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
Definition of data types for geometry description.
bool fMakeTrig
Boolean which is passed as to whether to even attempt this trigger.
bool TriggerOnTPC_PD(std::vector< raw::RawDigit > rawTPC, std::vector< raw::OpDetWaveform > rawPD)
bool TriggerOnPD(std::vector< raw::OpDetWaveform > rawPD)
QTextStream & endl(QTextStream &s)
Event finding and building.
Signal from collection planes.
Definition: geo_types.h:146
void Configure(fhicl::ParameterSet const &pset)
bool TriggerOnWholeEvent(art::Event &event)