RawEVD35t_module.cc
Go to the documentation of this file.
1 //Use this module to create histograms for 35t FD TPCs
2 //The output file can be used to display time vs. channel hit information
3 //for U,V,Z planes using 'rawEVD35t.c' root script.
4 //Sep. 25, 2013, Seongtae Park
5 //Nov. 4, 2013, Thumbnail histograms are included in the root file
6 
7 #ifndef RawEVD35t_Module
8 #define RawEVD35t_Module
9 
10 // LArSoft includes
14 #include "lardataobj/RawData/raw.h"
22 
23 // Framework includes
28 #include "art_root_io/TFileService.h"
30 #include "canvas/Persistency/Common/FindManyP.h"
32 #include "fhiclcpp/ParameterSet.h"
33 
34 // ROOT includes.
35 #include "TH1.h"
36 #include "TH2.h"
37 #include "TTree.h"
38 #include "TLorentzVector.h"
39 #include "TVector3.h"
40 #include "TCanvas.h"
41 #include "TPad.h"
42 #include "TFile.h"
43 
44 // C++ Includes
45 #include <map>
46 #include <vector>
47 #include <algorithm>
48 #include <fstream>
49 #include <iostream>
50 #include <string>
51 #include <sstream>
52 #include <cmath>
53 
54 namespace AnalysisExample{
55 
56  class RawEVD35t : public art::EDAnalyzer{
57  public:
58 
59  explicit RawEVD35t(fhicl::ParameterSet const& pset);
60  virtual ~RawEVD35t();
61 
62  void beginJob();
63 
64  void beginRun(const art::Run& run);
65 
66  void reconfigure(fhicl::ParameterSet const& pset);
67 
68  void analyze(const art::Event& evt);
69 
70  unsigned int getAPAindex(unsigned int apa) {
71  for (int k=0; k<4; k++){if(apa==UVPlane[k]) {return k; }}
72  return -1;
73  }
74 
75  unsigned int getTPCindex(unsigned int tpc) {
76  for (int k=0; k<8; k++){if(tpc==ZPlane[k]) {return k; }}
77  return -1;
78  }
79 
80  private:
81 
82  // the parameters we'll read from the .fcl
84  //unsigned int fEvent; // unused
85 
86  // number of time bins for histogram ranges
87  unsigned int fNticks;
89 
90  // find channel boundaries for each view
91  unsigned int fUChanMin;
92  unsigned int fUChanMax;
93  unsigned int fVChanMin;
94  unsigned int fVChanMax;
95  unsigned int fZ0ChanMin;
96  unsigned int fZ0ChanMax;
97  unsigned int fZ1ChanMin;
98  unsigned int fZ1ChanMax;
99 
100  unsigned int fNofAPA;
101  unsigned int fChansPerAPA;
102  //unsigned int fUWireMax; // unused
103  //unsigned int fVWireMax; // unused
104  //unsigned int fZ0WireMax; // unused
105  //unsigned int fZ1WireMax; // unused
106 
107  //unsigned int fMinT, fMaxT, fMaxTimeRange; // unused
108 
109 
111 
112  std::vector<TH2I*> fTimeChanU;
113  std::vector<TH2I*> fTimeChanV;
114  std::vector<TH2I*> fTimeChanZ0;
115  std::vector<TH2I*> fTimeChanZ1;
116 
117  std::vector<TH2I*> fTimeChanThumbU;
118  std::vector<TH2I*> fTimeChanThumbV;
119  std::vector<TH2I*> fTimeChanThumbZ0;
120  std::vector<TH2I*> fTimeChanThumbZ1;
121 
122  TH2I* fChargeSumU;
123  TH2I* fChargeSumV;
124  TH2I* fChargeSumZ;
125 
126  unsigned int UVPlane[4]={3,2,1,0};
127  unsigned int ZPlane[8]={7,6,5,4,3,2,1,0};
128 
129  }; // class RawEVD35t
130 
131  //-----------------------------------------------------------------------
132 
133  // read in the parameters from the .fcl file
135  : EDAnalyzer(parameterSet)
136  {
137  this->reconfigure(parameterSet);
138  }
139 
140 
141  //-----------------------------------------------------------------------
142 
144  fRawDigitLabel = p.get< std::string >("RawDigitLabel");
145  // auto const* fDetProp = lar::providerFrom<detinfo::DetectorPropertiesService>();
146  // fNticks = fDetProp->NumberTimeSamples();
147  fNticks = (unsigned int) p.get< int >("TicksToDraw");
148  fUncompressWithPed = p.get< bool >("UncompressWithPed", true);
149  return;
150  }
151 
152 
153  //-----------------------------------------------------------------------
154 
156  }
157 
158  //-----------------------------------------------------------------------
159 
161  // Access ART's TFileService, which will handle creating and writing
162  // histograms and n-tuples for us.
164 
165  //Histogram names and titles
166  std::stringstream name, title;
167 
168  unsigned int UChMin;
169  unsigned int UChMax;
170  unsigned int VChMin;
171  unsigned int VChMax;
172  unsigned int Z0ChMin;
173  unsigned int Z0ChMax;
174  unsigned int Z1ChMin;
175  unsigned int Z1ChMax;
176  TH2I* TempHisto;
177 
178  std::ofstream outfile;
179  outfile.open("msglog.txt");
180 
181  // loop through channels in the first APA to find the channel boundaries for each view
182  // will adjust for desired APA after
183  fUChanMin = 0;
186  fZ1ChanMax = fChansPerAPA - 1;
187  for ( unsigned int c = fUChanMin + 1; c < fZ1ChanMax; c++ ){
188  if ( fGeom->View(c) == geo::kV && fGeom->View(c-1) == geo::kU ){
189  fVChanMin = c;
190  fUChanMax = c - 1;
191  }
192  if ( fGeom->View(c) == geo::kZ && fGeom->View(c-1) == geo::kV ){
193  fZ0ChanMin = c;
194  fVChanMax = c-1;
195  }
196  if ( fGeom->View(c) == geo::kZ && fGeom->ChannelToWire(c)[0].TPC == fGeom->ChannelToWire(c-1)[0].TPC + 1 ){
197  fZ1ChanMin = c;
198  fZ0ChanMax = c-1;
199  }
200  }
201 
202 outfile<<fChansPerAPA<<" "<<fGeom->Ncryostats()<<" "<<fNofAPA<<std::endl;
203 
204  unsigned int minT = 0;
205  unsigned int maxT = 0;
206  minT = 0;
207  maxT = fNticks;
208  unsigned int binT = (maxT-minT);
209 
210  for(unsigned int i=0;i<fNofAPA;i++){
211  UChMin=fUChanMin + i*fChansPerAPA;
212  UChMax=fUChanMax + i*fChansPerAPA;
213  VChMin=fVChanMin + i*fChansPerAPA;
214  VChMax=fVChanMax + i*fChansPerAPA;
215  Z0ChMin=fZ0ChanMin + i*fChansPerAPA;
216  Z0ChMax=fZ0ChanMax + i*fChansPerAPA;
217  Z1ChMin=fZ1ChanMin + i*fChansPerAPA;
218  Z1ChMax=fZ1ChanMax + i*fChansPerAPA;
219 
220  // construct the histograms; TH2 constructors: ("Name", "Title", NxBin, xMin, xMax, NyBin, yMax, yMin)
221  name.str("");
222  name << "fTimeChanU";
223  name << i;
224  title.str("");
225  title << "Time vs Channel(Plane U, APA";
226  title << i<<")";
227  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), UChMax - UChMin + 1, UChMin, UChMax, binT, minT, maxT);
228  fTimeChanU.push_back(TempHisto);
229 
230  name.str("");
231  name << "fTimeChanThumbU";
232  name << i;
233  title.str("");
234  title << "Time vs Channel(Plane U, APA";
235  title << i<<")";
236  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), 138, UChMin, UChMax, 138, minT, maxT);
237  fTimeChanThumbU.push_back(TempHisto);
238 
239  name.str("");
240  name << "fTimeChanV";
241  name << i;
242  title.str("");
243  title << "Time vs Channel(Plane V, APA";
244  title << i<<")";
245  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), VChMax - VChMin + 1, VChMin, VChMax, binT, minT, maxT);
246  fTimeChanV.push_back(TempHisto);
247 
248  name.str("");
249  name << "fTimeChanThumbV";
250  name << i;
251  title.str("");
252  title << "Time vs Channel(Plane V, APA";
253  title << i<<")";
254  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), 138, VChMin, VChMax, 138, minT, maxT);
255  fTimeChanThumbV.push_back(TempHisto);
256 
257  name.str("");
258  name << "fTimeChanZ0";
259  name << i;
260  title.str("");
261  title << "Time vs Channel(Plane Z0, APA";
262  title <<i<<")";
263  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), Z0ChMax - Z0ChMin + 1, Z0ChMin, Z0ChMax, binT, minT, maxT);
264  fTimeChanZ0.push_back(TempHisto);
265 
266  name.str("");
267  name << "fTimeChanThumbZ0";
268  name << i;
269  title.str("");
270  title << "Time vs Channel(Plane Z0, APA";
271  title <<i<<")";
272  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), 111, Z0ChMin, Z0ChMax, 111, minT, maxT);
273  fTimeChanThumbZ0.push_back(TempHisto);
274 
275  name.str("");
276  name << "fTimeChanZ1";
277  name << i;
278  title.str("");
279  title << "Time vs Channel(Plane Z1, APA";
280  title << i<<")";
281  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), Z1ChMax - Z1ChMin + 1, Z1ChMin, Z1ChMax, binT, minT, maxT);
282  fTimeChanZ1.push_back(TempHisto);
283 
284  name.str("");
285  name << "fTimeChanThumbZ1";
286  name << i;
287  title.str("");
288  title << "Time vs Channel(Plane Z1, APA";
289  title << i<<")";
290  TempHisto = tfs->make<TH2I>(name.str().c_str(),title.str().c_str(), 111, Z1ChMin, Z1ChMax, 111, minT, maxT);
291  fTimeChanThumbZ1.push_back(TempHisto);
292 
293  fTimeChanU[i]->SetStats(0); fTimeChanV[i]->SetStats(0);
294  fTimeChanZ0[i]->SetStats(0); fTimeChanZ1[i]->SetStats(0);
295  fTimeChanThumbU[i]->SetStats(0); fTimeChanThumbV[i]->SetStats(0);
296  fTimeChanThumbZ0[i]->SetStats(0); fTimeChanThumbZ1[i]->SetStats(0);
297 
298  fTimeChanU[i]->GetXaxis()->SetTitle("Channel"); fTimeChanU[i]->GetYaxis()->SetTitle("TDC");
299  fTimeChanV[i]->GetXaxis()->SetTitle("Channel"); fTimeChanV[i]->GetYaxis()->SetTitle("TDC");
300  fTimeChanZ0[i]->GetXaxis()->SetTitle("Channel"); fTimeChanZ0[i]->GetYaxis()->SetTitle("TDC");
301  fTimeChanZ1[i]->GetXaxis()->SetTitle("Channel"); fTimeChanZ1[i]->GetYaxis()->SetTitle("TDC");
302  }
303 
304  fChargeSumU= tfs->make<TH2I>("hChargeSumU","Charge Sum on U-planes", 2,0.5,2.5,2,0.5,2.5 );
305  fChargeSumV= tfs->make<TH2I>("hChargeSumV","Charge Sum on V-planes", 2,0.5,2.5,2,0.5,2.5 );
306  fChargeSumZ= tfs->make<TH2I>("hChargeSumZ","Charge Sum on Z-planes", 4,0.5,4.5,4,0.5,4.5);
307  fChargeSumU->SetStats(0); fChargeSumV->SetStats(0); fChargeSumZ->SetStats(0);
308 
309  }
310 
311  //-----------------------------------------------------------------------
312 
313  void RawEVD35t::beginRun(const art::Run& /*run*/){
314 
315  }
316 
317 
318  //-----------------------------------------------------------------------
319 
321 
322  unsigned int tpcid, cryoid;
323  std::stringstream thumbnameZ0, thumbnameZ1;
324 
325  // get the objects holding all of the raw data information
327  std::cout << "raw digit label check: " << fRawDigitLabel << std::endl;
328  event.getByLabel(fRawDigitLabel, Raw);
329 
330  // put it in a more easily usable form
331  std::vector< art::Ptr<raw::RawDigit> > Digits;
332  art::fill_ptr_vector(Digits, Raw);
333 
334  //loop through all RawDigits (over entire channels)
335  for(size_t d = 0; d < Digits.size(); d++){
337  digit=Digits.at(d);
338 
339  // get the channel number for this digit
340  uint32_t chan = digit->Channel();
341  unsigned int apa = std::floor( chan/fChansPerAPA );
342  tpcid=fGeom->ChannelToWire(chan)[0].TPC;
343  cryoid=fGeom->ChannelToWire(chan)[0].Cryostat;
344 
345  int nSamples = digit->Samples();
346  std::vector<short> uncompressed(nSamples);
347  // raw::Uncompress(digit->ADCs(), uncompressed, digit->Compression());
348  int pedestal = (int)digit->GetPedestal();
349  // std::cout << "channel " << chan << " pedestal " << pedestal << std::endl;
350  // uncompress the data
351  if (fUncompressWithPed){
352  raw::Uncompress(digit->ADCs(), uncompressed, pedestal, digit->Compression());
353  }
354  else{
355  raw::Uncompress(digit->ADCs(), uncompressed, digit->Compression());
356  }
357 
358  // subtract pedestals
359  std::vector<short> ladc(nSamples);
360  for (int i=0; i<nSamples; i++) ladc[i]=uncompressed[i]-pedestal;
361  // for (int i=0; i<nSamples; i++) {ladc[i]=uncompressed[i]-pedestal;
362  // if (i<10) std::cout << uncompressed[i] << " " << ladc[i] << std::endl;
363  // }
364  if( fGeom->View(chan) == geo::kU ){
365  for(unsigned int l=0;l<ladc.size();l++) {
366  if(ladc.at(l)!=0){
367  fTimeChanU[apa]->Fill(chan,l, ladc.at(l));
368  if(ladc.at(l)>0) fTimeChanThumbU[apa]->Fill(chan,l, ladc.at(l));
369  fChargeSumU->Fill(1+getAPAindex(apa)%2, 2-(getAPAindex(apa)/2),std::abs(ladc.at(l))/2);
370  }
371  }
372  }
373  if( fGeom->View(chan) == geo::kV ){
374  for(unsigned int l=0;l<ladc.size();l++) {
375  if(ladc.at(l)!=0){
376  fTimeChanV[apa]->Fill(chan,l, ladc.at(l));
377  if(ladc.at(l)>0) fTimeChanThumbV[apa]->Fill(chan,l, ladc.at(l));
378  fChargeSumV->Fill(1+getAPAindex(apa)%2, 2-(getAPAindex(apa)/2),std::abs(ladc.at(l))/2);
379  }
380  }
381  }
382  if ( fGeom->View(chan) == geo::kZ && fGeom->ChannelToWire(chan)[0].TPC % 2 == 0 ){
383  for(unsigned int l=0;l<ladc.size();l++) {
384  if(ladc.at(l)!=0){
385  fTimeChanZ0[apa]->Fill(chan,l, ladc.at(l));
386  if(ladc.at(l)>0) fTimeChanThumbZ0[apa]->Fill(chan,l, ladc.at(l));
387  fChargeSumZ->Fill(1+getTPCindex(cryoid*4+tpcid)%4, 4-(getTPCindex(cryoid*4+tpcid)/4),ladc.at(l));
388  }
389  }
390  }
391  if ( fGeom->View(chan) == geo::kZ && fGeom->ChannelToWire(chan)[0].TPC % 2 == 1 ){
392  for(unsigned int l=0;l<ladc.size();l++) {
393  if(ladc.at(l)!=0){
394  fTimeChanZ1[apa]->Fill(chan,l, ladc.at(l));
395  if(ladc.at(l)>0) fTimeChanThumbZ1[apa]->Fill(chan,l, ladc.at(l));
396  fChargeSumZ->Fill(1+getTPCindex(cryoid*4+tpcid)%4, 4-(getTPCindex(cryoid*4+tpcid)/4),ladc.at(l));
397  }
398  }
399  }
400 
401  } // end RawDigit loop
402 
403  return;
404  }
405 
407 
408 } // namespace AnalysisExample
409 
410 #endif // RawEVD35t_Module
static QCString name
Definition: declinfo.cpp:673
float GetPedestal() const
Definition: RawDigit.h:214
Store parameters for running LArG4.
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
art::ServiceHandle< geo::Geometry > fGeom
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:126
Declaration of signal hit object.
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.
void beginRun(const art::Run &run)
Definition of basic raw digits.
Planes which measure Z direction.
Definition: geo_types.h:128
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
Particle class.
static QStrList * l
Definition: config.cpp:1044
std::vector< TH2I * > fTimeChanU
unsigned int getTPCindex(unsigned int tpc)
Definition: Run.h:21
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
T abs(T value)
Planes which measure U.
Definition: geo_types.h:125
std::vector< TH2I * > fTimeChanThumbU
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
std::vector< TH2I * > fTimeChanV
unsigned int uint32_t
Definition: stdint.h:126
void analyze(const art::Event &evt)
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:231
unsigned int getAPAindex(unsigned int apa)
std::vector< TH2I * > fTimeChanThumbV
Declaration of cluster object.
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.
RawEVD35t(fhicl::ParameterSet const &pset)
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
p
Definition: test.py:223
std::vector< TH2I * > fTimeChanThumbZ1
std::vector< TH2I * > fTimeChanZ1
object containing MC truth information necessary for making RawDigits and doing back tracking ...
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:291
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:755
std::vector< TH2I * > fTimeChanZ0
void reconfigure(fhicl::ParameterSet const &pset)
QTextStream & endl(QTextStream &s)
std::vector< TH2I * > fTimeChanThumbZ0
Event finding and building.
unsigned int run