CosmicTrackRate_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CosmicTrackRate
3 // Module Type: analyzer
4 // File: CosmicTrackRate_module.cc
5 //
6 // Generated at Thu Oct 29 09:47:32 2015 by Martin Frank using artmod
7 // from cetpkgsupport v1_08_07.
8 ////////////////////////////////////////////////////////////////////////
9 
18 #include <fhiclcpp/ParameterSet.h>
20 
21 #include "RecoBase/Track.h"
22 
23 #include <TH1.h>
24 #include <TTimeStamp.h>
25 #include <TTree.h>
26 
27 #include <iostream>
28 #include <map>
29 #include <vector>
30 
31 namespace air
32 {
33  class CosmicTrackRate;
34 }
35 
37 {
38 public:
39  explicit CosmicTrackRate(fhicl::ParameterSet const & p);
40 
41  CosmicTrackRate(CosmicTrackRate const &) = delete;
42  CosmicTrackRate(CosmicTrackRate &&) = delete;
43  CosmicTrackRate & operator = (CosmicTrackRate const &) = delete;
45 
46  void analyze(art::Event const & e) override;
47  void beginJob() override;
48 
49 private:
51  unsigned event_counter_;
52 
53  TH1 *hist_;
54  TTree *tree_;
55  std::map<std::string, double> t_;
56 };
57 
58 
59 
61  EDAnalyzer(p),
62  track_label_(p.get<std::string>("track_label")),
64 {}
65 
66 
67 
69 {
71  hist_ = tfs->make<TH1D>("rate", "", 6001, -0.5, 6000.5);
72 
73  tree_ = tfs->make<TTree>("Event", "Cosmic Track Rate Information per Event");
74  std::vector<std::string> branch_names =
75  { "n_tracks", "hour", "minute", "second" };
76  for (auto const& name : branch_names)
77  tree_->Branch(name.c_str(), &t_[name], (name + "/D").c_str());
78 }
79 
80 
81 
83 {
85  //
86  // Extract Objects from the Event
87  //
89  e.getByLabel(track_label_, tracks);
90 
91  // copied straight from EventDisplay/HeaderDrawer.cxx:
92  unsigned long long int tsval = e.time().value();
93  const unsigned long int mask32 = 0xFFFFFFFFUL;
94  unsigned long int lup = ( tsval >> 32 ) & mask32;
95  unsigned long int llo = tsval & mask32;
96  TTimeStamp ts(lup, (int)llo);
97 
98  std::cout << "MF: (N Tracks, Time) = ("
99  << tracks->size()
100  << ", " << ts.AsString()
101  << ")" << std::endl;
102 
103  //
104  // Fill the Histogram and Tree
105  //
106  hist_->Fill(event_counter_, tracks->size());
107 
108  t_.at("n_tracks") = tracks->size();
109  unsigned hour, minute, second;
110  ts.GetTime(true, 0, &hour, &minute, &second);
111  t_.at("hour") = hour;
112  t_.at("minute") = minute;
113  t_.at("second") = second;
114 
115  tree_->Fill();
116 }
117 
const XML_Char * name
Definition: expat.h:151
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
std::map< std::string, double > t_
constexpr TimeValue_t value() const
Definition: Timestamp.h:24
CosmicTrackRate(fhicl::ParameterSet const &p)
void analyze(art::Event const &e) override
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
OStream cout
Definition: OStream.cxx:6
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
CosmicTrackRate & operator=(CosmicTrackRate const &)=delete
Timestamp time() const
Definition: Event.h:61
Float_t e
Definition: plot.C:35
enum BeamMode string