ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/eff2.C
(Generate patch)

Comparing UserCode/FGolf/Tools/eff2.C (file contents):
Revision 1.1 by fgolf, Mon Nov 8 03:15:09 2010 UTC vs.
Revision 1.2 by fgolf, Sun May 22 21:51:56 2011 UTC

# Line 16 | Line 16
16   // Method by pointer
17   TH2F* eff2(TH2F* h1, TH2F* h2, const char* name) {
18  
19 <  // first, verify that all histograms have same binning
20 <  // nx is the number of visible bins
21 <  // nxtot = nx+2 includes underflow and overflow
22 <  Int_t nx = h1->GetNbinsX();
23 <  if (h2->GetNbinsX() != nx) {
24 <    std::cout << "Histograms must have same number of bins" << std::endl;
25 <    return 0;
26 <  }
27 <
28 <  // get the new histogram
29 <  TH2F* temp = (TH2F*) h1->Clone(name);
30 <  temp->SetTitle(name);
31 <  temp->Reset();
32 <  temp->Sumw2();
19 >    // first, verify that all histograms have same binning
20 >    // nx is the number of visible bins
21 >    // nxtot = nx+2 includes underflow and overflow
22 >    Int_t nx = h1->GetNbinsX();
23 >    if (h2->GetNbinsX() != nx) {
24 >        std::cout << "Histograms must have same number of bins" << std::endl;
25 >        return 0;
26 >    }
27 >
28 >    // get the new histogram
29 >    TH2F* temp = (TH2F*) h1->Clone(name);
30 >    temp->SetTitle(name);
31 >    temp->Reset();
32 >    temp->Sumw2();
33  
34 <  // Do the calculation
35 <  temp->Divide(h2, h1, 1., 1., "B");
34 >    // Do the calculation
35 >    temp->Divide(h2, h1, 1., 1., "B");
36  
37 <  // Done
38 <  return temp;
37 >    // Done
38 >    return temp;
39   }
40  
41  
42   // Method by name
43   TH2F* eff2(const char* name1, const char* name2, const char* name) {
44  
45 <  // Get a list of object and their iterator
46 <  TList* list = gDirectory->GetList() ;
47 <  TIterator* iter = list->MakeIterator();
48 <
49 <  // Loop over objects, set the pointers
50 <  TObject* obj;
51 <  TH2F* h1 = 0;
52 <  TH2F* h2 = 0;
53 <  TString str1 = Form("%s", name1);
54 <  TString str2 = Form("%s", name2);
55 <  while (obj = iter->Next()) {
56 <    TString objName = obj->GetName();
57 <    if (objName == str1) h1 = (TH2F*) obj;
58 <    if (objName == str2) h2 = (TH2F*) obj;
59 <  }
60 <
61 <  // quit if not found
62 <  if (h1 == 0) {
63 <    std::cout << "Histogram " << name1 << " not found" << std::endl;
64 <    return 0;
65 <  }
66 <  if (h2 == 0) {
67 <    std::cout << "Histogram " << name2 << " not found" << std::endl;
68 <    return 0;
69 <  }
70 <
71 <  // Call the method by pointer
72 <  TH2F* temp = eff2(h1, h2, name);
73 <  return temp;
45 >    // Get a list of object and their iterator
46 >    TList* list = gDirectory->GetList() ;
47 >    TIterator* iter = list->MakeIterator();
48 >
49 >    // Loop over objects, set the pointers
50 >    TObject* obj;
51 >    TH2F* h1 = 0;
52 >    TH2F* h2 = 0;
53 >    TString str1 = Form("%s", name1);
54 >    TString str2 = Form("%s", name2);
55 >    while ((obj = iter->Next())) {
56 >        TString objName = obj->GetName();
57 >        if (objName == str1) h1 = (TH2F*) obj;
58 >        if (objName == str2) h2 = (TH2F*) obj;
59 >    }
60 >
61 >    // quit if not found
62 >    if (h1 == 0) {
63 >        std::cout << "Histogram " << name1 << " not found" << std::endl;
64 >        return 0;
65 >    }
66 >    if (h2 == 0) {
67 >        std::cout << "Histogram " << name2 << " not found" << std::endl;
68 >        return 0;
69 >    }
70 >
71 >    // Call the method by pointer
72 >    TH2F* temp = eff2(h1, h2, name);
73 >    return temp;
74   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines