StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BbcVertex.cxx
1 // $Id: BbcVertex.cxx,v 1.3 2007/07/12 19:25:36 fisyak Exp $
2 
3 #include <assert.h>
4 #include <stdlib.h>
5 
6 #include <TClonesArray.h>
7 #include <TObjArray.h>
8 #include <TH1.h>
9 #include <TH2.h>
10 
11 #include "BbcVertex.h"
12 #include "BbcHex.h"
13 #include "TMath.h"
14 ClassImp(BbcVertex)
15 
16 //--------------------------------------------------
17 //--------------------------------------------------
19 
20  nInpEve=0;
21  HList=0;
22  memset(hA,0, sizeof(hA));
23  unixTime0=0;
24  cm2tdcCh=-999;
25 
26  int iew,ih;
27  char cEW[mxEW]={'E','W'};
28  for(iew=0;iew<mxEW;iew++) {
29  for(ih=0;ih<mxHex;ih++) {
30  char name[100];
31  sprintf(name,"bbc%c%02d",cEW[iew],ih+1);
32  BbcHex *x=new BbcHex(ih,name);
33  x->setCalib(0,0,0,0);
34  x->clear();
35  hex[iew][ih]=x;
36  }
37  }
38 
39 }
40 
41 //--------------------------------------------------
42 //--------------------------------------------------
43 BbcVertex::~BbcVertex() {/* noop */}
44 
45 
46 //-------------------------------------------------
47 //-------------------------------------------------
48 void BbcVertex::clear(){
49  unixTime=0;
50  int iew,ih;
51  for(iew=0;iew<mxEW;iew++)
52  for(ih=0;ih<mxHex;ih++)
53  hex[iew][ih]->clear();
54 
55  onlTdiff=-999;
56  onlTdiff=-997;
57  zTpc=-998;
58 }
59 
60 
61 //-------------------------------------------------
62 //-------------------------------------------------
63 void BbcVertex::initRun(int runID){
64  printf(" BbcVertex::initRun(%d), cm2tdcCh=%f\n",runID, cm2tdcCh);
65  assert(TMath::Abs(cm2tdcCh)<20);
66 
67 }
68 
69 //-------------------------------------------------
70 //-------------------------------------------------
71 void BbcVertex::init(){
72  int i;
73  hA[0]=new TH1F ("onlvd","zTpc - Z(BBC) ; (cm)",50,-100,100);
74  hA[1]=(TH1F*)new TH2F ("onlvv","BBC zTPC vs. onlTdiff; (TDC ch); Z vert (cm)",50,150,350,50,-200,200);
75  hA[2]=(TH1F*)new TH2F ("onlvd2","BBC (onlZbbc-zTPC)/cm2ch vs. onlTdiff; (TDC ch); #D Z vert (TDC ch)",50,150,350,50,-20,20);
76 
77  for(i=0;i<3;i++) hA[i]->SetLineColor(kGreen);
78 
79 
80  hA[7]=(TH1F*)new TH2F ("vd2","BBC (oflZbbc-zTPC)/cm2ch vs. oflTdiff+256; (TDC ch); #D Z vert (TDC ch)",50,150,350,50,-20,20);
81 
82  hA[8]=(TH1F*)new TH2F ("vk","BBC iW vs. iE",16,.5,16.5,16,0.5,16.5);
83  hA[9]=(TH1F*)new TH2F ("va","BBC adcW vs. adcE",156,-0.5,155.5,156,-0.5,155.5);
84  hA[10]=(TH1F*)new TH2F ("vt","BBC tdcW vs. tdcE",128,-0.5,255.5,128,-0.5,255.5);
85  hA[11]=(TH1F*)new TH2F ("vv","BBC zTPC vs. oflTdiff+256; (TDC ch); Z vert (cm)",50,150,350,50,-200,200);
86 
87  hA[12]=new TH1F ("vd","zTpc - Z(BBC) ; (cm)",50,-100,100);
88  hA[13]=(TH1F*)new TH2F ("vE","BBC zTpc - Z(BBC) vs. adcE ; ADC; (cm)",120,0.5,120.5,50,-100,100);
89  hA[14]=(TH1F*)new TH2F ("vW","BBC zTpc - Z(BBC) vs. adcW ; ADC; (cm)",120,0.5,120.5,50,-100,100);
90 
91  hA[15]=(TH1F*)new TH2F ("vU","TPC vertex Z vs run time ; minutes; cm ",120,0,60, 50,-200,200);
92  hA[16]=(TH1F*)new TH2F ("vD","Ztpc - Zbbc vs run time ; minutes; cm ",120,0,60, 50,-200,200);
93 
94  hA[17]=new TH1F ("ts","sum of T_E + T_W ; raw chan",100,0,300);
95 
96 
97  if(HList) {
98  for(i=0;i<=17;i++) {
99  if(hA[i]==0) continue;
100  HList->Add(hA[i]);
101  }
102  }
103 
104  char cEW[mxEW]={'E','W'};
105  int iew,ih;
106  for(iew=0;iew<mxEW;iew++) {
107  for(ih=0;ih<mxHex;ih++) {
108  char tt1[100],tt2[100];
109  sprintf(tt1,"w%c%02d",cEW[iew],ih+1);
110  sprintf(tt2,"%s , dZ vs. ADC ; ADC(chan) ;#Delta Z (cm)",tt1);
111  TH2F *h=new TH2F (tt1,tt2,60,0.5,120.5,25,-100,100);
112  hC[iew][ih]=h;
113  HList->Add(h);
114  }
115  }
116 
117  clear();
118 }
119 //-------------------------------------------------
120 //-------------------------------------------------
121 void BbcVertex::finish(){
122 
123  printf("\n BbcVertex::finish() nInpEve=%d\n",nInpEve);
124 
125 
126 }
127 
128 //-------------------------------------------------
129 //-------------------------------------------------
130 int BbcVertex:: findTime(BbcHex **D){
131  int i;
132  float tMax=0;
133  int iT=-1;
134  for(i=0;i<mxHex;i++) {
135  // printf("i=%d a=%d t=%d iT=%d tMin=%d\n",i,D[i]->adc,D[i]->tdc,iT,tMin);
136  if(D[i]->adc<5) continue;
137  if(D[i]->tdc>245) continue;
138  if(D[i]->tof<tMax) continue;
139  tMax=D[i]->tof;
140  iT=i;
141  }
142  // printf("minT=%d iT=%d\n",tMin,iT);
143  assert(iT>=0);
144  return iT;
145 }
146 
147 
148 //-------------------------------------------------
149 //-------------------------------------------------
150 void BbcVertex:: export2NN(BbcHex **D){
151  int key[mxHex];
152  memset(key,0,sizeof(key));
153  int k=0, nk=3;
154 
155  for(k=0;k<nk;k++) {
156  int i;
157  float tMax=0;
158  int iT=-1;
159  for(i=0;i<mxHex;i++) {
160  // if(k==0) printf("i=%d a=%d t=%d \n",i,D[i]->adc,D[i]->tdc);
161  if(key[i]) continue;
162  if(D[i]->adc<5) continue;
163  if(D[i]->tdc>245) continue;
164  if(D[i]->tof<tMax) continue;
165  tMax=D[i]->tof;
166  iT=i;
167  }
168  if(iT>=0) {
169  key[iT]=100+k;
170  printf("%d %d %d ",iT,D[iT]->adc,D[iT]->tdc);
171  } else {
172  printf("-1 0 0 ");
173  }
174  // printf("Tmax=%.1f iT=%d\n",tMax,iT);
175  }
176 
177 }
178 
179 
180 //-------------------------------------------------
181 //-------------------------------------------------
182 void BbcVertex::print(){
183  printf("\n BbcVertex::print()\n dump:\n");
184 }
185 
186 //-------------------------------------------------
187 //-------------------------------------------------
188 void BbcVertex:: doVertex(){
189  if(zTpc>200) return;
190  //printf("TPC: Z=%f\n",zTpc);
191  //................ online vertex info
192  float onlZ=-(onlTdiff-256)*cm2tdcCh; // now in cm
193  float onlDz=onlZ-zTpc; // in cm
194  float onlTcorr=onlDz/cm2tdcCh; // in TDC chan
195  //printf("onl: tDiff=%f Z=%f Dz=%f Tcorr=%f\n", onlTdiff,onlZ,onlDz,onlTcorr);
196 
197  hA[0]->Fill(onlDz);
198  ( (TH2F*) hA[1])->Fill(onlTdiff,zTpc);
199  ( (TH2F*) hA[2])->Fill(onlTdiff,onlTcorr);
200 
201 
202  //............... offline vertex info
203  printf("## ");
204  export2NN(hex[0]);
205  export2NN(hex[1]);
206  printf(" %f\n",zTpc);
207  return; //tmp
208 
209  int iE=findTime(hex[0]);
210  int iW=findTime(hex[1]);
211  int kE=iE+1;
212  int kW=iW+1;
213 
214  float tE=hex[0][iE]->tof;
215  float tW=hex[1][iW]->tof;
216  float aE=hex[0][iE]->adc;
217  float aW=hex[1][iW]->adc;
218  float oflTdiff=256.+(tE-tW);
219 
220  float oflZ=-(oflTdiff-256)*cm2tdcCh; // now in cm
221  float oflDz=oflZ-zTpc; // in cm
222  float oflTcorr=oflDz/cm2tdcCh; // in TDC chan
223  //printf("ofl: tE=%f tW=%f\n", tE, tW);
224  //printf("ofl: tDiff=%f Z=%f Dz=%f Tcorr=%f\n", oflTdiff,oflZ,oflDz,oflTcorr);
225 
226 #if 0
227  float diff=onlTdiff -oflTdiff;
228  if(TMath::Abs(diff)>0.01)
229  printf("DIFIDIF: Z=%f onlTd=%f oflTd=%f difT=%f\n",zTpc,onlTdiff,oflTdiff,diff);
230 #endif
231 
232 
233  // if(iW!=0) return;
234  //if(kE!=3&& kE!=4) return;
235  // if(kW==9) return; // skip one not calibrated
236  // if(kW!=1&& kW!=3&& kW!=6&& kW!=8&& kW!=9&& kW!=13&& kW!=15) return;
237  //hex[0][iE]->print(); hex[1][iW]->print();
238  // printf(" tDif onl=%d ofl=%f dd=%f\n",b.tDif,tDif, b.tDif-tDif);
239 
240  ( (TH2F*) hA[8])->Fill(kE,kW);
241  ( (TH2F*) hA[9])->Fill(aE,aW);
242  ( (TH2F*) hA[10])->Fill(tE,tW);
243  ( (TH2F*) hA[11])->Fill(oflTdiff,zTpc);
244  ( (TH2F*) hA[7])->Fill(oflTdiff,oflTcorr);
245  hA[12]->Fill(oflDz);
246 
247  float time1= unixTime-unixTime0;
248  time1/=60; // converte to minutes
249  ( (TH2F*) hA[15])->Fill(time1,zTpc);
250  ( (TH2F*) hA[16])->Fill(time1,oflDz);
251  hA[17]->Fill(tE+tW);
252 
253  calibWalk(hex[1][iW],hex[0][iE],oflDz,hC[0]); // doEast
254  calibWalk(hex[0][iE],hex[1][iW],oflDz,hC[1]); // doWest
255 
256  // old stuff
257  ( (TH2F*) hA[13])->Fill(aE,oflDz);
258  ( (TH2F*) hA[14])->Fill(aW,oflDz);
259 
260 
261 if(0) {//new stuff
262  int iew,ih;
263  int adcMin=5;
264  int nT[mxEW];
265  for(iew=0;iew<mxEW;iew++){
266  nT[iew]=0;
267  for(ih=0;ih<mxHex;ih++) {
268  if( hex[iew][ih]->adc<adcMin) continue;
269  nT[iew]++;
270  hex[iew][ih]->print();
271  }
272  }
273  printf("nT-E=%d nT-W=%d\n\n",nT[0],nT[1]);
274 
275  }
276 
277 }
278 
279 
280 //-------------------------------------------------
281 //-------------------------------------------------
282 void BbcVertex::calibWalk( BbcHex *x, BbcHex *y, float dz, TH2F **h){
283  // int id=0;
284  // if (x ->id!=id) return;
285  // // if( x->adc<25) return;
286  // printf(" %d+%d %d %d\n", x->id,y->id, unixTime, unixTime-unixTime0);
287 
288  assert(y->id>=0 && y->id<mxHex);
289  h[y->id]->Fill(y->adc,dz);
290 }
291 
292 
293 //-------------------------------------------------
294 //-------------------------------------------------
295 void BbcVertex::readCalib(char *fname) {
296  printf("readCalib('%s')\n",fname);
297  FILE *fd=fopen(fname,"r");
298  //printf("file opened fd=%p %s\n",fd,fname);
299  if(fd==0) {
300  printf("file %s was not open\n",fname);
301  printf(" fix it, (JB)\n\n");
302  assert(1==0);
303  }
304 
305  int nd=0,nl=0;;
306  while (1 ) {
307  const int mx=1000;
308  char buf[mx];
309  char * ret=fgets(buf,mx,fd);
310  if(ret==0) break;// EOF
311  nl++;
312  if(buf[0]=='#') continue; // commented out record
313  char name[100];
314  float a,b,c,d;
315  int n=sscanf(buf,"%s %f %f %f %f",name,&a,&b,&c,&d);
316  if(n!=5) {
317  printf("faulty %d line in %s\n",nl,fname);
318  printf("n=%d buf='%s'\n fix it, (JB)\n\n",n,buf);
319  assert(1==2);
320  }
321  nd++;
322 
323  // find this PMT
324  int iew,ih;
325  int ok=0;
326  for(iew=0;iew<mxEW;iew++)
327  for(ih=0;ih<mxHex;ih++){
328  if(strstr(hex[iew][ih]->name,name)==0) continue;
329  ok=1;
330  hex[iew][ih]->setCalib(a,b,c,d);
331  break;
332  }
333  if(ok!=1) {
334  printf("faulty BbcPMT name=%s in %d line in %s\n",name,nl,fname);
335  printf("n=%d buf='%s'\n fix it, (JB)\n\n",n,buf);
336  assert(1==3);
337  }
338  }
339 
340  fclose(fd);
341  printf("BbcVertex::readCalib() done, found %d valid records\n",nd);
342  return;
343 }
344 
345 
346 /*******************************************************
347  * $Log: BbcVertex.cxx,v $
348  * Revision 1.3 2007/07/12 19:25:36 fisyak
349  * Add includes for TMath for ROOT 5.16
350  *
351  * Revision 1.2 2004/12/04 05:07:38 balewski
352  * export to NN
353  *
354  * Revision 1.1 2004/08/31 03:44:13 balewski
355  * first
356  *
357  * Revision 1.6 2004/08/26 04:39:40 balewski
358  *
359  */
360 
361 
Definition: tof.h:15
Definition: BbcHex.h:4