ActivityTrigger.cxx
Go to the documentation of this file.
1 // ActivityTrigger.cxx
2 //
3 // Karl Warburton --- karlwarb@iastate.edu
4 // May 2017
5 //
6 // A activity trigger class for the DAQ trigger framework.
7 //
8 
9 #ifndef ActivityTrigger_CXX
10 #define ActivityTrigger_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 activity 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("ActivityTrigger_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("ActivityTrigger_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::ActivityTrigger::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 activity TPC trigger , fMakeTrig is " << fMakeTrig << ", and (size) fNumber is now " << fNumber << std::endl;
123 
124  // --- For now just trigger on how raw::RawDigits there are in this event...
125  if (fNumber > 3700) {
126  fTrigDecision = true;
127  } else {
128  fTrigDecision = false;
129  }
130 
131  // --- Return the result of the trigger.
132  return fTrigDecision;
133 } // TriggerOnTPC
134 
135 //----------------------------------------------------------------------
136 //-- The trigger algorithm on just the Photon Detector OpDetWaveforms --
137 //----------------------------------------------------------------------
138 bool triggersim::ActivityTrigger::TriggerOnPD( std::vector< raw::OpDetWaveform > rawPD) {
139  // --- If for some reason you changed your mind about making this trigger...
140  if (!fMakeTrig) return false;
141 
142  // --- Now do stuff...
143  fNumber = rawPD.size();
144  for (unsigned int Wave=0; Wave < rawPD.size(); ++Wave) {
145  if (Wave < 5) {
146  raw::OpDetWaveform ThisWaveform = rawPD[Wave]; // Also, rawPD.at(Wave);
147  std::cout << " Looking at Wave " << Wave << " of " << rawPD.size() << ", it was on channel " << ThisWaveform.ChannelNumber() << ", at time " << ThisWaveform.TimeStamp()
148  << ", there are " << ThisWaveform.Waveform().size() << " ADCs in this waveform " << std::endl;
149  std::vector< short > WaveformVec = ThisWaveform.Waveform();
150  for (unsigned int WaveformLoop=0; WaveformLoop < WaveformVec.size(); ++WaveformLoop) {
151  if (WaveformLoop < 5) {
152  std::cout << " Element " << WaveformLoop << " of " << WaveformVec.size() << " has ADC value " << WaveformVec.at(WaveformLoop) << std::endl;
153  } // If WaveformLoop < 5
154  } // Loop over the Waveform() data member
155  } // If Wave < 5
156  } // Loop over rawPD
157 
158  // --- If there are any OpDetWaveforms return true.
159  if (fNumber) {
160  fTrigDecision = true;
161  } else {
162  fTrigDecision = false;
163  }
164 
165  // --- Return the result of the trigger.
166  return fTrigDecision;
167 } // TriggerOnPD
168 
169 //----------------------------------------------------------------------
170 //----- The trigger algorithm on the RawDigits and OpDetWaveforms ------
171 //----------------------------------------------------------------------
172 bool triggersim::ActivityTrigger::TriggerOnTPC_PD( std::vector< raw::RawDigit > rawTPC, std::vector< raw::OpDetWaveform > rawPD) {
173  // --- If for some reason you changed your mind about making this trigger...
174  if (!fMakeTrig) return false;
175 
176  // --- Now do stuff...
177  std::cout << " The size of the RawDigits is " << rawTPC.size() << ", and the size of the OpDetWaveforms is " << rawPD.size() << std::endl;
178 
179  // --- Look at the above two function about how to access information out of either of these data products...
180 
181  // --- Just default the trigger to true.
182  fTrigDecision = true;
183 
184  // --- Return the result of the trigger.
185  return fTrigDecision;
186 } // TriggerOnTPC_PD
187 
188 //----------------------------------------------------------------------
189 //----- The trigger algorithm on the RawDigits and OpDetWaveforms ------
190 //----------------------------------------------------------------------
191 bool triggersim::ActivityTrigger::TriggerOnTriggers( std::vector<triggersim::BasicTrigger> triggerVec) {
192 
193  std::cout << " Looking at TriggerOnTriggers...I currently have " << triggerVec.size() << " triggers." << std::endl;
194  for (unsigned int TrigVecLoop=0; TrigVecLoop < triggerVec.size(); ++TrigVecLoop) {
195  //triggersim::BasicTrigger ThisTrig = triggerVec.at(TrigVecLoop);
196  //std::cout << " Looking at Trigger " << TrigVecLoop << ", TrigDecision " << ThisTrig.TrigDecision() << ", TrigType " << ThisTrig.TrigType()
197  // << ", TrigSubtype " << ThisTrig.TrigSubType()
198  std::cout << " Looking at Trigger " << TrigVecLoop << ", TrigDecision " << triggerVec[TrigVecLoop].TrigDecision() << ", TrigType " << triggerVec[TrigVecLoop].TrigType()
199  << ", TrigSubtype " << triggerVec[TrigVecLoop].TrigSubType()
200 
201  << std::endl;
202  }
203 
204 
205  // --- Just default the trigger to true.
206  fTrigDecision = true;
207 
208  // --- Return the result of the trigger.
209  return fTrigDecision;
210 } // TriggerOnTriggers
211 
212 
213 //----------------------------------------------------------------------
214 #endif
215 //----------------------------------------------------------------------
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
void Configure(fhicl::ParameterSet const &pset)
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
Signal from induction planes.
Definition: geo_types.h:145
unsigned int fNumber
Some random number to change.
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
bool TriggerOnPD(std::vector< raw::OpDetWaveform > rawPD)
bool TriggerOnTPC_PD(std::vector< raw::RawDigit > rawTPC, std::vector< raw::OpDetWaveform > rawPD)
bool fMakeTrig
Boolean which is passed as to whether to even attempt this trigger.
Definition of data types for geometry description.
bool TriggerOnWholeEvent(art::Event &event)
bool fTrigDecision
did the trigger algorithm decide to keep this event?
bool TriggerOnTriggers(std::vector< triggersim::BasicTrigger > triggerVec)
QTextStream & endl(QTextStream &s)
Event finding and building.
Signal from collection planes.
Definition: geo_types.h:146