BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
mergeAlign.cpp
Go to the documentation of this file.
1#include <cstring>
2#include <fstream>
3#include <iomanip>
4#include <iostream>
5#include <string>
6#include <vector>
7
8#include "TCanvas.h"
9#include "TFile.h"
10#include "TFolder.h"
11#include "TLatex.h"
12#include "TObjArray.h"
13#include "TPostScript.h"
14#include "TProfile.h"
15#include "TSpline.h"
16#include "TStyle.h"
17#include "TTree.h"
18
19#include "include/MdcAlignPar.h"
20#include "include/MdcCosGeom.h"
21#include "include/ResiAlign.h"
22#include "include/fun.h"
23
24using namespace std;
25
26int main( int argc, char* argv[] ) {
27 char* jobname;
28 if ( argc > 1 ) { jobname = argv[1]; }
29 else
30 {
31 cout << "bad argument" << endl;
32 return -1;
33 }
34
35 string path = "";
36 string strJob = jobname;
37 cout << "strJob: " << strJob << endl;
38 string::size_type ilast = strJob.find_last_of( "/" );
39 if ( string::npos != ilast ) { path = strJob.substr( 0, ilast ); }
40
41 int alignMeth;
42 string alignFile;
43 string confname;
44 string str;
45 string strtmp;
46 ifstream fjob( jobname );
47 if ( !fjob.is_open() )
48 {
49 cout << "ERROR: can not read jobOption: " << jobname << endl;
50 return 0;
51 }
52 else
53 {
54 cout << "Open jobOption: " << jobname << endl;
55 while ( getline( fjob, str ) )
56 {
57 if ( str.find( "//", 0 ) != string::npos ) { continue; }
58 else if ( str.find( "MdcGeomSvc.alignFilePath", 0 ) != string::npos )
59 {
60 string::size_type i1 = str.find_first_of( "\"" );
61 string::size_type i2 = str.find_last_of( "\"" );
62 alignFile = str.substr( i1 + 1, i2 - i1 - 1 );
63 }
64 else if ( str.find( "MdcAlignAlg.ConfigFile", 0 ) != string::npos )
65 {
66 string::size_type i1 = str.find_first_of( "\"" );
67 string::size_type i2 = str.find_last_of( "\"" );
68 confname = str.substr( i1 + 1, i2 - i1 - 1 );
69 }
70 else if ( str.find( "MdcAlignAlg.MdcAlignMeth", 0 ) != string::npos )
71 {
72 string::size_type i1 = str.find_first_of( "=" );
73 string::size_type i2 = str.find_last_of( ";" );
74 strtmp = str.substr( i1 + 1, i2 - i1 - 1 );
75 sscanf( strtmp.c_str(), "%d", &alignMeth );
76 }
77 }
78 }
79
80 MdcCosGeom* pGeom = 0;
81 pGeom = new MdcCosGeom( "/home/bes/wulh/document/wireconf.txt",
82 "/home/bes/wulh/calibConst/MdcAlignPar_ini.txt" );
83 pGeom->initialize( 0.0 );
84
85 TObjArray* hlist = new TObjArray( 0 );
86 AlignBase* pAlign;
87 if ( 0 == alignMeth ) pAlign = new ResiAlign();
88 else
89 {
90 cout << "Error AlignType" << endl;
91 return 0;
92 }
93 pAlign->init( hlist, pGeom );
94
95 vector<string> fhistname = getHistList();
96 if ( 0 == fhistname.size() )
97 {
98 cout << "hist file path: " << path << endl;
99 fhistname = getHistList( path );
100 }
101 for ( unsigned nf = 0; nf < fhistname.size(); nf++ )
102 {
103 TFile* fin = new TFile( fhistname[nf].c_str() );
104 if ( !fin->IsOpen() ) { continue; }
105 else
106 {
107 cout << "merge hist file " << nf << ": " << fhistname[nf] << endl;
108 pAlign->mergeHist( fin );
109 fin->Close();
110 }
111 }
112
113 // read align par.
114 MdcAlignPar* alignPar = new MdcAlignPar();
115 alignPar->initAlignPar();
116 alignPar->rdAlignPar( alignFile );
117
118 // fit for alignment
119 pAlign->align( alignPar );
120
121 TFile fhist( "histall.root", "recreate" );
122 fhist.cd();
123 hlist->Write();
124 fhist.Close();
125
126 // output new alignment file
127 alignPar->wrtAlignPar();
128
129 return 0;
130}
vector< string > getHistList()
virtual void align(MdcAlignPar *alignPar)=0
Definition AlignBase.cpp:14
virtual void mergeHist(TFile *fhist)=0
Definition AlignBase.cpp:12
virtual void init(TObjArray *hlist, MdcCosGeom *pGeom)=0
Definition AlignBase.cpp:10
void initAlignPar()
void wrtAlignPar()
bool rdAlignPar(std::string alignFile)
int main()
Definition phokhara.cc:42