|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 12 | +#include <array> |
| 13 | +#include <iostream> |
| 14 | +#include <fstream> |
| 15 | +#include <vector> |
| 16 | +#include "RStringView.h" |
| 17 | +#include <Rtypes.h> |
| 18 | +#include "DetectorsRaw/RawFileReader.h" |
| 19 | +#include "DetectorsRaw/RDHUtils.h" |
| 20 | +#include "EMCALReconstruction/CaloFitResults.h" |
| 21 | +#include "EMCALReconstruction/Bunch.h" |
| 22 | +#include "EMCALReconstruction/CaloRawFitterStandard.h" |
| 23 | +#include "EMCALReconstruction/AltroDecoder.h" |
| 24 | +#include "EMCALReconstruction/CaloRawFitterGamma2.h" |
| 25 | +//#include "EMCALReconstruction/RawHeaderStream.h" |
| 26 | +#endif |
| 27 | + |
| 28 | +using namespace o2::emcal; |
| 29 | + |
| 30 | +/// \brief Testing the standard raw fitter on run2 to run3 converted data |
| 31 | +void RawFitterTESTMulti(const char* configfile = "") |
| 32 | +{ |
| 33 | + |
| 34 | + const Int_t NoiseThreshold = 3; |
| 35 | + |
| 36 | + o2::raw::RawFileReader reader(configfile); |
| 37 | + reader.init(); |
| 38 | + |
| 39 | + // define the standard raw fitter |
| 40 | + //o2::emcal::CaloRawFitterStandard RawFitter; |
| 41 | + o2::emcal::CaloRawFitterGamma2 RawFitter; |
| 42 | + RawFitter.setAmpCut(NoiseThreshold); |
| 43 | + RawFitter.setL1Phase(0.); |
| 44 | + |
| 45 | + while (1) { |
| 46 | + int tfID = reader.getNextTFToRead(); |
| 47 | + if (tfID >= reader.getNTimeFrames()) { |
| 48 | + std::cerr << "nothing left to read after " << tfID << " TFs read" << std::endl; |
| 49 | + break; |
| 50 | + } |
| 51 | + std::vector<char> dataBuffer; // where to put extracted data |
| 52 | + std::cout << "Next iteration: Number of links: " << reader.getNLinks() << std::endl; |
| 53 | + for (int il = 0; il < reader.getNLinks(); il++) { |
| 54 | + auto& link = reader.getLink(il); |
| 55 | + std::cout << "Decoding link " << il << std::endl; |
| 56 | + |
| 57 | + auto sz = link.getNextTFSize(); // size in bytes needed for the next TF of this link |
| 58 | + dataBuffer.resize(sz); |
| 59 | + link.readNextTF(dataBuffer.data()); |
| 60 | + |
| 61 | + // Parse |
| 62 | + o2::emcal::RawReaderMemory parser(dataBuffer); |
| 63 | + while (parser.hasNext()) { |
| 64 | + parser.next(); |
| 65 | + //std::cout << "next page \n"; |
| 66 | + if (o2::raw::RDHUtils::getFEEID(parser.getRawHeader()) >= 40) |
| 67 | + continue; |
| 68 | + |
| 69 | + //std::cout<<rawreader.getRawHeader()<<std::endl; |
| 70 | + |
| 71 | + // use the altro decoder to decode the raw data, and extract the RCU trailer |
| 72 | + o2::emcal::AltroDecoder decoder(parser); |
| 73 | + std::cout << "Decoding" << std::endl; |
| 74 | + decoder.decode(); |
| 75 | + |
| 76 | + //std::cout << decoder.getRCUTrailer() << std::endl; |
| 77 | + std::cout << "Found number of channels: " << decoder.getChannels().size() << std::endl; |
| 78 | + |
| 79 | + // Loop over all the channels |
| 80 | + for (auto& chan : decoder.getChannels()) { |
| 81 | + std::cout << "processing next channel idx " << chan.getChannelIndex() << ", " << chan.getHardwareAddress() << std::endl; |
| 82 | + // define the conatiner for the fit results, and perform the raw fitting using the stadnard raw fitter |
| 83 | + //continue; |
| 84 | + std::cout << "Channel has " << chan.getBunches().size() << " bunches " << std::endl; |
| 85 | + try { |
| 86 | + o2::emcal::CaloFitResults fitResults = RawFitter.evaluate(chan.getBunches(), 0, 0); |
| 87 | + |
| 88 | + // print the fit output |
| 89 | + //std::cout << "The Time is : " << fitResults.getTime() << " And the Amplitude is : " << fitResults.getAmp() << std::endl; |
| 90 | + std::cout << "Fit done" << std::endl; |
| 91 | + } catch (o2::emcal::CaloRawFitter::RawFitterError_t& fiterror) { |
| 92 | + std::cerr << "Error processing raw fit: " << o2::emcal::CaloRawFitter::createErrorMessage(fiterror) << std::endl; |
| 93 | + for (auto bunch : chan.getBunches()) { |
| 94 | + std::cout << "Next bunch: " << bunch.getADC().size() << " entries" << std::endl; |
| 95 | + bool first = true; |
| 96 | + for (auto en : bunch.getADC()) { |
| 97 | + if (!first) { |
| 98 | + std::cout << ", "; |
| 99 | + } |
| 100 | + std::cout << en; |
| 101 | + first = false; |
| 102 | + } |
| 103 | + std::cout << std::endl; |
| 104 | + } |
| 105 | + std::cout << "Channel end" << std::endl; |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + reader.setNextTFToRead(++tfID); |
| 111 | + } |
| 112 | +} |
0 commit comments