46 int nPadsx,
int nPadsy)
48 c.Print(fileName.c_str());
50 c.Divide(nPadsx, nPadsy);
53void CompareTask::pdfOutput()
56 TCanvas*
c =
autoCanvas(
"c",
"c", mHistosAtVertex[0], &nPadsx, &nPadsy);
57 TCanvas*
c2 =
autoCanvas(
"c2",
"c2", mHistosAtVertex[0], &nPadsx, &nPadsy);
58 c->Print(fmt::format(
"{}[", mOutputPdfFileName).c_str());
60 auto toPdf2 = [&](std::function<
void(
const std::array<std::vector<TH1*>, 2>&, TCanvas*)>
func) {
61 func(mHistosAtVertex,
c);
65 auto toPdf5 = [&](std::function<
void(
const std::array<std::vector<TH1*>, 5>&, TCanvas*)>
func) {
66 func(mComparisonsAtVertex,
c);
78 c->Print(mOutputPdfFileName.c_str());
82 c->Print(mOutputPdfFileName.c_str());
86 c->Print(mOutputPdfFileName.c_str());
91 c->Print(mOutputPdfFileName.c_str());
92 c2->Print(mOutputPdfFileName.c_str());
96 c->Print(mOutputPdfFileName.c_str());
101 c->Print(mOutputPdfFileName.c_str());
102 c2->Print(mOutputPdfFileName.c_str());
106 c->Print(mOutputPdfFileName.c_str());
110 c->Print(mOutputPdfFileName.c_str());
114 c->Print(fmt::format(
"{}]", mOutputPdfFileName).c_str());
119 auto outputFileName = ic.
options().
get<std::string>(
"outfile");
120 mOutputPdfFileName = ic.
options().
get<std::string>(
"pdf-outfile");
121 mPrintDiff = ic.
options().
get<
bool>(
"print-diff");
122 mPrintAll = ic.
options().
get<
bool>(
"print-all");
123 mApplyTrackSelection = ic.
options().
get<
bool>(
"apply-track-selection");
124 mPrecision = ic.
options().
get<
double>(
"precision");
127 mOutputRootFile = std::make_unique<TFile>(outputFileName.c_str(),
"RECREATE");
145 auto stop = [
this]() {
146 LOGP(warning,
"Number of differences in ROF-by-ROF comparison: {}", mNofDifferences);
148 if (!mOutputPdfFileName.empty()) {
151 mOutputRootFile->cd();
152 mOutputRootFile->WriteObject(&mHistosAtVertex,
"histosAtVertex");
153 mOutputRootFile->WriteObject(&mComparisonsAtVertex,
"comparisonsAtVertex");
154 mOutputRootFile->WriteObject(&mTrackResidualsAtFirstCluster,
"trackResidualsAtFirstCluster");
155 mOutputRootFile->WriteObject(&mClusterResiduals,
"clusterResiduals");
156 mOutputRootFile->Close();
164 std::list<ExtendedTrack> tracks;
165 constexpr double vx{0.0};
166 constexpr double vy{0.0};
167 constexpr double vz{0.0};
168 for (
const auto& mchTrack : mchTracks) {
169 tracks.emplace_back(mchTrack,
clusters, vx, vy, vz);
175 const std::list<ExtendedTrack>& tracks1,
176 const std::list<ExtendedTrack>& tracks2)
178 if (tracks1.size() > 0 || tracks2.size() > 0) {
179 LOGP(warning,
"{} tracks1: {} tracks2: {}", prefix, tracks1.size(), tracks2.size());
180 for (
const auto& t : tracks1) {
181 LOGP(warning,
"Track1 {}", t.asString());
183 for (
const auto& t : tracks2) {
184 LOGP(warning,
"Track2 {}", t.asString());
190 gsl::span<const TrackMCH> tfTracks,
191 gsl::span<const Cluster> tfClusters)
194 return convert(mchTracks, tfClusters);
200 LOGP(info,
"TF {}",
tf);
206 auto rofs1 = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs1");
207 auto itracks1 = pc.
inputs().
get<gsl::span<TrackMCH>>(
"tracks1");
208 auto iclusters1 = pc.
inputs().
get<gsl::span<Cluster>>(
"clusters1");
209 auto rofs2 = pc.
inputs().
get<gsl::span<ROFRecord>>(
"rofs2");
210 auto itracks2 = pc.
inputs().
get<gsl::span<TrackMCH>>(
"tracks2");
211 auto iclusters2 = pc.
inputs().
get<gsl::span<Cluster>>(
"clusters2");
213 bool areSameRofs = std::equal(rofs1.begin(), rofs1.end(),
214 rofs2.begin(), rofs2.end(),
216 return r1.getBCData() == r2.getBCData() && r1.getBCWidth() == r2.getBCWidth();
219 LOGP(warning,
"ROFs are different --> cannot perform ROF-by-ROF comparison");
222 auto nROFs = std::max(rofs1.size(), rofs2.size());
223 for (
auto i = 0;
i < nROFs; ++
i) {
225 std::list<ExtendedTrack> tracks1{};
226 if (
i < rofs1.size()) {
228 mNTracksAll[0] += tracks1.size();
229 if (mApplyTrackSelection) {
236 std::list<ExtendedTrack> tracks2{};
237 if (
i < rofs2.size()) {
239 mNTracksAll[1] += tracks2.size();
240 if (mApplyTrackSelection) {
252 mTrackResidualsAtFirstCluster,
253 mClusterResiduals[4]);
258 LOG(warning) <<
"--> " << nDiff <<
" differences found in ROF " << rofs1[
i];
260 mNofDifferences += nDiff;
269void CompareTask::printStat()
274 auto print = [](TString selection,
int n1,
int n2) {
276 printf(
"%s | %8d | %8d | %7s ± %4s %%\n", selection.Data(), n1, n2,
"nan",
"nan");
278 double eff = double(n2) / n1;
279 double diff = 100. * (eff - 1.);
280 double err = 100. * std::max(1. / n1, std::sqrt(eff * std::abs(1. - eff) / n1));
281 printf(
"%s | %8d | %8d | %7.2f ± %4.2f %%\n", selection.Data(), n1, n2, diff, err);
286 printf(
"-------------------------------------------------------\n");
287 printf(
"selection | file 1 | file 2 | diff\n");
288 printf(
"-------------------------------------------------------\n");
290 print(
"all ", mNTracksAll[0], mNTracksAll[1]);
292 print(
"matched ", mNTracksMatch[0], mNTracksMatch[1]);
294 print(
"selected ", mHistosAtVertex[0][0]->GetEntries(), mHistosAtVertex[1][0]->GetEntries());
296 double pTRange[6] = {0., 0.5, 1., 2., 4., 1000.};
297 for (
int i = 0;
i < 5; ++
i) {
298 TString selection = (
i == 0) ? TString::Format(
"pT < %.1f GeV/c", pTRange[1])
299 : ((
i == 4) ? TString::Format(
"pT > %.1f ", pTRange[4])
300 : TString::Format(
"%.1f < pT < %.1f", pTRange[
i], pTRange[
i + 1]));
301 int n1 = mHistosAtVertex[0][0]->Integral(mHistosAtVertex[0][0]->GetXaxis()->FindBin(pTRange[
i] + 0.01),
302 mHistosAtVertex[0][0]->GetXaxis()->FindBin(pTRange[
i + 1] - 0.01));
303 int n2 = mHistosAtVertex[1][0]->Integral(mHistosAtVertex[1][0]->GetXaxis()->FindBin(pTRange[
i] + 0.01),
304 mHistosAtVertex[1][0]->GetXaxis()->FindBin(pTRange[
i + 1] - 0.01));
305 print(selection, n1, n2);
308 double pRange[6] = {0., 5., 10., 20., 40., 10000.};
309 for (
int i = 0;
i < 5; ++
i) {
310 TString selection = (
i == 0) ? TString::Format(
"p < %02.0f GeV/c ", pRange[1])
311 : ((
i == 4) ? TString::Format(
"p > %02.0f ", pRange[4])
312 : TString::Format(
"%02.0f < p < %02.0f ", pRange[
i], pRange[
i + 1]));
313 int n1 = mHistosAtVertex[0][4]->Integral(mHistosAtVertex[0][4]->GetXaxis()->FindBin(pRange[
i] + 0.01),
314 mHistosAtVertex[0][4]->GetXaxis()->FindBin(pRange[
i + 1] - 0.01));
315 int n2 = mHistosAtVertex[1][4]->Integral(mHistosAtVertex[1][4]->GetXaxis()->FindBin(pRange[
i] + 0.01),
316 mHistosAtVertex[1][4]->GetXaxis()->FindBin(pRange[
i + 1] - 0.01));
317 print(selection, n1, n2);
320 printf(
"-------------------------------------------------------\n");
bool const GPUTPCGMMerger::trackCluster const clcomparestruct * c2
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
T get(const char *key) const
ServiceRegistryRef services()
ConfigParamRegistry const & options()
InputRecord & inputs()
The inputs associated with this processing context.
int getNEntries() const
get the number of associated objects
int getFirstIdx() const
get the index of the first associated object
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
std::list< ExtendedTrack > convert(gsl::span< const TrackMCH > mchTracks, gsl::span< const Cluster > clusters)
std::list< ExtendedTrack > getExtendedTracks(const ROFRecord &rof, gsl::span< const TrackMCH > tfTracks, gsl::span< const Cluster > tfClusters)
void run(o2::framework::ProcessingContext &pc)
CompareTask(std::shared_ptr< o2::base::GRPGeomRequest > req)
void dump(std::string prefix, const std::list< ExtendedTrack > &tracks1, const std::list< ExtendedTrack > &tracks2)
void init(o2::framework::InitContext &ic)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining PrimaryVertex explicitly as messageable.
void drawPlainHistosAtVertex(const std::array< std::vector< TH1 * >, 2 > &histos, TCanvas *c=nullptr)
void createHistosForTrackResiduals(std::vector< TH1 * > &histos)
void fillHistosAtVertex(const std::list< ExtendedTrack > &tracks, const std::vector< TH1 * > &histos)
void selectTracks(std::list< ExtendedTrack > &tracks)
void drawClusterTrackResidualsSigma(const std::vector< TH1 * > &histos1, const std::vector< TH1 * > &histos2, const char *extension, TCanvas *c1=nullptr, TCanvas *c2=nullptr)
void drawClusterClusterResiduals(const std::vector< TH1 * > &histos, const char *extension, TCanvas *c=nullptr)
void drawClusterTrackResidualsRatio(const std::vector< TH1 * > &histos1, const std::vector< TH1 * > &histos2, const char *extension, TCanvas *c=nullptr)
int compareEvents(std::list< ExtendedTrack > &tracks1, std::list< ExtendedTrack > &tracks2, double precision, bool printDiff, bool printAll, std::vector< TH1 * > &trackResidualsAtFirstCluster, std::vector< TH1 * > &clusterClusterResiduals)
void drawRatioHistosAtVertex(const std::array< std::vector< TH1 * >, 2 > &histos, TCanvas *c=nullptr)
void fillClusterTrackResiduals(const std::list< ExtendedTrack > &tracks, std::vector< TH1 * > &histos, bool matched)
void createHistosAtVertex(std::vector< TH1 * > &histos, const char *extension)
void drawDiffHistosAtVertex(const std::array< std::vector< TH1 * >, 2 > &histos, TCanvas *c=nullptr)
void fillComparisonsAtVertex(std::list< ExtendedTrack > &tracks1, std::list< ExtendedTrack > &tracks2, const std::array< std::vector< TH1 * >, 5 > &histos)
void drawTrackResiduals(std::vector< TH1 * > &histos, TCanvas *c=nullptr)
TCanvas * autoCanvas(const char *title, const char *name, const std::vector< TH1 * > &histos, int *nPadsx=nullptr, int *nPadsy=nullptr)
void createHistosForClusterResiduals(std::vector< TH1 * > &histos, const char *extension, double range)
void outputToPdfClearDivide(const std::string fileName, TCanvas &c, int nPadsx, int nPadsy)
void drawClusterTrackResiduals(const std::vector< TH1 * > &histos1, const std::vector< TH1 * > &histos2, const char *extension, TCanvas *c=nullptr)
void drawComparisonsAtVertex(const std::array< std::vector< TH1 * >, 5 > histos, TCanvas *c=nullptr)
std::unique_ptr< GPUReconstructionTimeframe > tf
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters