Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:25

0001 #include <iostream>
0002 #include <fstream>
0003 #include <cmath>
0004 #include <fcntl.h>
0005 
0006 #if !defined(__CINT__)
0007 #include <TH2.h>
0008 #include <TF1.h>
0009 #include <TNtuple.h>
0010 #endif
0011  
0012 
0013 using namespace std;
0014 
0015 //#define PRINT 
0016 
0017 TNtuple *  ntuple;  // to see outside the macro.
0018 
0019 int make_ntuple_lin() {   // run with .x
0020 //int main() {   // run with .L & main()
0021 
0022 // INput file 
0023   ifstream in_file;  // data file pointer
0024   char filename[80] = "phCalibrationFit_C0.dat";
0025   
0026   in_file.open(filename, ios::in ); // in C++
0027   if (in_file.bad()) {
0028     cout << " File not found " << endl;
0029     return(1); // signal error
0030   }
0031   cout << " file opened : " << filename << endl;
0032 
0033   char line[500];
0034   for (int i = 0; i < 3; i++) {
0035     in_file.getline(line, 500,'\n');
0036     cout<<line<<endl;
0037   }
0038   // Create NTuple 
0039   const int nvar=5;
0040   char *chvar = "p0:p1:roc:col:row";
0041   tfile = new TFile ( "phCalibrationFit_C0.root" , "RECREATE" );
0042   ntuple = new TNtuple("ntuple","NTUPLE",chvar);
0043   float p[nvar];
0044   
0045 
0046  const int max_inputs = 10000;
0047  float par0,par1,par2,par3;
0048  int rocid,colid,rowid;
0049  string name;
0050  rocid=0;
0051 
0052  // Read MC tracks
0053  for(int i=0;i<(52*80);i++)  { // loop over pixels
0054  //for(int i=0;i<10;i++)  { // loop over pixels
0055    
0056    //in_file >> par0 >> par1 >> par2 >> par3 >> name >> colid 
0057    //   >> rowid;
0058    in_file >> par0 >> par1 >> name >> colid >> rowid;
0059    if (in_file.bad()) { // check for errors
0060      cerr << "Cannot read data file" << endl;
0061      return(1);
0062    }
0063    if ( in_file.eof() != 0 ) {
0064      cerr << in_file.eof() << " " << in_file.gcount() << " " 
0065       << in_file.fail() << " " << in_file.good() << " end of file " 
0066       << endl;
0067      break;;
0068    }
0069    
0070    //cout <<" line "<<i<<" "<<par0<<" "<<par1<<" "<<colid<<" "<<rowid<<endl;
0071    //cout <<i<<endl;
0072    
0073    p[0]=par0;
0074    p[1]=par1;
0075    //p[2]=par2;
0076    //p[3]=par3;
0077    p[2]=float(rocid);
0078    p[3]=float(colid);
0079    p[4]=float(rowid);
0080    ntuple->Fill(p); 
0081 
0082  }   
0083 
0084 /* Visualization */
0085  //ntuple->Draw("adc1:delay"); 
0086 
0087 in_file.close();
0088 cout << " Close input file " << endl;
0089 
0090 tfile->Write();
0091 tfile->Close();
0092 
0093 return(0);
0094 }
0095 
0096 
0097 
0098