RawDigit2DAQHit_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // Class: RawDigit2DAQHit
3 // Module Type: producer
4 // File: RawDigit2DAQHit_module.cc
5 //
6 // Generated at Mon Apr 29 07:46:14 2013 by Matthew Tamsett using artmod
7 // from art v1_02_06.
8 ////////////////////////////////////////////////////////////////////////
13 
15 #include "DAQChannelMap/DAQChannelMap.h"
18 #include "NovaDAQConventions/DAQConventions.h"
19 #include "RawData/RawDigit.h"
20 #include "RawData/RawTrigger.h"
22 #include "SummaryData/RunData.h"
24 
25 #include <string>
26 #include <vector>
27 
28 namespace raw2daq {
29  class RawDigit2DAQHit;
30 }
31 
32 // using unsigned long long rather than uint64_t to ensure consistent behavior on OSX and LINUX
33 
34 //--------------------------------------------------------------------
36 public:
37  explicit RawDigit2DAQHit(fhicl::ParameterSet const & p);
38  virtual ~RawDigit2DAQHit();
39  void produce(art::Event & event) override;
40 
41 private:
42  std::string fRawDigitLabel; ///< label of where to find Raw Digits
43  std::string fRawTriggerLabel; ///< label of where to find Raw Triggers
45 
46 protected:
47  void FillDAQHits(art::Handle< std::vector<rawdata::RawDigit> > & RawDigits,
48  std::unique_ptr<std::vector<novaddt::DAQHit> > & DAQHits,
49  unsigned long long event_time
50  );
51 };
52 //---------------------------------------------------------------------
54  : fRawDigitLabel (p.get< std::string >("RawDigitLabel")),
55  fRawTriggerLabel (p.get< std::string >("RawTriggerLabel"))
56 {
57  // Call appropriate Produces<>() functions here.
58  mf::LogInfo("RawDigit2DAQHit") << "=== raw2daq:::RawDigit2DAQHit instantiate";
59  mf::LogInfo("RawDigit2DAQHit") << "\t RawDigitLabel: " << fRawDigitLabel;
60  mf::LogInfo("RawDigit2DAQHit") << "\t RawTriggerLabel: " << fRawTriggerLabel;
61  produces< std::vector<novaddt::DAQHit>, art::InEvent>();
62 
63 }
64 //---------------------------------------------------------------------
66 {
67  // Clean up dynamic memory and other resources here.
68 }
69 //---------------------------------------------------------------------
71 {
72  // Implementation of required member function here.
73  // get the RawDigit list
75  event.getByLabel(fRawDigitLabel, RawDigits);
76  // make a vector to store the DAQHits into
77  std::unique_ptr<std::vector<novaddt::DAQHit> > DAQHits(new std::vector<novaddt::DAQHit>);
78 
79  // Get the raw trigger to get the event time
81  event.getByLabel(fRawTriggerLabel, RawTriggers);
82  // Currently no triggers should be configured to have more than one raw trigger per event
83  // The vector nature is reserved for exotic supernovae triggers
84  assert(RawTriggers->size()==1);
85  unsigned long long event_time = RawTriggers->at(0).fTriggerTimingMarker_TimeStart;
86 
87  // Make a DAQHit for every RawDigit and write it out
88  FillDAQHits(RawDigits, DAQHits, event_time);
89  // add DAQHits into the event
90  event.put(std::move(DAQHits));
91 }
92 //---------------------------------------------------------------------
93 void raw2daq::RawDigit2DAQHit::FillDAQHits(art::Handle< std::vector<rawdata::RawDigit> > & RawDigits,
94  std::unique_ptr<std::vector<novaddt::DAQHit> > & DAQHits,
95  unsigned long long event_time
96  )
97 {
98  const unsigned int nDigits = RawDigits->size();
100 
102  const novadaq::cnv::DetId det = rh->DetId();
103 
104  // loop over digits
105  for(unsigned int iDigit=0; iDigit < nDigits; ++iDigit){
106  const rawdata::RawDigit* digit = &(*RawDigits)[iDigit];
107  const daqchannelmap::lchan channel = digit->Channel();
108  const daqchannelmap::dchan daqchannel = cmap->Map()->encodeDChan(channel);
109 
110  if (digit->NADC() < 4) // use DCS
111  DAQHits->emplace_back(det,
112  daqchannel,
113  novaddt::ADC(digit->ADC()),
114  novaddt::TDC(digit->TDC() + event_time));
115 
116  else { // using WaveformProcessor
117  novaddt::TDC theTDC;
118  novaddt::ADC theADC;
119  int16_t adc1 = digit->ADC(1) - digit->ADC(0);
120  int16_t adc2 = digit->ADC(2) - digit->ADC(0);
121  int16_t adc3 = digit->ADC(3) - digit->ADC(0);
122 
123 
124  //
125  // Time Conversion: Offline TDC -> Raw TDC
126  //
127  if (event_time > std::numeric_limits<int64_t>::max())
128  {
129  std::cerr << "\n\tThe event time is too large to fit into int64_t.\n"
130  << std::endl;
131  assert(false);
132  }
133 
134  int32_t offline_tdc = digit->TDC();
135  // This casting of uint64 to int64 is okay because our event time only
136  // goes up to 56 bits and we checked above.
137  int64_t integer_raw_tdc =
138  static_cast<int64_t>(event_time) + static_cast<int64_t>(offline_tdc);
139  unsigned long long raw_tdc = static_cast<unsigned long long>(integer_raw_tdc);
140  uint32_t raw_tdc_low = raw_tdc & 0x00000000FFFFFFFF;
141  unsigned long long raw_tdc_high = raw_tdc >> 32;
142 
143 
144  wpr->setup(raw_tdc_low, raw_tdc_high, adc1, adc2, adc3, digit->ADC());
145 
146  DAQHits->emplace_back(det,
147  daqchannel,
148  wpr->getADC(),
149  wpr->getTDC());
150  }
151  } // end of loop on raw digits
152 }
153 
154 //---------------------------------------------------------------------
std::string fRawTriggerLabel
label of where to find Raw Triggers
novadaq::cnv::DetId DetId() const
What detector are we in?
TH2 * rh
Definition: drawXsec.C:5
int32_t TDC() const
The time of the last baseline sample.
Definition: RawDigit.h:94
void FillDAQHits(art::Handle< std::vector< rawdata::RawDigit > > &RawDigits, std::unique_ptr< std::vector< novaddt::DAQHit > > &DAQHits, unsigned long long event_time)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const char * p
Definition: xmltok.h:285
OStream cerr
Definition: OStream.cxx:7
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
DEFINE_ART_MODULE(TestTMapFile)
std::string fRawDigitLabel
label of where to find Raw Digits
void setup(daqdataformats::RawMicroSlice *theMicro, daqdataformats::RawNanoSlice *theNano)
Service for extracting timing and pulse height information from traces with multipoint readout...
void produce(art::Event &event) override
RawDigit2DAQHit(fhicl::ParameterSet const &p)
int16_t ADC(uint32_t i) const
Definition: RawDigit.cxx:58
uint32_t NADC() const
Definition: RawDigit.h:81
uint32_t Channel() const
Definition: RawDigit.h:84
assert(nhit_max >=nhit_nbins)
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
uint32_t dchan
< DAQ Channel Map Package
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
art::ServiceHandle< novaddt::WaveformProcessor > wpr
enum BeamMode string