TPCHits_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TPCHits
3 // Module Type: analyzer
4 // File: TPCHits_module.cc
5 //
6 // Generated at Wed Nov 18 16:12:15 2015 by Jonathan Davies using artmod
7 // from cetpkgsupport v1_08_07.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
20 
21 
22 //lbne-artdaq includes
23 #include "lbne-raw-data/Overlays/TpcMilliSliceFragment.hh"
24 #include "artdaq-core/Data/Fragment.hh"
25 
26 
27 //larsoft
32 
33 //ROOT
34 #include "TH1I.h"
35 #include "TH2I.h"
36 #include "TMath.h"
37 
38 #include <sstream>
39 
40 namespace nearline {
41  class TPCHits;
42 }
43 
45 public:
46  explicit TPCHits(fhicl::ParameterSet const & p);
47  // The destructor generated by the compiler is fine for classes
48  // without bare pointers or other resource use.
49 
50  // Plugins should not be copied or assigned.
51  TPCHits(TPCHits const &) = delete;
52  TPCHits(TPCHits &&) = delete;
53  TPCHits & operator = (TPCHits const &) = delete;
54  TPCHits & operator = (TPCHits &&) = delete;
55 
56  // Required functions.
57  void analyze(art::Event const & e) override;
58  void reconfigure(fhicl::ParameterSet const & p);
59  void endJob();
60  void makeHistograms();
61  void printRawDigitTimingInfo(art::Event const & e);
62  void printTpcFragTimingInfo(art::Event const & e);
63 
64 
65 private:
69 
70  //Variables for comparing previous to next event
74 
76 
77 
78  std::vector<unsigned int> fTotalNumHitsPerTPC;
79  std::vector<TH1I*> fHistNumHitsPerTPC;
80  std::vector<TH1I*> fHistNumTicksPerEvent;
81  std::vector<TH1I*> fHistNumTicksPerEventPair;
82  std::vector<TH2I*> fHistNumTicksPerEventVsLast;
83 
84 
85  std::vector<unsigned int> fNumChansTPC;
86  std::vector<unsigned int> fNumTicksTPC;
87  std::vector<unsigned int> fNumChansTPCLastEvent;
88  std::vector<unsigned int> fNumTicksTPCLastEvent;
89  std::vector<unsigned int> fNumChansTPCTwoEvents;
90  std::vector<unsigned int> fNumTicksTPCTwoEvents;
91 
92 
93 };
94 
95 
97  :
98  EDAnalyzer(p) // ,
99  // More initializers here.
100 {
101  reconfigure(p);
102 
104  fTotalNumHitsPerTPC = std::vector<unsigned int>(geom->NTPC());
105  fNumChansTPC = std::vector<unsigned int>(geom->NTPC());
106  fNumTicksTPC = std::vector<unsigned int>(geom->NTPC());
107  fNumChansTPCLastEvent = std::vector<unsigned int>(geom->NTPC());
108  fNumTicksTPCLastEvent = std::vector<unsigned int>(geom->NTPC());
109  fNumChansTPCTwoEvents = std::vector<unsigned int>(geom->NTPC());
110  fNumTicksTPCTwoEvents = std::vector<unsigned int>(geom->NTPC());
111 
112 
113  makeHistograms();
114 
115 }
116 
118 
119  mf::LogInfo loginfo("TPCHits");
120  loginfo << "====================================" << "\n"
121  << "Making Histograms" << "\n"
122  << "====================================" << "\n";
123 
126  auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
127 
128  const double samplingRate = detprop->SamplingRate();
129  const unsinged int millisliceSize = 5e6;
130  const unsigned int maxNumTicksPerEvent = millisliceSize / samplingRate;
131 
132  fHistNumHitsPerTPC = std::vector<TH1I*> (geom->NTPC());
133  fHistNumTicksPerEvent = std::vector<TH1I*>(geom->NTPC());
134  fHistNumTicksPerEventPair = std::vector<TH1I*>(geom->NTPC());
135  fHistNumTicksPerEventVsLast = std::vector<TH2I*>(geom->NTPC());
136 
137  //Currently 5ms of data per pair of events
138  //Sampling rate of the TPC is 2MHz (0.5 ns spacing) -> can get this from the det properties
139  //That means that 5000 / 0.5 = 10,000 ticks per 2 events
140  //Max number of hits is therefore == 10,000 * nwires per TPC
141 
142  loginfo << "Making Number of Hits per TPC Histograms\n";
143 
144  for(size_t tpc = 0; tpc < fHistNumHitsPerTPC.size(); tpc++){
145  std::ostringstream histName;
146  histName << "hist_num_hits_tpc_" << tpc;
147 
148  std::ostringstream histTitle;
149  histTitle << "Number of hits per event TPC " << tpc << ";Log_{10}(Number of hits);Number of events";
150 
151  const unsigned int numPlanes = geom->Nplanes(tpc);
152  unsigned int totalNumWires = 0;
153  for(unsigned int plane=0;plane<numPlanes;plane++){
154  unsigned int numWires = geom->Nwires(plane, tpc);
155  totalNumWires += numWires;
156  }//plane
157 
158  unsigned int maxNumHits = totalNumWires * maxNumTicksPerEvent;
159 
160  int numBins = 100;
161  int binLow = -1;
162  int binHigh = TMath::Log10(maxNumHits);
163  TH1I* tempHist = tfs->make<TH1I>(histName.str().c_str(), histTitle.str().c_str(), numBins, binLow, binHigh);
164  fHistNumHitsPerTPC.at(tpc) = tempHist;
165  loginfo << "histName: " << histName.str() << "\n";
166  }
167 
168  loginfo << "\n"
169  << "Making Number of ticks / wire / event / TPC Histograms\n";
170 
171  for(size_t tpc = 0; tpc < fHistNumTicksPerEvent.size(); tpc++){
172  std::ostringstream histName;
173  histName << "hist_num_ticks_per_event_tpc_" << tpc;
174 
175  std::ostringstream histTitle;
176  histTitle << "Number of ticks / wire / event in TPC " << tpc << ";Number of ticks;Number of events";
177 
178  int numBins = 100;
179  int binLow = 0;
180  int binHigh = maxNumTicksPerEvent;
181  TH1I* tempHist = tfs->make<TH1I>(histName.str().c_str(), histTitle.str().c_str(), numBins, binLow, binHigh);
182  fHistNumTicksPerEvent.at(tpc) = tempHist;
183  loginfo << "histName: " << histName.str() << "\n";
184  }//tpc
185 
186  loginfo << "\n"
187  << "Making Number of ticks / wire / event pair / TPC Histograms\n";
188 
189  for(size_t tpc = 0; tpc < fHistNumTicksPerEventPair.size(); tpc++){
190  std::ostringstream histName;
191  histName << "hist_num_ticks_per_event_pair_tpc_" << tpc;
192 
193  std::ostringstream histTitle;
194  histTitle << "Number of ticks / wire / event pair in TPC " << tpc << ";Number of ticks;Number of event pairs";
195 
196  int numBins = 100;
197  int binLow = 0;
198  int binHigh = maxNumTicksPerEvent;
199  TH1I* tempHist = tfs->make<TH1I>(histName.str().c_str(), histTitle.str().c_str(), numBins, binLow, binHigh);
200  fHistNumTicksPerEventPair.at(tpc) = tempHist;
201  loginfo << "histName: " << histName.str() << "\n";
202  }//tpc
203 
204  loginfo << "\n"
205  << "Making Number of ticks / wire / event vs last / TPC Histograms\n";
206 
207  for(size_t tpc = 0; tpc < fHistNumTicksPerEventVsLast.size(); tpc++){
208  std::ostringstream histName;
209  histName << "hist_num_ticks_per_event_vs_last_tpc_" << tpc;
210 
211  std::ostringstream histTitle;
212  histTitle << "Number of ticks / wire / event vs last event in TPC " << tpc << ";Number of ticks;Number of ticks (last)";
213 
214  int numBins = 100;
215  int binLow = 0;
216  int binHigh = maxNumTicksPerEvent;
217  TH2I* tempHist = tfs->make<TH2I>(histName.str().c_str(), histTitle.str().c_str(), numBins, binLow, binHigh, numBins, binLow, binHigh);
218  fHistNumTicksPerEventVsLast.at(tpc) = tempHist;
219  loginfo << "histName: " << histName.str() << "\n";
220  }//tpc
221 
222  loginfo << "====================================" << "\n"
223  << "Finished Making Histograms" << "\n"
224  << "====================================" << "\n";
225 }
226 
228 
229  fTPCHitTag = p.get<art::InputTag>("TPCHitTag", "a:b:c");
230  fRawDigitsTag = p.get<art::InputTag>("RawDigitsTag", "a:b:c");
231  fPrintRawDigitTimingInfo = p.get<bool>("fPrintRawDigitTimingInfo", true);
232  fPrintTpcFragTimingInfo = p.get<bool>("fPrintTpcFragTimingInfo", true);
233 
234  mf::LogInfo("TPCHits") << "====================================" << "\n"
235  << "Parameter Set" << "\n"
236  << "====================================" << "\n"
237  << "fTPCHitTag: " << fTPCHitTag << "\n"
238  << "fRawDigitsTag: " << fRawDigitsTag << "\n"
239  << "fPrintRawDigitTimingInfo: " << fPrintRawDigitTimingInfo << "\n"
240  << "fPrintTpcFragTimingInfo: " << fPrintTpcFragTimingInfo << "\n"
241  << "====================================" << "\n";
242 }
243 
245 
246  mf::LogInfo("TPCHits::printTpcFragTimingInfo") << "Hello World" << std::endl;
247 
248  art::Handle<artdaq::Fragments> rawFragments;
249  art::InputTag tpcFragTag("daq:TPC");
250  bool retVal = e.getByLabel("daq:TPC", rawFragments);
251  if(retVal==true)
252  mf::LogInfo("TPCHits::printTpcFragTimingInfo") << "Getting TPC Frag SUCCESS: " << tpcFragTag << std::endl;
253  else{
254  mf::LogWarning("TPCHits::printTpcFragTimingInfo") << "Getting TPC Frag FAIL: " << tpcFragTag << std::endl;
255  return;
256  }
257  try { rawFragments->size(); }
258  catch(std::exception e) {
259  mf::LogError("TPCHits::printTpcFragTimingInfo") << "WARNING: Issue with rawFragments for TPC hits" << std::endl;
260  return;
261  }
262 
263  for(size_t fragIndex = 0; fragIndex < rawFragments->size(); fragIndex++){
264  const artdaq::Fragment &singleFragment = rawFragments->at(fragIndex);
265  lbne::TpcMilliSliceFragment msf(singleFragment);
266  auto nMicroSlices = msf.microSliceCount();
267 
268  mf::LogInfo("TPCHits::printTpcFragTimingInfo") << "fragIndex: " << fragIndex
269  << " fragmentID: " << singleFragment.fragmentID()
270  << " ms counter: " << nMicroSlices
271  << std::endl;
272 
273  }//fragIndex
274 }
275 
276 
277 
279 
280  art::EventID eventID = e.id();
281  art::Timestamp timestamp = e.time();
282  art::EventNumber_t event = e.event();
283 
284  mf::LogInfo("TPCHits::printRawDigitTimingInfo") << "EventID: " << eventID
285  << " time: " << timestamp.value()
286  << " EventNum: " << event
287  << std::endl;
288 
289  if((timestamp.value() - fTimestampLast.value() < 0) || (event - fEventLast < 0)){
290  mf::LogInfo("TPCHits::printRawDigitTimingInfo") << "ERROR - negative delta timestamp of eventnum" << std::endl;
291  }
292 
293  fEventIDLast = eventID;
294  fTimestampLast = timestamp;
295  fEventLast = event;
296 }
297 
298 
300 {
301 
304  return;//FIXME
305 
307  std::vector<unsigned int> thisNumHits(geom->NTPC());
310 
311  bool retVal = e.getByLabel(fTPCHitTag, hitHandle);
312  if(retVal==true)
313  ;
314  //mf::LogInfo("TPCHits") << "Getting Hits SUCCESS: " << fTPCHitTag << std::endl;
315  else{
316  mf::LogWarning("TPCHits") << "Getting Hits FAIL: " << fTPCHitTag << std::endl;
317  return;
318  }
319 
320  try { hitHandle->size(); }
321  catch(std::exception e) {
322  mf::LogError("TPCHits") << "WARNING: Issue with hitHandle for TPC hits" << std::endl;
323  return;
324  }
325 
326  if(!hitHandle.isValid()){
327  mf::LogError("TPCHits") << "Run: " << e.run()
328  << ", SubRun: " << e.subRun()
329  << ", Event: " << e.event()
330  << " is NOT VALID";
331  throw cet::exception("hits NOT VALID");
332  return;
333  }
334 
335 
336  retVal = e.getByLabel(fRawDigitsTag, digitHandle);
337  if(retVal==true)
338  ;
339  //mf::LogInfo("TPCHits") << "Getting RawDigits SUCCESS: " << fRawDigitsTag << std::endl;
340  else{
341  mf::LogWarning("TPCHits") << "Getting RawDigits FAIL: " << fRawDigitsTag << std::endl;
342  return;
343  }
344 
345  try { digitHandle->size(); }
346  catch(std::exception e) {
347  mf::LogError("TPCHits") << "WARNING: Issue with digitHandle for RawDigits" << std::endl;
348  return;
349  }
350 
351  if(!digitHandle.isValid()){
352  mf::LogError("TPCHits") << "Run: " << e.run()
353  << ", SubRun: " << e.subRun()
354  << ", Event: " << e.event()
355  << " is NOT VALID";
356  throw cet::exception("RawDigit NOT VALID");
357  return;
358  }
359 
360  std::vector<art::Ptr<recob::Hit> > hitlist;
361  art::fill_ptr_vector(hitlist, hitHandle);
362 
363  // size_t numHits = hitlist.size();
364  // mf::LogInfo("TPCHits") << "NumHits: " << numHits << " hits" << std::endl;
365  for (size_t tpchit_index = 0; tpchit_index<hitlist.size(); ++tpchit_index){
366  geo::WireID wireid = hitlist[tpchit_index]->WireID();
367  thisNumHits.at(wireid.TPC)++;
368  fTotalNumHitsPerTPC.at(wireid.TPC)++;
369  }//hit
370 
371  for(size_t tpc=0; tpc < fHistNumHitsPerTPC.size();tpc++){
372  TH1I* tempHist = fHistNumHitsPerTPC.at(tpc);
373  if(thisNumHits.at(tpc)==0)
374  tempHist->Fill(-1);
375  else
376  tempHist->Fill(TMath::Log10(thisNumHits.at(tpc)));
377  }//tpc
378 
379  size_t numDigitChans = digitHandle->size();
380  // mf::LogInfo("TPCHits") << "numDigitChans: " << numDigitChans << std::endl;
381  // size_t numChans = geom->Nchannels();
382  // mf::LogInfo("TPCHits") << "numChans: " << numChans << std::endl;
383 
384  fNumChansTPC = std::vector<unsigned int> (geom->NTPC());
385  fNumTicksTPC = std::vector<unsigned int> (geom->NTPC());
386  for(size_t rdIter=0;rdIter<numDigitChans;rdIter++){
387  art::Ptr<raw::RawDigit> digitVec(digitHandle, rdIter);
388  auto channel = digitVec->Channel();
389  auto numSamples = digitVec->Samples();
390  std::vector<geo::WireID> wids = geom->ChannelToWire(channel);
391 
392  if(wids.at(0).Plane !=2 ) continue;
393  fNumChansTPC.at(wids.at(0).TPC)++;
394  fNumTicksTPC.at(wids.at(0).TPC)+=numSamples;
395  fNumChansTPCTwoEvents.at(wids.at(0).TPC)++;
396  fNumTicksTPCTwoEvents.at(wids.at(0).TPC)+=numSamples;
397 
398 
399  }//rdIter
400 
401  // mf::LogError loginfo("TPCHits");
402  // loginfo << "Numbers of channels\n";
403  // for(size_t tpc=0;tpc<fNumChansTPC.size();tpc++){
404  // if(tpc!=5) continue;
405  // loginfo << "tpc: " << tpc
406  // << " numChannels: " << fNumChansTPC.at(tpc)
407  // << " numSamples: " << fNumTicksTPC.at(tpc)
408  // << " numSamplesTwoEvents: " << fNumTicksTPCTwoEvents.at(tpc)
409  // << "\n";
410 
411  // }
412 
413  for(size_t tpc=0;tpc<fHistNumTicksPerEvent.size();tpc++){
414 
415  unsigned int numChans = fNumChansTPC.at(tpc);
416  unsigned int numTicks = fNumTicksTPC.at(tpc);
417  unsigned int numTicksLastEvent = fNumTicksTPCLastEvent.at(tpc);
418  // unsigned int numTicksEventPair = fNumTicksTPCTwoEvents.at(tpc);
419 
420  // if(numTicks>0){
421  // mf::LogInfo loginfo("TPCHits");
422  // loginfo << "tpc: " << tpc << "\n"
423  // << " numTicks: " << numTicks << "\n"
424  // << " numTicksEventPair: " << numTicksEventPair << "\n";
425  // }
426 
427  if(numChans==0) continue;
428  TH1I* tempHist = fHistNumTicksPerEvent.at(tpc);
429  tempHist->Fill(numTicks/numChans);
430 
431  tempHist = fHistNumTicksPerEventPair.at(tpc);
432  // tempHist->Fill(numTicksEventPair/numChans);
433  tempHist->Fill((numTicksLastEvent+numTicks)/numChans);
434 
435  TH2I* tempHist2D = fHistNumTicksPerEventVsLast.at(tpc);
436  tempHist2D->Fill(numTicks/numChans, numTicksLastEvent/numChans);
437 
438  }//tpc
439 
444 
445 }
446 
448 
449  std::ostringstream os;
450 
451  os << "====================================" << "\n"
452  << "End Job" << "\n"
453  << "====================================" << "\n";
454 
455  for(size_t i=0; i<fTotalNumHitsPerTPC.size(); i++) os << "i: " << i << " contents: " << fTotalNumHitsPerTPC.at(i) << std::endl;
456 
457  os << "====================================" << "\n";
458  mf::LogInfo("TPCHits") << os.str();
459 
460 
461 }
462 
std::vector< TH1I * > fHistNumTicksPerEventPair
EventNumber_t event() const
Definition: DataViewImpl.cc:96
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< TH2I * > fHistNumTicksPerEventVsLast
Declaration of signal hit object.
void analyze(art::Event const &e) override
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< TH1I * > fHistNumHitsPerTPC
Definition of basic raw digits.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
std::vector< unsigned int > fNumChansTPCTwoEvents
constexpr TimeValue_t value() const
Definition: Timestamp.h:23
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
void printTpcFragTimingInfo(art::Event const &e)
bool isValid() const
Definition: Handle.h:183
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
const double e
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
void reconfigure(fhicl::ParameterSet const &p)
TPCHits & operator=(TPCHits const &)=delete
void printRawDigitTimingInfo(art::Event const &e)
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< unsigned int > fNumTicksTPC
std::vector< TH1I * > fHistNumTicksPerEvent
std::vector< unsigned int > fNumTicksTPCTwoEvents
std::vector< unsigned int > fNumChansTPC
std::vector< unsigned int > fNumChansTPCLastEvent
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
p
Definition: test.py:223
art::InputTag fTPCHitTag
std::vector< unsigned int > fNumTicksTPCLastEvent
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
art::Timestamp fTimestampLast
art::InputTag fRawDigitsTag
TPCHits(fhicl::ParameterSet const &p)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:291
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:402
std::vector< unsigned int > fTotalNumHitsPerTPC
art::EventNumber_t fEventLast
EventID id() const
Definition: Event.cc:37
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
Event finding and building.
art::EventID fEventIDLast