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

TH1D* projectProfile2DAlongX ( TProfile2D *  prof2d)

Definition at line 5 of file UtilityMacros.cc.

References SiStripPI::mean, dataset::name, nevt, and mathSSE::sqrt().

5  {
6 
7  TH1D* res=nullptr;
8 
9  if(prof2d) {
10  char name[200];
11  sprintf(name,"%s_proj",prof2d->GetName());
12  res = new TH1D(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)*prof2d->GetBinEntries(ibin)+
23  prof2d->GetBinContent(ibin)*prof2d->GetBinContent(ibin)*prof2d->GetBinEntries(ibin);
24  nevt += prof2d->GetBinEntries(ibin);
25  }
26  double mean = nevt==0 ? 0: sum/nevt;
27  double meansq = nevt==0 ? 0: sumsq/nevt;
28  double err = meansq >= mean*mean ? sqrt(meansq-mean*mean) : 0;
29  err = nevt==0 ? 0 : err/sqrt(nevt);
30  res->SetBinContent(iy,mean);
31  res->SetBinError(iy,err);
32  }
33  }
34 
35  return res;
36 }
Definition: Electron.h:6
T sqrt(T t)
Definition: SSEVec.h:18
TH1D* projectProfile2DAlongY ( TProfile2D *  prof2d)

Definition at line 38 of file UtilityMacros.cc.

References SiStripPI::mean, dataset::name, nevt, and mathSSE::sqrt().

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