27 void calcBins(
int binWidth,
int divisor,
long int start_time,
long int last_time,
long int current_time,
28 long int & binDiff,
long int &
diff) {
40 long int diff_current_start = current_time - start_time;
41 long int diff_last_start = last_time - start_time;
47 binDiff = diff_current_start/divisor/binWidth - diff_last_start/divisor/binWidth;
48 diff = (current_time - last_time)/divisor;
50 if(diff >= binWidth) {
51 while(diff >= binWidth) diff -= binWidth;
58 if(!bins || !h)
return;
59 if(h->GetXaxis()->IsVariableBinSize())
return;
66 if(!h->GetSumw2()) h->Sumw2();
67 int nBins = h->GetXaxis()->GetNbins();
76 int firstBin, lastBin, bound, increment;
87 bound = nBins - bins + 1;
94 int shift = increment * bins;
96 if( h->IsA() == TClass::GetClass(
"TProfile") ){
98 TProfile *
p =
static_cast<TProfile *
>(
h);
102 double nentries = p->GetEntries();
103 for(
int i = firstBin;
i != firstBin +
shift;
i += increment) nentries -= p->GetBinEntries(
i);
104 p->SetEntries(nentries);
106 TArrayD* sumw2 = p->GetSumw2();
108 for(
int i = firstBin;
i != bound;
i += increment){
110 p->SetBinContent(
i, p->GetBinContent(
i+shift ) * p->GetBinEntries(
i+shift ) );
111 p->SetBinEntries(
i, p->GetBinEntries(
i+shift ) );
112 sumw2->SetAt( sumw2->GetAt(
i+shift ),
i );
115 for(
int i = bound;
i != lastBin + increment;
i += increment){
116 p->SetBinContent(
i, 0 );
117 p->SetBinEntries(
i, 0 );
118 sumw2->SetAt( 0.,
i );
121 }
else if( h->InheritsFrom(
"TH2") ){
123 TH2 *h2 =
static_cast<TH2 *
>(
h);
124 int nBinsY = h2->GetYaxis()->GetNbins();
127 double nentries = h2->GetEntries();
128 for(
int i = firstBin;
i != firstBin +
shift;
i += increment)
129 for(
int j=0 ;
j<=nBinsY+1 ;
j++) nentries -= h2->GetBinContent(
i,
j);
131 h2->SetEntries(nentries);
133 for(
int i = firstBin;
i != bound;
i += increment)
134 for(
int j = 0;
j <= nBinsY + 1;
j++)
135 h2->SetBinContent(
i,
j, h2->GetBinContent(
i+shift,
j) );
137 for(
int i = bound;
i != lastBin + increment;
i += increment)
138 for(
int j = 0;
j <= nBinsY + 1;
j++)
139 h2->SetBinContent(
i,
j, 0 );
141 }
else if( h->InheritsFrom(
"TH1") ){
144 double nentries = h->GetEntries();
145 for(
int i = firstBin;
i != firstBin +
shift;
i += increment) nentries -= h->GetBinContent(
i);
147 h->SetEntries(nentries);
149 for(
int i = firstBin;
i != bound;
i += increment)
150 h->SetBinContent(
i, h->GetBinContent(
i+shift) );
152 for(
int i = bound;
i != lastBin + increment;
i += increment)
153 h->SetBinContent(
i, 0 );
174 TAxis *xax = h->GetXaxis();
175 if( h->GetXaxis()->IsVariableBinSize() )
return;
177 double xmax = xax->GetXmax();
178 double xmin = xax->GetXmin();
179 int nbins = xax->GetNbins();
182 xax->Set(nbins, xmin - shift, xmax - shift);
184 xax->Set(nbins, xmin + shift, xmax + shift);
196 int nbins = p->GetXaxis()->GetNbins();
200 y += p->GetBinContent(
i);
219 TString
name(cur->IsA()->GetName());
221 if(
name.Contains(
"TProfile")) {
224 else if(
name.Contains(
"TH2")) {
226 mean = ((TH2F*)cur)->GetEntries() - ((TH2F*)pre)->GetEntries();
231 mean = ((TH2F*)cur)->GetEntries();
235 float nxybins = ((TH2F*)cur)->GetNbinsX()*((TH2F*)cur)->GetNbinsY();
236 if(nxybins < 1.) nxybins = 1.;
240 else if(
name.Contains(
"TH1")) {
242 ((TH1F*)pre)->Sumw2();
243 ((TH1F*)pre)->Add((TH1F*)pre,(TH1F*)cur,-1,1);
244 mean = ((TH1F*)pre)->GetMean();
245 rms = ((TH1F*)pre)->GetRMS();
248 mean = ((TH1F*)cur)->GetMean();
249 rms = ((TH1F*)cur)->GetRMS();
264 ret = (TObject*) (me->
getRootObject()->Clone(title.c_str()));
void getAverageFromTProfile(TProfile *p, double &mean, double &rms)
void shiftAxis(TH1 *h, Directions d, double shift)
void shift2Left(TH1 *h, int bins)
void shift(TH1 *h, Directions d, int bins)
Ecal Monitor Utility functions.
TObject * getRootObject(void) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
TObject * cloneIt(MonitorElement *me, std::string histo)
void calcBins(int binWidth, int divisor, long int start_time, long int last_time, long int current_time, long int &binDiff, long int &diff)
void shift2Right(TH1 *h, int bins)
void getMeanRms(TObject *pre, TObject *cur, double &mean, double &rms)