BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
insert_run_calib.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4#include <cstring>
5#include <string>
6#include <vector>
7#include <TFile.h>
8#include <TTree.h>
9#include <TString.h>
10#include <stdlib.h>
11
12int const num_item = 9;
13TString str_name_list[num_item]={"runcalib",
14 "gaincalib",
15 "resolcalib",
16 "wiregcalib",
17 "ggscalib",
18 "ddgcalib",
19 "entracalib",
20 "zdepcalib",
21 "layergcalib"};
23using namespace std;
24
25int main(int argc, char *argv[]){
26 if(argc<2){
27 cout << "plase append the old calibration const root file, Ex. insert_run_calib.exe old.root [runlist.txt]" << endl;
28 return 0;
29 }
30 TString str_old = argv[1];
31 TString str_runlist = "runlist.txt";
32 if(argc>=3) str_runlist = argv[2];
33 cout << "old file: " << str_old << " runlist file: " << str_runlist << endl;
34 TFile f_old(str_old); //input
35 TFile f_new("new.root","recreate");
36 for(int i=0; i<num_item; i++) arr_tree[i] = ((TTree*)f_old.Get(str_name_list[i]))->CloneTree();
37 ifstream in(str_runlist);
38 if(!in){
39 cout << "cannot open runlist.txt" << endl;
40 return 0;
41 }
42 char str[255];
43 int in_runno(0);
44 int runno, evtfrom, evtto;
45 Double_t runmean, rungain, runresol;
46 while(in){
47 in.getline(str, 255);
48 sscanf(str ,"%d", &in_runno);
49 if(!in_runno) continue; // protect of read at the end
50 arr_tree[0]->SetBranchAddress("runno", &runno );
51 arr_tree[0]->SetBranchAddress("evtfrom", &evtfrom );
52 arr_tree[0]->SetBranchAddress("evtto", &evtto );
53 arr_tree[0]->SetBranchAddress("runmean", &runmean);
54 arr_tree[0]->SetBranchAddress("rungain", &rungain);
55 arr_tree[0]->SetBranchAddress("runresol", &runresol);
56 int min_diff(10000);
57 double temp_runmean(0), temp_rungain(0), temp_runresol(0);
58 for(Long64_t i=0; i<arr_tree[0]->GetEntries(); i++){
59 arr_tree[0]->GetEntry(i);
60 if( ((runno-in_runno)<0 && abs(runno-in_runno)<=min_diff) || ((runno-in_runno)>0 && abs(runno-in_runno)<min_diff)){ // only the closest events block is selected
61 min_diff = abs(runno-in_runno);
62 temp_runmean = runmean;
63 temp_rungain = rungain;
64 temp_runresol = runresol;
65 }
66 }
67 runno = in_runno;
68 evtfrom = 0;
69 evtto = 1000000000;
70 runmean = temp_runmean;
71 rungain = temp_rungain;
72 runresol = temp_runresol;
73 cout << "runno " << runno << endl;
74 arr_tree[0]->Fill();
75 in_runno = 0;
76 }
77
78 f_new.cd();
79 for(int j=0; j<num_item; j++) arr_tree[j]->Write(str_name_list[j]);
80 f_new.Close();
81 f_old.Close();
82}
curve Write()
TString str_name_list[num_item]
int const num_item
TTree * arr_tree[num_item]
int main()
Definition: test_IFile.cxx:11