12 #if !defined(__CINT__) || defined(__MAKECINT__)
18 #include "TTimeStamp.h"
28 ifstream in1(
"currents.txt");
29 ifstream in2(
"run_times.txt");
30 ofstream out2(
"dbout.csv");
31 ofstream out3(
"dbout.txt");
44 TFile scf(
"cur.root",
"RECREATE");
45 TNtupleD sc(
"cur",
"current",
"t:Ioe:Iie:Iow:Iiw:res:run:Y:M:D:h:m:s:begin:end");
57 double mincur,maxcur,dcur,maxdcur=0;
59 double last_missing_resistance=0;
60 double last_resistor=0;
61 double maxsec = 2147483647.0;
67 printf(
"Maximum current difference = %f\n",maxdcur);
74 if (in1.eof()) Finish();
77 for (i=1; i<size1; i++) in1 >> ff1[i];
80 if (in1.eof()) nexttime = maxsec;
81 for (i=size1; i<size1+size2; i++) ff1[i] = 0;
82 if ((++li1)%LI==0) printf(
"Line1 = %d , time = %f\n",li1,ff1[0]);
86 for (
int i=0; i<size2; i++) in2 >> ff2[i];
88 for (
int i=0; i<size2; i++) ff2[i]=0;
93 if ((++li2)%LI==0) printf(
"Line2 = %d , time = %f\n",li2,ff2[7]);
97 for (
int i=0; i<size2; i++) ff1[i+size1] = ff2[i];
102 TTimeStamp begin1((UInt_t) ff2[1],(UInt_t) ff2[2],(UInt_t) ff2[3],
103 (UInt_t) ff2[4],(UInt_t) ff2[5],(UInt_t) ff2[6]);
104 tOffset = begin1.GetSec() - (UInt_t) ff2[7];
105 printf(
"Found time offset to be: %u\n",tOffset);
109 TDatime newbegin(tOffset + (UInt_t) ff1[0]);
110 newbegin.Set(newbegin.Convert(kTRUE));
111 ff2[1] = newbegin.GetYear();
112 ff2[2] = newbegin.GetMonth();
113 ff2[3] = newbegin.GetDay();
114 ff2[4] = newbegin.GetHour();
115 ff2[5] = newbegin.GetMinute();
116 ff2[6] = newbegin.GetSecond();
123 for (
int i=0; i<6; i++) ii[i] = (
int) ff2[i+1];
127 Double_t ring = 80.5;
128 Double_t reference = TMath::Max(ff3[2],ff3[3]);
129 Double_t missing_resistance = 364.44*(1.0 - reference/ff3[4]);
133 if (last_missing_resistance && TMath::Abs(missing_resistance - last_missing_resistance) > 0.5) {
134 printf(
"BIG RESISTANCE JUMP: %f -> %f :: dif = %f\n",
135 last_missing_resistance,missing_resistance,missing_resistance-last_missing_resistance);
138 if ((last_missing_resistance && TMath::Abs(missing_resistance - last_missing_resistance) < 0.1)
139 || (last_missing_resistance > 0.2 && missing_resistance > 0.2)
140 || (last_missing_resistance < 0.2 && missing_resistance < 0.2)) {
142 printf(
"SMALL RESISTANCE JUMP: %f -> %f :: dif = %f\n",
143 last_missing_resistance,missing_resistance,missing_resistance-last_missing_resistance);
148 TString outname = Form(
"dbout/tpcFieldCageShort.%04d%02d%02d.%02d%02d%02d.C",ii[0],ii[1],ii[2],ii[3],ii[4],ii[5]);
150 if (writing) out1 =
new ofstream(outname.Data());
152 double missing_res2 = missing_resistance;
153 missing_res2 = (missing_resistance > 0.2 ? 0.345 : 0.0);
155 TString buffer = Form(
"\"%d\",\"%s\",\"33\",\"1\",",dataid,eT);
157 buffer += Form(
"\"%04d-%02d-%02d %02d:%02d:%02d\",\"ofl\",\"1\",\"0\",",ii[0],ii[1],ii[2],ii[3],ii[4],ii[5]);
158 buffer += Form(
"\"1.0\",\"1.0\",\"%5.3f\",\"%7.5f\",\"%7.5f\"",ring,0.0,missing_res2);
159 if (writing) (*out1) << buffer << endl;
160 out2 << buffer << endl;
162 buffer = Form(
"%04d%02d%02d %02d%02d%02d",ii[0],ii[1],ii[2],ii[3],ii[4],ii[5]);
163 buffer += Form(
" 1.0 1.0 %5.3f %7.5f %7.5f",ring,0.0,missing_res2);
164 out3 << buffer << endl;
166 last_missing_resistance = missing_resistance;
167 last_resistor = resistor;
170 if (ff3[2]==0) {printf(
"ZERO CURRENT!...\n"); pflag=2;}
171 int tt = (int) (ff4[0]-ff3[0]);
173 {pflag=0; cout << outname <<
" :: " << dcur <<
" :: " << tcnt <<
" :: " << ff3[0] <<
174 "," << tt <<
"," << (int) ff2[0] <<
"," << ff3[4] << endl;}
177 if (writing) {out1->close();
delete out1; out1=0;}
181 void ResetMeasure() {
184 dcur = maxcur-mincur;
185 if (dcur>0.15) {printf(
"LARGE CURRENT SPREAD: %f\n",dcur); pflag=1;}
186 if (dcur>maxdcur) maxdcur = dcur;
189 if (tcnt>1)
for (
int i=1; i<size3; i++) ff3[i] /= ff3[0];
194 for (
int i=0; i<size3; i++) { ff3[i]=0; ff4[i]=0; }
200 void IncludeThisMeasure() {
202 for (
int i=1; i<size3; i++)
if (ff1[i] < 76.0)
return;
208 if (tcnt>1) avg /= ff3[0];
209 if (TMath::Abs(avg-ff1[4]) > 0.045) ResetMeasure();
213 if (tcnt==1)
for (
int i=0; i<size3; i++) ff3[i]=0;
215 if (tcnt>0) tdiff = ff1[0]-ff4[0];
216 if (tdiff == 0) tdiff = 0.001;
219 for (
int i=1; i<size3; i++) ff3[i] += tdiff*0.5*(ff1[i]+ff4[i]);
220 for (
int i=0; i<size3; i++) ff4[i] = ff1[i];
225 if (ff1[4]>maxcur) maxcur = ff1[4];
226 if (ff1[4]<mincur) mincur = ff1[4];
237 IncludeThisMeasure();
242 for (
int i=0; i<size2; i++) ff2[i]=0;
248 Double_t time = ff1[0];
250 while (time > ff2[8]) FindNextRun();
252 if (nexttime > ff2[7]) UseThisRun();
259 void matchTpcFieldCageShorts(
char* T,
double lr,
double lm,
int i) {
263 last_missing_resistance = lm;