Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tileHelper.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file tileHelper.C
1 
2 
3 // **************************************************************************
4 
6  if(ACTIVECHANNELS) {
7  cout<<"<tileHelper>: Wrong instantiation sequence - hLabHelper already exists. EXITING"<<endl;
8  // return;
9  }
10  // ONLY ACTIVE channels will be copyed from .prdf to adc
14  samples = NSAMPLES;
17  // assumption is that out of all stored ADC channels the first detchannels
18  // correspon to detector we study, the rest is everything else
19 
20  tileCalib = new Double_t [detchannels];
21  tileCalPeak = new Double_t [detchannels];
22  fiberLY = new Double_t [fibers];
23  fiberY = new Double_t [fibers];
24  yFit = NULL;
25  fLY = NULL;
26  for(int ifb = 0; ifb<fibers; ifb++) {fiberY[ifb] = 15.-2.5*(ifb+1); if(ifb) fiberY[ifb] -= 2.5;}
27 
28 }
29 
30 // **************************************************************************
31 
32 int tileHelper::evLoop(int run, int evToProcess, int fToProcess){
33  hLabHelper * hlHelper = hLabHelper::getInstance();
34  hlHelper -> setPRDFRun(run);
36 
37  int OK;
38 
39 
40  Eventiterator *it = new fileEventiterator(hlHelper->prdfName, OK);
41  if (OK)
42  {
43  cout <<"<evLoop> Couldn't open input file " << hlHelper->prdfName << endl;
44  delete(it);
45  return 0;
46  }
47 
48  Event *evt;
49  int eventseq(0);
50  // Loop over events
51  while ( (evt = it->getNextEvent()) != 0 )
52  {
53  hlHelper->eventseq = evt->getEvtSequence();
54 
55  if ( evt->getEvtType() != 1 ) {
56  cout << "eventseq " << hlHelper->eventseq << " event type = " << evt->getEvtType() << endl;
57  continue;
58  }
59  // ev_display->Divide(nx_c,ny_c);
60  // ev_display->SetBit(TPad::kClearAfterCR);
61 
62  // Get sPHENIX Packet
63  Packet_hbd_fpgashort *spacket = dynamic_cast<Packet_hbd_fpgashort*>( evt->getPacket(21101) );
64  if ( spacket )
65  {
66  spacket->setNumSamples( NSAMPLES );
67  // int nmod_per_fem = spacket->iValue(0,"NRMODULES");
68  //cout << "nmod_per_fem " << nmod_per_fem << endl;
69  if(hlHelper->eventsread%1000==0) cout <<"RUN "<<hlHelper->runnumber<<" EVENT "<<hlHelper->eventseq <<" - "<<hlHelper->eventsread<<endl;
70  hlHelper->eventsread++;
71  for (int ich=0; ich<ACTIVECHANNELS; ich++) {
72  for (int is=0; is<NSAMPLES; is++) {
73  hlHelper->adc[ich][is] = spacket->iValue(hlHelper->active[ich],is);
74  // cout<<"<evLoop Event "<< hclt->eventseq<<" ich/is/adc "<<ich<<" - "<<is<<" - "<< hlHelper->adc[ich][is]<<" active "<<hlHelper->active[ich]<<endl;
75  }
76  }
77  hlHelper->collect();
79  tileTiming();
80  delete spacket;
81  }
82 
83  delete evt;
84  hlHelper-> thcl -> Fill();
85  if ((evToProcess>0&&hlHelper->eventsread>=evToProcess)||hlHelper->eventsread>270000) break;
86  }
87  // Normalize trigger histogramm to get per event hit count (number of channels above threshold)
88  int nbs = runsum.trhits->GetNbinsX()-1;
89  for(int bx = 1; bx<=nbs; bx++){
90  float normx = runsum.trhits->GetBinContent(bx);
91  if(normx<=0.) continue;
92  for (int threshold = 1; threshold<=CHANNELTHRESHOLDS; threshold++) {
93  float cont = runsum.hits_tpc->GetBinContent(bx,threshold);
94  runsum.hits_tpc->SetBinContent(bx, threshold, cont/normx);
95  }
96  }
97 
98  if (hlHelper->eventsread>1) runsum.hits_tpc->Scale(1./(Double_t)hlHelper->eventsread);
99  // status();
100  cout<<"ALLDONE for RUN "<<hlHelper->runnumber<<" Events "<<hlHelper->eventsread<<endl;
101  delete it;
102  hlHelper->thcl -> Write();
103  hlHelper->fhcl -> Write();
104  hlHelper->fhcl -> Close();
105 
106  // closeLoop();
107  return eventseq;
108 
109 }
110 
111 // **************************************************************************
113  hLabHelper * hlHelper = hLabHelper::getInstance();
114  int nx_c = ACTIVECHANNELS<=12? 2 : 4;
115  int ny_c = ACTIVECHANNELS/nx_c+ACTIVECHANNELS%nx_c;
116  if(!(fiberDisplay=(TCanvas*)(gROOT->FindObject("fiberDisplay")))) {
117 
118  TString fD = "Fiber Amplitudes (black - raw, red - fit) Run "; fD += runId.Data();
119  // TString fD = "Fiber Amplitudes (black - raw, red - fit, blue - integral) Run "; fD += hlHelper->prdfName;
120  fiberDisplay = new TCanvas("fiberDisplay",fD,400*nx_c,200*ny_c);
121  fiberDisplay->Divide(nx_c, ny_c);
122  }
123  Double_t ymx[ACTIVECHANNELS], xmx[ACTIVECHANNELS];
124  for (int ich=0; ich<ACTIVECHANNELS; ich++){
125  Double_t rvmax, fvmax, ivmax(0), rvrms, fvrms, ivrms(0), rvmean, fvmean, ivmean(0);
126  rvmax = hlHelper->rpeak[ich]->GetMaximum();
127  fvmax = hlHelper->fm[ich]->GetMaximum();
128  // ivmax = hlHelper->fint[ich]->GetMaximum();
129  rvrms = hlHelper->rpeak[ich]->GetRMS();
130  fvrms = hlHelper->fm[ich]->GetRMS();
131  // ivrms = hlHelper->fint[ich]->GetRMS();
132  rvmean = hlHelper->rpeak[ich]->GetMean();
133  fvmean = hlHelper->fm[ich]->GetMean();
134  // ivmean = hlHelper->fint[ich]->GetMean();
135 
136  Double_t ym = std::max(max(rvmax, fvmax), ivmax);
137  ymx[ich] = (int)(log10(ym)); ymx[ich] = pow(10., ymx[ich]);
138  while(ymx[ich]<ym) ymx[ich] *=2;
139  Double_t xm = std::max(max(rvmean+4*rvrms, fvmean+4*fvrms), ivmean+4*ivrms); xmx[ich] = (int)(log10(xm)); xmx[ich] = pow(10., xmx[ich]);
140  while(xmx[ich]<xm) xmx[ich] *=2;
141  cout<<"chan "<<ich<<" rvmax "<<rvmax<<" fvmax "<<fvmax<<" ivmax "<<ivmax<<" xm "<<xm<<" xmx "<<xmx[ich]<<endl;
142  }
143  Double_t xm(0.);
144  for (int ich=0; ich<ACTIVECHANNELS; ich++){
145  // just to make x-scales on left and right for the same fiber identical
146  hlHelper->rpeak[ich]->SetLineColor(1); hlHelper->rpeak[ich]->SetMaximum(ymx[ich]);
147  hlHelper->fm[ich] ->SetLineColor(2); hlHelper->fm[ich] ->SetMaximum(ymx[ich]);
148  hlHelper->fint[ich] ->SetLineColor(4); hlHelper->fint[ich] ->SetMaximum(ymx[ich]);
149  if(!(ich%2)) xm = max(xmx[ich], xmx[ich+1]);
150  cout<<"chan "<<ich<<" xrange "<<xm<<endl;
151  fiberDisplay->cd(ich+1); hlHelper->rpeak[ich]->SetAxisRange(0., xm); hlHelper->rpeak[ich]->Draw();
152  hlHelper->fm[ich]->Draw("same");
153  // hlHelper->fint[ich]->Draw("same");
154  }
155  fiberDisplay->Update();
156 }
157 
158 // **************************************************************************
160  hLabHelper * hlHelper = hLabHelper ::getInstance();
161  int runnumber = hlHelper->runnumber;
162  ACTIVECHANNELS = 0;
163  for (int ich = 0; ich<TILECHANNELS; ich++) hlHelper->active[ich] = runnumber<803? feech1[ich] : feech2[ich];
164  ACTIVECHANNELS += TILECHANNELS;
165  for (int ich = 0; ich<TILETRIGGERCH; ich++) {
166  if(runnumber<1125) {
167  hlHelper->active[TILECHANNELS+ich] = -1;
168  } else if(runnumber>=1125&&runnumber<1152) {
169  hlHelper->active[TILECHANNELS+ich] = trch1125[ich];
170  if(hlHelper->active[TILECHANNELS+ich]>=0) ACTIVECHANNELS ++;
171  } else {
172  hlHelper->active[TILECHANNELS+ich] = trch1152[ich];
173  if(hlHelper->active[TILECHANNELS+ich]>=0) ACTIVECHANNELS ++;
174  }
175  }
176 }
177 // **************************************************************************
179  hLabHelper * hlHelper = hLabHelper ::getInstance();
180  int runnumber = hlHelper->runnumber;
181  if(runnumber<864) {
182  for (int ich = 0; ich<TILECHANNELS; ich++) tileCalib[ich] = sc_779[ich];
183  } else if (runnumber<1061) {
184  for (int ich = 0; ich<TILECHANNELS; ich++) tileCalib[ich] = sc_900[ich];
185  } else if (runnumber<1123) {
186  for (int ich = 0; ich<TILECHANNELS; ich++) tileCalib[ich] = sc_1061[ich];
187  } else {
188  for (int ich = 0; ich<TILECHANNELS; ich++) tileCalib[ich] = sc_1123[ich];
189  }
190 }
191 
192 // **************************************************************************
193 
195  evtsum.reset();
196  uSum = 0.; cSum = 0.;
197  luSum = 0.; lcSum = 0.;
198  ruSum = 0.; rcSum = 0.;
199  YF = 0.;
200  YU = 0.; YC = 0.;
201  XU = 0.; XC = 0.;
202  sumFU = 0.; sumFC = 0.;
203  muxU = -100.; muxC = -100.; muxFU = -100.; muxFC = -100.;
204  muxUCh = 0; muxCCh = 0; muxUFiber = 0; muxCFiber = 0;
205  for(int ith = 0; ith<CHANNELTHRESHOLDS; ith++) hitcnt[ith] = 0;
206  for(int ifb = 0; ifb<fibers; ifb++) fiberLY[ifb] = 0.;
207  if(yFit) {delete yFit; yFit = NULL;}
208  if(fLY) {delete fLY; fLY = NULL;}
209 
210 }
211 
212 
213 // **************************************************************************
214 
216  hLabHelper * hlHelper = hLabHelper ::getInstance();
217  for(int ich = 0; ich<detchannels; ich++) {
218  for(int ith = 0; ith<CHANNELTHRESHOLDS; ith++) {
219  if(int(hlHelper->rawPeak[ich]/TRIGGERRES) >= ith) hitcnt[ith]++; else break;
220  }
221  }
222  // trigger hit multiplicity plot
224  for(int ith=0; ith<CHANNELTHRESHOLDS; ith++) {if(hitcnt[ith]) runsum.hits_tpc->Fill(uSum/TRIGGERRES, ith, hitcnt[ith]) ; else break;}
225 
226 
227 }
228 
229 // **************************************************************************
230 
232  // build eventsum (adc sum without pedestal subtruction)
233  hLabHelper * hlHelper = hLabHelper ::getInstance();
234  for(int is = 0; is < NSAMPLES; is++){
235  evtsum.evtadcsum[is] = 0.;
236  for (int ich = 0; ich < detchannels; ich++) { evtsum.evtadcsum[is] += hlHelper->adc[ich][is];}
237  }
238  for (int is = 0; is < NSAMPLES; is++) evtsum.evtGraph->SetPoint(is,(Double_t)is,evtsum.evtadcsum[is]);
239  fitTileSignal();
240  // do the fit and compare parameter distribution in individual channels and total sum
241  // minimize the number of free parameters and compare timing RMS for "all free" anf "Some constrained"
242  ;
243 }
244 // **************************************************************************
245 
247  hLabHelper * hlHelper = hLabHelper ::getInstance();
248  // build eventsum (adc sum without pedestal subtruction)
249  for(int is = 0; is < NSAMPLES; is++){
250  evtsum.evtadcsum[is] = 0.;
251  for (int ich = 0; ich < detchannels; ich++) {
252  evtsum.evtadcsum[is] += hlHelper->adc[ich][is];
253  }
254  }
255  for (int is = 0; is < NSAMPLES; is++) evtsum.evtGraph->SetPoint(is,(Double_t)is,evtsum.evtadcsum[is]);
256  // cout<<"<tileDisplay> call to fitTileSignal"<<endl;
257  fitTileSignal();
258  TCanvas * tiledisplay = (TCanvas *)(gROOT->FindObject("tiledisplay"));
259  if(!tiledisplay) tiledisplay = new TCanvas("tiledisplay","sPhenix tile display", 300, 300, 800, 500);
260  else tiledisplay->Clear();
261  // tiledisplay->Divide(1,2);
262  // tiledisplay->cd(1);
263  // tiledisplay->SetEditable(kTRUE);
264  evtsum.evtGraph->SetMarkerStyle(20);
265  evtsum.evtGraph->SetMarkerSize(0.4);
266 
267  evtsum.evtGraph->Draw("acp");
268  tiledisplay->Update();
269  // tiledisplay->cd(2);
270  evtsum.evtShape->Draw("same");
271  tiledisplay->Update();
272  // tiledisplay->Clear();
273 }
274 
275 // **************************************************************************
276 
278  // hLabHelper * hlHelper = hLabHelper ::getInstance();
279  int nx_c = ACTIVECHANNELS<=12? 2 : 4;
280  int ny_c = ACTIVECHANNELS/nx_c+ACTIVECHANNELS%nx_c;
281  if(!(triggerDisplay=(TCanvas*)(gROOT->FindObject("triggerDisplay")))) {
282  TString fD = "Fiber Amplitudes (black - raw, red - fit) Run "; fD += runId.Data();
283  // TString fD = "Fiber Amplitudes (black - raw, red - fit, blue - integral) Run "; fD += hlHelper->prdfName;
284  triggerDisplay = new TCanvas("triggerDisplay",fD,400*nx_c,200*ny_c);
285  triggerDisplay->Divide(nx_c, ny_c);
286  }
287 }
288 // **************************************************************************
289 
290 // let's now see if all this game with patterning was worth trying
291 void tileHelper::tilePattern(Int_t nx, Int_t ny, Int_t run, Int_t mod){
292  TH2 * pcPat(NULL); // pattern of pixel conts measured in different tile areas
293  TH1 ** pcPatH(NULL); // Collections of hits from different tile areas
294 //TF1 ** pcPatF(NULL); // Fits to the histograms of hits in different tile areas
295  xdivisions = nx;
296  ydivisions = ny;
297  hLabHelper * hlHelper = hLabHelper ::getInstance();
298  TFile *f;
299  if(!(f=hlHelper->attachrootrun(run))) {
300  cout<<"<ERROR> pattern(): root file for runNumber "<<hlHelper->runnumber<<" not in the list"<<endl;
301  return;
302  }
303  f->cd();
304  gStyle ->SetOptFit();
305  // hn = "Total Pixel Count vs impact position RunId = "; hn += Id; hn += ";Calibated X [cm];Calibrated Y [cm];Pixels";
306  // pc_imp = new TH3F("pc_imp", hn, 25, 0., 25., 15, 0., 15., 1000, 0, 200.);
307  if((lyPattern = (TCanvas*)(gROOT->FindObject("lyPattern")))) delete lyPattern;
308  if((lyFits = (TCanvas*)(gROOT->FindObject("lyFits")))) delete lyFits;
309 
310  TString lyp = "Pattern of light yield "; lyp += runId.Data();
311  TString lyd = "LYD "; lyd += runId.Data();
312  lyPattern = new TCanvas(lyd, lyp, 400, 400);
313  TString lyv = "LIV "; lyv += runId.Data();
314  TString lyf = "Fits to the measurenments of light yield "; lyf += (mod==0? "(pc_imp) " : "(pc_fimp)"); lyf += runId.Data();
315  lyFits = new TCanvas("lyv", lyf, 200*nx, 200*ny);
316  lyFits ->Divide(xdivisions, ydivisions);
317 
318  TH3 * pcimp = (TH3F *) (gROOT->FindObject(mod==0? "pc_imp" : "pc_fimp"));
319  // TH3 * pc_imp = (TH3F *) (gROOT->FindObject("pc_imp"));
320  if(!pcimp) {
321  cout<<"<ERROR> pattern(): "<<(mod==0? "(pc_imp) " : "(pc_fimp)")<<" Scatterplot is not found"<<endl;
322  return;
323  }
324  Int_t nximp = pcimp->GetNbinsX(); Int_t nyimp = pcimp->GetNbinsY();
325  Int_t nzimp = pcimp->GetNbinsZ();
326  // Double_t dx = pcimp->GetXaxis()->GetBinWidth(1); Double_t dy = pcimp->GetYaxis()->GetBinWidth(1);
327  Double_t dxr = tileSizeX / nx; Double_t dyr = tileSizeY / ny;
328  // total number of cells to combine
329  Int_t dnx = nximp/nx; Int_t dny = nyimp/ny;
330  if(dnx*nx!=nximp || dny*ny!=nyimp) {
331  cout<<"Patterning request does not match your binning in the pixel count distribution pcimp"<<endl;
332  return;
333  }
334  pcPat = (TH2F *) (gROOT->FindObject("pcPat"));
335  if(pcPat) delete pcPat;
336  pcPat = new TH2F("pcPat", " fitted positions of maxima in pcimp pixel distributions", nx, 0., 25., ny, 0., 15.);
337  pcPatH = new TH1 * [nx*ny];
338  for (int iy = 0; iy<ny; iy++){
339  for (int ix = 0; ix<nx; ix++){
340  Int_t cpad = nx*(ny-iy-1) + ix +1;
341  TString hn = "h_"; hn += ix; hn += "_"; hn += iy;
342  TString ht = "Pixel count. Range X = "; ht += (dxr*ix); ht += " | "; ht += (dxr*(ix+1));
343  ht += " Y = "; ht += (dyr*iy); ht += " | "; ht += (dyr*(iy+1));
344  if((pcPatH[iy*nx+ix]=(TH1 *) (gROOT->FindObject(hn)))) delete pcPatH[iy*nx+ix];
345  pcPatH[iy*nx+ix] = new TH1D(hn, ht, nzimp, 0., pcimp->GetZaxis()->GetXmax());
346  // fill that histogramm
347  pcimp->ProjectionZ(hn, 1+dnx*ix, dnx*(ix+1), 1+dny*iy, dny*(iy+1));
348  // draw that histogramm
349  lyFits -> cd(cpad);
350  pcPatH[iy*nx+ix]-> Draw();
351  // check for total number of entries in the histogram, if less then minimum - go to next one
352  Int_t entries = pcPatH[iy*nx+ix]->GetEntries();
353  if(entries<minProjEntries) continue;
354  // rebin the histogramm to get at least 50 hits at the peak
355  Double_t norm;
356  while (((norm=pcPatH[iy*nx+ix]->GetMaximum())<50.||
357  pcPatH[iy*nx+ix]->GetBinCenter(pcPatH[iy*nx+ix]->GetMaximumBin())<=10)&&
358  pcPatH[iy*nx+ix]->GetNbinsX()>50 ) {
359  Int_t combine = 2;
360  while((pcPatH[iy*nx+ix]->GetNbinsX()/combine)*combine!=pcPatH[iy*nx+ix]->GetNbinsX()) combine++;
361  pcPatH[iy*nx+ix] = pcPatH[iy*nx+ix]->Rebin(combine);
362  }
363  // redrow the histogramm
364  pcPatH[iy*nx+ix]-> Draw();
365  // fit that histogramm
366  Double_t mean = pcPatH[iy*nx+ix]->GetMean();
367  Double_t rms = pcPatH[iy*nx+ix]->GetRMS();
368  Double_t p[6];
369  p[0] = norm; p[1] = mean; p[2] = rms; p[3] = 0.; p[4] = 0.; p[5] = 0.;
370  TF1 * fg = new TF1("fg","[0]*TMath::Gaus(x,[1],[2])", 15., pcimp->GetZaxis()->GetXmax());
371  fg -> SetParameters(p);
372  fg -> SetParLimits(0, 0.1*norm,10.*norm);
373  fg -> SetParLimits(1, mean-rms, mean+rms);
374  fg -> SetParLimits(2, rms/2., 2.*rms);
375  pcPatH[iy*nx+ix]->Fit(fg, "r");
376  fg ->GetParameters(p);
377  TF1 * fgb = new TF1("fgb","[0]*TMath::Gaus(x,[1],[2])+[3]+[4]*x+[5]*x*x", 15., pcimp->GetZaxis()->GetXmax());
378  fgb ->SetParameters(p);
379  fgb ->SetParLimits(1, p[1]-rms,p[1]+rms);
380  fgb ->SetParLimits(2, rms/2,2.*rms);
381  fgb ->SetParLimits(3, 0., p[0]);
382  pcPatH[iy*nx+ix]->Fit(fgb, "r");
383  lyFits ->Update();
384  fgb ->GetParameters(p);
385  // fill the patten 2D plot
386  pcPat->Fill(dxr*(ix+0.5), dyr*(iy+0.5), p[1]);
387  }
388  }
389  lyPattern->cd();
390  pcPat->Draw("lego2");
391 }
392 
393 // **************************************************************************
394 
396  hLabHelper * hlHelper = hLabHelper ::getInstance();
397  // tile specific data
398  for (int ich=0; ich<detchannels; ich++) {
399  tileCalPeak[ich] = hlHelper->fitPeak[ich]/tileCalib[ich];
400  evtsum.times[ich] = hlHelper->fitTime[ich];
401  evtsum.chi2[ich] = hlHelper->fitChi2[ich];
402  uSum += hlHelper->rawPeak[ich];
403  cSum += tileCalPeak[ich];
404  runsum.cdata ->Fill(ich, tileCalPeak[ich]);
405  if(ich%2) {
406 
407  // right ends
408  ruSum += hlHelper->rawPeak[ich];
409  rcSum += tileCalPeak[ich];
410  } else {
411  // lefy ends
412  luSum += hlHelper->rawPeak[ich];
413  lcSum += tileCalPeak[ich];
414  }
415  }
416  // Maximum amplitude in detector
417  for (int ich=0; ich<detchannels; ich++){
418  if(hlHelper->rawPeak[ich] >=muxU) {muxUCh = ich; muxU = hlHelper->rawPeak[ich];}
419  if(tileCalPeak[ich] >=muxC) {muxCCh = ich; muxC = tileCalPeak[ich];}
420  if(ich%2) {
421  // hard wired: fiber Y's in the tiles
422  int fiber = ich/2;
423  float y = fiberY[fiber];
424  sumFU += hlHelper->rawPeak[ich]; sumFC += tileCalPeak[ich];
425  YU += y*sumFU; YC += y*sumFC;
426  if(sumFU >= muxFU) {muxUFiber = ich/2; muxFU = sumFU;}
427  if(sumFC >= muxFC) {muxCFiber = ich/2; muxFC = sumFC;}
428  fiberLY[ich/2] = sumFC;
429  } else {
430  sumFU = hlHelper->rawPeak[ich]; sumFC = tileCalPeak[ich];
431  }
432  }
433  YU /= uSum; YC /= cSum; YF = getYFit();
436  evtsum.yChi2 = yFit->GetChisquare()/yFit->GetNDF();
437  evtsum.ySigma = yFit->GetParameter(2);
443  ras = ((hlHelper->rawPeak[muxUFiber*2+1]-hlHelper->rawPeak[muxUFiber*2]) /(hlHelper->rawPeak[muxUFiber*2]+hlHelper->rawPeak[muxUFiber*2+1]));
447  rtas = (ruSum - luSum) /(ruSum + luSum);
448  ctas = (rcSum - lcSum) /(rcSum + lcSum);
449  runsum.rtasym-> Fill(rtas);
450  runsum.ctasym-> Fill(ctas);
451  XU = 12.5+12.5*rtas; /* XC = 12.5+12.5*ctas; */ XC = AsymToX(ctas);
452  runsum.XY -> Fill(XC, YF);
453  runsum.ry -> Fill(YU);
454  runsum.cy -> Fill(YC);
455  runsum.fy -> Fill(YF);
456  runsum.rx -> Fill(XU);
457  runsum.cx -> Fill(XC);
458  runsum.rimp -> Fill(XU, YU);
459  runsum.cimp -> Fill(XC, YC);
460  runsum.cx_pc -> Fill(XC, cSum);
461  runsum.cy_pc -> Fill(YC, cSum);
462  runsum.fy_pc -> Fill(YF, cSum);
463  runsum.cimpW -> Fill(XC, YC, cSum);
464  for(int ith=0; ith<CHANNELTHRESHOLDS; ith++) {if(hitcnt[ith]) runsum.treff->Fill(hitcnt[ith], ith, cSum) ; else break;}
465  runsum.pc_imp ->Fill(XC, YC, cSum);
466  runsum.pc_fimp->Fill(XC, YF, cSum);
467  evtsum.evtpc = cSum;
469  // cout<<"<collectTileSummary> YF/tChi2/yChi2 "<<YF<<" * "<<evtsum.tChi2<<" * "<< evtsum.yChi2<<endl;
472  reject();
475  if(evtsum.ySigma<4.5) {
476  runsum.yCleaned -> Fill(YF);
478  if(!evtsum.rejectCode<100) runsum.yKept -> Fill(YF);
479  }
481  Double_t tower_pc = hlHelper->fitPeak[9]/0.05; // pixels in the tower
483  runsum.td_t_tw -> Fill(evtsum.evttime-hlHelper->fitTime[9], evtsum.evtpc, tower_pc);
484  }
485  tileTrigger();
486 }
487 
488 // **************************************************************************
489 
491  // Let's do Y first
492  yFit = new TF1("yFit", "[0]*exp(-abs(x-[1])/[2])", 0., tileSizeY);
493  Double_t par[] = {20., tileSizeY/2., 1.};
494  yFit -> SetParameters(par);
495  yFit -> SetParLimits(1, 0., tileSizeY);
496  yFit -> SetParLimits(2, 0., 5.);
497  fLY = new TGraph(fibers, fiberY, fiberLY);
498  fLY -> Fit(yFit, "rq", "nq", 0., tileSizeY);
499  yFit->GetParameters(par);
500  runsum.Y0 -> Fill(par[0]);
501  runsum.Y1 -> Fill(par[1]);
502  runsum.Y2 -> Fill(par[2]);
503 
504  return par[1];
505 }
506 
507 // **************************************************************************
508 
510  // Let's do Y first
511  yFit = new TF1("yFit", "[0]*exp(-abs(x-[1])/[2])", 0., tileSizeY);
512  Double_t par[] = {20., tileSizeY/2., 1.};
513  yFit -> SetParameters(par);
514  yFit -> SetParLimits(1, 0., tileSizeY);
515  yFit -> SetParLimits(2, 0., 4.);
516  fLY = new TGraph(fibers, fiberY, fiberLY);
517  fLY -> Fit(yFit, "rq", "nq", 0., tileSizeY);
518  yFit->GetParameters(par);
519  runsum.Y0 -> Fill(par[0]);
520  runsum.Y1 -> Fill(par[1]);
521  runsum.Y2 -> Fill(par[2]);
522  // Now X
523  Float_t slope(0.);
524  Float_t dsl = 0.5/20;
525  for (int isl = 0; isl< 20; isl++){
526  slope = dsl/2.+dsl*isl;
527  Double_t X = 12.5*(1 + ctas/slope);
528  runsum.XvsSl->Fill(X, slope);
529 
530  }
531 }
532 // **************************************************************************
533 
535  // zero approximation to fit parameters
536  // use pulse data to find location of maximum
537  // hLabHelper * hlHelper = hLabHelper ::getInstance();
538  int rTime = 0;
539  Double_t rVal = 0.;
540  for (int iSample = RISETIME-1; iSample <= NSAMPLES-FALLTIME; iSample++) {
541  if(evtsum.evtadcsum[iSample]>rVal) {
542  rVal = evtsum.evtadcsum[iSample];
543  rTime = iSample;
544  }
545  }
546  rVal -= PEDESTAL*detchannels;
547  if(rVal<0.) rVal = 0.;
548  Double_t par0[6];
549  par0[0] = rVal/3.;
550  par0[1] = max(0.,(Double_t)(rTime-RISETIME));
551  par0[2] = 4.;
552  par0[3] = 1.6;
553  par0[4] = PEDESTAL*detchannels; // we do not do pedestal subtrastion at this time
554  par0[5] = 0; // slope of the pedestals is initially set to "0"
555  evtsum.evtShape->SetParameters(par0);
556  for(int parn=0; parn<6; parn++) evtsum.evtShape->SetParLimits(parn, par0Min[parn], par0Max[parn]);
557  evtsum.evtShape->SetParLimits(4, PEDESTAL*(detchannels-1), PEDESTAL*(detchannels+1));
558  // fitFunc->cd(chan+1); // shapes[chan]->Draw();
559  // gPad->Modified();
560  evtsum.evtGraph->Fit(evtsum.evtShape, "RQWM", "NQ", 0., (Double_t)NSAMPLES);
561  evtsum.evtShape->GetParameters(evtsum.evtfitpar);
562  evtsum.evtpedestal = (evtsum.evtfitpar[4]+evtsum.evtfitpar[5]*rTime); //
563  evtsum.evtSignal->SetParameters(evtsum.evtfitpar);
564  evtsum.evtSignal->SetParameter(4, 0.);
565  evtsum.evtSignal->SetParameter(5, 0.);
566  evtsum.evtpeak = evtsum.evtSignal->GetMaximum(par0Min[1], par0Max[1]);
567  evtsum.evttime = evtsum.evtSignal->GetMaximumX(par0Min[1], par0Max[1]);
568  evtsum.tChi2 = evtsum.evtShape->GetChisquare()/evtsum.evtShape->GetNDF();
569  // cout<<"<fitTileSignal> Peak "<< evtsum.evtpeak<<" Time "<<evtsum.evttime<<" Chi2 "<<evtsum.tChi2 <<endl;
570  // ev_display->cd(chan+1);
571  // shapes[hlHelper->chan]->Draw("same");
572 
573 }
574 
575 // **************************************************************************
576 
578  hLabHelper * hlHelper = hLabHelper ::getInstance();
579  hlHelper-> fhcl-> cd();
580  TString hn = "Raw data: Events peaking in channel RunId = "; hn += runId; hn += ";Channel #;ADC Peak (events with max in this channel) [counts]";
581  rmax = new TH2F("rmax", hn, TILECHANNELS, 0, TILECHANNELS, 2050, 0., 2050.);
582  hn = "Total Pixel Count with tighter triggering RunId = "; hn += runId; hn += ";HitMultThr;HitAmplThr [trigger counts];Pixels";
583  treff = new TH3F("treff", hn, HITMULTTHRESHOLDS, 0, HITMULTTHRESHOLDS, CHANNELTHRESHOLDS, 0, CHANNELTHRESHOLDS, 1000, 0., 200.);
584  hn = "Total Pixel Count vs impact position RunId = "; hn += runId; hn += ";Calibated X [cm];Calibrated Y [cm];Pixels";
585  pc_imp = new TH3F("pc_imp", hn, 250, 0., 25., 150, 0., 15., 1000, 0, 200.);
586  hn += " Y Fitted";
587  pc_fimp = new TH3F("pc_fimp", hn, 250, 0., 25., 150, 0., 15., 1000, 0, 200.);
588  hn = "Fit to the Pixel Count vs impact position RunId = "; hn += runId; hn += ";Calibated X [cm];Calibrated Y [cm];Pixels";
589  pc_pat = new TH2F("pc_pat", hn, 25, 0., 25., 15, 0., 15.);
590  hn += " Y Fitted";
591  pc_fpat = new TH2F("pc_fpat", hn, 25, 0., 25., 15, 0., 15.);
592  hn = "Raw Fiber sum (R+L), Peak in this fiber RunId = "; hn += runId; hn += ";Fiber #;Fiber ADC Sum (events with max in this fiber) [counts]";
593  rfsum = new TH2F("rfsum", hn, TILEFIBERS, 0, TILEFIBERS, 2050, 0., 2050.);
594  hn = "Raw Total sum, Peak in this fiber RunId = "; hn += runId; hn += ";Fiber #;Event ADC Sum (events with max in this fiber) [counts]";
595  rtsum = new TH2F("rtsum", hn, TILEFIBERS, 0, TILEFIBERS, 2050, 0., 2050.);
596  hn = "Raw Fiber Asymmetry RunId = "; hn += runId; hn += ";Fiber #;Fiber R/L Asymmetry";
597  rfasym = new TH2F("rfasym", hn, TILEFIBERS, 0, TILEFIBERS, 200, -1., 1.);
598  hn = "Raw Event Asymmetry RunId = "; hn += runId; hn += ";Event Raw R/L Event Asymmetry";
599  rtasym = new TH1F("rtasym", hn, 200, -1., 1.);
600  hn = "Raw X RunId = "; hn += runId; hn += ";Event Raw X-coordinate [cm]";
601  rx = new TH1F("rx", hn, 250, 0., 25.);
602  hn = "Raw Y RunId = "; hn += runId; hn += ";Event Raw Y-coordinate [cm]";
603  ry = new TH1F("ry", hn, 150, 0., 15.);
604  hn = "Raw impact position RunId = "; hn += runId; hn += ";Raw X [cm];Raw Y [cm]";
605  rimp = new TH2F("rimp", hn, 250, 0., 25., 150, 0., 15.);
606 
607  hn = "Calibrated data: Fitted Maxima RunId = "; hn += runId; hn += ";Channel #; Calibrated Fit Peak [pixels]";
608  cdata = new TH2F("cdata", hn, TILECHANNELS, 0, TILECHANNELS, 1000, 0., 200.);
609  hn = "Calibrated data: Events peaking in channel RunId = "; hn += runId; hn += ";Channel #;Calibrated Fit Peak (evens with max in this channel) [pixels]";
610  cmax = new TH2F("cmax", hn, TILECHANNELS, 0, TILECHANNELS, 1000, 0., 200.);
611  hn = "Calibrated Fiber sum (R+L), Peak in the fiber RunId = "; hn += runId; hn += ";Fiber #;Calibrated Fiber Sum (events with max in this fiber) [pixels]";
612  cfsum = new TH2F("cfsum", hn, TILEFIBERS, 0, TILEFIBERS, 1000, 0., 200.);
613  hn = "Calibrated Total sum, Peak in this fiber RunId = "; hn += runId; hn += ";Fiber #;Calibrated Total Sum (events with max in this fiber) [pixels]";
614  ctsum = new TH2F("ctsum", hn, TILEFIBERS, 0, TILEFIBERS, 1000, 0., 200.);
615  hn = "Calibrated Fiber Asymmetry RunId = "; hn += runId; hn += ";Fiber #;Fiber R/L Asymmetry (calibrated)";
616  cfasym = new TH2F("cfasym", hn, TILEFIBERS, 0, TILEFIBERS, 200, -1., 1.);
617  hn = "Calibrated Event Asymmetry RunId = "; hn += runId; hn += ";Event R/L Event Asymmetry (calibrated)";
618  ctasym = new TH1F("ctasym", hn, 200, -1., 1.);
619  hn = "Calibrated X RunId = "; hn += runId; hn += ";Calibrated X [cm]";
620  cx = new TH1F("cx", hn, 250, 0., 25.);
621  hn = "Calibrated Y RunId = "; hn += runId; hn += ";Calibrated Y [cm]";
622  cy = new TH1F("cy", hn, 150, 0., 15.);
623  hn = "Fitted Y RunId = "; hn += runId; hn += ";Fitted Y [cm]";
624  fy = new TH1F("fy", hn, 150, 0., 15.);
625  hn = "Calibrated Impact Position RunId = "; hn += runId; hn += ";Calibrated X [cm];Calibrated Y [cm]";
626  cimp = new TH2F("cimp", hn, 250, 0., 25., 150, 0., 15.);
627  hn = "Calibrated Pixel Count (Y) vs X-impact RunId = "; hn += runId; hn +=";Calibrated X [cm];Calibrated Total Sum [pixels]";
628  cx_pc = new TH2F("cx_pc", hn, 250, 0., 25., 1000, 0., 200.);
629  hn = "Calibrated Pixel Count (Y) vs Y-impact RunId = "; hn += runId; hn +=";Calibrated Y [cm];Calibrated Total Sum [pixels]";
630  cy_pc = new TH2F("cy_pc", hn, 150, 0., 15., 1000, 0., 200.);
631  hn = "Calibrated Pixel Count (Y) vs Fitted Y-impact RunId = "; hn += runId; hn +=";Fitted Y [cm];Calibrated Total Sum [pixels]";
632  fy_pc = new TH2F("fy_pc", hn, 150, 0., 15., 1000, 0., 200.);
633  hn = "Calibrated Weighted Impact Position RunId = "; hn += runId; hn +=";Calibrated X [cm];Calibrated Y [cm]";
634  cimpW = new TH2F("cimpW", hn, 250, 0., 25., 150, 0., 15.);
635 
636  // Trigger related data
637  // Pixel count above threshold vs total pixel count (based on calibrated data)
638  hn = "Uncalibrated trigger sum [trigger counts] RunId = "; hn += runId; hn += runId; hn += ";Trigger hits;";
639  trhits = new TH1F("trhits", hn, 500, 0., 500.);
640  hn = "Number of hits in triggered events vs channel threshold(Y) and total trigger sum (X) RunId = "; hn += runId; hn += ";TotalSum [trigger counts];Trigger THr [trigger counts]";
641  hits_tpc = new TH2F("hits_tpc",hn, 500, 0., 100., CHANNELTHRESHOLDS, 0, CHANNELTHRESHOLDS);
642 
643  //
644  // debugging muon impact computations
645  // TH2 * XvsSl, * XY; // X value vs assumption about slope in the X vs Asymmetry
646  // TH1 * y0, *y1, *y2; // Parameters from the tile-Y fit
647  Y0 = new TH1F("Y0", "Y-coordinate fit P(0)", 200, 0., 200.);
648  Y1 = new TH1F("Y1", "Y-coordinate fit P(1)", 100, 0., 15.);
649  Y2 = new TH1F("Y2", "Y-coordinate fit P(2)", 100, 0., 10.);
650  y_yChi2 = new TH2F("y_yChi2", "yFit: Chi2 at different fitted Y values", 150,0.,15., 100,0.,50.);
651  s_y_Chi2 = new TH2F("s_y_Chi2", "Chi2 of tile signal vs Chi2 of Y coordinate", 100, 0., 500., 100, 0., 50.);
652  y_ys = new TH2F("y_ys", "yFit sigma vs fitted Y", 150,0.,15. ,100, 0., 5.);
653  yCleaned = new TH1F("yCleaned", "Fitted Y after event rejection (fit sigma <4.5)", 150,0.,15.);
654  yKept = new TH1F("yKept", "Fitted Y after event rejection (s<4.5, rejectcode=0)", 150,0.,15.);
655  XvsSl = new TH2F("XvsSl", "X-Coordinate computed using different asymmentry slopes", 275, -15., 40., 20, 0., 0.5);
656  XY = new TH2F("XY", "Muon Impact: x vs Y. Fit Y vs Best X", 225, -15., 40., 75, 0., 15.);
657  td_r_l = new TH2F("td_r_l", "R/L Timing difference in hit fiber vs PixelCount in Hit Fiber", 200, -1, 1., 200, 0., 100.);
658  td_t_tw = new TH3F("td_t_tw", "Tile-to-tower time difference(X) vs Pixel Counts in tile(Y) and tower(Z)", 200, -1. ,1., 100, 0., 100., 100, 0., 100.);
659  trcode = new TH1F("trcode", "Tile reject codes ", 1000, 0., 1000.);
660  yc_rcode = new TH2F("yc_rcode","Tile reject code vs Cleaned Y ", 150, 0., 15., 1000, 0., 1000.);
661 
662 }
663 // **************************************************************************
664 
666  // test fit results in individual channels, compare to fit of the tile sum
667  // hLabHelper * hlHelper = hLabHelper ::getInstance();
668  hLabHelper * hlHelper = hLabHelper::getInstance();
669  evtsum.rejectCode = 0;
670  for(int ich = 0; ich< TILECHANNELS; ich++) {if(evtsum.chi2[ich]>10.) evtsum.rejectCode ++;}
671  for(int ich = 0; ich< TILECHANNELS; ich++) {if(abs(evtsum.times[ich]-evtsum.evttime)>2.) evtsum.rejectCode += 10;}
672  for(int ich = 0; ich< TILECHANNELS; ich++) {if(hlHelper->rawPeak[ich]<2.) evtsum.rejectCode += 100;}
673  return evtsum.rejectCode;
674 }
675 
676 
677 // **************************************************************************
678 
680  hLabHelper * hlHelper = hLabHelper ::getInstance();
681  hlHelper->getFileLists();
682  // rootfile * rfile;
683  list<rootfile>::iterator next;
684  for (next = hlHelper->roots.begin(); next != hlHelper->roots.end(); ++next){
685  ;
686  }
687 }