#include #include #include #include #include #include #include "fits.h" int calscope_persistent(const char *name, const char *drsname, size_t pixelnr, UInt_t maxevents) { //****************************************************************************** //Read a datafile and plot the DRS-calibrated data //ATTENTION: only works for ROI=1024 // (array indices of the calibration wrong otherwise) //Example call in ROOT: //root [74] .x calscope.C++("20110804_024.fits","20110804_023.drs.fits",10,1348) //T. Krähenbühl, August 2011, tpk@phys.ethz.ch //****************************************************************************** gROOT->SetStyle("Plain"); //------------------------------------------- //Open the files //------------------------------------------- fits datafile(name); fits drsfile(drsname); if (!datafile) { cout << "Couldn't properly open the datafile." << endl; return 1; } if (!drsfile) { cout << "Couldn't properly open the drsfile." << endl; return 1; } //------------------------------------------- //Print the headers //------------------------------------------- cout << "-------------------- Data Header -------------------" << endl; datafile.PrintKeys(); cout << "----------------- DRS Calib Header -----------------" << endl; drsfile.PrintKeys(); cout << "------------------- Data Columns -------------------" << endl; datafile.PrintColumns(); cout << "---------------- DRS Calib Columns -----------------" << endl; drsfile.PrintColumns(); cout << "--------------------- Data --------------------" << endl; //------------------------------------------- //Get the sizes of the data columns //------------------------------------------- const size_t data_n = datafile.GetN("Data"); //Size of column "Data" = #Pixel x ROI const size_t drs_n = drsfile.GetN("BaselineMean"); if(drs_n!=data_n) { cout << "Data and DRS file incompatible (Px*ROI disagree)" << endl; return 1; } const UInt_t data_roi = datafile.GetUInt("NROI"); // Value from header const UInt_t data_px = datafile.GetUInt("NPIX"); //------------------------------------------- //Link the data to variables //------------------------------------------- unsigned int data_num; datafile.SetRefAddress("EventNum", data_num); vector data(data_n); datafile.SetVecAddress("Data", data); vector dataOffset(data_px); datafile.SetVecAddress("StartCellData", dataOffset); vector drs_basemean(drs_n); drsfile.SetVecAddress("BaselineMean", drs_basemean); vector drs_gainmean(drs_n); drsfile.SetVecAddress("GainMean", drs_gainmean); vector drs_triggeroffsetmean(drs_n); drsfile.SetVecAddress("TriggerOffsetMean", drs_triggeroffsetmean); drsfile.GetRow(0); //Read the calibration data //------------------------------------------- //Create the canvas, plot and title //------------------------------------------- char title[500]; std::sprintf(title,"Data: %s, DRS: %s, Px %i",name,drsname,pixelnr); TCanvas *canv = new TCanvas( "canv", "Mean values of the first event", 100, 10, 700, 500 ); TProfile *pix = new TProfile("pix", title, 1024, -0.5, 1023.5); pix->GetXaxis()->SetTitle("DRS bin (@2 GHz)"); pix->GetYaxis()->SetTitle("Amplitude (mV)"); char ptitle[500]; std::sprintf(ptitle,"Data: %s, DRS: %s, Px %i",name,drsname); TCanvas *pcanv = new TCanvas( "pcanv", title, 800, 10, 700, 500 ); TH2F *pers = new TH2F("pers",ptitle,1024,-0.5,1023.5,200,-49.5,150.5); pers->GetXaxis()->SetTitle("DRS bin (@2 GHz)"); pers->GetYaxis()->SetTitle("Amplitude (mV)"); //------------------------------------------- //Iterate over the events //------------------------------------------- if(maxevents==0) maxevents = datafile.GetNumRows(); // for (size_t i=0; iFill(k,sample); pers->Fill(k,sample); } // } } //------------------------------------------- //Draw the data //------------------------------------------- canv->cd(); pix->Draw(); canv->Modified(); canv->Update(); pcanv->cd(); pers->Draw("col"); pcanv->Modified(); pcanv->Update(); return 0; }