35int main(
int argc,
char* argv[] ) {
43 sscanf( strcal,
"%d", &fgCal );
45 else if ( argc > 1 ) { jobname = argv[1]; }
48 cout <<
"bad argument" << endl;
51 if ( fgCal <= 0 ) cout <<
"do not calibrate " << endl;
54 string strJob = jobname;
55 cout <<
"strJob: " << strJob << endl;
56 string::size_type ilast = strJob.find_last_of(
"/" );
57 if ( string::npos != ilast ) { path = strJob.substr( 0, ilast ); }
64 ifstream fjob( jobname );
65 if ( !fjob.is_open() )
67 cout <<
"ERROR: can not read jobOption: " << jobname << endl;
72 cout <<
"Open jobOption: " << jobname << endl;
73 while ( getline( fjob, str ) )
75 if ( str.find(
"//", 0 ) != string::npos ) {
continue; }
76 else if ( str.find(
"CalibRootCnvSvc.Mdcrootfile", 0 ) != string::npos )
78 string::size_type i1 = str.find_first_of(
"\"" );
79 string::size_type i2 = str.find_last_of(
"\"" );
80 constname = str.substr( i1 + 1, i2 - i1 - 1 );
82 else if ( str.find(
"MdcCalibAlg.ConfigFile", 0 ) != string::npos )
84 string::size_type i1 = str.find_first_of(
"\"" );
85 string::size_type i2 = str.find_last_of(
"\"" );
86 confname = str.substr( i1 + 1, i2 - i1 - 1 );
88 else if ( str.find(
"MdcCalibAlg.MdcCalFlg", 0 ) != string::npos )
90 string::size_type i1 = str.find_first_of(
"=" );
91 string::size_type i2 = str.find_last_of(
";" );
92 strtmp = str.substr( i1 + 1, i2 - i1 - 1 );
93 sscanf( strtmp.c_str(),
"%d", &calType );
99 pGeom =
new MdcCosGeom(
"/home/bes/wulh/document/wireconf.txt",
100 "/home/bes/wulh/calibConst/MdcAlignPar_ini.txt" );
104 for ( lay = 0; lay < 15; lay++ )
gNEntr[lay] = 1;
105 for ( lay = 15; lay < 43; lay++ )
gNEntr[lay] = 2;
110 ifstream fconfig( confname.c_str() );
111 if ( !fconfig.is_open() )
113 cout <<
"ERROR: can not read config file" << endl;
118 cout <<
"Open config file: " << confname << endl;
119 while ( fconfig >> strconfig )
121 if (
'#' == strconfig[0] ) { getline( fconfig, strcomment ); }
122 else if (
"TimeShift" == strconfig ) { fconfig >>
gTimeShift; }
123 else if (
"TesMin" == strconfig ) { fconfig >>
gTesMin; }
124 else if (
"TesMax" == strconfig ) { fconfig >>
gTesMax; }
125 else if (
"FlagIniCalConst" == strconfig ) { fconfig >>
gFgIniCalConst; }
126 else if (
"FlagUpdateTmInPreT0" == strconfig ) { fconfig >>
gPreT0SetTm; }
127 else if (
"InitT0" == strconfig ) { fconfig >>
gInitT0; }
128 else if (
"T0Shift" == strconfig ) { fconfig >>
gT0Shift; }
129 else if (
"TminFitChindf" == strconfig ) { fconfig >>
gTminFitChindf; }
130 else if (
"TmaxFitChindf" == strconfig ) { fconfig >>
gTmaxFitChindf; }
131 else if (
"ResidualType" == strconfig ) { fconfig >>
gResiType; }
132 else if (
"UpdateSigma" == strconfig ) { fconfig >>
gCalSigma; }
133 else if (
"FixXtC0" == strconfig ) { fconfig >>
gFixXtC0; }
134 else if (
"RawTimeFitRange" == strconfig )
136 for ( lay = 0; lay <
NLAYER; lay++ )
147 TObjArray* hlist =
new TObjArray( 0 );
149 if ( 0 == calType ) pcal =
new IniCalib();
150 else if ( 1 == calType ) pcal =
new PreXtCalib();
151 else if ( 2 == calType ) pcal =
new PreT0Calib();
152 else if ( 3 == calType ) pcal =
new XtCalib();
153 else if ( 4 == calType ) pcal =
new GrXtCalib();
155 else if ( 5 == calType ) pcal =
new T0Calib();
156 else if ( 8 == calType ) pcal =
new QtCalib();
159 cout <<
"Error CalibType" << endl;
162 pcal->
init( hlist, pGeom );
165 if ( 0 == fhistname.size() )
167 cout <<
"hist file path: " << path << endl;
170 for (
unsigned nf = 0; nf < fhistname.size(); nf++ )
172 TFile* fin =
new TFile( fhistname[nf].c_str() );
173 if ( !fin->IsOpen() ) {
continue; }
176 cout <<
"merge hist file " << nf <<
": " << fhistname[nf] << endl;
186 if ( constname ==
"" )
187 { constname =
"/home/bes/wulh/calibConst/MdcCalibConst_11397_psi3770_652b_v1.root"; }
188 TFile fconst( constname.c_str() );
189 if ( !fconst.IsOpen() )
191 cout <<
"ERROR: " << constname <<
" does not exist" << endl;
194 cout <<
"Open calib const file " << constname << endl;
198 TTree* xttree = (TTree*)fconst.Get(
"XtTree" );
199 xttree->SetBranchAddress(
"xtkey", &
key );
200 xttree->SetBranchAddress(
"xtpar", &xtpar );
201 entry = (int)xttree->GetEntries();
202 for (
int i = 0; i < entry; i++ )
204 xttree->GetEntry( i );
210 TTree* t0tree = (TTree*)fconst.Get(
"T0Tree" );
211 t0tree->SetBranchAddress(
"t0", &t0 );
212 t0tree->SetBranchAddress(
"delt0", &delt0 );
213 entry = (int)t0tree->GetEntries();
214 for (
int i = 0; i < entry; i++ )
216 t0tree->GetEntry( i );
223 TTree* qttree = (TTree*)fconst.Get(
"QtTree" );
224 qttree->SetBranchAddress(
"qtpar0", &qtpar0 );
225 qttree->SetBranchAddress(
"qtpar1", &qtpar1 );
226 entry = (int)qttree->GetEntries();
227 for (
int i = 0; i < entry; i++ )
229 qttree->GetEntry( i );
235 TTree* sdtree = (TTree*)fconst.Get(
"SdTree" );
236 sdtree->SetBranchAddress(
"sdkey", &
key );
237 sdtree->SetBranchAddress(
"sdpar", &sdpar );
238 entry = sdtree->GetEntries();
239 for (
int i = 0; i < entry; i++ )
241 sdtree->GetEntry( i );
245 TObjArray* newXtList =
new TObjArray( 0 );
246 TList* list = fconst.GetListOfKeys();
247 int listSize = (int)( list->GetSize() );
248 cout <<
"Number of trees in old calib const file: " << listSize << endl;
252 for (
int i = 0; i < listSize; i++ )
254 TTree* tree = (TTree*)fconst.Get( list->At( i )->GetName() );
255 string strName( tree->GetName() );
256 if ( string::npos != strName.find(
"trNewXt" ) )
258 TTree* t2 = tree->CopyTree(
"" );
259 newXtList->Add( t2 );
265 gStyle->SetCanvasBorderMode( 0 );
266 gStyle->SetCanvasColor( 10 );
267 gStyle->SetOptFit( 0011 );
268 gStyle->SetStatColor( 10 );
269 gStyle->SetStatBorderSize( 1 );
270 gStyle->SetStatFont( 42 );
271 gStyle->SetStatFontSize( 0.04 );
272 gStyle->SetStatX( 0.9 );
273 gStyle->SetStatY( 0.9 );
274 gStyle->SetPadColor( 10 );
275 gStyle->SetFuncColor( 2 );
277 TObjArray* r2tList =
new TObjArray( 0 );
280 pcal->
calib( calconst, newXtList, r2tList );
282 TFile fhist(
"histall.root",
"recreate" );
288 if ( fgCal > 0 )
writeConst( calconst, newXtList, r2tList );