GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Area1.C
Go to the documentation of this file.
1 
3 void Area1()
4 {
5  const Int_t MAXMARKERS = 100 ;
6  Int_t i, nbmarkers; Stat_t x[MAXMARKERS], areas[MAXMARKERS]; Int_t ind[MAXMARKERS];
7 
8  // Area1 is an action on pad
9  if ( TVirtualPad::Pad() == NULL ) return;
10 
11  // look for an histogram and markers in the current pad
12  TH1 *hist;
13  TIter next(gPad->GetListOfPrimitives());
14 
15  hist = NULL; nbmarkers = 0;
16  while ( (obj = next()) ) {
17  if ( obj->InheritsFrom("TMarker") ) {
18  x[nbmarkers++] = ((TMarker*)obj)->GetX();
19  }
20  if ( obj->InheritsFrom("TH1") ) { hist = (TH1 *)obj; }
21  }
22  if ( hist == NULL || nbmarkers < 2 ) {
23  printf("There is no histograms or enough clicks in the current pad to realise an integration \n"); return; }
24 
25  TMath::Sort(nbmarkers,x,ind,false); // in case markers have been added without order
26 
27  // compute the area between two consecutives markers
28  Double_t integral = 0.0; Int_t first_bin, last_bin; Stat_t first_bin_c, last_bin_c;
29 
30  for ( i = 0; i < nbmarkers - 1; i++ ) {
31 
32  first_bin = hist->FindBin( x[ind[i]] ); last_bin = hist->FindBin( x[ind[i+1]] );
33  Double_t sum = 0.0;
34  for (Int_t bin = first_bin; bin < last_bin; bin++ ) {
35  sum += hist->GetBinWidth(bin)*hist->GetBinContent(bin);
36  // meanx += hist->GetBinCenter(i)*hist->GetBinContent(i);
37  }
38  areas[i] = sum; integral += sum;
39  }
40 
41  printf("\n");
42  printf("******************* AREA1 RESULTS ******************* \n");
43  for ( i = 0; i < nbmarkers - 1; i++ ) { // now write results on the standardoutput
44  first_bin = hist->FindBin( x[ind[i]] ); last_bin = hist->FindBin( x[ind[i+1]] );
45  if ( integral == 0.0 ) {
46  printf(" Integral %d from %.1f (%d) to %1.f (%d): %1.f \n",i,x[ind[i]],first_bin,x[ind[i+1]],last_bin,areas[i]);
47  }
48  else {
49  printf(" Integral %d from %.1f (%d) to %1.f (%d): %1.f (%.1f \%) \n",i,x[ind[i]],first_bin,x[ind[i+1]],last_bin,areas[i],100.0*areas[i]/integral);
50  }
51  }
52  printf("\n");
53  printf(" Total from %.1f (%d) to %1.f (%d): %1.f \n",x[ind[0]],first_bin,x[ind[nbmarkers-1]],last_bin,integral);
54  printf("***************************************************** \n");
55 
56 }
57 
58 
printf("******************************************************************** \n")
void Area1()
Function to integrate the areas between markers.
Definition: Area1.C:3