Ejemplo n.º 1
0
       void convert (int begin, int end,char file[]){
           ifstream fin;   // CAS 
           static integer count=0;
           uinteger length;
           CASblock buffer;
           ShuttlePar block;
           if(begin==0){
              HBNT(1,"CAS Data"," ");
              HBNAME(1,"CASData",(int*)(&block),"StationR,StationTheta,StationPhi,GrMedPhi,StationYaw,StationPitch,StationRoll,StationSpeed,SunR,SunTheta,SunPhi,Time:I");

           }
           // open fin;
           AString fname(CAS_dir);
           fname+="/";
           fname+=file;
           fin.open(fname);
           if(fin){
              cout <<"convert-I-Openfile "<<fname<<" ("<<++count<<")"<<endl;
              while(!fin.eof()){
                fin.read((char*)(&length),sizeof(integer));
                fin.seekg(fin.tellg()+20*sizeof(integer));
                fin.read((char*)(&(buffer.CASmsg)),length-20*sizeof(integer)); 
                int ret=Cas2Shuttle(buffer,block);
                if(ret>0){
                   if(updShuttle(block,0))HFNT(1);
                 }
                 else cerr<<"Error no "<< ret <<" decoding block in file "<<fname<<endl;
              }
              fin.close();
           }
           else{
             cerr <<"convert-E-UnableToOpenfile "<<fname<<endl;
             return;
           }
           if(end==0){
                // last file 
                // close everything
                updShuttle(block,1);
                int ntuple_entries;
                HNOENT(1, ntuple_entries);
                cout << " Closing CAS ntuple  with "<< ntuple_entries 
                << " events" << endl;
                char hpawc[256]="//PAWC";
                HCDIR (hpawc, " ");
                char houtput[9]="//output";
                HCDIR (houtput, " ");
                integer ICYCL=0;
                HROUT (1, ICYCL, " ");
                HREND ("output");
                CLOSEF(1);


           }
      
       }
Ejemplo n.º 2
0
int test_24_end(int pass)
  {
  int      j, hid, icfeb, ilayer, isegment, n, noent;
  float    par[3], sigpar[3];
  float    avg_all, avg[NLAYER][5];

/* Fit the cluster sum distribution in each section with the Landau function
 * (two-parameter), and save the average Landau peak in each HV segment.
 */
  fprintf(fp, "\nLandau fit parameters, errors, and chisq\n");
  for (ilayer = 0; ilayer < NLAYER; ilayer++)
    {
    for (isegment = 0; isegment < nsegments; isegment++)
      {
      avg[ilayer][isegment] = 0;
      n = 0;
      for (icfeb = 0; icfeb < ncfebs; icfeb++)
	{
        j = ncfebs * isegment + icfeb;
        hid = 100 * (ilayer + 1) + 10 * (isegment + 1) + (icfeb + 1);
        HNOENT(hid, noent);
        if (noent > 0)
	  {
          landau_fit_(&hid, par, sigpar, &chisq[ilayer][j]);
          peak[ilayer][j] = par[1];

          fprintf(fp, "  L%d seg%d cfeb%d  %6.0f %6.0f %6.0f  %4.0f %4.0f "
		  "%4.0f  %6.2f\n", ilayer+1, isegment+1, icfeb+1, par[0], par[1],
		  par[2], sigpar[0], sigpar[1], sigpar[2], chisq[ilayer][j]);

          avg[ilayer][isegment] += peak[ilayer][j];
          n += 1;

          HFILL(24, peak[ilayer][j], 0.0, 1.0);
          HFILL(25, chisq[ilayer][j], 0.0, 1.0);
	  }
        else
	  {
          peak[ilayer][j] = 0;
          chisq[ilayer][j] = 0;
	  }
	}

      if (n > 0) avg[ilayer][isegment] /= n;
      else avg[ilayer][isegment] = 0.;
      }
    }

/* Equalization logic */
/* Assume Landau peak p = exp(c * (volts-2683)) as a typical dependence, where
 * c = ln(2)/130 (gain increases by a factor of two every 130 volts) = .00533. 
 * To first approx, dv = dp / (c * p). Find dv to make all segments peak at 
 * PNOM adc counts.
 * From HV scan of ME234/2-001, we find p = exp(5.61 * (volts - 2470)), and
 * c = ln(2)/124 = .00561.
 */
  for (ilayer = 0; ilayer < NLAYER; ilayer++)
    {
    for (isegment = 0; isegment < nsegments; isegment++)
      {
      if (avg[ilayer][isegment] > 0) dv[ilayer][isegment] = 
				       (PNOM - avg[ilayer][isegment]) / (C * avg[ilayer][isegment]); 
      else dv[ilayer][isegment] = 9990.;
      }
    }

  for (ilayer = 0; ilayer < NLAYER; ilayer++)
    {
    avg_all = 0;
    n = 0;
    for (isegment = 0; isegment < nsegments; isegment++)
      {
      if (avg[ilayer][isegment] > 1.)
	{
        avg_all += avg[ilayer][isegment];
        n++;
	}
      }
    if (n > 0)
      {
      avg_all /= n;
      dv_all[ilayer] = (PNOM - avg_all) / (C * avg_all);
      }
    else dv_all[ilayer] = 9990.;
    }

  return 0;
  }