TemplateTriggerProd_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TemplateTriggerProd
3 // Module Type: producer
4 // File: TemplateTriggerProd_module.cc
5 //
6 // Generated at Tuesday March 29 2016 by Michael Baird using the old
7 // copy and paste method...
8 //
9 // Modified by Karl Warburton May 9th 2017 to reflect the move away
10 // services (for better or worse...)
11 // --- contact information --- karlwarb@iastate.edu
12 //
13 ////////////////////////////////////////////////////////////////////////
14 
15 // C++ includes
16 
17 // ROOT includes
18 #include "TH1F.h"
19 #include "TTree.h"
20 
21 // Framework includes
26 //#include "art/Framework/Principal/Run.h"
27 //#include "art/Framework/Principal/SubRun.h"
30 #include "fhiclcpp/ParameterSet.h"
37 
38 // DUNETPC specific includes
41 
42 // The trigger classes which you're including
44 
45 namespace triggersim { // Declare that we are working in the triggersim namespace
46 
48 
49  public:
50 
51  explicit TemplateTriggerProd(fhicl::ParameterSet const & pset);
52 
53  // Plugins should not be copied or assigned.
54  TemplateTriggerProd(TemplateTriggerProd const &) = delete;
58 
59  // The main guts...
60  void produce(art::Event& event) override;
61 
62  void reconfigure(fhicl::ParameterSet const & pset);
63 
64  // If you want to another function...
65  // void YourFunction();
66 
67  // Declare our classes as data members...
69 
70  private:
71 
72  // --- We want to use backtracker later backtracker.
74 
75  // declare fcl input variables here
79  // Your fcl params to send to the trigger functions...
80  };
81 
82  //......................................................
84  TempTrig()
85  {
86  // --- Declare what this module is puttting in the art event.
87  produces< std::vector<triggersim::BasicTrigger> >();
88  // --- Configure my trigger module.
89  this->reconfigure(pset);
90  // --- Configure my trigger class.
91  TempTrig.Configure( pset );
92  }
93 
94 
95 
96  //......................................................
98  {
99  // --- Pull the variables from the fcl file.
100  fAString = pset.get<std::string> ("AString");
101  fRawDigitLabel = pset.get<std::string> ("RawDigitLabel");
102  fOpDetWaveLabel = pset.get<std::string> ("OpDetWaveLabel");
103 
104  // To convince ourselves that they have been set, print them out...
105  std::cout << "\n------In my trigger module------\nThe fcl params have been set to :"
106  << "\n fAString: " << fAString
107  << "\n fRawDigitLabel: " << fRawDigitLabel
108  << "\n fOpDetWaveLabel: " << fOpDetWaveLabel
109  << "\n-------------------------------\n"
110  << std::endl;
111  }
112 
113  //......................................................
115  {
116  // --- Make the vector of BasicTrigger objects:
117  std::unique_ptr< std::vector<triggersim::BasicTrigger> > triggers(new std::vector<triggersim::BasicTrigger>);
118 
119  // --- Lift out the TPC raw digits:
120  auto rawdigits = event.getValidHandle<std::vector<raw::RawDigit> >(fRawDigitLabel);
121  if ( rawdigits.failedToGet() )
122  mf::LogError("TemplateTrigger_Producer") << "The raw::RawDigit you gave me " << fRawDigitLabel << " is not in the event..." << std::endl;
123 
124  std::cout << "Let's get some rawdigit stuff...Size " << rawdigits->size() << " rawdigits[0]->samples() " << (*rawdigits)[0].Samples() << std::endl;
125 
126  // --- Lift out the Photon Detector OpDetWaveforms:
127  auto waveforms = event.getValidHandle<std::vector<raw::OpDetWaveform> >(fOpDetWaveLabel);
128  if ( rawdigits.failedToGet() )
129  mf::LogError("TemplateTrigger_Producer") << "The raw::OpDetWaveform you gave me " << fOpDetWaveLabel << " is not in the event..." << std::endl;
130 
131  // --- Lets get the MCTruth information out of the event using the backtracker we defined earlier...
132  const sim::ParticleList& plist = pi_serv->ParticleList();
133  // --- Now loop through the particle list.
134  for ( sim::ParticleList::const_iterator ipar = plist.begin(); ipar!=plist.end(); ++ipar) {
135  // --- Grab this particle.
136  simb::MCParticle *particle = ipar->second;
137  // Let's just write out what our primary particles are...
138  if (particle->Process() != "primary") continue; // Can also check that particle->Mother() != 0.
139  std::cout << "-- Particle with TrackID " << particle->TrackId() << ", which was a " << particle->PdgCode() << " was a primary and had initial energy " << particle->E()
140  << ", " << particle->NumberTrajectoryPoints() << " trajectory points, and " << particle->NumberDaughters() << " daughters. Process - " << particle->Process()
141  << std::endl;
142  }
143 
144  // **************************************************
145  // *********** Trigger on the whole event ***********
146  // **************************************************
147  std::cout << "\nLet's trigger on the whole event...." << std::endl;
148 
149  // --- Now call the class...
150  bool EvTrigDec = TempTrig.TriggerOnWholeEvent( event );
151 
152  // --- Make my basic trigger and push it back
154  triggers->push_back( my_ev_trig );
155 
156  std::cout << "I have now left my trigger, it's decision was " << EvTrigDec << ".\n" << std::endl;
157 
158  // **************************************************
159  // ************* Trigger on the TPC info ************
160  // **************************************************
161  std::cout << "\nLet's trigger on the TPC info...." << std::endl;
162 
163  // --- Now call the class...
164  bool TPCTrigDec = TempTrig.TriggerOnTPC( *rawdigits );
165 
166  // --- Make my basic trigger and push it back
168  triggers->push_back( my_tpc_trig );
169 
170  std::cout << "I have now left my trigger, it's decision was " << TPCTrigDec << ".\n" << std::endl;
171 
172  // **************************************************
173  // ******** Trigger on the OpDetWaveform info *******
174  // **************************************************
175  std::cout << "\nLet's trigger on the OpDetWaveform info...." << std::endl;
176 
177  // --- Now call the class...
178  bool PDTrigDec = TempTrig.TriggerOnPD( *waveforms );
179 
180  // --- Make my basic trigger and push it back
182  triggers->push_back( my_pd_trig );
183 
184  std::cout << "I have now left my trigger, it's decision was " << PDTrigDec << ".\n" << std::endl;
185 
186 
187  // **************************************************
188  // *** Trigger on the OpDetWaveform and TPC info ****
189  // **************************************************
190  std::cout << "\nLet's trigger on the TPC and OpDetWaveform info...." << std::endl;
191 
192  // --- Now call the class...
193  bool TPC_PD_TrigDec = TempTrig.TriggerOnTPC_PD( *rawdigits, *waveforms );
194 
195  // --- Make my basic trigger and push it back
196  triggersim::BasicTrigger my_tpc_pd_trig( TPC_PD_TrigDec , triggersim::kNu, triggersim::kNuBeam);
197  triggers->push_back( my_tpc_pd_trig );
198 
199  std::cout << "I have now left my trigger, it's decision was " << TPC_PD_TrigDec << ".\n" << std::endl;
200 
201 
202  // **************************************************
203  // **** Trigger some of the triggers we've made *****
204  // **************************************************
205  std::cout << "\nLet's trigger on the triggers I've just made...." << std::endl;
206 
207  // --- Now call the class...
208  bool Trig_TrigDec = TempTrig.TriggerOnTriggers( *triggers );
209 
210  // --- Make my basic trigger and push it back
211  triggersim::BasicTrigger my_trig_trig( Trig_TrigDec , triggersim::kNu, triggersim::kNuBeam);
212  triggers->push_back( my_trig_trig );
213 
214  std::cout << "I have now left my trigger, it's decision was " << Trig_TrigDec << ".\n" << std::endl;
215 
216  // **************************************************
217  // ******* Now put all of that into the event *******
218  // **************************************************
219  event.put(std::move(triggers));
220 
221  } // TemplateTriggerProd::produce()
222  //......................................................
223  // If you want to another function...
224 
225  //......................................................
227 } // namespace triggersim
double E(const int i=0) const
Definition: MCParticle.h:233
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
int PdgCode() const
Definition: MCParticle.h:212
bool TriggerOnTPC(std::vector< raw::RawDigit > rawTPC)
std::string string
Definition: nybbler.cc:12
void produce(art::Event &event) override
art::ServiceHandle< cheat::ParticleInventoryService > pi_serv
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
bool TriggerOnTriggers(std::vector< triggersim::BasicTrigger > triggerVec)
void reconfigure(fhicl::ParameterSet const &pset)
intermediate_table::const_iterator const_iterator
const unsigned int kNu
Definition: TriggerTypes.h:17
std::string Process() const
Definition: MCParticle.h:215
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:217
int TrackId() const
Definition: MCParticle.h:210
TemplateTriggerProd & operator=(TemplateTriggerProd const &)=delete
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
const sim::ParticleList & ParticleList() const
bool TriggerOnTPC_PD(std::vector< raw::RawDigit > rawTPC, std::vector< raw::OpDetWaveform > rawPD)
bool TriggerOnPD(std::vector< raw::OpDetWaveform > rawPD)
TemplateTriggerProd(fhicl::ParameterSet const &pset)
QTextStream & endl(QTextStream &s)
Event finding and building.
const unsigned int kNuBeam
Definition: TriggerTypes.h:45
void Configure(fhicl::ParameterSet const &pset)
bool TriggerOnWholeEvent(art::Event &event)