ProtoDUNEDataUtils.cxx
Go to the documentation of this file.
1 #include "ProtoDUNEDataUtils.h"
2 
5 
8 
11 
13  this->reconfigure(p);
14 }
15 
17 
18 }
19 
21  fTimingTag = p.get<art::InputTag>("TimingTag");
22  fRawDigitTag = p.get<art::InputTag>("RawDigitTag");
23  fRawDigitTimeStampTag = p.get<art::InputTag>("RawDigitTimeStampTag");
24 }
25 
26 // Access the trigger information to see if this is a beam trigger
28 
29  bool isBeam = false;
30 
31  // Accessing the trigger information as done in DataPrepModule
32  // The information is stored in the time stamps
33  auto timeStamps = evt.getHandle<std::vector<raw::RDTimeStamp>>(fTimingTag);
34 
35  // Return false if we have no time stamps
36  if (!timeStamps) return isBeam;
37  // We should only have one RDTimeStamp
38  if (timeStamps->size() > 1) return isBeam;
39 
40  // Access the trigger information. Beam trigger flag = 0xc
41  const raw::RDTimeStamp& timeStamp = timeStamps->at(0);
42  isBeam = (timeStamp.GetFlags() == 0xc);
43 
44  return isBeam;
45 }
46 
47 
48 // ----------------------------------------------------------------------------
50 
51 
52  // Get pd channel map
54 
55  // set only saves unique elements
56  std::set<int> apaset;
57 
58  // Get raw digits time stamps
59  std::vector<art::Ptr<raw::RDTimeStamp> > digitTSlist;
60 
61 
62  // Get raw digits
63  std::vector<art::Ptr<raw::RawDigit> > digitlist;
64 
65  auto RawdigitListHandle = evt.getHandle< std::vector<raw::RawDigit> >(fRawDigitTag);
66  if (RawdigitListHandle){
67 
68  art::fill_ptr_vector(digitlist, RawdigitListHandle);
69 
70  for(auto const & dptr : digitlist) {
71  const raw::RawDigit& digit = *dptr;
72  // Get the channel number for this digit
73  uint32_t chan = digit.Channel();
74 
75  int iapa = channelMap->APAFromOfflineChannel(chan);
76  if(iapa != apa) continue;
77  // Get the channel FEMB and WIB
78  int WIB = channelMap->WIBFromOfflineChannel(chan); // 0-4
79  int FEMB = channelMap->FEMBFromOfflineChannel(chan); // 1-4
80  //int FEMBchan = channelMap->FEMBChannelFromOfflineChannel(chan);
81  int iFEMB = ((WIB*4)+(FEMB-1)); //index of the FEMB 0-19
82 
83  apaset.insert(iFEMB);
84  }
85  }
86 
87  else{ // if raw digits have been dropped use RDTimeStamps instead
88 
89  auto RawdigitTSListHandle = evt.getHandle< std::vector<raw::RDTimeStamp> >(fRawDigitTimeStampTag);
90  art::fill_ptr_vector(digitTSlist, RawdigitTSListHandle);
91 
92  for(auto const & dptr : digitTSlist) {
93 
94  const raw::RDTimeStamp & digit = *dptr;
95 
96  // Get the channel number for this digit
97  uint16_t chan = digit.GetFlags();
98 
99  int iapa = channelMap->APAFromOfflineChannel(chan);
100  if(iapa != apa) continue;
101  // Get the channel FEMB and WIB
102  int WIB = channelMap->WIBFromOfflineChannel(chan); // 0-4
103  int FEMB = channelMap->FEMBFromOfflineChannel(chan); // 1-4
104  //int FEMBchan = channelMap->FEMBChannelFromOfflineChannel(chan);
105  int iFEMB = ((WIB*4)+(FEMB-1)); //index of the FEMB 0-19
106 
107  apaset.insert(iFEMB);
108  }
109  }
110  return (apaset.size());
111 }
112 
113 
114 // ----------------------------------------------------------------------------
115 // returns true if timestamps are consistent, and fills the timestamp number in the timestamp argument. timestamp2
116 // should be the same as timestamp if this method returns true, and apainconsist should be zero.
117 // returns false if inconsistent, and the timestamp argument is one of the timestamps present, and timestamp2 is
118 // another one if it disagrees. apainconsist is the apa number of the first clashing channel
119 
121  ULong64_t &timestamp, ULong64_t &timestamp2,
122  int &apainconsist) const
123 {
125  std::vector<art::Ptr<raw::RDTimeStamp> > TSlist;
126  auto RawTSListHandle = evt.getHandle< std::vector<raw::RDTimeStamp> >(fRawDigitTimeStampTag);
127  art::fill_ptr_vector(TSlist, RawTSListHandle);
128 
129  timestamp = 0;
130  timestamp2 = 0;
131  apainconsist = 0;
132  bool tsi = false;
133 
134  for(auto const & tsptr : TSlist)
135  {
136  const raw::RDTimeStamp & rdts = *tsptr;
137  uint16_t chan = rdts.GetFlags();
138  int iapa = channelMap->APAFromOfflineChannel(chan);
139  if (apas.find(iapa) != apas.end())
140  {
141  ULong64_t ts = rdts.GetTimeStamp();
142  if (tsi)
143  {
144  if (ts != timestamp)
145  {
146  apainconsist = iapa;
147  timestamp2 = ts;
148  return false;
149  }
150  }
151  else
152  {
153  tsi = true;
154  timestamp = ts;
155  timestamp2 = ts;
156  }
157  }
158  }
159  //std::cout << "All timestamps equal at: " << timestamp << " for APAs: ";
160  //for (auto const &iter : apas)
161  // {
162  // std::cout << iter << " ";
163  //}
164  //std::cout << std::endl;
165  return true;
166 }
uint16_t GetFlags() const
Definition: RDTimeStamp.h:46
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
unsigned int APAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate.
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
ProtoDUNEDataUtils(fhicl::ParameterSet const &pset)
ULong64_t GetTimeStamp() const
Definition: RDTimeStamp.h:42
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
bool CheckTimeStampConsistencyForAPAs(art::Event const &evt, std::set< int > apas, ULong64_t &timestamp, ULong64_t &timestamp2, int &apainconsist) const
Check for consistency of timestamp values for a set of APAs. True if consistent, false if there are m...
void reconfigure(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
bool IsBeamTrigger(art::Event const &evt) const