00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020
00021
00022
00023
00024
00026
00027 #include <Stiostream.h>
00028 #include "Stiostream.h"
00029 #include <stdio.h>
00030 #include <unistd.h>
00031 #include <errno.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #include <fcntl.h>
00035 #include <math.h>
00036 #include <string.h>
00037
00038 #include "TFile.h"
00039 #include "TH1.h"
00040 #include "TH2.h"
00041 #include "TH3.h"
00042 #include "TNtuple.h"
00043
00044 #include "St_DataSetIter.h"
00045
00046 #include "StDAQMaker/StDAQReader.h"
00047 #include "StDaqLib/TPC/fee_pin.h"
00048
00049 #include "StTpcFEEGainCalibMaker.h"
00050 #include "StTpcCalibSetup.h"
00051 #include "StTpcCalibSector.h"
00052
00053 ClassImp(StTpcFEEGainCalibMaker)
00054
00055
00056
00057
00058 StTpcFEEGainCalibMaker::StTpcFEEGainCalibMaker(const char *aMakerName,
00059 const StTpcCalibSetup* aSetup)
00060 :
00061 StMaker(aMakerName),
00062 mSetup(aSetup)
00063 {
00064
00065 }
00066
00067
00068
00069
00070 StTpcFEEGainCalibMaker::~StTpcFEEGainCalibMaker(){
00071 delete [] mTpcCalibSector;
00072 }
00073
00074
00075
00076 Int_t StTpcFEEGainCalibMaker::Init(){
00077
00078
00079
00080 int tNumberOfSector=24;
00081
00082 static int tNPadAtRow[45]={
00083 88,96,104,112,118,126,134,142,150,158,166,174,182,
00084 98,100,102,104,106,106,108,110,112,112,114,116,118,120,122,122,
00085 124,126,128,128,130,132,134,136,138,138,140,142,144,144,144,144};
00086 ifstream* tBadFile = new ifstream(mSetup->getBadFileName());
00087 if(tBadFile->fail()) {
00088 cout << "Couldn't open bad file "
00089 << mSetup->getBadFileName() << endl
00090 << "Please run this macro with CalibType=1 before" << endl;
00091 return kStFatal;
00092 }
00093 ifstream* tDeadFile = new ifstream(mSetup->getDeadFileName());
00094 if(tDeadFile->fail()) {
00095 cout << "Couldn't open bad file "
00096 << mSetup->getDeadFileName() << endl
00097 << "Please run this macro with CalibType=2 before" << endl;
00098 return kStFatal;
00099 }
00100
00101 mTpcCalibSector = new StTpcCalibSector*[tNumberOfSector];
00102 for(int tiSect=0;
00103 tiSect<tNumberOfSector;
00104 tiSect++){
00105 mTpcCalibSector[tiSect]= new StTpcCalibSector(mSetup,(tiSect+1),
00106 tNPadAtRow);
00107 mTpcCalibSector[tiSect]->readBadTable(tBadFile);
00108 mTpcCalibSector[tiSect]->readDeadTable(tDeadFile);
00109 }
00110 tBadFile->close();
00111 tDeadFile->close();
00112 delete tBadFile;
00113
00114 return kStOK;
00115 }
00116
00117
00118
00119
00120 Int_t StTpcFEEGainCalibMaker::Make(){
00121
00122 int tNumberOfSector=24;
00123
00124 static St_DataSet * tDataSet=GetDataSet("StDAQReader");
00125
00126 static StDAQReader *tDAQReader=(StDAQReader*)(tDataSet->GetObject());
00127
00128 static StTPCReader *tZSupReader=tDAQReader->getTPCReader();
00129
00130 if(!tZSupReader) {cout << "Coudln't get the reader " << endl;return kStWarn;}
00131 for(int tiSect=0;
00132 tiSect< tNumberOfSector;
00133 tiSect++){
00134 mTpcCalibSector[tiSect]->updateGain(tZSupReader);
00135 }
00136
00137 return kStOK;
00138 }
00139
00140 void StTpcFEEGainCalibMaker::PrintInfo(){
00141 printf("**************************************************************\n");
00142 printf("* $Id: StTpcFEEGainCalibMaker.cxx,v 1.8 2007/04/28 17:57:17 perev Exp $\n");
00143 printf("**************************************************************\n");
00144 if (Debug()) StMaker::PrintInfo();
00145 }
00146
00147 void StTpcFEEGainCalibMaker::CalcElectronicConvertor(int** aPadToFeeConvertor,
00148 int** aPadToRDOConvertor){
00149
00150
00151 for(int tiFee=0;tiFee<182;tiFee++){
00152 for(int tiPin=0;tiPin<32;tiPin++){
00153 if(row_vs_fee[tiFee][tiPin]!=0 && pad_vs_fee[tiFee][tiPin]!=0){
00154 aPadToFeeConvertor[(row_vs_fee[tiFee][tiPin]-1)]
00155 [(pad_vs_fee[tiFee][tiPin]-1)]=(tiFee+1);
00156 aPadToRDOConvertor[(row_vs_fee[tiFee][tiPin]-1)]
00157 [(pad_vs_fee[tiFee][tiPin]-1)]=
00158 rdo_vs_fee[tiFee][tiPin];
00159 }
00160 }
00161 }
00162 }
00163
00164 Int_t StTpcFEEGainCalibMaker::Finish(){
00165 cout << "StTpcFEEGainCalibMaker::Finish()" << endl;
00166
00167
00168 int tNumberOfSector=24;
00169
00170 TFile *tHFile = new TFile(mSetup->getRootOutFileName(),"recreate");
00171 ofstream* tCalibFile = new ofstream(mSetup->getGainCalibFileName());
00172
00173 for(int tiSect=0;
00174 tiSect<tNumberOfSector;
00175 tiSect++){
00176 mTpcCalibSector[tiSect]->calcGainCoeficient();
00177 mTpcCalibSector[tiSect]->writeGainHisto();
00178 mTpcCalibSector[tiSect]->writeCalibCoefTable(tCalibFile);
00179
00180 }
00181
00182 tHFile->Close();
00183 tCalibFile->close();
00184 return kStOK;
00185 }
00186
00187
00188