00001
00002 #include <map>
00003 #include "TKey.h"
00004 #include <TH2F.h>
00005 #include <TROOT.h>
00006 #include <TRint.h>
00007 #include <TKey.h>
00008 #include <TList.h>
00009 #include <TTree.h>
00010 #include <TFile.h>
00011 #include <stdlib.h>
00012 #include <TSystem.h>
00013 #include <iostream>
00014 #include <sstream>
00015 #include "Log.hh"
00016
00017 #include "MicroException.hh"
00018 #include <string>
00019
00020 #include "mysql/Mysql.hh"
00021
00022
00023 #include "root/CaloRun.hh"
00024 #include "root/CaloEvent.hh"
00025 #include "root/CaloHit.hh"
00026 #include "root/MTRun.hh"
00027 #include "root/MTEvent.hh"
00028 #include "root/MTChannel.hh"
00029
00030 using namespace std;
00031
00032
00033 int main(int argc, char**argv){
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
00075
00076
00077
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
00096
00097
00098
00099
00100
00101 int nbHits = evt->GetNHits();
00102
00103
00104 float xtel = 0;
00105 float ytel = 0;
00106
00107 float xextrapol = xtel - xoffset;
00108 float yextrapol = ytel - yoffset;
00109
00110 hnhit->Fill(nbHits);
00111
00112
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 }
00138
00139 hnhit_roi->Fill(nhit_roi);
00140
00141 }
00142 }
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 }