Project
Loading...
Searching...
No Matches
test-raw2digit.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <TSystem.h>
13#include <TTree.h>
15#include "Framework/Logger.h"
17#include <TFile.h>
18#include <cstring>
19
20using namespace o2::ft0;
21int main()
22{
23 struct EventFT0_t {
24 o2::ft0::Digit mDigit;
25 std::vector<o2::ft0::ChannelData> mVecChannelData;
26 bool operator==(const EventFT0_t& other) const
27 {
28 return mDigit == other.mDigit && mVecChannelData == other.mVecChannelData;
29 }
30 void print() const
31 {
32 mDigit.printLog();
33 for (const auto& entry : mVecChannelData) {
34 entry.printLog();
35 }
36 }
37 };
38 std::vector<EventFT0_t> vecTotalEvents, vecTotalEvents2;
39 gSystem->Exec("$O2_ROOT/bin/o2-sim -n 10 -m FT0 -g pythia8pp");
40 gSystem->Exec("$O2_ROOT/bin/o2-sim-digitizer-workflow -b");
41 TFile flIn("ft0digits.root");
42 std::unique_ptr<TTree> treeInput((TTree*)flIn.Get("o2sim"));
43 std::vector<Digit> vecDigits;
44 std::vector<Digit>* ptrVecDigits = &vecDigits;
45 std::vector<ChannelData> vecChannelData;
46 std::vector<ChannelData>* ptrVecChannelData = &vecChannelData;
47 treeInput->SetBranchAddress(Digit::sDigitBranchName, &ptrVecDigits);
48 treeInput->SetBranchAddress(ChannelData::sDigitBranchName, &ptrVecChannelData);
49 std::cout << "Tree nEntries:" << treeInput->GetEntries() << std::endl;
50 for (int iEvent = 0; iEvent < treeInput->GetEntries(); iEvent++) { //Iterating TFs in tree
51 treeInput->GetEntry(iEvent);
52 for (const auto& digit : (*ptrVecDigits)) { //Iterating over all digits in given TF
53 auto itBegin = ptrVecChannelData->begin();
54 std::advance(itBegin, digit.ref.getFirstEntry());
55 auto itEnd = ptrVecChannelData->begin();
56 std::advance(itEnd, digit.ref.getFirstEntry() + digit.ref.getEntries());
57 //Event within given TF
58 auto eventFT0 = EventFT0_t{digit, std::vector<ChannelData>{itBegin, itEnd}};
59 vecTotalEvents.push_back(eventFT0);
60 }
61 }
62 std::cout << "\n===================================\n";
63 for (auto const& entry : vecTotalEvents) {
64 entry.print();
65 }
66 std::cout << "\n===================================\n";
67
68 std::cout << "\nTOTAL EVENTS: " << vecTotalEvents.size() << std::endl;
69 std::cout << "Simulation completed!" << std::endl;
70 gSystem->Exec("$O2_ROOT/bin/o2-ft0-digi2raw --file-for link --configKeyValues \"HBFUtils.nHBFPerTF=128;HBFUtils.orbitFirst=0\"");
71 gSystem->Exec("$O2_ROOT/bin/o2-raw-file-reader-workflow -b --input-conf FT0raw.cfg --configKeyValues \"HBFUtils.nHBFPerTF=128;HBFUtils.orbitFirst=0\"|$O2_ROOT/bin/o2-ft0-flp-dpl-workflow -b");
72 TFile flIn2("o2_ft0digits.root");
73 std::unique_ptr<TTree> treeInput2((TTree*)flIn2.Get("o2sim"));
74 std::cout << "Reconstruction completed!" << std::endl;
75
76 treeInput2->SetBranchAddress(Digit::sDigitBranchName, &ptrVecDigits);
77 treeInput2->SetBranchAddress(ChannelData::sDigitBranchName, &ptrVecChannelData);
78 std::cout << "Tree nEntries: " << treeInput2->GetEntries() << std::endl;
79 for (int iEvent = 0; iEvent < treeInput2->GetEntries(); iEvent++) { //Iterating TFs in tree
80 treeInput2->GetEntry(iEvent);
81 for (const auto& digit : (*ptrVecDigits)) { //Iterating over all digits in given TF
82 auto itBegin = ptrVecChannelData->begin();
83 std::advance(itBegin, digit.ref.getFirstEntry());
84 auto itEnd = ptrVecChannelData->begin();
85 std::advance(itEnd, digit.ref.getFirstEntry() + digit.ref.getEntries());
86 //Event within given TF
87 auto eventFT0 = EventFT0_t{digit, std::vector<ChannelData>{itBegin, itEnd}};
88 vecTotalEvents2.push_back(eventFT0);
89 }
90 }
91 std::cout << "\n===================================\n";
92 for (auto const& entry : vecTotalEvents2) {
93 entry.print();
94 }
95 std::cout << "\n===================================\n";
96 std::cout << "\nTOTAL EVENTS: " << vecTotalEvents2.size() << std::endl;
97 if (vecTotalEvents == vecTotalEvents2) {
98 std::cout << "\n TEST IS OK!\n";
99 } else {
100 std::cout << "\nDIFFERENCE BETWEEN SRC AND DEST\n";
101 std::cout << "\n===============================\n";
102 for (int iEntry = 0; iEntry < std::max(vecTotalEvents.size(), vecTotalEvents2.size()); iEntry++) {
103 if (iEntry < vecTotalEvents.size() && iEntry < vecTotalEvents2.size()) {
104 if (vecTotalEvents[iEntry] == vecTotalEvents2[iEntry]) {
105 continue;
106 }
107 }
108 std::cout << "\nEntryID: " << iEntry;
109 std::cout << "\n------------------------------SOURCE------------------------------\n";
110 if (iEntry < vecTotalEvents.size()) {
111 vecTotalEvents[iEntry].print();
112 } else {
113 std::cout << "\nEMPTY!\n";
114 }
115 std::cout << "\n------------------------------DESTINATION------------------------------\n";
116 if (iEntry < vecTotalEvents2.size()) {
117 vecTotalEvents2[iEntry].print();
118 } else {
119 std::cout << "\nEMPTY!\n";
120 }
121 }
122 std::cout << "\nERROR!\n";
123 }
124 return 0;
125}
void print() const
int main()
Definition of the Names Generator class.
GLuint entry
Definition glcorearb.h:5735
static constexpr char sDigitBranchName[]
Definition ChannelData.h:28
void printLog() const
Definition Digit.cxx:38
static constexpr char sDigitBranchName[]
Definition Digit.h:60
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
VectorOfTObjectPtrs other
TFile flIn("test_ctf_cpv.root")