/////////////////////////////////////////////////////////////////////////////// // main.c #include "wrapper.h" #include "rawdata.h" int main(int argc,char *args[]) { char inFile[]="c:\\makent\\R0857P00.BIN"; // Create root objects, including output file RootManager *pRoot = new RootManager(); pRoot->Open("ap.exe"); // create RawData object RawData *pRaw = new RawData(); pRaw->Open(inFile); char *pBinary = pRaw->GetHeader(); pRoot->FillHeader(inFile,pBinary,1024); double dZ = 0; while(pRaw->ReadNext()!=RawData::END_OF_FILE) { double x0,x1,y0,y1,dPulse,dRate; float specHV,aperHV; unsigned short flag; pRaw->GetEvent(flag,x0,x1,y0,y1,specHV,aperHV,dPulse,dRate); pRoot->Fill(flag); if (flag!=0xf) continue; pRoot->Fill(x0,x1,y0,y1,(float)dZ,specHV,aperHV,dPulse,dRate); dZ++; } // pRoot->Close(); delete pRaw; delete pRoot; return 0; } /////////////////////////////////////////////////////////////////////////////// // rawdata.h class RawData { public: enum {OK = 0}; enum {FILE_NOT_FOUND = -1}; enum {END_OF_FILE = -2}; enum {BAD_HIT_REG = -3}; enum {BAD_FILE_VERSION = -4}; CRawData(); int Open(char *infile); int ReadNext(); int GetEvent(unsigned short &flag,double &x0,double &x1,double &y0,double &y1,float &specHV,float &aperHV,double &pulse,double &rate); char *GetHeader(); }; /////////////////////////////////////////////////////////////////////////////// // wrapper.h class TFile; class TNtuple; class TH1F; class TH1C; class TApplication; class RootManager { public: enum{ RAW = 1}; enum{ CUT = 2}; RootManager(); ~RootManager(); void Open(const char *fname); void Fill(double x0,double x1,double y0,double y1,double z,float specHv,float aperHv,double pulse,double rate); void Fill(unsigned short flag); void FillHeader(const char *title,char *buf,int size); void Close(); private: TFile *m_hFile; TNtuple *m_Ntuple; TH1F *m_hits; TH1F *m_doubles; TH1F *m_flag; TH1C *m_Header; TApplication *m_pApp; }; /////////////////////////////////////////////////////////////////////////////// // wrapper.c #include "stdlib.h" #include "TROOT.h" #include "TApplication.h" #include "TFile.h" #include "TNtuple.h" #include "TH1.h" #include "wrapper.h" TROOT root("rint", "The ROOT Interactive Interface"); //////////////////////////////////////////////////////////////// RootManager::RootManager() { // ctor - create the TApplication() object int argc=0; char *argv[50]; m_pApp = new TApplication("App",&argc,argv); } RootManager::~RootManager() { // dtor - note: since version 3.03/9, the delete m_pApp causes program to stall // for 10 seconds or so - eliminated delete m_hFile; //delete m_pApp; } void RootManager::Open(const char *fname) { // Create an output root file and create the objects to save char pname[132]; strcpy(pname,getenv("ROOTSYS")); strcat(pname,"\\"); strcat(pname,fname); m_hFile = new TFile(pname,"RECREATE","ap data"); m_Ntuple = new TNtuple("nt","Raw","x:y:tof:z:v:delta:pulse:vap:erate"); m_hits = new TH1F("pHits","hits",16,-.5,15.5); m_doubles = new TH1F("pDoubles","double hits",16,-.5,15.5); m_flag = new TH1F("pFlag","flag",256,-.5,255.5); } void RootManager::Fill(double x0,double x1,double y0,double y1,double z,float specHv,float aperHv,double pulse,double rate) { // fill the ntuple Float_t x = (Float_t)(x0-x1+.01); Float_t y = (Float_t)(y0-y1+.01); Float_t tof = (Float_t)(0.25*(x0+x1+y0+y1)+.01); Float_t delta = (Float_t)(x0+x1-y0-y1+.01); m_Ntuple->Fill(x,y,tof,(Float_t)z,(Float_t)specHv,delta,(Float_t)pulse,(Float_t)aperHv,(Float_t)rate); } void RootManager::Close() { // write the output file m_hFile->Write(); } void RootManager::Fill(unsigned short flag) { // fill the histograms m_hits->Fill((Float_t)(flag&0xf)); m_doubles->Fill((Float_t)(flag>>4)); m_flag->Fill((Float_t)flag); } void RootManager::FillHeader(const char *title,char *buf,int size) { // buf points to a chunk of binary data - store it in a TH1C: // create the histo, store buf in it and write the data. m_Header = new TH1C("pHeader","Header",size,0.,1.); char *p = m_Header->GetArray(); memcpy(&p[1],buf,size); //for(int i=0;iSetTitle(title); m_Header->Write(); delete m_Header; }