StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
avrPMB.C
1 // averages mip peak position for BPM tubes
2 
3  float x1=1+0.05, x2=x1+60;
4 int nbx=10*60;
5 TH1F *hBPMg=new TH1F("bpmG","Average MIP position per PMB, err=RMS; X= PMB + pmt/10; MIP (adc)",nbx,x1,x2);
6 TH1F *hBPMu=new TH1F("bpmU","Number of used pixels per PMB; X= PMB + pmt/10; number of tiles",nbx,x1,x2);
7 TH1F *hBPMq=new TH1F("bpmQ","QA error flag per PMB (Y=0 is good); X= PMB_ID + pmt_ID/10;error code",nbx,x1,x2);
8 
9 FILE *fcsv=0;
10 
11 final() {
12  fcsv=fopen("bprsPMBmipGain.csv","w");
13  fprintf(fcsv,"average MIP ADC over 16 (or less) working BPRS tiles; ver=1.6\n");
14  fprintf(fcsv,"PMB,pmt, QAflag, nUsedPix, avrMIP (adc), rmsMIP (adc),PDF page # , all mapped softIDs\n");
15 
16  for(int b=1; b<=60;b++)
17  avrPMB(b);
18  fprintf(fcsv,"\nQAflag=0x0 : good MIP signal in this pmt \n");
19  fprintf(fcsv,"QAflag bit=0x1 : no histo \n");
20  fprintf(fcsv,"QAflag bit=0x2 : too few working pixels \n");
21  fprintf(fcsv,"QAflag bit=0x4 : too narrow RMS \n");
22  fprintf(fcsv,"QAflag bit=0x8 : too low mean ADC \n");
23  fclose(fcsv); fcsv=0;
24 
25  c=new TCanvas("aa1","aa1",1300,800);
26  c->Divide(1,3);
27  gStyle->SetOptStat(10);
28  c->cd(1); hBPMg->Draw(); gPad->SetGrid();
29  c->cd(3); hBPMu->Draw(); gPad->SetGrid();
30  c->cd(2); hBPMq->Draw(); gPad->SetGrid();
31  hBPMg->SetAxisRange(0.,100.); hBPMg->SetMarkerColor(kRed); hBPMg->SetMarkerStyle(5);
32  hBPMu->SetAxisRange(0.,100.); hBPMu->SetFillColor(kBlue);hBPMu->SetLineColor(kBlue);
33  hBPMq->SetAxisRange(0.,100.); hBPMq->SetFillColor(kRed);hBPMq->SetLineColor(kRed);
34 }
35 
36 
37 //=================================
38 avrPMB(int box0=2) {
39  gStyle->SetOptStat(1110);
40  gStyle->SetOptFit(1);
41  gStyle->SetPalette(1,0);
42  // get mapping of softID to this PMT
43  // buildSoftList(box,pmt);
44 
45  // get spectra for every BPRS pixel
46  char *fnameO="calib-nov-21-2008/barrelMipSpectV6ok.hist.root";
47  fd=new TFile(fnameO); assert(fd->IsOpen());
48  printf("Read %s\n", fd->GetName());
49  //fd->ls();
50 
51  float cut_nUsed=5;
52  float cut_adcL=2.5;
53  float cut_rms=0.5;
54 
55  int box1=box0, box2=box0;
56  for(int box=box1; box<=box2; box++) {
57  c=new TCanvas("aa","aa",800,500); c->Divide(4,2);
58  c->cd(8); hBPMg->Draw();
59  c->cd(7); hBPMu->Draw();
60  c->cd(6); hBPMq->Draw();
61  hBPMg->SetAxisRange(box,box+1.);
62  hBPMu->SetAxisRange(box,box+1.);
63  hBPMq->SetAxisRange(box,box+1.);
64  char tt[100];
65  for( int pmt=1; pmt<=5; pmt++) {
66  sprintf(tt,"gainBPM%d_%d",box,pmt);
67  printf(" get:%s:\n",tt);
68  TH1F *h=fd->Get(tt);
69  if(h==0) {
70  if(fcsv) fprintf("%d,%d, 0,1, noHisto",box,pmt);
71  printf("missing=%s \n",tt); continue;}
72  float xVal=box+pmt/10.;
73  c->cd(pmt);
74  h->Draw(); h->SetMaximum(10);
75  float nUsed=h->GetEntries();
76  hBPMu->Fill(xVal,nUsed);
77  float mean=h->GetMean();
78  float rms=h->GetRMS();
79  int flag=0;
80  if(nUsed<cut_nUsed) flag+=2;
81  if(rms<cut_rms) flag+=4;
82  if(mean<cut_adcL) flag+=8;
83  if(flag)hBPMq->Fill(xVal,flag);
84  if(flag==0) { int bin=hBPMg->FindBin(xVal);
85  hBPMg->SetBinContent(bin,mean);
86  hBPMg->SetBinError(bin,rms);
87  }
88  if(fcsv) {
89  fprintf(fcsv,"%d,%d,%d, %d, %.2f, %.2f, %2d,",box,pmt,flag,nUsed,mean,rms,5*(box-1)+pmt);
90  printSoftList(box,pmt);
91  }
92  }
93  } // LOOP over boxes
94 
95 }
96 
97 //------------------------
98 void printSoftList(int box=11, int pmt=1) {
99  fd1=new TFile("calib-nov-8-2008/map-softID-bprsPmt-Rory.root"); assert(fd1->IsOpen());
100  // printf("Opened: %s\n",fd1->GetName());// fd1->ls();
101  TH1I * mapBprsPmt=(TH1I*) fd1->Get("bprsPmt"); assert(mapBprsPmt);
102  //mapBprsPmt->Draw();
103 
104  int y= box*10+pmt;
105  for(int b=1;b<=4800;b++) {
106  if(y!=(int)mapBprsPmt->GetBinContent(b)) continue;
107  if(fcsv)fprintf(fcsv,"%d ",b);
108  }
109  if(fcsv) fprintf(fcsv,"\n");
110  fd1->Close();
111 }