| 1 | #include <TROOT.h>
|
|---|
| 2 | #include <TCanvas.h>
|
|---|
| 3 | #include <TH1.h>
|
|---|
| 4 |
|
|---|
| 5 | #include <stdint.h>
|
|---|
| 6 | #include <cstdio>
|
|---|
| 7 |
|
|---|
| 8 | #include "fits.h"
|
|---|
| 9 | #include "FOpenDataFile.c"
|
|---|
| 10 | #include "FOpenCalibFile.c"
|
|---|
| 11 | #include "FPedestalAllPx.c"
|
|---|
| 12 |
|
|---|
| 13 | int testFPedestalAllPx(
|
|---|
| 14 | const char *name = "../raw/20110916_025.fits",
|
|---|
| 15 | const char *drsname = "../raw/20110916_024.drs.fits")
|
|---|
| 16 | {
|
|---|
| 17 | //******************************************************************************
|
|---|
| 18 | //Read a datafile and plot the DRS-calibrated data
|
|---|
| 19 | //ATTENTION: only works for ROI=1024
|
|---|
| 20 | // (array indices of the calibration wrong otherwise)
|
|---|
| 21 | //Example call in ROOT:
|
|---|
| 22 | //root [74] .x calscope.C++("20110804_024.fits","20110804_023.drs.fits",10,1348)
|
|---|
| 23 | //T. Kr�henb�hl, August 2011, tpk@phys.ethz.ch
|
|---|
| 24 | //******************************************************************************
|
|---|
| 25 |
|
|---|
| 26 | gROOT->SetStyle("Plain");
|
|---|
| 27 |
|
|---|
| 28 | //-------------------------------------------
|
|---|
| 29 | //Open the file
|
|---|
| 30 | //-------------------------------------------
|
|---|
| 31 | fits datafile(name);
|
|---|
| 32 | if (!datafile)
|
|---|
| 33 | {
|
|---|
| 34 | cout << "Couldn't properly open the datafile." << endl;
|
|---|
| 35 | return 1;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | //-------------------------------------------
|
|---|
| 39 | //Get the data
|
|---|
| 40 | //-------------------------------------------
|
|---|
| 41 | vector<int16_t> data;
|
|---|
| 42 | vector<int16_t> data_offset;
|
|---|
| 43 | unsigned int data_num;
|
|---|
| 44 | size_t data_n;
|
|---|
| 45 | UInt_t data_px;
|
|---|
| 46 | UInt_t data_roi;
|
|---|
| 47 | FOpenDataFile(datafile, data, data_offset, data_num, data_n, data_roi, data_px);
|
|---|
| 48 |
|
|---|
| 49 | //-------------------------------------------
|
|---|
| 50 | //Get the DRS calibration
|
|---|
| 51 | //-------------------------------------------
|
|---|
| 52 | size_t drs_n;
|
|---|
| 53 | vector<float> drs_basemean;
|
|---|
| 54 | vector<float> drs_gainmean;
|
|---|
| 55 | vector<float> drs_triggeroffsetmean;
|
|---|
| 56 |
|
|---|
| 57 | FOpenCalibFile(drsname, drs_basemean, drs_gainmean, drs_triggeroffsetmean, drs_n);
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | //-------------------------------------------
|
|---|
| 61 | //Check the sizes of the data columns
|
|---|
| 62 | //-------------------------------------------
|
|---|
| 63 | if(drs_n!=data_n)
|
|---|
| 64 | {
|
|---|
| 65 | cout << "Data and DRS file incompatible (Px*ROI disagree)" << endl;
|
|---|
| 66 | return 1;
|
|---|
| 67 | }
|
|---|
| 68 | else{
|
|---|
| 69 | cout << "Data and DRS file compatible" << endl;
|
|---|
| 70 | // continue
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | //-------------------------------------------
|
|---|
| 75 | //Create the title
|
|---|
| 76 | //-------------------------------------------
|
|---|
| 77 | // char title[500];
|
|---|
| 78 | // std::sprintf(title,"Data: %s, DRS: %s, Px %i Ev %i",name,drsname,pixelnr,eventnr);
|
|---|
| 79 |
|
|---|
| 80 | //-------------------------------------------
|
|---|
| 81 | //Get the pedestals & RMS
|
|---|
| 82 | //-------------------------------------------
|
|---|
| 83 | float pedestal_mean[data_px];
|
|---|
| 84 | float pedestal_rms[data_px];
|
|---|
| 85 |
|
|---|
| 86 | FPedestalAllPx(datafile, data, data_offset, drs_basemean, drs_gainmean, drs_triggeroffsetmean, data_px, data_roi, pedestal_mean, pedestal_rms);
|
|---|
| 87 |
|
|---|
| 88 | // vector<float> calevent(data_px*data_roi); //Vector for the calibrated event
|
|---|
| 89 | // FGetCalEvent(data, data_offset, drs_basemean, drs_gainmean, drs_triggeroffsetmean, calevent, data_px, data_roi);
|
|---|
| 90 |
|
|---|
| 91 | //-------------------------------------------
|
|---|
| 92 | //Draw the data
|
|---|
| 93 | //-------------------------------------------
|
|---|
| 94 |
|
|---|
| 95 | TCanvas *canv_mean= new TCanvas( "canv_mean", "mean in mV", 30, 300, 900, 500 );
|
|---|
| 96 | TH1F* histo_mean = new TH1F("histo_mean","Value of maximal probability",2000,-99.5,100.5);
|
|---|
| 97 | TCanvas *canv_rms= new TCanvas( "canv_rms", "RMS in mV", 960, 300, 900, 500 );
|
|---|
| 98 | TH1F* histo_rms = new TH1F("histo_rms","RMS in mV",2000,-99.5,100.5);
|
|---|
| 99 |
|
|---|
| 100 | for (int j=0; j<data_px; j++)
|
|---|
| 101 | {
|
|---|
| 102 | histo_mean->Fill(pedestal_mean[j]);
|
|---|
| 103 | histo_rms->Fill(pedestal_rms[j]);
|
|---|
| 104 | }
|
|---|
| 105 | // histo_mean->GetYaxis()->SetRangeUser(0,150);
|
|---|
| 106 |
|
|---|
| 107 | canv_mean->cd();
|
|---|
| 108 | histo_mean->Draw();
|
|---|
| 109 | canv_mean->Modified();
|
|---|
| 110 | canv_mean->Update();
|
|---|
| 111 | canv_rms->cd();
|
|---|
| 112 | histo_rms->Draw();
|
|---|
| 113 | canv_rms->Modified();
|
|---|
| 114 | canv_rms->Update();
|
|---|
| 115 |
|
|---|
| 116 | return 0;
|
|---|
| 117 | }
|
|---|