9 #include "art/Framework/Core/EDAnalyzer.h"
10 #include "art/Framework/Core/ModuleMacros.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Principal/Handle.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "fhiclcpp/types/Table.h"
16 #include "fhiclcpp/types/Atom.h"
18 #include "canvas/Utilities/Exception.h"
21 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTFragment.hh"
22 #include "artdaq-core/Data/Fragment.hh"
23 #include "artdaq-core/Data/ContainerFragment.hh"
24 #include "sbndaq-artdaq-core/Overlays/FragmentType.hh"
27 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTTranslator.hh"
30 #include "art_root_io/TFileService.h"
68 fhicl::Sequence<uint8_t>
Mac {
70 Comment(
"mac addresses for each FEB in the diasychain")
85 art::ServiceHandle<art::TFileService>
tfs;
125 : EDAnalyzer(config) , macs(config().Mac())
128 for(
int i=0; i<(int)
macs.size(); i++){
130 for(
int ch=0; ch<32; ch++){
133 macToHistos[macs[i]]->push_back(
tfs->make<TH1F>(hname.c_str(),htitle.c_str(),4100,0,4100));
137 for(
int i=0; i<32; i++) {
158 for(
size_t j=0; j<5; j++){
178 calTree =
tfs->make<TTree>(
"calAnalyzerTree",
"SiPM/FEB channel calibration data");
180 calTree->Branch(
"mac5", &fMac5,
"mac5/b");
181 calTree->Branch(
"active", fActive,
"active[32]/O");
182 calTree->Branch(
"gain", fGain,
"gain[32]/F");
183 calTree->Branch(
"gainErr", fGainErr,
"gainErr[32]/F");
184 calTree->Branch(
"gainXsqr", fGainXsqr,
"gainXsqr[32]/F");
185 calTree->Branch(
"gainNdf", fGainNdf,
"gainNdf[32]/s");
186 calTree->Branch(
"gainPed", fGainPed,
"gainPed[32]/F");
187 calTree->Branch(
"gainPedErr", fGainPedErr,
"gainPedErr[32]/F");
188 calTree->Branch(
"nPeak", fNpeak,
"nPeak[32]/s");
189 calTree->Branch(
"peakXsqr", fPeakXsqr,
"peakXsqr[32][5]/F");
190 calTree->Branch(
"peakNdf", fPeakNdf,
"peakNdf[32][5]/s");
191 calTree->Branch(
"peakMean", fPeakMean,
"peakMean[32][5]/F");
192 calTree->Branch(
"peakMeanErr", fPeakMeanErr,
"peakMeanErr[32][5]/F");
193 calTree->Branch(
"peakNorm", fPeakNorm,
"peakNorm[32][5]/F");
194 calTree->Branch(
"peakNormErr", fPeakNormErr,
"peakNormErr[32][5]/F");
195 calTree->Branch(
"peakSigma", fPeakSigma,
"peakSigma[32][5]/F");
196 calTree->Branch(
"peakSigmaErr", fPeakSigmaErr,
"peakSigmaErr[32][5]/F");
197 calTree->Branch(
"ped", fPed,
"ped[32]/F");
198 calTree->Branch(
"pedErr", fPedErr,
"pedErr[32]/F");
199 calTree->Branch(
"pedXsqr", fPedXsqr,
"pedXsqr[32]/F");
200 calTree->Branch(
"pedNdf", fPedNdf,
"pedNdf[32]/s");
201 calTree->Branch(
"pedSigma", fPedSigma,
"pedSigma[32]/F");
202 calTree->Branch(
"pedSigmaErr", fPedSigmaErr,
"pedSigmaErr[32]/F");
203 calTree->Branch(
"pedNorm", fPedNorm,
"pedNorm[32]/F");
204 calTree->Branch(
"pedNormErr", fPedNormErr,
"pedNormErr[32]/F");
205 calTree->Branch(
"threshAdc", fThreshADC,
"threshAdc[32]/I");
206 calTree->Branch(
"threshPe", fThreshPE,
"threshPe[32]/F");
207 calTree->Branch(
"nAbove", fNabove,
"nAbove[32]/I");
214 std::vector<icarus::crt::BernCRTTranslator> hit_vector;
216 auto fragmentHandles = evt.getMany<artdaq::Fragments>();
217 for (
auto handle : fragmentHandles) {
218 if (!handle.isValid() || handle->size() == 0)
221 auto this_hit_vector = icarus::crt::BernCRTTranslator::getCRTData(*handle);
223 hit_vector.insert(hit_vector.end(),this_hit_vector.begin(),this_hit_vector.end());
227 for(
auto &
hit : hit_vector) {
231 if(macToHistos.find(fMac5) == macToHistos.end())
return;
233 for(
int ch=0; ch<32; ch++) {
234 macToHistos[fMac5]->at(ch)->Fill(
hit.adc[ch] );
242 std::cout <<
"done filling histograms..." << std::endl;
243 std::cout <<
"found " << macToHistos.size() <<
" FEBs" << std::endl;
244 if(!macToHistos.begin()->second->empty()){
245 std::cout <<
"first histo size: " << macToHistos.begin()->second->at(0)->Integral()
246 <<
" entries" << std::endl;
249 std::cout <<
"hist vect is empty!" << std::endl;
252 for(
auto const& macHist : macToHistos){
254 uint8_t mac = macHist.first;
255 vector<TH1F*>* hvec = macHist.second;
257 std::cout <<
"construct instance of CrtCal for mac5 " << (short)mac << std::endl;
261 std::cout <<
"retreiving cal data..." << std::endl;
262 fMac5 = macHist.first;
263 bool* ptrActive = cal->GetActive();
264 float* ptrGain = cal->GetGain();
265 float* ptrGainErr = cal->GetGainErr();
266 float* ptrGainXsqr = cal->GetGainXsqr();
267 short* ptrGainNdf = cal->GetGainNdf();
268 float* ptrGainPed = cal->GetGainPed();
269 float* ptrGainPedErr = cal->GetGainPedErr();
270 short* ptrNpeak = cal->GetNpeak();
271 float** ptrPeakNorm = cal->GetPeakNorm();
272 float** ptrPeakNormErr = cal->GetPeakNormErr();
273 float** ptrPeakSigma = cal->GetPeakSigma();
274 float** ptrPeakSigmaErr = cal->GetPeakSigmaErr();
275 float** ptrPeakMean = cal->GetPeakMean();
276 float** ptrPeakMeanErr = cal->GetPeakMeanErr();
277 float** ptrPeakXsqr = cal->GetPeakXsqr();
278 short** ptrPeakNdf = cal->GetPeakNdf();
279 float* ptrPed = cal->GetPed();
280 float* ptrPedErr = cal->GetPedErr();
281 float* ptrPedXsqr = cal->GetPedXsqr();
282 short* ptrPedNdf = cal->GetPedNdf();
283 float* ptrPedSigma = cal->GetPedSigma();
284 float* ptrPedSigmaErr = cal->GetPedSigmaErr();
285 float* ptrPedNorm = cal->GetPedNorm();
286 float* ptrPedNormErr = cal->GetPedNormErr();
287 int* ptrThreshADC = cal->GetThreshADC();
288 float* ptrThreshPE = cal->GetThreshPE();
289 int* ptrNabove = cal->GetNabove();
292 for(
size_t i=0; i<32; i++){
293 if(ptrActive!=
nullptr) fActive[i] = ptrActive[i];
294 if(ptrGain!=
nullptr) fGain[i] = ptrGain[i];
295 if(ptrGainErr!=
nullptr) fGainErr[i] = ptrGainErr[i];
296 if(ptrGainXsqr!=
nullptr) fGainXsqr[i] = ptrGainXsqr[i];
297 if(ptrGainNdf!=
nullptr) fGainNdf[i] = ptrGainNdf[i];
298 if(ptrGainPed!=
nullptr) fGainPed[i] = ptrGainPed[i];
299 if(ptrGainPedErr!=
nullptr) fGainPedErr[i] = ptrGainPedErr[i];
300 if(ptrNpeak!=
nullptr) fNpeak[i] = ptrNpeak[i];
301 if(ptrPed!=
nullptr) fPed[i] = ptrPed[i];
302 if(ptrPedErr!=
nullptr) fPedErr[i] = ptrPedErr[i];
303 if(ptrPedXsqr!=
nullptr) fPedXsqr[i] = ptrPedXsqr[i];
304 if(ptrPedNdf!=
nullptr) fPedNdf[i] = ptrPedNdf[i];
305 if(ptrPedSigma!=
nullptr) fPedSigma[i] = ptrPedSigma[i];
306 if(ptrPedSigmaErr!=
nullptr) fPedSigmaErr[i] = ptrPedSigmaErr[i];
307 if(ptrPedNorm!=
nullptr) fPedNorm[i] = ptrPedNorm[i];
308 if(ptrPedNormErr!=
nullptr) fPedNormErr[i] = ptrPedNormErr[i];
309 if(ptrThreshADC!=
nullptr) fThreshADC[i] = ptrThreshADC[i];
310 if(ptrThreshPE!=
nullptr) fThreshPE[i] = ptrThreshPE[i];
311 if(ptrNabove!=
nullptr) fNabove[i] = ptrNabove[i];
313 for(
size_t j=0; j<5; j++){
314 if(ptrPeakNorm!=
nullptr) fPeakNorm[i][j] = ptrPeakNorm[i][j];
315 if(ptrPeakNormErr!=
nullptr) fPeakNormErr[i][j] = ptrPeakNormErr[i][j];
316 if(ptrPeakSigma!=
nullptr) fPeakSigma[i][j] = ptrPeakSigma[i][j];
317 if(ptrPeakSigmaErr!=
nullptr) fPeakSigmaErr[i][j] = ptrPeakSigmaErr[i][j];
318 if(ptrPeakMean!=
nullptr) fPeakMean[i][j] = ptrPeakMean[i][j];
319 if(ptrPeakMeanErr!=
nullptr) fPeakMeanErr[i][j] = ptrPeakMeanErr[i][j];
320 if(ptrPeakXsqr!=
nullptr) fPeakXsqr[i][j] = ptrPeakXsqr[i][j];
321 if(ptrPeakNdf!=
nullptr) fPeakNdf[i][j] = ptrPeakNdf[i][j];
325 std::cout <<
"fill tree event" << std::endl;
float fPeakSigmaErr[32][5]
float fPeakNormErr[32][5]
fhicl::Sequence< uint8_t > Mac
float fPeakMeanErr[32][5]
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
BEGIN_PROLOG vertical distance to the surface Name
map< uint8_t, vector< TH1F * > * > macToHistos
std::string to_string(WindowPattern const &pattern)
virtual void analyze(art::Event const &evt)
art::EDAnalyzer::Table< Config > Parameters
CrtCalAnalyzer(Parameters const &config)
art::ServiceHandle< art::TFileService > tfs
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout
virtual ~CrtCalAnalyzer()