Campaign4Lib.hh
00001 #ifndef RUN4LIB_H
00002 #define RUN4LIB_H
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <vector>
00007 #include "EventData.hh"
00008
00009
00010
00011 bool nodesync (EventData* event)
00012 {
00013 return (event->status == 0);
00014 }
00015 bool nosat (EventData* event)
00016 {
00017 return (event->saturated == 0);
00018 }
00019 bool baseline (EventData* event)
00020 {
00021 return (bool)(event->GetChannelByID(-2)->baseline.found_baseline);
00022 }
00023 bool start_time (EventData* event)
00024 {
00025 return (bool)(event->GetChannelByID(-2)->pulses[0].start_time <= 0. && event->GetChannelByID(-2)->pulses[0].start_time >= -0.13);
00026 }
00027
00028 bool late_peak (EventData* event, int n_pulse)
00029 {
00030 return (bool)(event->GetChannelByID(-2)->pulses[n_pulse].peak_time - event->GetChannelByID(-2)->pulses[n_pulse].start_time > 0.2);
00031 }
00032
00033 bool more_one_pulses (EventData* event)
00034 {
00035 return (bool)(event->GetChannelByID(-2)->npulses > 1);
00036 }
00037
00038 bool s1s2_Identifier (EventData* event, Int_t& s1_pulse_number, std::vector<Int_t>& s2_pulse_number)
00039 {
00040 Int_t npulses = event->GetChannelByID(-2)->npulses;
00041 s1_pulse_number = -1;
00042 s2_pulse_number.clear();
00043
00044 Double_t max_t_drift = 105.;
00045
00046 switch (npulses)
00047 {
00048
00049 case 0:
00050 s1_pulse_number = -1;
00051 break;
00052
00053 case 1:
00054 s1_pulse_number = 0;
00055 break;
00056
00057 case 2:
00058 if((event->GetChannelByID(-2)->pulses[1].end_time - event->GetChannelByID(-2)->pulses[1].start_time) < 6.)
00059
00060 {
00061 s1_pulse_number = 0;
00062 }
00063 else
00064 {
00065 s1_pulse_number = 0;
00066 s2_pulse_number.push_back(1);
00067 }
00068 break;
00069
00070 case 3:
00071 s1_pulse_number = 0;
00072
00073 if( (event->sum_of_int[1].npe/event->sum_of_int[2].npe) < 0.001
00074 && ((event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift) )
00075 {
00076
00077
00078 s2_pulse_number.push_back(2);
00079 }
00080 else if( (event->sum_of_int[1].npe/event->sum_of_int[2].npe) > 0.001
00081 && ((event->GetChannelByID(-2)->pulses[1].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift)
00082 && ((event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) > max_t_drift))
00083 {
00084
00085 s2_pulse_number.push_back(1);
00086 }
00087 else if( (event->GetChannelByID(-2)->pulses[1].start_time - event->GetChannelByID(-2)->pulses[0].start_time) > max_t_drift )
00088 {
00089
00090 }
00091 else if( (event->sum_of_int[1].npe/event->sum_of_int[2].npe) > 0.001
00092 && (event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift )
00093 {
00094
00095 s2_pulse_number.push_back(1);
00096 s2_pulse_number.push_back(2);
00097 }
00098
00099 break;
00100
00101 case 4:
00102 s1_pulse_number = 0;
00103
00104
00105 if( (event->sum_of_int[1].npe/event->sum_of_int[2].npe) < 0.001)
00106 {
00107
00108 if( ((event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift)
00109 && ((event->GetChannelByID(-2)->pulses[3].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift) )
00110 {
00111
00112 s2_pulse_number.push_back(2);
00113 s2_pulse_number.push_back(3);
00114 }
00115 else if( ((event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift)
00116 && ((event->GetChannelByID(-2)->pulses[3].start_time - event->GetChannelByID(-2)->pulses[0].start_time) > max_t_drift) )
00117 {
00118
00119 s2_pulse_number.push_back(2);
00120 }
00121 }
00122
00123 else if( ((event->sum_of_int[1].npe/event->sum_of_int[3].npe) < 0.001)
00124 && ((event->sum_of_int[2].npe/event->sum_of_int[3].npe) < 0.001) )
00125 {
00126
00127 s2_pulse_number.push_back(3);
00128 }
00129
00130 else if( ((event->sum_of_int[1].npe/event->sum_of_int[2].npe) > 0.001)
00131 && ((event->sum_of_int[2].npe/event->sum_of_int[3].npe)> 0.001
00132 && event->sum_of_int[3].npe>10.))
00133 {
00134 s2_pulse_number.push_back(1);
00135 }
00136
00137 else if( ((event->sum_of_int[1].npe/event->sum_of_int[2].npe) > 0.001)
00138 && ((event->sum_of_int[3].npe/event->sum_of_int[2].npe) < 0.001)
00139 && ((event->GetChannelByID(-2)->pulses[2].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift))
00140 {
00141 s2_pulse_number.push_back(1);
00142 s2_pulse_number.push_back(2);
00143 }
00144
00145 else if( ((event->sum_of_int[1].npe/event->sum_of_int[2].npe) > 0.001)
00146 && ((event->sum_of_int[2].npe/event->sum_of_int[3].npe) > 0.001)
00147 && ((event->GetChannelByID(-2)->pulses[3].start_time - event->GetChannelByID(-2)->pulses[0].start_time) < max_t_drift)
00148 && event->sum_of_int[3].npe>10.)
00149 {
00150 s2_pulse_number.push_back(1);
00151 s2_pulse_number.push_back(2);
00152 s2_pulse_number.push_back(3);
00153 }
00154 break;
00155 }
00156
00157 return true;
00158 }
00159
00160 bool load_position_recon_file (std::string filename, std::vector<std::vector <double> >& calib_points)
00161 {
00162 std::ifstream fin(filename.c_str());
00163 if(!fin.is_open())
00164 {
00165 std::cout<<"Unable to open position calibration file "
00166 <<filename<<std::endl;;
00167 return false;
00168 }
00169
00170 calib_points.clear();
00171 std::string line;
00172 while(std::getline(fin,line))
00173 {
00174 std::stringstream s(line);
00175 double val;
00176 std::vector<double> vals;
00177 while(s>>val)
00178 vals.push_back(val);
00179
00180 if( sqrt(vals[0]*vals[0]+vals[1]*vals[1]) <= 8.25*2.54/2. )
00181 calib_points.push_back(vals);
00182
00183 }
00184
00185 std::cout<<"Loaded "<<calib_points.size()<<" calibration points for position reconstruction.\n";
00186
00187 if(calib_points.size() == 0)
00188 return false;
00189
00190 return true;
00191 }
00192
00193 bool position_eval (EventData* event, int n_pulse, double& x, double& y, std::vector<std::vector<double> > calib_points)
00194 {
00195 if ( n_pulse < 0
00196 || (n_pulse + 1 > event->GetChannelByID(-2)->npulses))
00197 {
00198 cout << "No such pulse" << endl;
00199 return false;
00200 }
00201
00202 x = -10; y = -10;
00203
00204
00205 double total_charge = event->sum_of_int[n_pulse].fixed_npe2;
00206 std::vector<double> frac_charge (event->channels.size(), 0);
00207 std::vector<double> err_frac_charge (event->channels.size(), 0);
00208
00209 for (int j = 0; j < (int)event->channels.size() - 1; j++)
00210 {
00211
00212 frac_charge[j] = (-(event->GetChannelByID(j)->pulses[n_pulse].fixed_int2)/(event->GetChannelByID(j)->spe_mean))/total_charge;
00213 err_frac_charge[j] = sqrt(frac_charge[j])/total_charge;
00214 }
00215
00216
00217 double minchi2=1E12;
00218 for(size_t pt=0; pt < calib_points.size(); ++pt)
00219 {
00220 double chi2=0;
00221 for (int j = 0; j < (int)event->channels.size() - 1; j++)
00222 {
00223
00224 double val = calib_points[pt][2+2*j];
00225 double eval = calib_points[pt][3+2*j];
00226 chi2 += (frac_charge[j]-val)*(frac_charge[j]-val)
00227 /(err_frac_charge[j]*err_frac_charge[j] + eval*eval);
00228 }
00229
00230 if(chi2<minchi2)
00231 {
00232 minchi2 = chi2;
00233 x = calib_points[pt][0];
00234 y = calib_points[pt][1];
00235 }
00236
00237 }
00238
00239 return true;
00240 }
00241
00242 double drift_time_eval (EventData* event, int n_pulse_1, int n_pulse_2)
00243 {
00244 if ( n_pulse_1 < 0
00245 || n_pulse_2 < 0
00246 || (n_pulse_1 + 1 > event->GetChannelByID(-2)->npulses)
00247 || (n_pulse_2 + 1 > event->GetChannelByID(-2)->npulses))
00248 {
00249 cout << "No such pulse" << endl;
00250 return -1;
00251 }
00252
00253 return (event->GetChannelByID(-2)->pulses[n_pulse_2].start_time
00254 - event->GetChannelByID(-2)->pulses[n_pulse_1].start_time);
00255 }
00256
00257 #endif