DarkRate.C
00001 #include "TROOT.h"
00002 #include "TCanvas.h"
00003 #include "TFile.h"
00004 #include "TCut.h"
00005 #include "TTree.h"
00006 #include "TString.h"
00007 #include <algorithm>
00008 #include <string>
00009 #include <iomanip>
00010 #include <iostream>
00011
00012
00013
00014 int GetDarkHits(TTree* Events, double threshold, double trigtime=0)
00015 {
00016 TString cut = "channels.pulses.integral > ";
00017 cut += threshold;
00018 int hits = Events->Draw("channels.pulses.integral", cut,"goff");
00019 std::cout<<"Number of hits: "<<hits<<std::endl;
00020 if(trigtime > 0){
00021 std::cout<<"Dark Rate: "<<1.*hits / (trigtime * Events->GetEntries())
00022 <<" +/- "
00023 <<sqrt(hits) / (trigtime * Events->GetEntries())
00024 <<std::endl;
00025 }
00026 return hits;
00027 }
00028
00029 int ProcessDarkRateFile(const char* filename, double threshold,
00030 double trigtime=0)
00031 {
00032 static bool loaded = false;
00033 if(!loaded){
00034 gROOT->ProcessLine(".L lib/libDict.so");
00035 loaded=true;
00036 }
00037 TFile fin(filename);
00038 if(!fin.IsOpen() || fin.IsZombie()){
00039 std::cerr<<"Unable to open file "<<filename<<std::endl;
00040 return -1;
00041 }
00042 TTree* Events = (TTree*)(fin.Get("Events"));
00043 if(!Events){
00044 std::cerr<<"Unable to open Events tree in file "<<filename<<std::endl;
00045 return -2;
00046 }
00047 return GetDarkHits(Events, threshold, trigtime);
00048 }
00049