Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-08 08:15:48

0001 /* 

0002  *  \class TPNCor

0003  *

0004  *  \author: Julie Malcles - CEA/Saclay

0005  */
0006 
0007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/TPNCor.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include <sstream>
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <fstream>
0013 
0014 #include <cmath>
0015 
0016 using namespace std;
0017 
0018 //ClassImp(TPNCor)

0019 
0020 // Constructor...

0021 TPNCor::TPNCor(string filename) {
0022   // Initialize

0023 
0024   isFileOK = 0;
0025 
0026   for (int i = 0; i < iSizePar; i++) {
0027     for (int j = 0; j < iSizeGain; j++) {
0028       corParams[j][i] = 0.0;
0029     }
0030   }
0031 
0032   // Get values from file

0033 
0034   FILE *test;
0035   test = fopen(filename.c_str(), "r");
0036   int gain;
0037   double aa, bb, cc;
0038   std::ifstream fin;
0039 
0040   if (test) {
0041     fclose(test);
0042     fin.open(filename.c_str());
0043     while (fin.peek() != EOF) {
0044       fin >> gain >> aa >> bb >> cc;
0045 
0046       if (gain < iSizeGain) {
0047         corParams[gain][0] = aa;
0048         corParams[gain][1] = bb;
0049         corParams[gain][2] = cc;
0050       }
0051     }
0052     isFileOK = 1;
0053     fin.close();
0054   } else {
0055     cout << " No PN linearity corrections file found, no correction will be applied " << endl;
0056   }
0057 }
0058 
0059 // Destructor

0060 TPNCor::~TPNCor() {}
0061 
0062 double TPNCor::getPNCorrectionFactor(double val0, int gain) {
0063   double cor = 0;
0064   double corr = 1.0;
0065   double pn = val0;
0066   double xpn = val0 / 1000.0;
0067 
0068   if (isFileOK == 0)
0069     return 1.0;
0070 
0071   if (gain > iSizeGain)
0072     cout << "Unknown gain, gain has to be lower than " << iSizeGain << endl;
0073 
0074   if (gain < iSizeGain) {
0075     cor = xpn * (corParams[gain][0] + xpn * (corParams[gain][1] + xpn * corParams[gain][2]));
0076 
0077     if (pn != 0)
0078       corr = 1.0 - cor / pn;
0079     else
0080       corr = 1.0;
0081   }
0082 
0083   return corr;
0084 }