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