/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/BOOST/TofSim/TofSim-00-02-33/dat/writeTree.cc File Reference

#include <unistd.h>

Go to the source code of this file.

Functions

void writeTree ()


Function Documentation

void writeTree (  ) 

Definition at line 3 of file writeTree.cc.

References f1, file, genRecEmupikp::i, ganga-rec::j, n1, nPhi, nR, nZ, t(), and x.

00003                 {
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         //if(access(file,F_OK) < 0) // Check if the file exists or not. Thx to zoujh.
00030         //{
00031         //  cout << "The file does NOT exist!" << endl;
00032         //  continue;
00033         //}
00034         //else
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.; // 200 events per run ; 10k photons per event
00050           //cout << "norm:" << norm << "; efficiency0: " << efficiency0 << "\n" << endl;
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 }


Generated on Tue Nov 29 23:17:13 2016 for BOSS_7.0.2 by  doxygen 1.4.7