CMS 3D CMS Logo

Functions
UtilityMacros.cc File Reference
#include <cmath>
#include "TH1D.h"
#include "TProfile2D.h"

Go to the source code of this file.

Functions

TH1D * projectProfile2DAlongX (TProfile2D *prof2d)
 
TH1D * projectProfile2DAlongY (TProfile2D *prof2d)
 

Function Documentation

◆ projectProfile2DAlongX()

TH1D* projectProfile2DAlongX ( TProfile2D *  prof2d)

Definition at line 5 of file UtilityMacros.cc.

References submitPVResolutionJobs::err, ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::endcap::ix(), ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::endcap::iy(), SiStripPI::mean, mergeVDriftHistosByStation::name, nevt, and mathSSE::sqrt().

5  {
6  TH1D* res = nullptr;
7 
8  if (prof2d) {
9  char name[200];
10  sprintf(name, "%s_proj", prof2d->GetName());
11  res = new TH1D(
12  name, prof2d->GetTitle(), prof2d->GetNbinsY(), prof2d->GetYaxis()->GetXmin(), prof2d->GetYaxis()->GetXmax());
13  res->SetDirectory(nullptr);
14  res->Sumw2();
15  for (int iy = 1; iy < prof2d->GetNbinsY() + 1; ++iy) {
16  double sum = 0.;
17  double sumsq = 0.;
18  double nevt = 0.;
19  for (int ix = 1; ix < prof2d->GetNbinsX() + 1; ++ix) {
20  const int ibin = prof2d->GetBin(ix, iy);
21  sum += prof2d->GetBinContent(ibin) * prof2d->GetBinEntries(ibin);
22  sumsq += prof2d->GetBinError(ibin) * prof2d->GetBinError(ibin) * prof2d->GetBinEntries(ibin) *
23  prof2d->GetBinEntries(ibin) +
24  prof2d->GetBinContent(ibin) * prof2d->GetBinContent(ibin) * prof2d->GetBinEntries(ibin);
25  nevt += prof2d->GetBinEntries(ibin);
26  }
27  double mean = nevt == 0 ? 0 : sum / nevt;
28  double meansq = nevt == 0 ? 0 : sumsq / nevt;
29  double err = meansq >= mean * mean ? sqrt(meansq - mean * mean) : 0;
30  err = nevt == 0 ? 0 : err / sqrt(nevt);
31  res->SetBinContent(iy, mean);
32  res->SetBinError(iy, err);
33  }
34  }
35 
36  return res;
37 }
Definition: Electron.h:6
T sqrt(T t)
Definition: SSEVec.h:23
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)

◆ projectProfile2DAlongY()

TH1D* projectProfile2DAlongY ( TProfile2D *  prof2d)

Definition at line 39 of file UtilityMacros.cc.

References submitPVResolutionJobs::err, ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::endcap::ix(), ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::endcap::iy(), SiStripPI::mean, mergeVDriftHistosByStation::name, nevt, and mathSSE::sqrt().

39  {
40  TH1D* res = nullptr;
41 
42  if (prof2d) {
43  char name[200];
44  sprintf(name, "%s_proj", prof2d->GetName());
45  res = new TH1D(
46  name, prof2d->GetTitle(), prof2d->GetNbinsX(), prof2d->GetXaxis()->GetXmin(), prof2d->GetXaxis()->GetXmax());
47  res->SetDirectory(nullptr);
48  res->Sumw2();
49  for (int ix = 1; ix < prof2d->GetNbinsX() + 1; ++ix) {
50  double sum = 0.;
51  double sumsq = 0.;
52  double nevt = 0.;
53  for (int iy = 1; iy < prof2d->GetNbinsY() + 1; ++iy) {
54  const int ibin = prof2d->GetBin(ix, iy);
55  sum += prof2d->GetBinContent(ibin) * prof2d->GetBinEntries(ibin);
56  sumsq += prof2d->GetBinError(ibin) * prof2d->GetBinError(ibin) * prof2d->GetBinEntries(ibin) *
57  prof2d->GetBinEntries(ibin) +
58  prof2d->GetBinContent(ibin) * prof2d->GetBinContent(ibin) * prof2d->GetBinEntries(ibin);
59  nevt += prof2d->GetBinEntries(ibin);
60  }
61  double mean = nevt == 0 ? 0 : sum / nevt;
62  double meansq = nevt == 0 ? 0 : sumsq / nevt;
63  double err = meansq >= mean * mean ? sqrt(meansq - mean * mean) : 0;
64  err = nevt == 0 ? 0 : err / sqrt(nevt);
65  res->SetBinContent(ix, mean);
66  res->SetBinError(ix, err);
67  }
68  }
69 
70  return res;
71 }
Definition: Electron.h:6
T sqrt(T t)
Definition: SSEVec.h:23
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)