| 1 | #include <TROOT.h> | 
|---|
| 2 | #include <TCanvas.h> | 
|---|
| 3 | #include <TProfile.h> | 
|---|
| 4 | #include <TTimer.h> | 
|---|
| 5 | #include <TH1F.h> | 
|---|
| 6 | #include <TH2F.h> | 
|---|
| 7 | #include <Getline.h> | 
|---|
| 8 | #include <TLine.h> | 
|---|
| 9 | #include <TBox.h> | 
|---|
| 10 | #include <TMath.h> | 
|---|
| 11 | #include <TFile.h> | 
|---|
| 12 | #include <TStyle.h> | 
|---|
| 13 |  | 
|---|
| 14 | #include <stdio.h> | 
|---|
| 15 | #include <stdint.h> | 
|---|
| 16 | #include <cstdio> | 
|---|
| 17 | #include <deque> | 
|---|
| 18 |  | 
|---|
| 19 | #define NPIX  1440 | 
|---|
| 20 | #define NCELL 1024 | 
|---|
| 21 | #define FAD_MAX_SAMPLES 1024 | 
|---|
| 22 |  | 
|---|
| 23 | #define HAVE_ZLIB | 
|---|
| 24 | #include "fits.h" | 
|---|
| 25 |  | 
|---|
| 26 | #include "openFits.h" | 
|---|
| 27 | #include "openFits.c" | 
|---|
| 28 |  | 
|---|
| 29 | #include "discriminator.h" | 
|---|
| 30 | #include "discriminator.C" | 
|---|
| 31 | #include "factfir.C" | 
|---|
| 32 |  | 
|---|
| 33 | #include "FOpenDataFile.h" | 
|---|
| 34 | #include "FOpenDataFile.c" | 
|---|
| 35 |  | 
|---|
| 36 | #include "DrsCalibration.C" | 
|---|
| 37 | #include "DrsCalibration.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include "SpikeRemoval.h" | 
|---|
| 40 | #include "SpikeRemoval.C" | 
|---|
| 41 |  | 
|---|
| 42 | bool breakout=false; | 
|---|
| 43 | int verbosityLevel = 1; | 
|---|
| 44 |  | 
|---|
| 45 | int NEvents; | 
|---|
| 46 | vector<int16_t> AllPixelDataVector; | 
|---|
| 47 | vector<int16_t> StartCellVector; | 
|---|
| 48 | unsigned int CurrentEventID; | 
|---|
| 49 | size_t PXLxROI; | 
|---|
| 50 | UInt_t RegionOfInterest; | 
|---|
| 51 | UInt_t NumberOfPixels; | 
|---|
| 52 |  | 
|---|
| 53 | size_t TriggerOffsetROI, RC; | 
|---|
| 54 | vector<float> Offset, Gain, TriggerOffset; | 
|---|
| 55 |  | 
|---|
| 56 | vector<float> Ameas(FAD_MAX_SAMPLES);  // copy of the data (measured amplitude | 
|---|
| 57 | vector<float> Vcorr(FAD_MAX_SAMPLES);  // corrected Values | 
|---|
| 58 | vector<float> Vslide(FAD_MAX_SAMPLES);  // sliding average result | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | TH1F *waveform = NULL; | 
|---|
| 62 | TCanvas *funnycanvas = NULL; | 
|---|
| 63 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 64 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 65 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 66 | // read FACT raw data | 
|---|
| 67 | //      * remove spikes | 
|---|
| 68 | //      * calculate baseline | 
|---|
| 69 | //      * find peaks (CFD and normal discriminator) | 
|---|
| 70 | //      * compute pulse height and pulse integral spektrum of the peaks | 
|---|
| 71 | int example_new( | 
|---|
| 72 | char *datafilename              = "datafile.fits.gz", | 
|---|
| 73 | const char *drsfilename = "calibfile.drs.fits.gz", | 
|---|
| 74 | int firstevent                  = 0, | 
|---|
| 75 | int nevents                     = -1, | 
|---|
| 76 | int firstpixel                  = 0, | 
|---|
| 77 | int npixel                      = -1 | 
|---|
| 78 | ) | 
|---|
| 79 | { | 
|---|
| 80 | gStyle->SetPalette(1,0); | 
|---|
| 81 | gROOT->SetStyle("Plain"); | 
|---|
| 82 |  | 
|---|
| 83 | // create a new TH1F for displaying the wave form ... the binning will be set again, just before we use it | 
|---|
| 84 | // so the binning is here just a dummy setting... | 
|---|
| 85 | waveform = new TH1F("waveform", "content of current pixel in current Event", 1024,-0.5,1023.5); | 
|---|
| 86 | funnycanvas = new TCanvas("funnycanvas","funny title", 0 , 0 ,300,300); | 
|---|
| 87 |  | 
|---|
| 88 | fits * datafile; | 
|---|
| 89 | // Opens the raw data file and 'binds' the variables given as | 
|---|
| 90 | // Parameters to the data file. So they are filled with | 
|---|
| 91 | // raw data as soon as datafile->GetRow(int) is called. | 
|---|
| 92 | NEvents = openDataFits( datafilename, &datafile, | 
|---|
| 93 | AllPixelDataVector, StartCellVector, CurrentEventID, | 
|---|
| 94 | RegionOfInterest, NumberOfPixels, PXLxROI, verbosityLevel); | 
|---|
| 95 | if (NEvents == 0){ | 
|---|
| 96 | cout << "return code of OpenDataFile:" << datafilename<< endl; | 
|---|
| 97 | cout << "is zero -> aborting." << endl; | 
|---|
| 98 | return 1; | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | if (verbosityLevel > 0) | 
|---|
| 102 | cout <<"number of events in file: "<< NEvents << "\t"; | 
|---|
| 103 | if ( nevents == -1 || nevents > NEvents ) nevents = NEvents; // -1 means all! | 
|---|
| 104 | if (verbosityLevel > 0) | 
|---|
| 105 | cout <<"of, which "<< nevents << "will be processed"<< endl; | 
|---|
| 106 |  | 
|---|
| 107 | if (verbosityLevel > 0) | 
|---|
| 108 | cout <<"Total # of Pixel: "<< NumberOfPixels << "\t"; | 
|---|
| 109 | if ( npixel == -1 || npixel > (int)NumberOfPixels  ) npixel = (int)NumberOfPixels; // -1 means all! | 
|---|
| 110 | if (verbosityLevel > 0) | 
|---|
| 111 | cout <<"of, which "<< npixel << "will be processed"<< endl; | 
|---|
| 112 |  | 
|---|
| 113 | RC = openCalibFits( drsfilename, Offset, Gain, TriggerOffset, TriggerOffsetROI); | 
|---|
| 114 | if (RC == 0){ | 
|---|
| 115 | cout << "return code of openCalibFits:" << drsfilename << endl; | 
|---|
| 116 | cout << "is zero -> aborting." << endl; | 
|---|
| 117 | return 1; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | //----------------------------------------------------------------------------- | 
|---|
| 121 | // Loops over Every Event and Pixel | 
|---|
| 122 | //----------------------------------------------------------------------------- | 
|---|
| 123 | cout << "Processing Events in total: " << nevents << endl; | 
|---|
| 124 |  | 
|---|
| 125 | for ( int ev = firstevent; ev < firstevent + nevents; ev++) { | 
|---|
| 126 | // Get an Event --> consists of 1440 Pixel ...erm....data | 
|---|
| 127 | datafile->GetRow( ev ); | 
|---|
| 128 |  | 
|---|
| 129 | for ( int pix = firstpixel; pix < firstpixel+npixel; pix++ ){ | 
|---|
| 130 |  | 
|---|
| 131 | applyDrsCalibration( Ameas,pix,12,12, | 
|---|
| 132 | Offset, Gain, TriggerOffset, | 
|---|
| 133 | RegionOfInterest, AllPixelDataVector, StartCellVector); | 
|---|
| 134 |  | 
|---|
| 135 | // finds spikes in the raw data, and interpolates the value | 
|---|
| 136 | // spikes are: 1 or 2 slice wide, positive non physical artifacts | 
|---|
| 137 | removeSpikes (Ameas, Vcorr); | 
|---|
| 138 |  | 
|---|
| 139 | // filter Vcorr with sliding average using FIR filter function | 
|---|
| 140 | sliding_avg(Vcorr, Vslide, 8); | 
|---|
| 141 |  | 
|---|
| 142 |  | 
|---|
| 143 | waveform->GetXaxis()->Set(Vslide.size() , -0.5 , Vslide.size()-0.5); | 
|---|
| 144 |  | 
|---|
| 145 | for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ | 
|---|
| 146 | waveform->SetBinContent( sl, Vslide[sl] ); | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 |  | 
|---|
| 150 | waveform->Draw(); | 
|---|
| 151 | funnycanvas->Modified(); | 
|---|
| 152 | funnycanvas->Update(); | 
|---|
| 153 |  | 
|---|
| 154 | //Process gui events asynchronously during input | 
|---|
| 155 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE); | 
|---|
| 156 | timer.TurnOn(); | 
|---|
| 157 | TString input = Getline("Type 'q' to exit, <return> to go on: "); | 
|---|
| 158 | timer.TurnOff(); | 
|---|
| 159 | if (input=="q\n") { | 
|---|
| 160 | breakout=true; | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | if (breakout) break; | 
|---|
| 164 | } // end of loop over pixels | 
|---|
| 165 | if (breakout) break; | 
|---|
| 166 | }       // end of loop over pixels | 
|---|
| 167 |  | 
|---|
| 168 | cout << "Event processing done." << endl; | 
|---|
| 169 |  | 
|---|
| 170 | return 0; | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|