// COMET software includes #include "IMidasBank.hxx" #include "IMidasFile.hxx" #include "IMidasBankProxy.hxx" #include "IMidasBankProxyRegistry.hxx" #include "ICOMETRawEvent.hxx" // oaRawEvent includes #include "ITripTDigitBank.hxx" #include "IMidasTripTDigitItr.hxx" #include "IMidasTripTDigit.hxx" // ROOT includes #include "TApplication.h" #include "TFile.h" #include "TH1F.h" #include "TH2F.h" #include #include "TString.h" #include "TSystem.h" #include #include #include #include #include TFile *gFile = NULL; TH1F *gHHAdc = NULL; TH1F *gHLAdc = NULL; TH2F *gTFBHitMap = NULL; TH2F *gRMMHitMap = NULL; TH1F *gTime = NULL; TH1F *gCycle = NULL; //____________________________________________________________________________ void Book() { // Book some very basic histograms to show the data gHHAdc = new TH1F("High Gain ADC","High Gain ADC", 1024,0.,1024.); gHLAdc = new TH1F("Low Gain ADC","Low Gain ADC", 1024,0.,1024.); gCycle = new TH1F("Integration Cycle","Integration Cycle", 23,0.,23.); gTFBHitMap = new TH2F("TFB Hit Map","TFB Hit Map", 64,0.,64.,48,0.,48.); gRMMHitMap = new TH2F("RMM Hit Map", "RMM Hit Map 0=P0D, 1=INGRID, 2=ECAL, 3=SMRD", 12,0.,12.,5,0.,5.); gTime = new TH1F("Time distribution","Time Distribution", 1000,0.,1024.*1024.*16.); } //____________________________________________________________________________ void Event(COMET::ICOMETRawEvent* re) { // Loop over all banks of type TTripTHitBank COMET::IHandle triptBank; while ( triptBank = re->GetMidasBank("",triptBank) ) { const Char_t *name = triptBank->GetName(); Int_t rmm = (name[2]>'9')?(name[2]-'A'+10):(name[2]-'0'); // RMM is third digit in the bank name, 0123456789ABCDEFG... Int_t detector = (name[0]=='P') ? 0 : // P0D (name[0]=='I') ? 1 : // INGRID (name[0]=='E') ? 2 : // ECAL (name[0]=='S') ? 3 : 4; // SMRD : 4=Unknown // printf("Bank name %s rmm %d detector %d\n",name,rmm,detector); // ********* At this point, you probably want to be selective about which detector // ********* you want to use, e.g. if you only want to see the P0D, do this // ********* if (detector != 0) continue; // Create an iterator over digits COMET::IMidasTripTDigitItr itr(triptBank->GetMidasTripTDigitItr()); while ( ! itr.EOD() ) { COMET::IMidasTripTDigit digit(itr.Get()); Int_t lowadc = digit.GetLowGainADC(); Int_t highadc = digit.GetHighGainADC(); Int_t chan64 = digit.GetChannelNum() + 16*digit.GetTripTNum(); Int_t tfb = digit.GetTFBNum(); Int_t time = digit.GetTimeOffset(); Int_t cycle = digit.GetIntegrationNum(); // A little more work is needed to develop the time variable. The hardware records // a 44-bit offset from the nearest hardware 1-sec reset. To compress this, the // online subtracts a fixed offset and a further offset depending on the cycle // number. It fits it into 24 bits. We have plans to later further compress the // data and store this in a 12 bit number. For now, the digit.GetTimeOffset(); // only returns the compressed time. This should normally be OK. We will add // another two methods: GetFullTime() which will add back the offsets and give // the 44-bit number and GetTimeStatus() which will return codes for e.g. // 'there was no TDC hit on this channel'. At the moment 'no TDC hit on this channel' // is flagged by digit.GetTimeOffset() returning the value RAWDPT_DVX_FMT0_TIMENOHIT. // (which is 0x00FFFFF1). // This is why there is a big spike of entries in the right hand bin on the // gTime plot we make below). gHHAdc->Fill(highadc); gHLAdc->Fill(lowadc); gCycle->Fill(cycle); gTFBHitMap->Fill(chan64,tfb); gRMMHitMap->Fill(rmm,detector); gTime->Fill(time); } // End of loop over digits in this bank } // End of loop over banks of digits in this event } //____________________________________________________________________________ void ProcessFile(const char *FileName) { // Start by listing the available Access Classes. COMETLog("Access Classes available to interpret the MIDAS banks"); COMET::IMidasBankProxyRegistry::Instance().Print(); // Make sure file exists FileStat_t fs; if ( gSystem->GetPathInfo(FileName,fs) ) { std::cerr << "Cannot find file: " << FileName << std::endl; return; } COMET::IMidasFile mf; mf.Open(FileName); // Loop over events in this file while ( COMET::ICOMETRawEvent* re = mf.ReadRawEvent() ) { re->PromoteMidasBanks(false); Event(re); delete re; } // End loop over events } //____________________________________________________________________________ int main(int argc, char **argv) { // Get the filename from argv[1] before TApplication modifies the // argument list!!! if (argc != 2) { std::cerr << "usage: " << argv[0] << " " << std::endl; } char FileName[1000]; strncpy(FileName,argv[1],1000); printf("Filename %s\n",FileName); // Start the root system TApplication *app = new TApplication("TCRTestRead", &argc, argv); gROOT->SetBatch(); if (app) ; // This just removes 'unused variable app' compiler warning // Open an output root file. gFile = new TFile("AccessRawData.root","RECREATE","Demonstration ROOT file"); // Book the histograms Book(); // Analyse the data ProcessFile(FileName); // Close root histogram output file gFile->Write(); gFile->Close(); delete gFile; gFile = NULL; return 0; }