#include <map>
#include "TKey.h"
#include <TH2F.h>
#include <TROOT.h>
#include <TRint.h>
#include <TList.h>
#include <TTree.h>
#include <TFile.h>
#include <stdlib.h>
#include <TSystem.h>
#include <iostream>
#include <sstream>
#include "Log.hh"
#include "MicroException.hh"
#include <string>
#include "mysql/Mysql.hh"
#include "root/CaloRun.hh"
#include "root/CaloEvent.hh"
#include "root/CaloHit.hh"
#include "root/MTRun.hh"
#include "root/MTEvent.hh"
#include "root/MTChannel.hh"
Include dependency graph for readCaloHits.cpp:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 33 of file readCaloHits.cpp.
00033 { 00034 00035 if ( argc !=2 ) { 00036 FILE_LOG(logERROR) << "usage: example rootFile " << endl; 00037 exit(1); 00038 } 00039 00040 00041 int search = 1; 00042 TH2F * hxy = new TH2F("hxy","",100,0,100,100,0,100); 00043 TH1I * hnhit = new TH1I("hnhit","Number of hits",100,0,100); 00044 TH1I * hnhit_roi = new TH1I("hnhit_roi","Number of hits in region of interest",100,0,100); 00045 TH1F * hxres = new TH1F("hxres","Residual in x direction;xm2 - xtel",201,-100,100); 00046 TH1F * hyres = new TH1F("hyres","Residual in x direction;xm2 - xtel",201,-100,100); 00047 00048 string rootName; 00049 rootName.assign(argv[1]); 00050 int nbHit = 0; 00051 int nbEvt = 0; 00052 00053 TFile f(rootName.c_str()); 00054 TIter nextkey(f.GetListOfKeys()); 00055 TKey *key; 00056 00057 while (key = (TKey*)nextkey()) 00058 { 00059 00060 TString keyname = key->GetName(); 00061 if ((keyname == "hResidualX") || (keyname == "hResidualY")){} 00062 else{ 00063 00064 TTree *tree = (TTree*)key->ReadObj(); 00065 cout << "---------------------------- NEW TTREE ---------------------------"<< endl; 00066 nbEvt =0; 00067 nbHit = 0; 00068 00069 float xoffset = 0; 00070 float yoffset = 0; 00071 00072 try { 00073 CaloRun *run=dynamic_cast<CaloRun *>(tree->GetUserInfo()->First()); 00074 ////CaloRun *run=(CaloRun *)tree->GetUserInfo()->First(); 00075 00076 //xoffset = run->GetOffsetX(); 00077 //yoffset = run->GetOffsetY(); 00078 00079 cout << "Run[" << run->GetRunId() << "], temperature[" << run->GetTemperature() << "] pression[" << run->GetPressure() << "] " << endl ; 00080 cout << "Offset telescope - m2[" << xoffset << ", " << yoffset << "] " << endl ; 00081 } 00082 catch ( ... ) {} 00083 00084 CaloEvent *evt = new CaloEvent(); 00085 TBranch *branch= tree->GetBranch("CaloEvent"); 00086 branch->SetAddress(&evt); 00087 00088 CaloHit* hit =NULL; 00089 int nbEntries = tree->GetEntries(); 00090 for ( int evtNum = 0; evtNum < nbEntries ; evtNum++) 00091 { 00092 tree->GetEntry(evtNum); 00093 nbEvt++; 00094 /* 00095 cout << "**** Event Information "<< dec << evtNum+1 << "/" << nbEntries<< " ****" << endl; 00096 cout << " event num in TTree:" << evtNum <<endl; 00097 cout << " event id:" << evt->fEventId <<endl; 00098 00099 cout << " number of channel hit:" << evt->GetNHits() <<endl; 00100 */ 00101 int nbHits = evt->GetNHits(); 00102 //cout << "nb hits:" << nbHits << endl; 00103 00104 float xtel = 0;// evt->GetXTelescope(); 00105 float ytel = 0;//evt->GetYTelescope(); 00106 00107 float xextrapol = xtel - xoffset; 00108 float yextrapol = ytel - yoffset; 00109 00110 hnhit->Fill(nbHits); 00111 00112 //number of hits in region of interest 00113 int nhit_roi = 0; 00114 float xpos = 0; 00115 float ypos = 0; 00116 float xresidual = 0; 00117 float yresidual = 0; 00118 00119 for(int i=0 ; i < nbHits ; i++) 00120 { 00121 hit = (CaloHit*)evt->GetHits()->UncheckedAt(i); 00122 xpos = hit->GetX(); 00123 ypos = hit->GetY(); 00124 hxy->Fill(xpos,ypos); 00125 00126 00127 xresidual = xpos - xextrapol; 00128 yresidual = ypos - yextrapol; 00129 00130 hxres->Fill(xresidual); 00131 hyres->Fill(yresidual); 00132 00133 if ((fabs(xresidual)<=search) && (fabs(yresidual)<=search)) 00134 { 00135 nhit_roi++; 00136 } 00137 } // end hit 00138 00139 hnhit_roi->Fill(nhit_roi); 00140 00141 } // end event 00142 } // end run ( TTree ) 00143 } 00144 TFile tf("temp.root","RECREATE"); 00145 hxres->Write(); 00146 hyres->Write(); 00147 hxy->Write(); 00148 hnhit->Write(); 00149 hnhit_roi->Write(); 00150 00151 }