RawEventDisplay_module.cc
Go to the documentation of this file.
1 //Use this module to create 2D histos raw event display for protoDUNE detector
2 //Dec. 2016: taken from RawEVD35t module.
3 
4 
5 #ifndef RawEventDisplay_module
6 #define RawEventDisplay_module
7 
8 // LArSoft includes
12 
13 // Data type includes
14 #include "lardataobj/RawData/raw.h"
16 
17 
18 
19 // Framework includes
24 #include "art_root_io/TFileService.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
28 #include "fhiclcpp/ParameterSet.h"
29 
30 // ROOT includes.
31 #include "TH1.h"
32 #include "TH2.h"
33 #include "TTree.h"
34 #include "TLorentzVector.h"
35 #include "TVector3.h"
36 #include "TCanvas.h"
37 #include "TPad.h"
38 #include "TFile.h"
39 
40 // C++ Includes
41 #include <map>
42 #include <vector>
43 #include <algorithm>
44 #include <fstream>
45 #include <iostream>
46 #include <string>
47 #include <sstream>
48 #include <cmath>
49 
50 #ifdef __MAKECINT__
51 #pragma link C++ class vector<vector<int> >+;
52 #endif
53 
55 
57  public:
58 
59  explicit RawEventDisplay(fhicl::ParameterSet const& pset);
60  virtual ~RawEventDisplay();
61 
62  void beginJob();
63  void beginRun(const art::Run& run);
64  void reconfigure(fhicl::ParameterSet const& pset);
65  void analyze(const art::Event& evt);
66 
67  private:
68 
69  // Parameters in .fcl file
73 
74  // Branch variables for tree
75  unsigned int fEvent;
76  unsigned int fRun;
77  unsigned int fSubRun;
78 
79 
80  // TPC
81  unsigned int fNUCh;
82  unsigned int fNVCh;
83  unsigned int fNZCh;
84 
85  // find channel boundaries for each view
86  unsigned int fUChanMin;
87  unsigned int fUChanMax;
88  unsigned int fVChanMin;
89  unsigned int fVChanMax;
90  unsigned int fZChanMin;
91  unsigned int fZChanMax;
92  unsigned int fNticks;
93 
94  unsigned int fNofAPA;
95  unsigned int fChansPerAPA;
96 
97 
98  //unsigned int fMinT, fMaxT, fMaxTimeRange; // unused
99 
100  std::vector<TH2S*> fTimeChanU;
101  std::vector<TH2S*> fTimeChanV;
102  std::vector<TH2S*> fTimeChanZ;
103 
104 
105 
106 
107  // define nADC counts for uncompressed vs compressed
108  unsigned int nADC_uncompPed;
109 
110 
112 
113 
114  }; // RawEventDisplay
115 
116  //-----------------------------------------------------------------------
117 
119  this->reconfigure(parameterSet);
120 
121  }
122 
123  //-----------------------------------------------------------------------
124 
125 
127 
128 
129  //-----------------------------------------------------------------------
131  // place to define the histograms
132 
134  //Histogram names and titles
135  std::stringstream name, title;
136 
137  unsigned int UChMin;
138  unsigned int UChMax;
139  unsigned int VChMin;
140  unsigned int VChMax;
141  unsigned int ZChMin;
142  unsigned int ZChMax;
143  TH2S* TempHisto;
144 
145 
146  // Accquiring geometry data
149 
150  // taken from dune35t module a way to organise the channel mapping:
151  // loop through channels in the first APA to find the channel boundaries for each view
152  // will adjust for desired APA after
153  fUChanMin = 0;
154  fZChanMax = fChansPerAPA - 1;
155  for ( unsigned int c = fUChanMin + 1; c < fZChanMax; c++ ){
156  if ( fGeom->View(c) == geo::kV && fGeom->View(c-1) == geo::kU ){
157  fVChanMin = c;
158  fUChanMax = c - 1;
159  }
160  if ( fGeom->View(c) == geo::kZ && fGeom->View(c-1) == geo::kV ){
161  fZChanMin = c;
162  fVChanMax = c-1;
163  }
164  }
165 
166 
169  fNZCh=fZChanMax-fZChanMin+1;
170 
171 
172  unsigned int minT = 0;
173  unsigned int maxT = 0;
174  minT = 0;
175  maxT = fNticks;
176  unsigned int binT = (maxT-minT);
177 
178  for(unsigned int i=0;i<fNofAPA;i++){
179  UChMin=fUChanMin + i*fChansPerAPA;
180  UChMax=fUChanMax + i*fChansPerAPA;
181  VChMin=fVChanMin + i*fChansPerAPA;
182  VChMax=fVChanMax + i*fChansPerAPA;
183  ZChMin=fZChanMin + i*fChansPerAPA;
184  ZChMax=fZChanMax + i*fChansPerAPA;
185 
186  // construct the histograms; TH2 constructors: ("Name", "Title", NxBin, xMin, xMax, NyBin, yMax, yMin)
187  name.str("");
188  name << "fTimeChanU";
189  name << i;
190  title.str("");
191  title << "Time vs Channel(Plane U, APA";
192  title << i<<")";
193  TempHisto = tfs->make<TH2S>(name.str().c_str(),title.str().c_str(), UChMax - UChMin + 1, UChMin, UChMax, binT, minT, maxT);
194  fTimeChanU.push_back(TempHisto);
195 
196  name.str("");
197  name << "fTimeChanV";
198  name << i;
199  title.str("");
200  title << "Time vs Channel(Plane V, APA";
201  title << i<<")";
202  TempHisto = tfs->make<TH2S>(name.str().c_str(),title.str().c_str(), VChMax - VChMin + 1, VChMin, VChMax, binT, minT, maxT);
203  fTimeChanV.push_back(TempHisto);
204 
205  name.str("");
206  name << "fTimeChanZ";
207  name << i;
208  title.str("");
209  title << "Time vs Channel(Plane Z, APA";
210  title <<i<<")";
211  TempHisto = tfs->make<TH2S>(name.str().c_str(),title.str().c_str(), ZChMax - ZChMin + 1, ZChMin, ZChMax, binT, minT, maxT);
212  fTimeChanZ.push_back(TempHisto);
213 
214 
215  fTimeChanU[i]->SetStats(0);
216  fTimeChanV[i]->SetStats(0);
217  fTimeChanZ[i]->SetStats(0);
218 
219 
220  fTimeChanU[i]->GetXaxis()->SetTitle("Channel"); fTimeChanU[i]->GetYaxis()->SetTitle("TDC");
221  fTimeChanV[i]->GetXaxis()->SetTitle("Channel"); fTimeChanV[i]->GetYaxis()->SetTitle("TDC");
222  fTimeChanZ[i]->GetXaxis()->SetTitle("Channel"); fTimeChanZ[i]->GetYaxis()->SetTitle("TDC");
223  }
224 
225 
226  }
227 
228  //-----------------------------------------------------------------------
229 
231  // place to read databases or run independent info
232  }
233 
234  //-----------------------------------------------------------------------
235 
237 
238  // reconfigure without recompiling
239  // read in the parameters from the .fcl file
240  // allows for interactive changes of the parameter values
241 
242  fTPCInput = p.get< std::string >("TPCInputModule");
243  fTPCInstance = p.get< std::string >("TPCInstanceName");
244  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
245  fNticks = detProp.NumberTimeSamples();
246  return;
247  }
248 
249 
250 
251  //-----------------------------------------------------------------------
252 
254 
255  // called once per event
256 
257  fEvent = event.id().event();
258  fRun = event.run();
259  fSubRun = event.subRun();
260  std::cout << "EventNumber = " << fEvent << std::endl;
261 
262  // Get the objects holding raw information: RawDigit for TPC data
264  auto RawTPC = event.getHandle< std::vector<raw::RawDigit> >(itag1);
265 
266  // Fill pointer vectors - more useful form for the raw data
267  // a more usable form
268  std::vector< art::Ptr<raw::RawDigit> > RawDigits;
269  art::fill_ptr_vector(RawDigits, RawTPC);
270 
271 
272 
273  // Loop over all RawDigits (entire channels)
274  for(auto const & dptr : RawDigits) {
275  const raw::RawDigit & digit = *dptr;
276 
277  // Get the channel number for this digit
278  uint32_t chan = digit.Channel();
279  // number of samples in uncompressed ADC
280  int nSamples = digit.Samples();
281  unsigned int apa = std::floor( chan/fChansPerAPA );
282  int pedestal = (int)digit.GetPedestal();
283 
284  std::vector<short> uncompressed(nSamples);
285  // with pedestal
286  raw::Uncompress(digit.ADCs(), uncompressed, pedestal, digit.Compression());
287  // subtract pedestals
288  std::vector<short> uncompPed(nSamples);
289  for (int i=0; i<nSamples; i++) uncompPed.at(i)=uncompressed.at(i)-pedestal;
290 
291  // number of ADC uncompressed without pedestal
292  nADC_uncompPed=uncompPed.size();
293 
294 
295  //Induction Plane
296  if( fGeom->View(chan) == geo::kU){
297  for(unsigned int l=0;l<nADC_uncompPed;l++) {
298  if(uncompPed.at(l)!=0){
299  fTimeChanU[apa]->Fill(chan,l, uncompPed.at(l));
300  }
301  }
302  }// end of U View
303 
304  //Induction Plane
305  if( fGeom->View(chan) == geo::kV){
306  for(unsigned int l=0;l<nADC_uncompPed;l++) {
307  if(uncompPed.at(l)!=0){
308  fTimeChanV[apa]->Fill(chan,l, uncompPed.at(l));
309  }
310  }
311  }// end of V View
312 
313  if ( fGeom->View(chan) == geo::kZ){
314  for(unsigned int l=0;l<nADC_uncompPed;l++) {
315  if(uncompPed.at(l)!=0){
316  fTimeChanZ[apa]->Fill(chan,l, uncompPed.at(l));
317  }
318  }
319  }
320 
321 
322  } // RawDigits
323 
324  return;
325  }
326 
327 }
329 
330 
331 
332 #endif // RawEventDisplay
static QCString name
Definition: declinfo.cpp:673
float GetPedestal() const
Definition: RawDigit.h:214
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:130
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< raw::RawDigit > RawDigits
Definition: HDF5Utils.h:23
Planes which measure Z direction.
Definition: geo_types.h:132
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
static QStrList * l
Definition: config.cpp:1044
RawEventDisplay(fhicl::ParameterSet const &pset)
art framework interface to geometry description
Definition: Run.h:17
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
void reconfigure(fhicl::ParameterSet const &pset)
Planes which measure U.
Definition: geo_types.h:129
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
type * at(uint i)
Definition: qinternallist.h:81
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
QTextStream & endl(QTextStream &s)
Event finding and building.