BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
merge.cpp File Reference
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include "TFolder.h"
#include "TProfile.h"
#include "TObjArray.h"
#include "TList.h"
#include "TSpline.h"
#include "TPostScript.h"
#include "TLatex.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "include/MdcCalibConst.h"
#include "include/MdcCosGeom.h"
#include "include/fun.h"
#include "include/IniCalib.h"
#include "include/PreXtCalib.h"
#include "include/PreT0Calib.h"
#include "include/XtCalib.h"
#include "include/GrXtCalib.h"
#include "include/XtInteCalib.h"
#include "include/T0Calib.h"
#include "include/QtCalib.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file merge.cpp.

35 {
36 char* jobname;
37 char* strcal;
38 int fgCal = 1;
39 if(argc>2){
40 jobname = argv[1];
41 strcal = argv[2];
42 sscanf(strcal, "%d", &fgCal);
43 } else if(argc>1){
44 jobname = argv[1];
45 }else{
46 cout << "bad argument" << endl;
47 return -1;
48 }
49 if(fgCal <= 0) cout << "do not calibrate " << endl;
50
51 string path = "";
52 string strJob = jobname;
53 cout << "strJob: " << strJob << endl;
54 string::size_type ilast = strJob.find_last_of("/");
55 if(string::npos != ilast){
56 path = strJob.substr(0, ilast);
57 }
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 cout << "ERROR: can not read jobOption: " << jobname << endl;
67 return 0;
68 } else{
69 cout << "Open jobOption: " << jobname << endl;
70 while( getline(fjob, str) ){
71 if(str.find("//", 0) != string::npos){
72 continue;
73 } else if( str.find("CalibRootCnvSvc.Mdcrootfile", 0) != string::npos ){
74 string::size_type i1 = str.find_first_of("\"");
75 string::size_type i2 = str.find_last_of("\"");
76 constname = str.substr(i1+1, i2-i1-1);
77 } else if(str.find("MdcCalibAlg.ConfigFile", 0) != string::npos){
78 string::size_type i1 = str.find_first_of("\"");
79 string::size_type i2 = str.find_last_of("\"");
80 confname = str.substr(i1+1, i2-i1-1);
81 } else if(str.find("MdcCalibAlg.MdcCalFlg", 0) != string::npos){
82 string::size_type i1 = str.find_first_of("=");
83 string::size_type i2 = str.find_last_of(";");
84 strtmp = str.substr(i1+1, i2-i1-1);
85 sscanf(strtmp.c_str(), "%d", &calType);
86 }
87 }
88 }
89
90 MdcCosGeom* pGeom = 0;
91 pGeom = new MdcCosGeom("/home/bes/wulh/document/wireconf.txt", "/home/bes/wulh/calibConst/MdcAlignPar_ini.txt" );
92 pGeom -> initialize(0.0);
93
94 int lay;
95 for(lay=0; lay<15; lay++) gNEntr[lay] = 1;
96 for(lay=15; lay<43; lay++) gNEntr[lay] = 2;
97
98 // read config file
99 string strconfig;
100 string strcomment;
101 ifstream fconfig(confname.c_str());
102 if( ! fconfig.is_open() ){
103 cout << "ERROR: can not read config file" << endl;
104 return 0;
105 } else{
106 cout << "Open config file: " << confname << endl;
107 while( fconfig >> strconfig ){
108 if('#' == strconfig[0]){
109 getline(fconfig, strcomment);
110 } else if("TimeShift" == strconfig){
111 fconfig >> gTimeShift;
112 } else if("TesMin" == strconfig){
113 fconfig >> gTesMin;
114 } else if("TesMax" == strconfig){
115 fconfig >> gTesMax;
116 } else if("FlagIniCalConst" == strconfig){
117 fconfig >> gFgIniCalConst;
118 } else if("FlagUpdateTmInPreT0" == strconfig){
119 fconfig >> gPreT0SetTm;
120 } else if("InitT0" == strconfig){
121 fconfig >> gInitT0;
122 } else if("T0Shift" == strconfig){
123 fconfig >> gT0Shift;
124 } else if("TminFitChindf" == strconfig){
125 fconfig >> gTminFitChindf;
126 } else if("TmaxFitChindf" == strconfig){
127 fconfig >> gTmaxFitChindf;
128 } else if("ResidualType" == strconfig){
129 fconfig >> gResiType;
130 } else if("UpdateSigma" == strconfig){
131 fconfig >> gCalSigma;
132 } else if("FixXtC0" == strconfig){
133 fconfig >> gFixXtC0;
134 } else if("RawTimeFitRange" == strconfig){
135 for(lay=0; lay<NLAYER; lay++){
136 fconfig >> strtmp
137 >> gFgCalib[lay]
138 >> gTminFitRange[lay][0]
139 >> gTminFitRange[lay][1]
140 >> gTmaxFitRange[lay][0]
141 >> gTmaxFitRange[lay][1]
142 >> gInitTm[lay]
143 >> strtmp
144 >> gQmin[lay]
145 >> gQmax[lay];
146 }
147 }
148 }
149 }
150 fconfig.close();
151
152 TObjArray* hlist = new TObjArray(0);
153 CalibBase* pcal;
154 if(0 == calType) pcal = new IniCalib();
155 else if(1 == calType) pcal = new PreXtCalib();
156 else if(2 == calType) pcal = new PreT0Calib();
157 else if(3 == calType) pcal = new XtCalib();
158 else if(4 == calType) pcal = new GrXtCalib();
159 else if(9 == calType) pcal = new XtInteCalib();
160 else if(5 == calType) pcal = new T0Calib();
161 else if(8 == calType) pcal = new QtCalib();
162 else {cout << "Error CalibType" << endl; return 0;}
163 pcal->init(hlist, pGeom);
164
165 vector<string> fhistname = getHistList();
166 if(0==fhistname.size()){
167 cout << "hist file path: " << path << endl;
168 fhistname = getHistList(path);
169 }
170 for(unsigned nf=0; nf<fhistname.size(); nf++){
171 TFile* fin = new TFile(fhistname[nf].c_str());
172 if(!fin->IsOpen()){
173 continue;
174 } else{
175 cout << "merge hist file " << nf << ": " << fhistname[nf] << endl;
176 pcal->mergeHist(fin);
177 fin->Close();
178 }
179 }
180
181 // read calib const.
182 MdcCalibConst* calconst = new MdcCalibConst();
183// if(fgCal <= 0){constname = "/home/bes/wulh/calibConst/MdcCalibConst_11397_psi3770_652b_v1.root";}
184 if(constname==""){constname = "/home/bes/wulh/calibConst/MdcCalibConst_11397_psi3770_652b_v1.root";}
185 TFile fconst(constname.c_str());
186 if(!fconst.IsOpen()){
187 cout << "ERROR: " << constname << " does not exist" << endl;
188 return 0;
189 }
190 cout << "Open calib const file " << constname << endl;
191 int key;
192 double xtpar;
193 int entry;
194 TTree* xttree = (TTree*)fconst.Get("XtTree");
195 xttree -> SetBranchAddress("xtkey", &key);
196 xttree -> SetBranchAddress("xtpar", &xtpar);
197 entry = (int)xttree -> GetEntries();
198 for(int i=0; i<entry; i++){
199 xttree -> GetEntry(i);
200 calconst->fillXtpar(key, xtpar);
201 }
202
203 double t0;
204 double delt0;
205 TTree* t0tree = (TTree*)fconst.Get("T0Tree");
206 t0tree -> SetBranchAddress("t0", &t0);
207 t0tree -> SetBranchAddress("delt0", &delt0);
208 entry = (int)t0tree -> GetEntries();
209 for(int i=0; i<entry; i++){
210 t0tree -> GetEntry(i);
211 calconst->fillT0(t0);
212 calconst->fillDelT0(delt0);
213 }
214
215 double qtpar0;
216 double qtpar1;
217 TTree* qttree = (TTree*)fconst.Get("QtTree");
218 qttree -> SetBranchAddress("qtpar0", &qtpar0);
219 qttree -> SetBranchAddress("qtpar1", &qtpar1);
220 entry = (int)qttree -> GetEntries();
221 for(int i=0; i<entry; i++){
222 qttree -> GetEntry(i);
223 calconst->fillQtpar0(qtpar0);
224 calconst->fillQtpar1(qtpar1);
225 }
226
227 double sdpar;
228 TTree* sdtree = (TTree*)fconst.Get("SdTree");
229 sdtree -> SetBranchAddress("sdkey", &key);
230 sdtree -> SetBranchAddress("sdpar", &sdpar);
231 entry = sdtree -> GetEntries();
232 for(int i=0; i<entry; i++){
233 sdtree -> GetEntry(i);
234 calconst->fillSdpar(key, sdpar);
235 }
236
237 TObjArray* newXtList = new TObjArray(0);
238 TList* list = fconst.GetListOfKeys();
239 int listSize = (int)(list->GetSize());
240 cout << "Number of trees in old calib const file: " << listSize << endl;
241 if(listSize > 4){
242 gROOT->cd();
243 for (int i = 0; i<listSize; i++) {
244 TTree* tree = (TTree*)fconst.Get(list->At(i)->GetName());
245 string strName(tree->GetName());
246 if(string::npos != strName.find("trNewXt")){
247 TTree* t2 = tree->CopyTree("");
248 newXtList->Add(t2);
249 }
250 }
251 }
252 fconst.Close();
253
254 gStyle -> SetCanvasBorderMode(0);
255 gStyle -> SetCanvasColor(10);
256 gStyle -> SetOptFit(0011);
257 gStyle -> SetStatColor(10);
258 gStyle -> SetStatBorderSize(1);
259 gStyle -> SetStatFont(42);
260 gStyle -> SetStatFontSize(0.04);
261 gStyle -> SetStatX(0.9);
262 gStyle -> SetStatY(0.9);
263 gStyle -> SetPadColor(10);
264 gStyle -> SetFuncColor(2);
265
266 TObjArray* r2tList = new TObjArray(0);
267
268 // x-t calibration
269 pcal->calib(calconst, newXtList, r2tList);
270
271 TFile fhist("histall.root", "recreate");
272 fhist.cd();
273 hlist->Write();
274 fhist.Close();
275
276 // output new calib const file
277 if(fgCal > 0) writeConst(calconst, newXtList, r2tList);
278
279 return 0;
280}
data GetEntry(0)
data SetBranchAddress("time",&time)
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
Definition: Taupair.h:42
gStyle SetCanvasColor(0)
virtual void init(TObjArray *hlist, MdcCosGeom *pGeom)=0
Definition: CalibBase.cpp:14
virtual void mergeHist(TFile *fhist)=0
Definition: CalibBase.cpp:365
virtual void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)=0
Definition: CalibBase.cpp:711
void fillXtpar(int key, double val)
void fillQtpar0(double val)
void fillT0(double val)
void fillQtpar1(double val)
void fillDelT0(double val)
void fillSdpar(int key, double val)
std::ifstream ifstream
Definition: bpkt_streams.h:44