AlcapDAQ  1
xraycount.c
Go to the documentation of this file.
1 #include "TString.h"
2 #include "TFile.h"
3 #include "TH1D.h"
4 #include "TH2F.h"
5 #include "TSpectrum.h"
6 #include "TLine.h"
7 #include "TBox.h"
8 
9 #include <vector>
10 
11 double xraycount(int runlow, int runhigh, bool draw = false) {
12 
13  // What we'll be using
14  char fname[256];
15  int nMuons = 0;
16  double tVals[] = { -500., 500. };
17  double aVals[] = { 2820., 2860. };
18  TH1D* pyGeAmp = NULL;
19 
20  // Collect all the histograms of Ge-S heights
21  // (pile-up protected and within 500ns of a muon hit on either side)
22  for (int r = runlow; r <= runhigh; ++r) {
23  sprintf(fname, "/net/abner/data/RunPSI2013/hist/his%05d.root", r);
24  TFile fGe(fname, "READ");
25  TH2F* hGeTDiffAmp = (TH2F*)fGe.Get("hMuSC_Ge-S_AmplitudeVsTdiff_PP");
26  TH1D* hMuSCCount = (TH1D*)fGe.Get("muSC_count_raw");
27  nMuons += hMuSCCount->GetBinContent(2);
28  static int tBinLow = hGeTDiffAmp->GetXaxis()->FindBin(tVals[0]);
29  static int tBinHigh = hGeTDiffAmp->GetXaxis()->FindBin(tVals[1]);
30  if (pyGeAmp == NULL) {
31  pyGeAmp = (TH1D*)hGeTDiffAmp->ProjectionY("_py",tBinLow,tBinHigh)->Clone("hGeHeights");
32  pyGeAmp->SetDirectory(0);
33  } else {
34  TH1D* tmp = hGeTDiffAmp->ProjectionY("_py",tBinLow,tBinHigh);
35  pyGeAmp->Add(tmp);
36  }
37  fGe.Close();
38  }
39 
40  TSpectrum s;
41  TH1* bgGe = s.Background(pyGeAmp);
42 
43  int aBinLow = pyGeAmp->GetXaxis()->FindBin(aVals[0]);
44  int aBinHigh = pyGeAmp->GetXaxis()->FindBin(aVals[1]);
45  double nStops = pyGeAmp->Integral(aBinLow, aBinHigh);
46  double rate = nStops/(double)nMuons;
47  double bg = bgGe->Integral(aBinLow, aBinHigh);
48  double bgsrate = (nStops - bg)/(double)nMuons;
49  printf("Saw %d stops seen in Ge (with %d background) and %d muons in muSc\n", (int)nStops, (int)bg, nMuons);
50  printf("Rate: %g xrays/muons (%g background subtracted)\n", rate, bgsrate);
51 
52  if (draw) {
53  double geMax = pyGeAmp->GetMaximum();
54  TLine l1(aVals[0], 0., aVals[0], geMax);
55  TLine l2(aVals[1], 0., aVals[1], geMax);
56  TBox b(aVals[0], 0., aVals[1], geMax);
57 
58  pyGeAmp->GetYaxis()->SetRangeUser(0.,geMax);
59  pyGeAmp->SetStats(0);
60  bgGe->SetStats(0);
61  b.SetFillStyle(3004);
62  b.SetFillColor(kBlue);
63 
64  pyGeAmp->DrawClone();
65  bgGe->DrawClone("SAME");
66  l1.DrawClone("SAME");
67  l2.DrawClone("SAME");
68  b.DrawClone("SAME");
69  }
70 
71 
72  return rate;
73 }