StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bitshift.C
1 static const int Maxdet=4;
2 static const int Maxchl=578;
3 static const int Maxchs=288;
4 static const int Maxitr=20;
5 
6 void bitshift(int y=2015){
7  TFile *f = TFile::Open("DB.root");
8  TTree *t = (TTree*)f->Get("tr");
9  int year,iter,nstb,chan,bsft,offs,run,hts;
10  t->SetBranchAddress("year",&year);
11  t->SetBranchAddress("iter",&iter);
12  t->SetBranchAddress("nstb",&nstb);
13  t->SetBranchAddress("chan",&chan);
14  t->SetBranchAddress("bitshift",&bsft);
15  t->SetBranchAddress("offset",&offs);
16  t->SetBranchAddress("firstRun",&run);
17  t->SetBranchAddress("firstRunHTS",&hts);
18 
19  short bs[Maxitr][Maxdet][Maxchl];
20  int nline[Maxitr];
21  int runs[Maxitr][2];
22  memset(bs,0,sizeof(bs));
23  memset(runs,0,sizeof(runs));
24  memset(nline,0,sizeof(nline));
25 
26  Long64_t n = t->GetEntries();
27  cout << "n="<<n<<endl;
28  int maxiter=0;
29  for (Long64_t i=0; i<n; i++) {
30  t->GetEntry(i);
31  if(year==y){
32  if(maxiter<=iter) maxiter=iter;
33  printf("%4d %2d %2d %3d %3d %3d %4d %8d %8d\n",
34  i,year,iter,nstb,chan,bsft,offs,run,hts);
35  bs[iter][nstb-1][chan-1]=bsft;
36  runs[iter][0]=run;
37  runs[iter][1]=hts;
38  nline[iter]++;
39  }
40  }
41  printf("found up to iter=%d for run %d \n",maxiter,y);
42 
43  char file[100];
44  for(int it=0; it<=maxiter; it++){
45  if(nline[it]==0) continue;
46  sprintf(file,"fmsBitShiftGain_y%d_i%d_run%d.txt",y,it,runs[it][0]);
47  FILE* fp;
48  int nn=0, nup=0, ndn=0, nz=0;
49  if(fp=fopen(file,"w")){
50  printf("Writing %s\n",file);
51  for(int d=0; d<Maxdet; d++){
52  // printf("d=%d Maxdet=%d\n",d,Maxdet);
53  int max=Maxchl;
54  if(d>=2) max=Maxchs;
55  for(int c=0; c<max; c++){
56  //printf("%4d %2d %2d %3d %3d %3d\n",
57  // nn,y,it,d+8,c+1,bs[d][c]);
58  fprintf(fp,"%2d %3d %2d\n",d+8,c+1,bs[it][d][c]);
59  nn++;
60  if(bs[it][d][c]>0) nup++;
61  if(bs[it][d][c]<0) ndn++;
62  if(bs[it][d][c]==0) nz++;
63  }
64  }
65  fclose(fp);
66  printf("Closing %s\n",file);
67  printf("N=%d N_zero=%d N_positive=%d N_negative=%d\n",nn,nz,nup,ndn);
68  }else{
69  printf("Cannot openg %s\n",file);
70  }
71  }
72 }