#include "TH1I.h" #include "TProfile.h" #include "TFile.h" #include "TTimeStamp.h" #include "stdlib.h" #include #include #include #define NUM_ELEMENTS(aname) (sizeof(aname)/sizeof(aname[0])) namespace test{ // constants controlling the key // parameters of the test programme: // pixel matrix dimensions: const unsigned short ROW_COUNT=45; const unsigned short COL_COUNT=40; // number of charges const unsigned short CHARGE_COUNT=14; // number of phases const unsigned short PHASE_COUNT=1; // number of const int FILL_LOOP_COUNT=100000; // // a 2-D pixel address // class pixel_address{ public: pixel_address(int rnd=0):mRow(0),mCol(0){if(rnd){this->Rnd();}} pixel_address(const pixel_address & addr):mRow(addr.mRow),mCol(addr.mCol){} int operator<(const pixel_address & rhs)const{ if(this==&rhs){return 0;} if(mCol::iterator it=mQMap.begin(); std::map::iterator end=mQMap.end(); while(it!=end){delete it->second;it->second=0;++it;} mQMap.clear(); } TH1I * Histogram(unsigned short qidx){ TH1I * temp=0; //std::cout<<"mQMap.size() = "<::iterator it=mQMap.find(qidx); if(mQMap.end()==it){ if(0){ std::cout<<"charge index not found: " <second; } return temp; } int WriteResults(TDirectory * d){ std::map::iterator it=mQMap.begin(); std::map::iterator end=mQMap.end(); d->cd(); while(it!=end){ it->second->Write(); ++it; } return 0; } private: std::string mName; pixel_address mAddr; std::map mQMap; }; // // The set of histograms for a pixel: // T1 : a map of the time of discriminator leading edge to the charge injected // T2 : a map of the time of discriminator trailing edge to the charge injected // TOT: a map of the time of discriminator time over threshold to the charge injected // class pixel_histograms{ public: pixel_histograms(const pixel_address & addr): mAddr(addr), mT1(addr, "T1"), mT2(addr, "T2"), mTOT(addr, "TOT") { } int Fill() { for(unsigned short qidx(0); qidx!=CHARGE_COUNT; qidx++){ //std::cout<<"filling for charge index = "<Fill((rand()%100)+10); temp=mT2.Histogram(qidx); temp->Fill((rand()%100)+200); temp=mTOT.Histogram(qidx); temp->Fill(rand()%100); } return 0; } int WriteResults(TDirectory * d){ TDirectory * sd=0; // write out for T1: d->cd(); sd=d->mkdir("T1"); if(!sd){ std::cerr<<"unable to create sub-directory: T1\n"; }else{ mT1.WriteResults(sd); } // write out for T2: d->cd(); sd=d->mkdir("T2"); if(!sd){ std::cerr<<"unable to create sub-directory: T2\n"; }else{ mT2.WriteResults(sd); } // Write out for TOT: d->cd(); sd=d->mkdir("TOT"); if(!sd){ std::cerr<<"unable to create sub-directory: TOT\n"; }else{ mTOT.WriteResults(sd); } return 0; } private: pixel_address mAddr; charge_map mT1; charge_map mT2; charge_map mTOT; }; // // the histograms for the pixel array // // class matrix_histograms{ public: matrix_histograms(){} ~matrix_histograms(){// owns everything pointed to: clean-up std::map::iterator it=mMatrix.begin(); std::map::iterator e=mMatrix.end(); while(it!=e){delete it->second; it->second=0;++it;} mMatrix.clear(); } pixel_histograms * Pixel(const pixel_address & addr){ pixel_histograms * temp=0; std::map::iterator it=mMatrix.find(addr); if(it==mMatrix.end()){// not yet instanced: construct and insert std::cout<<"pixel histograms not found, creating new ones: "<second; } return temp; } int WriteResults(TDirectory * d){ std::map::iterator it=mMatrix.begin(); std::map::iterator e=mMatrix.end(); while(it!=e){ char dname[256]; snprintf(dname, NUM_ELEMENTS(dname)-1, "pixel_%d_%d",it->first.mCol,it->first.mRow); d->cd(); TDirectory * sd=d->mkdir(dname); if(!sd){ std::cerr<<"unable to create sub-directory: "<second->WriteResults(sd); } ++it; } } private: std::map mMatrix; }; // // a test "analysis" class // // // // class analysis{ public: analysis():mOutputFile("histos.root"){ TFile * fout=TFile::Open("histos.root", "RECREATE"); if(fout){ fout->Close();delete fout;fout=0; }else{/*a problem*/ std::cerr<<"unable to recreate file : "<mkdir(dirname); if(!d){ std::cerr<<"unable to create directory: "<WriteResults(d); } TTimeStamp write_done; fout->Flush(); TTimeStamp flush_done; fout->Close(); TTimeStamp close_done; delete fout; fout=0; TTimeStamp delete_done; std::cout<<"time to write = "<