00001 #include "TH2.h"
00002 #include "TCanvas.h"
00003 #include "TFile.h"
00004 #include "TApplication.h"
00005 #include "TTree.h"
00006 #include "TF1.h"
00007 #include "TNamed.h"
00008 #include "TGraph.h"
00009 #include "TProfile.h"
00010
00011 #include "TFndHdt.h"
00012
00013
00014 using namespace FROOT;
00015
00016 TFile *fHdtFile = 0;
00017
00018 TFndHdt *fCurHdtEv = 0;
00019 TTree *fHdtTree = 0;
00020
00021 TProfile *Nbhabha[K_N_TOFINO_SLABS], *Nkaon[K_N_TOFINO_SLABS];
00022 Int_t N_bhabha[K_N_TOFINO_SLABS], N_kaon[K_N_TOFINO_SLABS];
00023
00024 void DeclareHistos(Int_t run_number_start, Int_t run_number_stop){
00025
00026 TString hname;
00027 TString htitle;
00028
00029 Int_t N=run_number_stop-run_number_start+1;
00030
00031 for (Int_t sl=0; sl<12; sl++){
00032 hname.Form("Nbhabha_%d",sl+1);
00033 htitle.Form("Number of bhabha events TOFINO slab %d", sl+1);
00034 Nbhabha[sl] = new TProfile(hname, htitle, N, run_number_start-0.5, run_number_stop+0.5);
00035
00036 hname.Form("Nkaon_%d",sl+1);
00037 htitle.Form("Number of K+K- events TOFINO slab %d", sl+1);
00038 Nkaon[sl] = new TProfile(hname, htitle, N, run_number_start-0.5, run_number_stop+0.5);
00039 }
00040 }
00041
00042 void CloseHdtFile(){
00043
00044 if (fHdtTree){
00045 delete fHdtTree;
00046
00047 fHdtTree = 0;
00048 }
00049
00050 if(fHdtFile){
00051 if(fHdtFile->IsOpen()) fHdtFile->Close();
00052 delete fHdtFile;
00053 fHdtFile = 0;
00054 }
00055
00056 }
00057
00058 Int_t OpenHdtFile(const TString &runtype,const Int_t &run_num){
00059
00060
00061
00062
00063 CloseHdtFile();
00064
00065 TString runname = BuildRunName(runtype,run_num);
00066 TString fnam;
00067 fnam.Form("%s/%s.hdt.root",ExpandPathName("$FND_HDT").Data(),runname.Data());
00068
00069 if(gSystem->AccessPathName(fnam)){
00070 gROOT->Warning("OpenHdtFile","file \"%s\" not found",fnam.Data());
00071 return -1;
00072 }
00073
00074 gROOT->Info("OpenHdtFile","opening file \"%s\"",fnam.Data());
00075 fHdtFile = new TFile(fnam,"OPEN");
00076
00077 return 0;
00078 }
00079
00080
00081 Int_t LoadHdtTree(){
00082
00083
00084
00085
00086 if (fHdtTree){
00087 delete fHdtTree;
00088
00089 fHdtTree = 0;
00090 }
00091
00092 fHdtTree = (TTree *) ( fHdtFile->Get("FIN_HDT_TREE") );
00093 if(!fHdtTree){
00094 gROOT->Warning("LoadHdtTree","Problems while getting HDT tree from file");
00095 return -1;
00096 }
00097
00098
00099 fHdtTree->SetBranchAddress("fndhdt",&fCurHdtEv);
00100
00101 return 0;
00102 }
00103
00104 Short_t GetTrigType(){
00105 TFndTrig *cur_trig = (TFndTrig *) (fCurHdtEv->GetGts());
00106 Short_t hyp_bit=cur_trig->GetPU_cont_bit(0, 0);
00107 Short_t bha_bit=cur_trig->GetPU_cont_bit(0, 1);
00108 return hyp_bit*10+bha_bit;
00109 }
00110
00111 void GetMultiplicity(Int_t *mult){
00112
00113
00114 mult[0]=0; mult[1]=0;
00115
00116 TClonesArray *TofHits = fCurHdtEv->GetTofHits();
00117 Int_t lay, slab;
00118 TFndHTof *cur_hit = 0;
00119
00120 for(Int_t ic=0;ic< TofHits->GetEntries(); ic++) {
00121 cur_hit = (TFndHTof *) ( TofHits->At(ic) );
00122 cur_hit->GetLayer_Slab(lay, slab);
00123 if(lay==E_FIN_OUTER_LAYER) continue;
00124
00125 Bool_t both_adc = kFALSE;
00126 Bool_t both_tdcl = kFALSE;
00127 Bool_t both_tdch = kFALSE;
00128 if(cur_hit->GetBothAdc() == TFndHit::E_HIT_BOTH_CH ) both_adc = kTRUE;
00129 if(cur_hit->GetBothLowTdc() == TFndHit::E_HIT_BOTH_CH ) both_tdcl = kTRUE;
00130 if(cur_hit->GetBothHighTdc() == TFndHit::E_HIT_BOTH_CH ) both_tdch = kTRUE;
00131
00132 Double_t adce=cur_hit->GetAdcE();
00133 Double_t adcp=cur_hit->GetAdcP();
00134
00135 if(both_tdch&&adce>0&&adcp>0){
00136 mult[1]++;
00137 }
00138 if(both_tdcl&&adce>0&&adcp>0){
00139 mult[0]++;
00140 }
00141 }
00142 }
00143
00144 void FillHistos(const Int_t &run_num){
00145
00146 TClonesArray *TofHits = fCurHdtEv->GetTofHits();
00147
00148 Int_t lay, slab;
00149 TFndHTof *cur_hit = 0;
00150 Int_t mult[2];
00151 GetMultiplicity(mult);
00152 for(Int_t ic=0;ic< TofHits->GetEntries(); ic++) {
00153 cur_hit = (TFndHTof *) ( TofHits->At(ic) );
00154
00155 cur_hit->GetLayer_Slab(lay, slab);
00156
00157
00158 if(lay==E_FIN_OUTER_LAYER) continue;
00159
00160 Bool_t both_adc = kFALSE;
00161 Bool_t both_tdcl = kFALSE;
00162 Bool_t both_tdch = kFALSE;
00163 if(cur_hit->GetBothAdc() == TFndHit::E_HIT_BOTH_CH ) both_adc = kTRUE;
00164 if(cur_hit->GetBothLowTdc() == TFndHit::E_HIT_BOTH_CH ) both_tdcl = kTRUE;
00165 if(cur_hit->GetBothHighTdc() == TFndHit::E_HIT_BOTH_CH ) both_tdch = kTRUE;
00166
00167
00168
00169
00170
00171
00172
00173 Double_t adce=cur_hit->GetAdcE();
00174 Double_t adcp=cur_hit->GetAdcP();
00175
00176 if(both_tdcl && !both_tdch){
00177 if (GetTrigType()==1&&mult[0]==2) N_bhabha[slab-1]++;
00178 }
00179
00180 if(both_tdch){
00181 if (GetTrigType()==10&&mult[1]==2) N_kaon[slab-1]++;
00182 }
00183 }
00184 }
00185
00186 void EventLoop(const Int_t &run_num, const Int_t &nevs){
00187
00188 Int_t entries = fHdtTree->GetEntries();
00189
00190 Int_t cur_ev = 0;
00191 while(1){
00192 if(cur_ev >= entries){
00193 gROOT->Info("EventLoop","run completed");
00194 break;
00195 }
00196 if(nevs != -1 && cur_ev >= nevs){
00197 gROOT->Info("EventLoop","requested number of events reached");
00198 break;
00199 }
00200
00201 fHdtTree->GetEntry(cur_ev);
00202
00203 FillHistos(run_num);
00204
00205 if(cur_ev%3000 == 0 ) cout << "cur_ev: " << cur_ev << endl;
00206
00207
00208 cur_ev++;
00209 }
00210 }
00211
00212 void SaveHistos(const TString &fname){
00213 TFile *fOutFile = new TFile(fname,"RECREATE");
00214
00215 for(Int_t sl=0;sl<K_N_TOFINO_SLABS;sl++ ){
00216 Nbhabha[sl]->Write();
00217 Nkaon[sl]->Write();
00218 }
00219
00220
00221
00222
00223
00224 fOutFile->Close();
00225 delete fOutFile;
00226 fOutFile = 0;
00227
00228 }
00229
00230
00231 Int_t GetRunInfo(TString runtype,Int_t runnum){
00232
00233 TString run_path;
00234 run_path.Form("%s/%s.hdt.root",FROOT::ExpandPathName("$FND_HDT").Data(),FROOT::BuildRunName(runtype,runnum).Data());
00235
00236 TFile *hdt_file = new TFile(run_path);
00237 if (!hdt_file) return -1;
00238
00239
00240 TFndGenInfo *geninfo = (TFndGenInfo *)hdt_file->Get("TFndGenInfo");
00241
00242
00243
00244 TDatime d = geninfo->GetDateTime();
00245
00246 return (Int_t) d.Convert();
00247
00248 }
00249
00250 void CountNumberOfEvents(const TString &runtype,const Int_t &run_num_start,const Int_t &run_num_stop,const TString &root_filename){
00251
00252 DeclareHistos(run_num_start, run_num_stop);
00253
00254 for(Int_t cur_run=run_num_start; cur_run <=run_num_stop ; cur_run++){
00255 cout << "Filling from run \"" << runtype.Data() << "\" " << cur_run << endl;
00256 for (Int_t sl=0; sl<K_N_TOFINO_SLABS; sl++){
00257 N_bhabha[sl]=0; N_kaon[sl]=0;
00258 }
00259
00260 if(OpenHdtFile(runtype,cur_run) !=0) continue;
00261 if(LoadHdtTree() != 0) continue;
00262
00263 EventLoop(cur_run, -1);
00264 CloseHdtFile();
00265 for (Int_t sl=0; sl<K_N_TOFINO_SLABS; sl++){
00266 Nbhabha[sl]->Fill(cur_run, N_bhabha[sl]);
00267 Nkaon[sl]->Fill(cur_run, N_kaon[sl]);
00268 }
00269 }
00270 SaveHistos(root_filename);
00271 }