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  : EDProducer(p),
55  fRawDigitLabel (p.get< std::string >("RawDigitLabel")),
56  fRawTriggerLabel (p.get< std::string >("RawTriggerLabel"))
57 {
58  // Call appropriate Produces<>() functions here.
59  mf::LogInfo("RawDigit2DAQHit") << "=== raw2daq:::RawDigit2DAQHit instantiate";
60  mf::LogInfo("RawDigit2DAQHit") << "\t RawDigitLabel: " << fRawDigitLabel;
61  mf::LogInfo("RawDigit2DAQHit") << "\t RawTriggerLabel: " << fRawTriggerLabel;
62  produces< std::vector<novaddt::DAQHit>, art::InEvent>();
63 
64 }
65 //---------------------------------------------------------------------
67 {
68  // Clean up dynamic memory and other resources here.
69 }
70 //---------------------------------------------------------------------
72 {
73  // Implementation of required member function here.
74  // get the RawDigit list
76  event.getByLabel(fRawDigitLabel, RawDigits);
77  // make a vector to store the DAQHits into
78  std::unique_ptr<std::vector<novaddt::DAQHit> > DAQHits(new std::vector<novaddt::DAQHit>);
79 
80  // Get the raw trigger to get the event time
82  event.getByLabel(fRawTriggerLabel, RawTriggers);
83  // Currently no triggers should be configured to have more than one raw trigger per event
84  // The vector nature is reserved for exotic supernovae triggers
85  assert(RawTriggers->size()==1);
86  unsigned long long event_time = RawTriggers->at(0).fTriggerTimingMarker_TimeStart;
87 
88  // Make a DAQHit for every RawDigit and write it out
89  FillDAQHits(RawDigits, DAQHits, event_time);
90  // add DAQHits into the event
91  event.put(std::move(DAQHits));
92 }
93 //---------------------------------------------------------------------
94 void raw2daq::RawDigit2DAQHit::FillDAQHits(art::Handle< std::vector<rawdata::RawDigit> > & RawDigits,
95  std::unique_ptr<std::vector<novaddt::DAQHit> > & DAQHits,
96  unsigned long long event_time
97  )
98 {
99  const unsigned int nDigits = RawDigits->size();
101 
103  const novadaq::cnv::DetId det = rh->DetId();
104 
105  // loop over digits
106  for(unsigned int iDigit=0; iDigit < nDigits; ++iDigit){
107  const rawdata::RawDigit* digit = &(*RawDigits)[iDigit];
108  const daqchannelmap::lchan channel = digit->Channel();
109  const daqchannelmap::dchan daqchannel = cmap->Map()->encodeDChan(channel);
110 
111  if (digit->NADC() < 4) // use DCS
112  DAQHits->emplace_back(det,
113  daqchannel,
114  novaddt::ADC(digit->ADC()),
115  novaddt::TDC(digit->TDC() + event_time));
116 
117  else { // using WaveformProcessor
118  novaddt::TDC theTDC;
119  novaddt::ADC theADC;
120  int16_t adc1 = digit->ADC(1) - digit->ADC(0);
121  int16_t adc2 = digit->ADC(2) - digit->ADC(0);
122  int16_t adc3 = digit->ADC(3) - digit->ADC(0);
123 
124 
125  //
126  // Time Conversion: Offline TDC -> Raw TDC
127  //
128  if (event_time > std::numeric_limits<int64_t>::max())
129  {
130  std::cerr << "\n\tThe event time is too large to fit into int64_t.\n"
131  << std::endl;
132  assert(false);
133  }
134 
135  int32_t offline_tdc = digit->TDC();
136  // This casting of uint64 to int64 is okay because our event time only
137  // goes up to 56 bits and we checked above.
138  int64_t integer_raw_tdc =
139  static_cast<int64_t>(event_time) + static_cast<int64_t>(offline_tdc);
140  unsigned long long raw_tdc = static_cast<unsigned long long>(integer_raw_tdc);
141  uint32_t raw_tdc_low = raw_tdc & 0x00000000FFFFFFFF;
142  unsigned long long raw_tdc_high = raw_tdc >> 32;
143 
144 
145  wpr->setup(raw_tdc_low, raw_tdc_high, adc1, adc2, adc3, digit->ADC());
146 
147  DAQHits->emplace_back(det,
148  daqchannel,
149  wpr->getADC(),
150  wpr->getTDC());
151  }
152  } // end of loop on raw digits
153 }
154 
155 //---------------------------------------------------------------------
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
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
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:66
art::ServiceHandle< novaddt::WaveformProcessor > wpr
enum BeamMode string