#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <TFile.h>
#include <TTree.h>
#include <TString.h>
#include <stdlib.h>
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Variables | |
int const | num_item = 9 |
TString | str_name_list [num_item] |
TTree * | arr_tree [num_item] |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 25 of file insert_run_calib.cxx.
References abs, arr_tree, genRecEmupikp::i, ganga-rec::j, num_item, check_raw_filter::runno, and str_name_list.
00025 { 00026 if(argc<2){ 00027 cout << "plase append the old calibration const root file, Ex. insert_run_calib.exe old.root [runlist.txt]" << endl; 00028 return 0; 00029 } 00030 TString str_old = argv[1]; 00031 TString str_runlist = "runlist.txt"; 00032 if(argc>=3) str_runlist = argv[2]; 00033 cout << "old file: " << str_old << " runlist file: " << str_runlist << endl; 00034 TFile f_old(str_old); //input 00035 TFile f_new("new.root","recreate"); 00036 for(int i=0; i<num_item; i++) arr_tree[i] = ((TTree*)f_old.Get(str_name_list[i]))->CloneTree(); 00037 ifstream in(str_runlist); 00038 if(!in){ 00039 cout << "cannot open runlist.txt" << endl; 00040 return 0; 00041 } 00042 char str[255]; 00043 int in_runno(0); 00044 int runno; 00045 Double_t runmean, rungain, runresol; 00046 while(in){ 00047 in.getline(str, 255); 00048 sscanf(str ,"%d", &in_runno); 00049 if(!in_runno) continue; // protect of read at the end 00050 arr_tree[0]->SetBranchAddress("runno", &runno ); 00051 arr_tree[0]->SetBranchAddress("runmean", &runmean); 00052 arr_tree[0]->SetBranchAddress("rungain", &rungain); 00053 arr_tree[0]->SetBranchAddress("runresol", &runresol); 00054 int min_diff(10000); 00055 double temp_runmean(0), temp_rungain(0), temp_runresol(0); 00056 for(Long64_t i=0; i<arr_tree[0]->GetEntries(); i++){ 00057 arr_tree[0]->GetEntry(i); 00058 if(abs(runno-in_runno)<min_diff){ 00059 min_diff = abs(runno-in_runno); 00060 temp_runmean = runmean; 00061 temp_rungain = rungain; 00062 temp_runresol = runresol; 00063 } 00064 } 00065 runno = in_runno; 00066 runmean = temp_runmean; 00067 rungain = temp_rungain; 00068 runresol = temp_runresol; 00069 cout << "runno " << runno << endl; 00070 arr_tree[0]->Fill(); 00071 in_runno = 0; 00072 } 00073 00074 f_new.cd(); 00075 for(int j=0; j<num_item; j++) arr_tree[j]->Write(str_name_list[j]); 00076 f_new.Close(); 00077 f_old.Close(); 00078 }
int const num_item = 9 |
Definition at line 12 of file insert_run_calib.cxx.
TString str_name_list[num_item] |
Initial value:
{"runcalib", "gaincalib", "resolcalib", "wiregcalib", "ggscalib", "ddgcalib", "entracalib", "zdepcalib", "layergcalib"}
Definition at line 13 of file insert_run_calib.cxx.