Campaign4Example.C
00001 #include "TFile.h"
00002 #include "TChain.h"
00003 #include "TH1F.h"
00004 #include "TH2F.h"
00005 #include <iostream>
00006 #include <fstream>
00007 #include "math.h"
00008 #include <sstream>
00009 #include <string>
00010 #include <vector>
00011 #include <algorithm>
00012 #include "../include/Campaign4Lib.hh"
00013 #include "../include/DBLib.hh"
00014 #include "EventData.hh"
00015
00016 Bool_t USE_DB = kFALSE;
00017
00018 void Campaign4Example()
00019 {
00020 std::ostringstream os;
00021 std::string path = "../../data/ds10/data/test_processing/Run";
00022 std::vector<int> run_id_list;
00023 run_id_list.push_back(3007);
00024 run_id_list.push_back(3008);
00025
00026 TChain *chain = new TChain("Events");
00027
00028 if (! USE_DB)
00029 {
00030 std::cout<<"WARNING: Database access disabled ! Make sure to check run list manually"<<std::endl;
00031 }
00032
00033 for(vector<int>::const_iterator it = run_id_list.begin(); it != run_id_list.end(); it++)
00034 {
00035 if (USE_DB)
00036 {
00037 if ( ! DB_does_run_exist("rundb", "daqruns", *it))
00038 {
00039 std::cout<<"Run "<<(*it)<<" does not exist in the database"<<std::endl;
00040 continue;
00041 }
00042
00043 if(DB_get_string("rundb", "daqruns", *it, "comment").find("HARDWARE_ISSUE") != string::npos)
00044 {
00045 std::cout << "Run" << *it << " has HARDWARE ISSUES. Skipping ..." <<std::endl;
00046 continue;
00047 }
00048
00049 if(DB_get_string("rundb", "daqruns", *it, "type").find("laser") == string::npos
00050 && DB_get_string("rundb", "daqruns", *it, "type").find("*junk") == string::npos
00051 && DB_get_string("rundb", "daqruns", *it, "type").find("darkbox") == string::npos
00052 && DB_get_string("rundb", "daqruns", *it, "type").find("other") == string::npos)
00053
00054 {
00055 os.str("");
00056 os << path << setw(6) << setfill('0') << *it << ".root";
00057 chain->Add(os.str().c_str());
00058 }
00059 }
00060 else
00061 {
00062 os.str("");
00063 os << path << setw(6) << setfill('0') << *it << ".root";
00064 chain->Add(os.str().c_str());
00065 }
00066 }
00067
00068
00069 EventData* event = NULL;
00070 chain->SetBranchAddress("event", &event);
00071 int n_events = chain->GetEntries();
00072
00073
00074 TFile* f = new TFile ("Run4example.root", "RECREATE");
00075 TH1F* s1_hist = new TH1F("s1_hist", "S1 Spectrum", 100, 0, 2000);
00076 TH2F* s2s1_f90_hist = new TH2F("s2s1_f90_hist", "Log(S2/S1) vs F90", 100, 0, 1, 100, -3, 3.2);
00077
00078
00079 for(int n = 0; n < n_events; n = n + 1)
00080 {
00081
00082 if ( n % 10000 == 0)
00083 std::cout<<"Processing Event: "<<n<<"/"<<n_events<<std::endl;
00084
00085 chain->GetEntry(n);
00086
00087
00088 Int_t s1_pulse_number;
00089 std::vector<Int_t> s2_pulse_number;
00090 s1s2_Identifier(event, s1_pulse_number, s2_pulse_number);
00091
00092
00093 if (s1_pulse_number == -1)
00094 continue;
00095
00096 Int_t s2_multiplicity = s2_pulse_number.size();
00097 if (s2_multiplicity != 1)
00098 continue;
00099
00100
00101 Double_t s1_fixed = -1;
00102 if (event->sum_of_int[s1_pulse_number].fixed_npe1_valid)
00103 s1_fixed = event->sum_of_int[s1_pulse_number].fixed_npe1;
00104
00105
00106 Double_t s2_fixed = -1;
00107 if (event->sum_of_int[s2_pulse_number[0]].fixed_npe2_valid)
00108 s2_fixed = event->sum_of_int[s2_pulse_number[0]].fixed_npe2;
00109
00110
00111
00112 Double_t t_drift = -1;
00113 if (s2_multiplicity > 0)
00114 t_drift = drift_time_eval (event, s1_pulse_number, s2_pulse_number[0]);
00115
00116
00117 if ( start_time(event)
00118 && more_one_pulses(event)
00119 && nosat(event)
00120 && nodesync(event)
00121 && s1_fixed > 4.
00122 && s1_fixed < 600.
00123 && s2_multiplicity == 1
00124 && s2_fixed > 10.
00125 && t_drift > 10.
00126 && t_drift < 85.
00127 && ! late_peak (event, s1_pulse_number))
00128 {
00129 s1_hist->Fill(s1_fixed);
00130 s2s1_f90_hist->Fill(event->sum_of_int[s1_pulse_number].f90, TMath::Log10(s2_fixed/s1_fixed));
00131 }
00132 }
00133
00134 s1_hist->Write();
00135 s2s1_f90_hist->Write();
00136 f->Close();
00137 }