TemplateTriggerAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TemplateTriggerAna
3 // Module Type: analyzer
4 // File: TemplateTriggerAna_module.cc
5 //
6 // Generated at Fri Feb 19 08:55:48 2016 by Michael Baird using artmod
7 // from cetpkgsupport v1_10_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // C++ includes
11 
12 // ROOT includes
13 #include "TH1F.h"
14 #include "TTree.h"
15 
16 // Framework includes
23 #include "art_root_io/TFileDirectory.h"
24 #include "art_root_io/TFileService.h"
27 #include "fhiclcpp/ParameterSet.h"
29 
30 // DUNETPC specific includes
33 
34 namespace triggersim {
35 
37 
38 public:
39 
40  explicit TemplateTriggerAna(fhicl::ParameterSet const & p);
41 
42  // Plugins should not be copied or assigned.
43  TemplateTriggerAna(TemplateTriggerAna const &) = delete;
47 
48  // The main guts...
49  void analyze(art::Event const & evt) override;
50 
51  void reconfigure(fhicl::ParameterSet const & p);
52 
53  void beginJob() override;
54 
55  void ResetVars();
56 
57 private:
58 
59  // label for module that made trigger objects
61 
62  // a simple histo to be filled
63  TH1F *fTrigTypes;
64 
65  // The name of our TTree, and the variables which we want to put in it.
66  TTree *TrigAnaTree;
67  int Run; ///< The run which the trigger was taken from
68  int SubRun; ///< The SubRun which the trigger was taken from
69  int Event; ///< The event which the trigger was taken from
70  bool TrigDecision; ///< The decision of the trigger
71  int TrigType; ///< The type of trigger decision which was made
72  int TrigSubType; ///< The subtype of trigger decision which was made
73 };
74 
75 //......................................................
77  Run = -1;
78  SubRun = -1;
79  Event = -1;
80  TrigDecision = false;
81  TrigType = -1;
82  TrigSubType = -1;
83 }
84 
85 //......................................................
87  :
88  EDAnalyzer(p)
89 {
90  this->reconfigure(p);
91 }
92 
93 //......................................................
95 {
96  fTriggerLabel = p.get<std::string> ("TriggerLabel");
97 }
98 
99 //......................................................
101 {
102  // --- Make a handle to the TFileService - the thing that handles all the histogram and TTree outputs...
104  // --- Now we can declare the histrogram which we want to make.
105  fTrigTypes = tfs->make<TH1F>("fTrigTypes","Trigger Types;trig type;count",
106  101,-0.5,100.5);
107 
108  // --- Now we want to declare our TTree, and set the names of the variables in it...
109  TrigAnaTree = tfs->make<TTree>("TrigAnaTree", "Analysis tree from triggers");
110  TrigAnaTree -> Branch( "Run" , &Run );
111  TrigAnaTree -> Branch( "SubRun" , &SubRun );
112  TrigAnaTree -> Branch( "Event" , &Event );
113  TrigAnaTree -> Branch( "TrigDecision", &TrigDecision );
114  TrigAnaTree -> Branch( "TrigType" , &TrigType );
115  TrigAnaTree -> Branch( "TrigSubType" , &TrigSubType );
116 }
117 
118 
119 
120 //......................................................
122 
123  // --- Reset all of our variables...
124  ResetVars();
125 
126  // --- Get trigger data products out of the event...
127  auto triggers = evt.getValidHandle<std::vector<triggersim::BasicTrigger> >(fTriggerLabel);
128 
129  // --- Loop over trigger objects...
130  for(unsigned int i = 0; i < triggers->size(); ++i) {
131 
132  // --- Set our variables for the TTree...
133  Run = evt.run();
134  SubRun = evt.subRun();
135  Event = evt.event();
136 
137  TrigDecision = (*triggers)[i].TrigDecision();
138  TrigType = (*triggers)[i].TrigType();
139  TrigSubType = (*triggers)[i].TrigSubType();
140  // --- Print some info, and confirm to ourselves that our variables are correctly set...
141  std::cout << "\n----------Info for trigger " << i << ":"
142  << "\nTrigger Decision = " << (*triggers)[i].TrigDecision() << " " << TrigDecision
143  << "\nTrigger Type = " << (*triggers)[i].TrigType() << " " << TrigType
144  << "\nTrigger Sub-Type = " << (*triggers)[i].TrigSubType() << " " << TrigSubType
145  << "\nTrigger HardwareID = " << (*triggers)[i].TrigHardwareID()
146  << std::endl;
147 
148 
149  std::cout << "\nAnother way of printing out a trigger" << std::endl;
150  std::cout << (*triggers)[i] << std::endl;
151 
152  // --- Fill a histogram...
153  fTrigTypes->Fill((*triggers)[i].TrigType());
154 
155  // --- Fill a TTree...
156  TrigAnaTree -> Fill();
157  }
158 
159 }
160 
162 
163 }
EventNumber_t event() const
Definition: DataViewImpl.cc:85
std::string string
Definition: nybbler.cc:12
void reconfigure(fhicl::ParameterSet const &p)
TemplateTriggerAna(fhicl::ParameterSet const &p)
int Event
The event which the trigger was taken from.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
int TrigType
The type of trigger decision which was made.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
TemplateTriggerAna & operator=(TemplateTriggerAna const &)=delete
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
int SubRun
The SubRun which the trigger was taken from.
RunNumber_t run() const
Definition: DataViewImpl.cc:71
int Run
The run which the trigger was taken from.
bool TrigDecision
The decision of the trigger.
void analyze(art::Event const &evt) override
TCEvent evt
Definition: DataStructs.cxx:7
int TrigSubType
The subtype of trigger decision which was made.
QTextStream & endl(QTextStream &s)