File indexing completed on 2023-03-17 10:48:39
0001
0002
0003
0004
0005
0006
0007 #include <iostream>
0008 #include <fstream>
0009 #include <cmath>
0010 #include <fcntl.h>
0011
0012 #if !defined(__CINT__)
0013 #include <TH2.h>
0014 #include <TF1.h>
0015 #include <TNtuple.h>
0016 #endif
0017
0018
0019
0020 TNtuple * ntuple;
0021
0022 int make_ntuple_data() {
0023
0024
0025
0026 ifstream in_file;
0027 char filename[80] = "phCalibration_C0.dat";
0028 in_file.open(filename, ios::in );
0029
0030 cout << in_file.eof() << " " << in_file.bad() << " "
0031 << in_file.fail() << " " << in_file.good()<<endl;
0032
0033 if (in_file.fail()) {
0034 cout << " File not found " << endl;
0035 return(1);
0036 }
0037 cout << " file opened : " << filename << endl;
0038
0039 char line[500];
0040 for (int i = 0; i < 3; i++) {
0041 in_file.getline(line, 500,'\n');
0042 cout<<line<<endl;
0043 }
0044
0045 const int nvar=13;
0046 char *chvar = "d0:d1:d2:d3:d4:d5:d6:d7:d8:d9:roc:col:row";
0047 tfile = new TFile ( "phCalibration_C0.root" , "RECREATE" );
0048 ntuple = new TNtuple("ntuple","NTUPLE",chvar);
0049 float p[nvar];
0050
0051 float count[10] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
0052 float sum[10] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
0053 float par[10];
0054 int rocid=0,colid,rowid;
0055 string name;
0056 string str[10];
0057
0058
0059
0060 for(int i=0;i<(52*80);i++) {
0061
0062
0063
0064
0065
0066
0067
0068 in_file >> str[0] >> str[1] >> str[2] >> str[3] >> str[4]
0069 >> str[5] >> str[6] >> str[7] >> str[8] >> str[9]
0070 >> name >> colid >> rowid;
0071
0072 if (in_file.fail()) {
0073 cout << "Cannot read data file" << endl;
0074 return(1);
0075 }
0076 if ( in_file.eof() != 0 ) {
0077 cout<< " end of file " << endl;
0078 break;;
0079 }
0080
0081 #ifdef PRINT
0082 cout << " line " << i <<" ";
0083 for(int i1 =0;i1<10;i1++) { cout<<str[i1]<<" "; }
0084 cout<<colid<<" "<<rowid<<endl;
0085 #endif
0086
0087
0088 for(int i2 =0;i2<10;i2++) {
0089 if( str[i2] == "N/A" ) {
0090
0091 p[i2]=-9999.;
0092 } else {
0093 p[i2]=atof(str[i2].c_str());
0094 count[i2]++;
0095 sum[i2] += p[i2];
0096 }
0097 }
0098
0099 p[10]=float(rocid);
0100 p[11]=float(colid);
0101 p[12]=float(rowid);
0102 ntuple->Fill(p);
0103
0104
0105
0106
0107
0108 }
0109
0110
0111
0112
0113 in_file.close();
0114 cout << " Close input file " << endl;
0115 tfile->Write();
0116 tfile->Close();
0117
0118 for(int i2 =0;i2<10;i2++) {
0119 par[i2] = sum[i2]/count[i2];
0120 cout<<par[i2]<<" ";
0121 }
0122 cout<<endl;
0123
0124 return(0);
0125 }
0126
0127
0128
0129