DAQHit2Raw_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief A module to produce rawdata::RawDigits from NOvADDT DAQHits
3 /// \author Gavin S. Davies - gsdavies@iastate.edu
4 /// \date March 14 2013
5 ////////////////////////////////////////////////////////////////////////
6 
13 
15 #include "DAQChannelMap/DAQChannelMapConstants.h"
18 #include "NovaDAQConventions/DAQConventions.h"
19 #include "RawData/DAQHeader.h"
20 #include "RawData/RawDigit.h"
21 #include "RawData/RawTrigger.h"
22 #include "SummaryData/RunData.h"
23 
24 #include <boost/algorithm/string.hpp>
25 
26 #include <string>
27 #include <vector>
28 
29 #ifdef DARWINBUILD
30  #include <libgen.h>
31 #endif
32 
33 namespace daq2raw {
34  class DAQHit2Raw;
35 }
36 
37 // using unsigned long long rather than uint64_t to ensure consistent behavior on OSX and LINUX
38 
40 public:
41  explicit DAQHit2Raw(fhicl::ParameterSet const & p);
42  virtual ~DAQHit2Raw();
43 
44  void produce(art::Event & e) override;
45 
46  void beginRun(art::Run &run);
47 
49 
50 private:
53 
55  int fDetId;
56 
57 protected:
58 
59  int getDetIdFromFilename(const char* filename);
60 
61  void FillRawDigits(const novaddt::HitList & hitlist,
62  std::unique_ptr<std::vector<rawdata::RawDigit> >& rawlist
63  );
64 
65  void PopulateRawTrig(rawdata::RawTrigger & rawtrig,
66  art::Event const & evt
67  );
68 
69 };
70 
71 //-------------------------------------------------------------------------
73  : fDAQHitInput(p.get< std::string >("DAQHitInput")),
74  fAddRunInfo(p.get< bool >("AddRunInfo"))
75 {
76  produces<rawdata::DAQHeader, art::InEvent>();
77  produces< std::vector<rawdata::RawDigit>, art::InEvent>();
78  produces< std::vector<rawdata::RawTrigger>, art::InEvent>();
79  if (fAddRunInfo)
80  produces<sumdata::RunData, art::InRun>();
81 }
82 
83 //-------------------------------------------------------------------------
85 {
86 }
87 
88 //-------------------------------------------------------------------------
90 {
91  fileName = basename((char*)fb.fileName().c_str());
92 }
93 
94 //-------------------------------------------------------------------------
96 {
97  if(fAddRunInfo)
98  {
99  int detector = getDetIdFromFilename(fileName.c_str());
101  std::unique_ptr<sumdata::RunData> rundata(new sumdata::RunData(novadaq::cnv::DetId(detector), detFileBase));
102  run.put(std::move(rundata));
103  }
104 }
105 
106 //-------------------------------------------------------------------------
108 {
109  // get the vector of DAQHits (HitList)
111  e.getByLabel(fDAQHitInput,hlcol);
112 
113  novaddt::HitList hitlist;
114  for(unsigned int i = 0; i < hlcol->size(); ++i){
115  hitlist.push_back((*hlcol)[i]);
116  }
117 
118  //////////////////////////////////////////////
119  // Define data structures that we want to fill
120 
121  // Digitized data
122  std::unique_ptr<std::vector<rawdata::RawDigit> > digits(new std::vector<rawdata::RawDigit>);
123  // Trigger data:
124  std::unique_ptr<std::vector<rawdata::RawTrigger> > rtcol(new std::vector<rawdata::RawTrigger>);
125  // DAQ header:
126  // std::unique_ptr<rawdata::DAQHeader > daqcol(new rawdata::DAQHeader(daq_header));
127 
128 
129  // Write digitized data into the event
130  rawdata::RawDigit rawdig;
131  FillRawDigits(hitlist, digits);
132 
133  e.put(std::move(digits)); // Put RawDigits into event
134 
135  // Write the raw trigger into the event
136  rawdata::RawTrigger rawtrig;
137  PopulateRawTrig(rawtrig, e);
138  rtcol->push_back(rawtrig);
139 
140  e.put(std::move(rtcol)); // Put RawTrigger into event
141 
142  //Write the DAQHeader - for now don't bother
143  //e.put(std::move(daqcol), "daq"); // Module label
144 
145 }
146 
147 //---------------------------------------------------------------------------
149 {
151 
152  if (boost::find_first(filename, "ndos") || boost::find_first(filename, "NDOS")){
154  }
155  else if(boost::find_first(filename, "fardet") || boost::find_first(filename, "FarDet")){
157  }
158  else if(boost::find_first(filename, "neardet") || boost::find_first(filename, "NearDet")){
160  }
161  return fDetId;
162 }
163 
164 //---------------------------------------------------------------------------
166  art::Event const & evt
167  )
168 {
169  // Say this is MC:
170  rawtrig.fTriggerMask_MCBit = 1;
171 
172  // Units of DDT data are 5ms = 5*10^6ns
173  // This will need to be addressed in EventDisplay
174  // rawtrig.fTriggerRange_TriggerLength = fClocktick*fNumClockticksInSpill/5.e6;
175  // Hard-code for testing purposes
176  rawtrig.fTriggerRange_TriggerLength = 62.5*8000/5.e6;
177 
178  // Set the trigger time such that it increments by 0.1 seconds
179  // every event (to mimic calibration triggers, though not beam
180  // triggers). Also, add one "day" per subrun and one "year" per
181  // run, just to keep the times in different files different.
182  // I'm not making these FHICL parameters because we will want
183  // to do this properly (e.g., have each MC file representing a
184  // specific timestamp drawn to match real data).
185  //
186  // The TDC ticks run at 64 MHz
187 
188  static const unsigned long long ticksPerYear = (unsigned long long)(64000000) * 31556926;
189  static const unsigned long long ticksPerDay = (unsigned long long)(64000000) * 86400;
190  static const unsigned long long ticksPerEvent = (unsigned long long)(64000000) / 10; // 10 Hz trigger
191 
193  evt.run() * ticksPerYear +
194  evt.subRun() * ticksPerDay +
195  evt.event() * ticksPerEvent;
196 
197 }
198 
199 //------------------------------------------------------------------------
201  std::unique_ptr<std::vector<rawdata::RawDigit> >& rawlist
202  )
203 {
205 
206  // Loop over all hits in the HitList
207  const int nHits = hitlist.size();
208  for(int idx = 0; idx< nHits; idx++){
209  // instance of each DAQHit
210  const novaddt::DAQHit dhit = hitlist[idx];
211 
213  dhit.Plane().val,
214  dhit.Cell().val);
215 
216  // instance of RawDigit
217  rawdata::RawDigit rawdig;
218 
219  // Fill RawDigits
220  rawdig.SetChannel(lchan);
221  rawdig.SetTDC(dhit.TDC().val);
222  rawdig.SetADC(0,dhit.ADC().val);
223  rawdig.SetMC();
224 
225  rawlist->push_back(rawdig);
226  }
227 
228 }
229 
231 
std::string getDetectorGDML(const int detid) const
SubRunNumber_t subRun() const
Definition: Event.h:72
value_type val
Definition: BaseProducts.h:34
void SetTDC(int32_t iTDC)
Definition: RawDigit.cxx:116
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
std::string const & fileName() const
Definition: FileBlock.h:38
void SetChannel(uint32_t iChan)
Definition: RawDigit.h:99
int getDetIdFromFilename(const char *filename)
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
string filename
Definition: shutoffs.py:106
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:149
DEFINE_ART_MODULE(TestTMapFile)
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
Definition: Run.h:31
void beginRun(art::Run &run)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
Far Detector at Ash River, MN.
DAQHit2Raw(fhicl::ParameterSet const &p)
novaddt::ADC const & ADC() const
Definition: DAQHit.h:73
Prototype Near Detector on the surface at FNAL.
int evt
Near Detector in the NuMI cavern.
value_type val
Definition: BaseProducts.h:84
EventNumber_t event() const
Definition: Event.h:67
A module to produce rawdata::RawDigits from NOvADDT DAQHits.
Definition: run.py:1
void SetMC(bool isMC=true)
Definition: RawDigit.h:106
void FillRawDigits(const novaddt::HitList &hitlist, std::unique_ptr< std::vector< rawdata::RawDigit > > &rawlist)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
unsigned long long fTriggerTimingMarker_TimeStart
Definition: RawTrigger.h:38
novaddt::Cell const & Cell() const
Definition: DAQHit.h:71
void produce(art::Event &e) override
value_type val
Definition: BaseProducts.h:65
uint32_t fTriggerRange_TriggerLength
Definition: RawTrigger.h:40
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.h:77
void respondToOpenInputFile(const art::FileBlock &fb)
void PopulateRawTrig(rawdata::RawTrigger &rawtrig, art::Event const &evt)
enum BeamMode string