/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Mdc/DedxCalibAlg/DedxCalibAlg-00-01-15/share/shell/genRawScript/insert_run_calib.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <cstring>
00005 #include <string>
00006 #include <vector>
00007 #include <TFile.h>
00008 #include <TTree.h>
00009 #include <TString.h>
00010 #include <stdlib.h>
00011 
00012 int const num_item = 9;
00013 TString str_name_list[num_item]={"runcalib",
00014                                  "gaincalib",
00015                                  "resolcalib",
00016                                  "wiregcalib",
00017                                  "ggscalib",
00018                                  "ddgcalib",
00019                                  "entracalib",
00020                                  "zdepcalib",
00021                                  "layergcalib"};
00022 TTree *arr_tree[num_item];
00023 using namespace std;
00024 
00025 int main(int argc, char *argv[]){
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 }

Generated on Tue Nov 29 23:12:45 2016 for BOSS_7.0.2 by  doxygen 1.4.7