#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 Mysql mysql; 00041 00042 00043 00044 int search = 1; 00045 TH2F * hxy = new TH2F("hxy","",100,0,100,100,0,100); 00046 TH1I * hnhit = new TH1I("hnhit","Number of hits",100,0,100); 00047 TH1I * hnhit_roi = new TH1I("hnhit_roi","Number of hits in region of interest",100,0,100); 00048 TH1F * hxres = new TH1F("hxres","Residual in x direction;xm2 - xtel",201,-100,100); 00049 TH1F * hyres = new TH1F("hyres","Residual in x direction;xm2 - xtel",201,-100,100); 00050 00051 string rootName; 00052 rootName.assign(argv[1]); 00053 int nbHit = 0; 00054 int nbEvt = 0; 00055 00056 TFile f(rootName.c_str()); 00057 TIter nextkey(f.GetListOfKeys()); 00058 TKey *key; 00059 00060 while (key = (TKey*)nextkey()) 00061 { 00062 00063 TString keyname = key->GetName(); 00064 if ((keyname == "hResidualX") || (keyname == "hResidualY")){} 00065 else{ 00066 00067 TTree *tree = (TTree*)key->ReadObj(); 00068 cout << "---------------------------- NEW TTREE ---------------------------"<< endl; 00069 nbEvt =0; 00070 nbHit = 0; 00071 00072 float xoffset = 0; 00073 float yoffset = 0; 00074 00075 try { 00076 CaloRun *run=dynamic_cast<CaloRun *>(tree->GetUserInfo()->First()); 00077 ////CaloRun *run=(CaloRun *)tree->GetUserInfo()->First(); 00078 00079 //xoffset = run->GetOffsetX(); 00080 //yoffset = run->GetOffsetY(); 00081 00082 //cout << "RunId[" << run->GetRunId() << "], temperature[" << run->GetTemperature() << "] pression[" << run->GetPressure() << "] " << endl ; 00083 string beam; 00084 try { 00085 // ui32 runId = mysql.getRunIdFromDhcalId(715573); 00086 beam = mysql.getRunEnergy(run->GetRunId()); 00087 } 00088 catch (MicroException e) {} 00089 00090 ////cout << "Beam[" << beam << "]" << endl; 00091 //cout << "Offset telescope - m2[" << xoffset << ", " << yoffset << "] " << endl ; 00092 } 00093 catch ( ... ) {} 00094 00095 CaloEvent *evt = new CaloEvent(); 00096 TBranch *branch= tree->GetBranch("CaloEvent"); 00097 branch->SetAddress(&evt); 00098 00099 CaloHit* hit =NULL; 00100 int nbEntries = tree->GetEntries(); 00101 //cout << "**** Event nb entries " << dec << nbEntries << endl; 00102 bool micromegasHit = false; 00103 for ( int evtNum = 0; evtNum < nbEntries ; evtNum++) 00104 { 00105 tree->GetEntry(evtNum); 00106 UInt_t nbRPCHit=0; 00107 nbEvt++; 00108 //cout << "**** Event Information "<< dec << evtNum+1 << "/" << nbEntries<< " ****" << endl; 00109 //cout << " event num in TTree:" << evtNum <<endl; 00110 //cout << " event id:" << evt->GetEventId() <<endl; 00111 00112 //cout << " number of channel hit:" << evt->GetNHits() <<"for event[" << evt->GetEventId() << "]" << endl; 00113 int nbHits = evt->GetNHits(); 00114 //cout << "nb hits:" << nbHits << endl; 00115 00116 float xtel = 0;// evt->GetXTelescope(); 00117 float ytel = 0;//evt->GetYTelescope(); 00118 00119 float xextrapol = xtel - xoffset; 00120 float yextrapol = ytel - yoffset; 00121 00122 hnhit->Fill(nbHits); 00123 00124 //number of hits in region of interest 00125 int nhit_roi = 0; 00126 float xpos = 0; 00127 float ypos = 0; 00128 float xresidual = 0; 00129 float yresidual = 0; 00130 00131 for(int i=0 ; i < nbHits ; i++) 00132 { 00133 hit = (CaloHit*)evt->GetHits()->UncheckedAt(i); 00134 xpos = hit->GetX(); 00135 ypos = hit->GetY(); 00136 hxy->Fill(xpos,ypos); 00137 if ( hit->GetLayer() >= 50) 00138 { 00139 micromegasHit = true; 00140 } 00141 if ( hit->GetLayer() < 50 ) { nbRPCHit++ ;} 00142 00143 00144 xresidual = xpos - xextrapol; 00145 yresidual = ypos - yextrapol; 00146 00147 hxres->Fill(xresidual); 00148 hyres->Fill(yresidual); 00149 00150 if ((fabs(xresidual)<=search) && (fabs(yresidual)<=search)) 00151 { 00152 nhit_roi++; 00153 } 00154 } // end hit 00155 00156 hnhit_roi->Fill(nhit_roi); 00157 00158 if ( evt->GetNHits()> 130 && micromegasHit && nbRPCHit < 100 ) 00159 { 00160 cout << " number of channel hit:" << evt->GetNHits() <<"for event[" << evt->GetEventId() << "] RPCHIT[" << nbRPCHit << "]" << endl; 00161 } 00162 } // end event 00163 } // end run ( TTree ) 00164 } 00165 TFile tf("temp.root","RECREATE"); 00166 hxres->Write(); 00167 hyres->Write(); 00168 hxy->Write(); 00169 hnhit->Write(); 00170 hnhit_roi->Write(); 00171 00172 }