|
| 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 | +#include <TSystem.h> |
| 12 | +#include <TTree.h> |
| 13 | +#include "Framework/Logger.h" |
| 14 | +#include "DataFormatsFT0/Digit.h" |
| 15 | +#include <TFile.h> |
| 16 | +#include <cstring> |
| 17 | + |
| 18 | +using namespace o2::ft0; |
| 19 | + |
| 20 | +int main(int argc, char* argv[]) |
| 21 | +{ |
| 22 | + const std::string genDigDile{"ft0digits.root"}; |
| 23 | + const std::string decDigDile{"o2digit_ft0.root"}; |
| 24 | + const std::string branchBC{"FT0DIGITSBC"}; |
| 25 | + const std::string branchCH{"FT0DIGITSCH"}; |
| 26 | + |
| 27 | + if (gSystem->AccessPathName(genDigDile.c_str())) { |
| 28 | + LOG(FATAL) << "Generated digits file " << genDigDile << " is absent"; |
| 29 | + } |
| 30 | + TFile flIn(genDigDile.c_str()); |
| 31 | + std::unique_ptr<TTree> tree((TTree*)flIn.Get("o2sim")); |
| 32 | + if (!flIn.IsOpen() || flIn.IsZombie() || !tree) { |
| 33 | + LOG(FATAL) << "Failed to get tree from generated digits file " << genDigDile; |
| 34 | + } |
| 35 | + std::vector<o2::ft0::Digit> digitsBC, *ft0BCDataPtr = &digitsBC; |
| 36 | + std::vector<o2::ft0::ChannelData> digitsCh, *ft0ChDataPtr = &digitsCh; |
| 37 | + tree->SetBranchAddress("FT0DIGITSBC", &ft0BCDataPtr); |
| 38 | + tree->SetBranchAddress("FT0DIGITSCH", &ft0ChDataPtr); |
| 39 | + |
| 40 | + if (gSystem->AccessPathName(decDigDile.c_str())) { |
| 41 | + LOG(FATAL) << "Decoded digits file " << genDigDile << " is absent"; |
| 42 | + } |
| 43 | + |
| 44 | + TFile flIn2(decDigDile.c_str()); |
| 45 | + std::unique_ptr<TTree> tree2((TTree*)flIn2.Get("o2sim")); |
| 46 | + if (!flIn2.IsOpen() || flIn2.IsZombie() || !tree2) { |
| 47 | + LOG(FATAL) << "Failed to get tree from decoded digits file " << genDigDile; |
| 48 | + } |
| 49 | + std::vector<o2::ft0::Digit> digitsBC2, *ft0BCDataPtr2 = &digitsBC2; |
| 50 | + std::vector<o2::ft0::ChannelData> digitsCh2, *ft0ChDataPtr2 = &digitsCh2; |
| 51 | + tree2->SetBranchAddress("FT0DIGITSBC", &ft0BCDataPtr2); |
| 52 | + tree2->SetBranchAddress("FT0DIGITSCH", &ft0ChDataPtr2); |
| 53 | + |
| 54 | + int nbc = 0, nbc2 = 0, nch = 0, nch2 = 0; |
| 55 | + for (int ient = 0; ient < tree->GetEntries(); ient++) { |
| 56 | + tree->GetEntry(ient); |
| 57 | + int nbcEntry = digitsBC.size(); |
| 58 | + nbc += nbcEntry; |
| 59 | + for (int ibc = 0; ibc < nbcEntry; ibc++) { |
| 60 | + auto& bcd = digitsBC[ibc]; |
| 61 | + int bc = bcd.getBC(); |
| 62 | + auto channels = bcd.getBunchChannelData(digitsCh); |
| 63 | + nch += channels.size(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + for (int ient = 0; ient < tree2->GetEntries(); ient++) { |
| 68 | + tree2->GetEntry(ient); |
| 69 | + int nbc2Entry = digitsBC2.size(); |
| 70 | + nbc2 += nbc2Entry; |
| 71 | + for (int ibc = 0; ibc < nbc2Entry; ibc++) { |
| 72 | + auto& bcd2 = digitsBC2[ibc]; |
| 73 | + int bc2 = bcd2.getBC(); |
| 74 | + auto channels2 = bcd2.getBunchChannelData(digitsCh2); |
| 75 | + nch2 += channels2.size(); |
| 76 | + } |
| 77 | + } |
| 78 | + LOG(INFO) << "FT0 simulated: " << nbc << " triggers with " << nch << " channels"; |
| 79 | + LOG(INFO) << "FT0 decoded : " << nbc2 << " triggers with " << nch2 << " channels"; |
| 80 | + if (nbc != nbc2 || nch != nch2) { |
| 81 | + LOG(FATAL) << "Mismatch between the number of encoded and decoded objects"; |
| 82 | + } |
| 83 | + |
| 84 | + return 0; |
| 85 | +} |
0 commit comments