00001 #include <unistd.h>
00002
00003 void writeTree(){
00004 int rBin,phiBin,zBin;
00005 const int nR = 43;
00006 const int nPhi = 6;
00007 const int nZ = 6;
00008 float efficiency0,x[400],y[400];
00009 TTree *t = new TTree("effTree", "colEff");
00010
00011 float t1;
00012 TH1F* h1 = new TH1F("h1","time distr.(ns)",400,0,20);
00013 char file[200];
00014
00015 t->Branch("rBin", &rBin, "rBin/I");
00016 t->Branch("phiBin", &phiBin, "phiBin/I");
00017 t->Branch("zBin", &zBin, "zBin/I");
00018 t->Branch("efficiency0", &efficiency0, "efficiency0/F");
00019 t->Branch("x", x, "x[400]/F");
00020 t->Branch("y", y, "y[400]/F");
00021
00022 for (Int_t i = 0; i < nR; i++){
00023 rBin = i;
00024 for(Int_t j = 0; j<nPhi;j++){
00025 phiBin = j;
00026 for(Int_t k=0;k<nZ;k++){
00027 int rPos = 400+i*10;
00028 sprintf(file,"/ihepbatch/besd12/liuy/EndcapTof/OpInETof2/results/%d/timeSta_%d_%d_%d.root",rPos,rPos,j,k);
00029
00030
00031
00032
00033
00034
00035
00036 cout << "The file:" << file << endl;
00037 TFile* f1 = TFile::Open(file);
00038 TNtuple* n1 = (TNtuple*)f1 -> Get("timeTuple");
00039 n1->SetBranchAddress("inTimePre",&t1);
00040 int nEntries = (Int_t)n1->GetEntries();
00041 cout << "nEntries:" << nEntries << "\n" << endl;
00042
00043 for(int m=0;m<nEntries;m++)
00044 {
00045 n1->GetEntry(m);
00046 h1->Fill(t1);
00047 }
00048 double norm = h1->Integral();
00049 efficiency0 = norm/2000000.;
00050
00051 if(norm!=0)
00052 h1->Scale(1./norm);
00053 else
00054 {
00055 cout << "The eff is null!" << endl;
00056 continue;
00057 }
00058 TAxis* xaxis = h1->GetXaxis();
00059 for(int m=0;m<400;m++)
00060 {
00061 x[m] = xaxis->GetBinCenter(m);
00062 y[m] = h1->GetBinContent(m);
00063 }
00064 f1->Close();
00065
00066 zBin = k;
00067 t->Fill();
00068
00069 }
00070 }
00071
00072 }
00073 TFile *f = new TFile("effTree.root", "recreate");
00074 cout << "TTree write" <<endl;
00075 t->Write();
00076 f->Close();
00077 }
00078
00079