RawDigitOverlayDUNE35tAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: RawDigitOverlayDUNE35tAna
3 // Module Type: analyzer
4 // File: RawDigitOverlayDUNE35tAna_module.cc
5 //
6 // Generated at Nov 20 13:06:09 2015 by Wesley Ketchum using artmod
7 // from cetpkgsupport v1_08_07.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include <map>
11 
19 #include "fhiclcpp/ParameterSet.h"
21 
22 #include "art_root_io/TFileService.h"
23 
24 #include <sstream>
25 
26 #include "TTree.h"
27 
29 
31 
32 namespace mix {
33  const int kNMaxADCs = 100000000;
36  kRawData = 0,
39  kNoType = -9999
40  };
41 }
42 
43 
45 public:
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.
55 
56  // Required functions.
57  void analyze(art::Event const & e) override;
58  void beginJob() override;
59 
60 
61 
62 private:
63 
64  void FillADCVariables(art::Handle<std::vector<raw::RawDigit> > digit_handle, mix::RawDigitTypes type);
65  void Reset();
66 
67  std::map<mix::RawDigitTypes, std::string> fRawDigitModuleLabels;
68  std::map<mix::RawDigitTypes, art::Handle<std::vector<raw::RawDigit> > > fRawDigitProducts;
69 
70  TTree *fTree;
71  size_t fNADCs;
75 };
76 
77 
79  :
80  EDAnalyzer(p)
81 {
82  fRawDigitModuleLabels[mix::kRawData] = p.get<std::string>("DataRawDigitModuleLabel");
83  fRawDigitModuleLabels[mix::kRawMC] = p.get<std::string>("MCRawDigitModuleLabel");
84  fRawDigitModuleLabels[mix::kRawMixed] = p.get<std::string>("MixedRawDigitModuleLabel");
85 }
86 
89  fTree = tfs->make<TTree>("MRDT","MixerRawDigitTree");
90 
91  fTree->Branch("NADC",&fNADCs,"NADC/i");
92  fTree->Branch("ADC",fADCs,"ADC[NADC]/S");
93  fTree->Branch("ChannelID",fChannelIDs,"ChannelID[NADC]/I");
94  fTree->Branch("Type",fTypes,"Type[NADC]/I");
95 }
96 
98 {
99 
100  Reset();
102  std::cout<<"Num TPC channels is: " << geometry->Nchannels() << std::endl;
103 
104  for (int type_num = mix::kRawData; type_num <= mix::kRawMixed; type_num++){
105  mix::RawDigitTypes type = static_cast<mix::RawDigitTypes>(type_num);
107  if (!fRawDigitProducts[type].isValid()){
108  std::cerr<<"Could not find raw digit with label: " << fRawDigitModuleLabels[type] << std::endl;
109  }
110  else{
112  }
113  }
114 
115  /*
116  art::ServiceHandle<art::TFileService> tfs;
117 
118  art::Handle<std::vector<raw::RawDigit> > waveform1Handle,waveform2Handle,waveformSumHandle;
119  e.getByLabel(fRawDigitModule1,waveform1Handle);
120  e.getByLabel(fRawDigitModule2,waveform2Handle);
121  e.getByLabel(fRawDigitModuleSum,waveformSumHandle);
122  if(!waveform1Handle.isValid() || !waveform2Handle.isValid() || !waveformSumHandle.isValid()) throw std::runtime_error("some handle is not valid");
123  std::vector<raw::RawDigit> const& waveform1Vector(*waveform1Handle);
124  std::vector<raw::RawDigit> const& waveform2Vector(*waveform2Handle);
125  std::vector<raw::RawDigit> const& waveformSumVector(*waveformSumHandle);
126 
127  size_t histos_to_make = fAnaAlg.CheckOverlay(waveform1Vector,waveform2Vector,waveformSumVector);
128 
129  std::vector<TH1S*> histograms(histos_to_make);
130  for(size_t i_h=0; i_h<histograms.size(); i_h++){
131  std::stringstream hname; hname << "h" << i_h;
132  tfs->make<TH1S>(hname.str().c_str(),"GenericTitle",1,0,1);
133  }
134 
135  fAnaAlg.CreateOutputHistograms(histograms,
136  waveform1Vector,waveform2Vector,waveformSumVector,
137  e.run(),e.event());
138  */
139 
140  fTree->Fill();
141 }
142 
144  //Check if the handle is valid. If not, don't do anything :(
145  if (!digit_handle.isValid()){
146  std::cerr<<"Digit handle for type " << type << " not valid! Don't attempt to fill the tree for this product"<<std::endl;
147  return;
148  }
149  std::vector<raw::RawDigit> const& digitVector(*digit_handle);
150 
151  for (unsigned int i_raw = 0; i_raw < digitVector.size(); i_raw++){
152  raw::RawDigit raw_digit = digitVector[i_raw];
153 
154  raw::ChannelID_t channel = raw_digit.Channel();
155 
156  for (unsigned int i_adc = 0; i_adc < raw_digit.ADCs().size(); i_adc++){
157  fADCs[fNADCs] = raw_digit.ADCs()[i_adc];
159  fTypes[fNADCs] = static_cast<int>(type);
160  fNADCs++;
161  }
162  }
163 
164  return;
165 }
166 
168  fNADCs = 0;
169  for (int i = 0; i < mix::kNMaxADCs; i++){
170  fADCs[i] = -9999;
171  fChannelIDs[i] = -9999;
172  fTypes[i] = kNoType;
173  }
174 }
175 
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::string string
Definition: nybbler.cc:12
void analyze(art::Event const &e) override
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
void FillADCVariables(art::Handle< std::vector< raw::RawDigit > > digit_handle, mix::RawDigitTypes type)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
T get(std::string const &key) const
Definition: ParameterSet.h:231
RawDigitOverlayDUNE35tAna(fhicl::ParameterSet const &p)
std::map< mix::RawDigitTypes, art::Handle< std::vector< raw::RawDigit > > > fRawDigitProducts
std::map< mix::RawDigitTypes, std::string > fRawDigitModuleLabels
p
Definition: test.py:223
RawDigitOverlayDUNE35tAna & operator=(RawDigitOverlayDUNE35tAna const &)=delete
static QCString type
Definition: declinfo.cpp:672
raw::ChannelID_t fChannelIDs[mix::kNMaxADCs]
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
QTextStream & endl(QTextStream &s)