35 {
36 char* jobname;
37 char* strcal;
38 int fgCal = 1;
39 if ( argc > 2 )
40 {
41 jobname = argv[1];
42 strcal = argv[2];
43 sscanf( strcal, "%d", &fgCal );
44 }
45 else if ( argc > 1 ) { jobname = argv[1]; }
46 else
47 {
48 cout << "bad argument" << endl;
49 return -1;
50 }
51 if ( fgCal <= 0 ) cout << "do not calibrate " << endl;
52
53 string path = "";
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 ); }
58
59 int calType;
60 string constname;
61 string confname;
62 string str;
63 string strtmp;
64 ifstream fjob( jobname );
65 if ( !fjob.is_open() )
66 {
67 cout << "ERROR: can not read jobOption: " << jobname << endl;
68 return 0;
69 }
70 else
71 {
72 cout << "Open jobOption: " << jobname << endl;
73 while ( getline( fjob, str ) )
74 {
75 if ( str.find( "//", 0 ) != string::npos ) { continue; }
76 else if ( str.find( "CalibRootCnvSvc.Mdcrootfile", 0 ) != string::npos )
77 {
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 );
81 }
82 else if ( str.find( "MdcCalibAlg.ConfigFile", 0 ) != string::npos )
83 {
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 );
87 }
88 else if ( str.find( "MdcCalibAlg.MdcCalFlg", 0 ) != string::npos )
89 {
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 );
94 }
95 }
96 }
97
99 pGeom =
new MdcCosGeom(
"/home/bes/wulh/document/wireconf.txt",
100 "/home/bes/wulh/calibConst/MdcAlignPar_ini.txt" );
102
103 int lay;
104 for ( lay = 0; lay < 15; lay++ )
gNEntr[lay] = 1;
105 for ( lay = 15; lay < 43; lay++ )
gNEntr[lay] = 2;
106
107
108 string strconfig;
109 string strcomment;
110 ifstream fconfig( confname.c_str() );
111 if ( !fconfig.is_open() )
112 {
113 cout << "ERROR: can not read config file" << endl;
114 return 0;
115 }
116 else
117 {
118 cout << "Open config file: " << confname << endl;
119 while ( fconfig >> strconfig )
120 {
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 )
135 {
136 for ( lay = 0; lay <
NLAYER; lay++ )
137 {
141 }
142 }
143 }
144 }
145 fconfig.close();
146
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();
157 else
158 {
159 cout << "Error CalibType" << endl;
160 return 0;
161 }
162 pcal->
init( hlist, pGeom );
163
165 if ( 0 == fhistname.size() )
166 {
167 cout << "hist file path: " << path << endl;
169 }
170 for ( unsigned nf = 0; nf < fhistname.size(); nf++ )
171 {
172 TFile* fin =
new TFile( fhistname[nf].
c_str() );
173 if ( !fin->IsOpen() ) { continue; }
174 else
175 {
176 cout << "merge hist file " << nf << ": " << fhistname[nf] << endl;
178 fin->Close();
179 }
180 }
181
182
184
185
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() )
190 {
191 cout << "ERROR: " << constname << " does not exist" << endl;
192 return 0;
193 }
194 cout << "Open calib const file " << constname << endl;
196 double xtpar;
197 int entry;
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++ )
203 {
204 xttree->GetEntry( i );
206 }
207
208 double t0;
209 double delt0;
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++ )
215 {
216 t0tree->GetEntry( i );
219 }
220
221 double qtpar0;
222 double qtpar1;
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++ )
228 {
229 qttree->GetEntry( i );
232 }
233
234 double sdpar;
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++ )
240 {
241 sdtree->GetEntry( i );
243 }
244
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;
249 if ( listSize > 4 )
250 {
251 gROOT->cd();
252 for ( int i = 0; i < listSize; i++ )
253 {
254 TTree* tree = (TTree*)fconst.Get( list->At( i )->GetName() );
255 string strName( tree->GetName() );
256 if ( string::npos != strName.find( "trNewXt" ) )
257 {
258 TTree* t2 = tree->CopyTree( "" );
259 newXtList->Add( t2 );
260 }
261 }
262 }
263 fconst.Close();
264
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 );
276
277 TObjArray* r2tList = new TObjArray( 0 );
278
279
280 pcal->
calib( calconst, newXtList, r2tList );
281
282 TFile fhist( "histall.root", "recreate" );
283 fhist.cd();
284 hlist->Write();
285 fhist.Close();
286
287
288 if ( fgCal > 0 )
writeConst( calconst, newXtList, r2tList );
289
290 return 0;
291}
vector< string > getHistList()
double gTminFitRange[NLAYER][2]
double gTmaxFitRange[NLAYER][2]
void writeConst(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
virtual void init(TObjArray *hlist, MdcCosGeom *pGeom)=0
virtual void mergeHist(TFile *fhist)=0
virtual void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)=0
void fillXtpar(int key, double val)
void fillQtpar0(double val)
void fillQtpar1(double val)
void fillDelT0(double val)
void fillSdpar(int key, double val)
bool initialize(double rot)