DDTEvd_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CosmicUniformity
3 // Module Type: analyzer
4 // File: CosmicUniformity_module.cc
5 //
6 // Generated at Aug 12 2015 by Matthew Tamsett
7 ////////////////////////////////////////////////////////////////////////
8 
17 
18 #include "fhiclcpp/ParameterSet.h"
19 
20 
28 
30 #include <iomanip>
31 #include <stdlib.h>
32 #include "TH1.h"
33 #include "TFile.h"
34 #include <fstream>
35 #include <iostream>
36 
37 // To convert TDC to NOvA time
38 #include <NovaTimingUtilities/TimingUtilities.h>
39 // To convert vectors to lenght
41 
42 //---------------------------------------------------------------------
43 namespace novaddt {
44  class DDTEvd;
45 }
46 //---------------------------------------------------------------------
48  public:
49  explicit DDTEvd(fhicl::ParameterSet const & p);
50  virtual ~DDTEvd();
51  void analyze(art::Event const & e) override;
52  void endJob() override;
53 
54  private:
55  // Get 3D track
59 
60  // Handle file
61  ofstream fOutputEvd;
62 
63  // Funcitons
64  int GetX(DAQHit& h, TVector3 start, TVector3 end);
65  int GetY(DAQHit& h, TVector3 start, TVector3 end);
66  void WriteEventInfo(const art::Event& event);
67  void WriteTrackInfo(const Track3D& track, long timeStart, const HitList& hitlist);
68  void WriteHitListInfo(const HitList& hitlist, long timeStart, TVector3 start, TVector3 end);
69 };
70 //---------------------------------------------------------------------
72  : EDAnalyzer(p),
73  fTrack3DLabel(p.get<std::string>("Track3DLabel")),
74  fInputHitLabel(p.get<std::string>("InputHitLabel")),
75  fInputHitInstance(p.get<std::string>("InputHitInstance"))
76 {
77  std::cout << "--- novaddt::DDTEvd instantiate" << std::endl;
78  fOutputEvd.open("DDTEvd_Data.txt");
79 }
80 //---------------------------------------------------------------------
82 {
83  // Clean up dynamic memory and other resources here.
84 }
85 
86 
88 {
89  // Event info
91  event.getByLabel(fInputHitLabel, fInputHitInstance, header);
92  fOutputEvd << "E " << header->eventNumber << " ";
94 
95  // Tracks
97  event.getByLabel(fTrack3DLabel, tracks);
98 
99  // We need the hitlist just so we can get the times for the trigger
100  art::FindOneP<HitList> hls(tracks, event, fTrack3DLabel);
101 
102  int i = 0;
103 
104  // Write info for this event to file
105 
106 
107  for(const Track3D& track: *tracks)
108  {
109  const HitList& hlist = *hls.at(i);
110  i++;
111 
112  WriteTrackInfo(track, header->timeStart, hlist);
113  }
114 }
115 
116 void novaddt::DDTEvd::WriteTrackInfo(const Track3D& track, long timeStart, const HitList& hitlist)
117 {
118  TVector3 start = track.Start();
119  TVector3 end = track.End();
120  if(start.Y() < end.Y()) std::swap(start, end); // all tracks are down-going
121 
122  //Check whether 3D track vector makes sense
123  if(!track.Is3D() ||
124  (start.X() == 0 && end.X() == 0) ||
125  (start.Y() == 0 && end.Y() == 0) ||
126  (start.Z() == 0 && end.Z() == 0))
127  {
128  return;
129  }
130 
131  // Track info
132  fOutputEvd << "T ";
133  fOutputEvd << "(" << start.X() << "," << start.Y() << "," << start.Z() << ") ";
134  fOutputEvd << "(" << end.X() << "," << end.Y() << "," << end.Z() << ")";
136 
137  WriteHitListInfo(hitlist, timeStart, start, end);
138 
139 }
140 void novaddt::DDTEvd::WriteHitListInfo(const HitList& hitlist, long timeStart, TVector3 start, TVector3 end)
141 {
142  for(uint j = 0; j < hitlist.size(); j++)
143  {
144  if(j != 0)
145  fOutputEvd << ",";
146 
147  DAQHit h = hitlist.at(j);
148  int view = (int)h.View().val;
149  fOutputEvd << ((long)h.TDC().val - timeStart)/64 << "/";
150  fOutputEvd << (view == 1 ? (int)h.Cell().val : GetX(h, start, end)) << "/";
151  fOutputEvd << (view == 2 ? (int)h.Cell().val : GetY(h, start, end)) << "/";
152  fOutputEvd << (int)h.Plane().val << "/";
153  fOutputEvd << view;
154  }
155 
157 }
158 int novaddt::DDTEvd::GetX(DAQHit& h, TVector3 start, TVector3 end)
159 {
160  int z = h.Plane().val;
161 
162  double xSpread = end.X() - start.X();
163  double zSpread = end.Z() - start.Z();
164 
165  double zSpreadLoc = z - start.Z();
166 
167  double x = start.X() + xSpread * zSpreadLoc/zSpread;
168 
169  return round(x);
170 }
171 int novaddt::DDTEvd::GetY(DAQHit& h, TVector3 start, TVector3 end)
172 {
173  int z = h.Plane().val;
174 
175  double ySpread = end.Y() - start.Y();
176  double zSpread = end.Z() - start.Z();
177 
178  double zSpreadLoc = z - start.Z();
179 
180  double y = start.Y() + ySpread * zSpreadLoc/zSpread;
181 
182  return round(y);
183 }
184 
185 //---------------------------------------------------------------------
187 {
188  WriteEventInfo(event);
189 }
190 //---------------------------------------------------------------------
192 {
193  std::cout << "=== novaddt::DDTEvd endJob " << std::endl;
194  fOutputEvd.close();
195 }
196 
DDTEvd(fhicl::ParameterSet const &p)
void WriteTrackInfo(const Track3D &track, long timeStart, const HitList &hitlist)
const uint32_t NOVA_EPOCH
int GetX(DAQHit &h, TVector3 start, TVector3 end)
value_type val
Definition: BaseProducts.h:34
virtual ~DDTEvd()
novaddt::Plane const & Plane() const
Definition: DAQHit.h:70
novaddt::TDC const & TDC() const
Definition: DAQHit.h:74
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
value_type val
Definition: BaseProducts.h:109
Definition: event.h:19
const uint64_t NOVA_TIME_FACTOR
DEFINE_ART_MODULE(TestTMapFile)
void endJob() override
fvar< T > round(const fvar< T > &x)
Definition: round.hpp:23
TVector3 const & End() const
Definition: Track3D.h:46
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
void WriteEventInfo(const art::Event &event)
novaddt::View const & View() const
Definition: DAQHit.h:72
TVector3 const & Start() const
Definition: Track3D.h:45
const double j
Definition: BetheBloch.cxx:29
value_type val
Definition: BaseProducts.h:84
bool const & Is3D() const
Definition: Track3D.h:43
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
z
Definition: test.py:28
OStream cout
Definition: OStream.cxx:6
std::string fInputHitInstance
std::string fInputHitLabel
void analyze(art::Event const &e) override
ofstream fOutputEvd
value_type val
Definition: BaseProducts.h:137
novaddt::Cell const & Cell() const
Definition: DAQHit.h:71
int GetY(DAQHit &h, TVector3 start, TVector3 end)
void WriteHitListInfo(const HitList &hitlist, long timeStart, TVector3 start, TVector3 end)
Float_t e
Definition: plot.C:35
std::string fTrack3DLabel
enum BeamMode string
unsigned int uint