Changeset 12356
- Timestamp:
- 11/01/11 14:59:46 (13 years ago)
- Location:
- fact/tools/rootmacros
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/README.txt
r12264 r12356 1 1 README of FACT svntools/rootmacros 2 2 3 3 4 fbsl.C ROOT Macro computing the baseline for each pixel 5 the function is declared as: 6 int fbsl( 7 const char *datafilename = "path-to-datafile.fits.gz", 8 const char *drsfilename = "path-to-calibfile.drs.fits.gz", 9 const char *TextOutFileName = "./appendfile.txt", 10 const char *RootOutFileName = "./datafile.root", 11 int firstevent = 0, 12 int nevents = -1, 13 int firstpixel = 0, 14 int npixel = -1, 15 bool produceGraphic = false 16 ) 17 18 the baseline and its rms is calculated for each pixel based on the data, 19 given in the datafile. 20 the results are appended to a textfile 21 and the histograms ,which were used for caluculation, as well as some 22 overviews are stored in a root file. 23 the 4 ints: firstevent, nevents, firstpixel, npixel can be used to calculate 24 only for a subset 25 the last bool can be set to true, which will open 2 Canvases with overview 26 histograms. 27 28 for automatic production of baseline analysis one can call this macro like 29 this: 30 e.g. 31 root -l -q fbsl.C++'("/data00/fact-construction/raw/2011/10/26/20111026_036.fits.gz", "/data00/fact-construction/raw/2011/10/26/20111026_031.drs.fits.gz", "./fbsl.txt", "./20111026_036.root")' 32 33 34 on the ISDC cluster, I used /opt/root5.18.x86_64/bin/root for testing. -
fact/tools/rootmacros/factfir.C
r12304 r12356 2 2 #include <deque> 3 3 4 5 #ifndef FAD_MAX_SAMPLES6 #warning FAD_MAX_SAMPLES not defined. defining: FAD_MAX_SAMPLES to 10247 #define FAD_MAX_SAMPLES 10248 #endif9 10 4 // source vector is 11 // float Ameas[FAD_MAX_SAMPLES];12 5 void factfir(double b, vector<double> &a, int k, vector<float> &source, vector<float> &dest){ 13 6 //dest.clear(); 14 7 15 for (int slice =0; slice < FAD_MAX_SAMPLES; slice++) {8 for (int slice =0; slice < (int)source.size(); slice++) { 16 9 float currentval = 0; 17 10 18 11 for (int i=0; i < k ; i++){ 19 currentval += a[i] * source[ (slice - i + FAD_MAX_SAMPLES) % FAD_MAX_SAMPLES];12 currentval += a[i] * source[ (slice - i + source.size()) % source.size() ]; 20 13 } 21 14 dest[slice] = currentval / b; -
fact/tools/rootmacros/fbsl.C
r12307 r12356 16 16 #define HAVE_ZLIB 17 17 #include "fits.h" 18 //#include "TPKplotevent.c"19 //#include "FOpenDataFile.c"20 18 #include "FOpenCalibFile.c" 21 19 22 20 #include "zerosearch.C" 21 #include "factfir.C" 23 22 24 23 #define NPIX 1440 … … 28 27 #define FAD_MAX_SAMPLES 1024 29 28 30 vector<int16_t> data; 31 vector<int16_t> data_offset; 32 33 unsigned int data_num; 34 35 size_t data_n; 36 UInt_t data_px; 37 UInt_t data_roi; 29 //vector<int16_t> data; 30 //vector<int16_t> data_offset; 31 //unsigned int data_num; 32 //size_t data_n; 33 //UInt_t data_px; 34 //UInt_t data_roi; 35 vector<int16_t> Data; // vector, which will be filled with raw data 36 vector<int16_t> StartCells; // vector, which will be filled with DRS start positions 37 unsigned int EventID; // index of the current event 38 UInt_t RegionOfInterest; // Width of the Region, read out of the DRS 39 UInt_t NumberOfPixels; // Total number of pixel, read out of the camera 40 size_t PXLxROI; // Size of column "Data" = #Pixel x ROI 41 38 42 int NEvents; 39 43 int NBSLeve = 1000; … … 44 48 vector<float> drs_triggeroffsetmean; 45 49 46 int FOpenDataFile( fits & ); 50 size_t FOpenDataFile( 51 const char *datafilename, // path to fits file containing FACT raw data 52 fits * * datafile, // pointer to pointer, where to return the fits object 53 vector<int16_t> &Data, // vector, which will be filled with raw data 54 vector<int16_t> &StartCells, // vector, which will be filled with DRS start positions 55 unsigned int &EventID, // index of the current event 56 UInt_t &RegionOfInterest, // Width of the Region, read out of the DRS 57 UInt_t &NumberOfPixels, // Total number of pixel, read out of the camera 58 size_t &PXLxROI, // Size of column "Data" = #Pixel x ROI 59 // this can be used, to x-check RegionOfInterest and NumberOfPixels 60 int VerbosityLevel=1 61 ); 47 62 48 63 … … 57 72 vector<float> Vcfd2(FAD_MAX_SAMPLES); // CDF result + 2nd sliding average 58 73 59 #include "factfir.C"60 74 61 75 float getValue( int, int ); … … 75 89 76 90 TH1F* h; 77 TH2F* hStartCell; // id of the DRS physical pipeline cell where readout starts78 // x = pixel id, y = DRS cell id79 91 TH2F hPixelCellData( 80 92 "PixelPedestal", "PixelPedestal", NCELL, 0., NCELL, 200, -50., 150.); … … 85 97 TObjArray hListBaseline; 86 98 87 void BookHistos( int );88 void SaveHistograms( c har * );99 void BookHistos( int , int); 100 void SaveHistograms( const char * ); 89 101 90 102 // Create a canvas … … 97 109 98 110 int fbsl( 99 char *datafilename = "../../20110804_024.fits.gz", 100 const char *drsfilename = "../../20110804_023.drs.fits.gz", 101 int pixelnr = 0, 111 const char *datafilename = "path-to-datafile.fits.gz", 112 const char *drsfilename = "path-to-calibfile.drs.fits.gz", 113 const char *TextOutFileName = "./appendfile.txt", 114 const char *RootOutFileName = "./datafile.root", 102 115 int firstevent = 0, 103 int nevents = -1 ){ 104 // read and analyze FACT raw data 105 106 // sliding window filter settings 107 int k_slide = 16; 108 vector<double> a_slide(k_slide, 1); 109 double b_slide = k_slide; 110 111 // CFD filter settings 112 int k_cfd = 10; 113 vector<double> a_cfd(k_cfd, 0); 114 double b_cfd = 1.; 115 a_cfd[0]=0.75; 116 a_cfd[k_cfd-1]=-1.; 117 118 // 2nd slinding window filter 119 int ks2 = 16; 120 vector<double> as2(ks2, 1); 121 double bs2 = ks2; 122 gROOT->SetStyle("Plain"); 123 124 //------------------------------------------- 125 // Open the file 126 //------------------------------------------- 127 fits datafile( datafilename ); 128 if (!datafile) { 129 printf( "Could not open the file: %s\n", datafilename ); 130 return 1; 131 } 132 133 // access data 134 NEvents = FOpenDataFile( datafile ); 116 int nevents = -1, 117 int firstpixel = 0, 118 int npixel = -1, 119 bool produceGraphic = false 120 ){ 121 fits * datafile = NULL; 122 NEvents = FOpenDataFile( 123 datafilename, 124 &datafile, 125 Data, 126 StartCells, 127 EventID, 128 RegionOfInterest, 129 NumberOfPixels, 130 PXLxROI); 135 131 136 132 printf("number of events in file: %d\n", NEvents); … … 139 135 // the user would like to read. nevents = -1 means: read all 140 136 if ( nevents == -1 || nevents > NEvents ) nevents = NEvents; 141 142 143 // FILE *pedFile; 144 // pedFile = fopen("t.txt","u"); 145 // fprintf(pedFile,"# Pedestal Data"); 146 // fclose( pedFile ); 147 //------------------------------------------- 148 //Get the DRS calibration 149 //------------------------------------------- 137 138 if ( npixel == -1 || npixel > (int)NumberOfPixels) npixel = NumberOfPixels; 150 139 151 140 FOpenCalibFile(drsfilename, drs_basemean, drs_gainmean, drs_triggeroffsetmean, drs_n); 152 153 154 //Check the sizes of the data columns 155 if(drs_n!=data_n) 156 { 157 cout << "Data and DRS file incompatible (Px*ROI disagree)" << endl; 158 return 1; 159 } 160 // Book the histograms 161 // printf("call BookHistos\n"); 162 BookHistos( data_roi ); 163 // printf("returned from BookHistos\n"); 164 // Loop over events 165 cout << "--------------------- Data --------------------" << endl; 166 167 float value; 141 142 BookHistos( RegionOfInterest, npixel ); 168 143 169 // loop over events 170 // for ( int ev = firstevent; ev < nevents; ev++) { 144 // loop over events 171 145 for ( int ev = firstevent; ev < firstevent + nevents; ev++) { 172 146 173 datafile .GetRow( ev );147 datafile->GetRow( ev ); 174 148 175 149 if ( ev % 100 == 0 ){ 176 cout << "Event number: " << data_num<< endl;150 cout << "Event ID: " << EventID << endl; 177 151 } 178 152 179 153 // loop over pixel 180 for ( int pix = 0; pix < 1440; pix++ ){ 181 182 // hStartCell->Fill( pix, data_offset[pix] ); 183 154 for ( int pix = firstpixel ; pix < npixel+firstpixel ; pix++ ){ 155 184 156 // loop over DRS slices 185 for ( unsigned int sl = 0; sl < data_roi; sl++){ 186 157 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 187 158 Ameas[ sl ] = getValue(sl, pix); 188 189 159 } 190 // printf("Ameas[100] = %f\n", Ameas[100] ); 191 192 computeN1mean( data_roi ); // prepare spike removal 193 removeSpikes( data_roi ); // output in Vcorr 160 161 computeN1mean( RegionOfInterest ); // prepare spike removal 162 removeSpikes (RegionOfInterest ); // output in Vcorr 194 163 195 164 // filter Vcorr with sliding average using FIR filter function 196 factfir(b_slide , a_slide, k_slide, Vcorr, Vslide); 197 198 for ( unsigned int sl = 0; sl < data_roi; sl++){ 165 // 8 is here the HalfWidth of the sliding average window. 166 sliding_avg(Vcorr, Vslide, 8); 167 168 // factfir(b_slide , a_slide, k_slide, Vcorr, Vslide); 169 170 for ( unsigned int sl = 0; sl <RegionOfInterest ; sl++){ 199 171 // hPixelCellData.Fill( sl, Vcorr[sl] ); 200 hBaseline[pix ]->Fill( Vslide[sl] ) ;172 hBaseline[pix-firstpixel]->Fill( Vslide[sl] ) ; 201 173 } 202 174 } … … 204 176 205 177 FILE *fp; 206 TString fName; // name of the histogram file 207 /* create the filename for the histogram file */ 208 fName = datafilename; // use the name of the tree file 209 fName.Remove(fName.Length() - 5); // remove the extension .root 210 fName += "_bsl.txt"; // add the new extension 178 TString fName; 179 fName = TextOutFileName; 211 180 212 181 fp = fopen(fName, "a+"); 213 182 fprintf( fp, "FILE: %s\n", datafilename ); 214 fprintf( fp, "NEVENTS: %d\n", NEvents);215 NBSLeve = NEvents; // this has to be changed when computation on a subset of a run is implemented183 fprintf( fp, "NEVENTS: %d\n", nevents); 184 NBSLeve = nevents; // this has to be changed when computation on a subset of a run is implemented 216 185 fprintf( fp, "NBSLEVE: %d\n", NBSLeve ); 217 186 218 for (int pix = 0; pix < NPIX; pix++) { 219 //printf("Maximum bin pix[%d] %f\n", pix ,hBaseline[pix]->GetMaximumBin() ); 187 for (int pix = firstpixel; pix < firstpixel+npixel; pix++) { 220 188 221 189 float vmaxprob = hBaseline[pix]->GetXaxis()->GetBinCenter( 222 hBaseline[pix ]->GetMaximumBin() );190 hBaseline[pix-firstpixel]->GetMaximumBin() ); 223 191 224 192 fprintf( fp, "%8.3f", vmaxprob ); … … 227 195 hpltMeanBsl->SetBinContent(pix+1, vmaxprob ); 228 196 229 hRmsBsl->Fill(hBaseline[pix ]->GetRMS() );197 hRmsBsl->Fill(hBaseline[pix-firstpixel]->GetRMS() ); 230 198 hpltRmsBsl->SetBinContent( pix+1, hBaseline[pix]->GetRMS() ); 231 199 } 200 fprintf( fp, "\n" ); 232 201 233 202 fclose( fp ); 234 203 235 SaveHistograms( datafilename ); 236 237 TCanvas * cMeanBsl = new TCanvas(); 238 cMeanBsl->cd(); 239 hMeanBsl->Draw(); 240 //canv_mean->Modified(); 241 cMeanBsl->Update(); 242 243 TCanvas * cRmsBsl = new TCanvas(); 244 cRmsBsl->cd(); 245 hRmsBsl->Draw(); 246 //canv_rms->Modified(); 247 cMeanBsl->Update(); 248 204 SaveHistograms( RootOutFileName ); 205 if (produceGraphic){ 206 TCanvas * cMeanBsl = new TCanvas(); 207 cMeanBsl->cd(); 208 hMeanBsl->Draw(); 209 cMeanBsl->Update(); 210 211 TCanvas * cRmsBsl = new TCanvas(); 212 cRmsBsl->cd(); 213 hRmsBsl->Draw(); 214 cMeanBsl->Update(); 215 } 249 216 return( 0 ); 250 217 } … … 253 220 254 221 const float fract = 0.8; 255 float x, xp, xpp , x3p;222 float x, xp, xpp; 256 223 257 224 // assume that there are no spikes … … 323 290 // printf("pixel = %d, slice = %d\n", slice, pixel); 324 291 325 pixel_pt = pixel * data_roi;292 pixel_pt = pixel * RegionOfInterest; 326 293 slice_pt = pixel_pt + slice; 327 drs_cal_offset = ( slice + data_offset[ pixel ] )%data_roi;294 drs_cal_offset = ( slice + StartCells[ pixel ] )%RegionOfInterest; 328 295 cal_pt = pixel_pt + drs_cal_offset; 329 296 330 vraw = data[ slice_pt ] * dconv;297 vraw = Data[ slice_pt ] * dconv; 331 298 vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35; 332 299 … … 334 301 } 335 302 336 void BookHistos( int Samples ){303 void BookHistos( int Samples , int NumberOfPixel){ 337 304 // booking and parameter settings for all histos 338 305 … … 345 312 printf("inside BookHistos\n"); 346 313 347 for( int i = 0; i < N PIX; i++ ) {314 for( int i = 0; i < NumberOfPixel; i++ ) { 348 315 349 316 // printf("call sprintf [%d]\n", i ); … … 388 355 389 356 390 void SaveHistograms( c har * loc_fname ){357 void SaveHistograms( const char * loc_fname ){ 391 358 392 359 TString fName; // name of the histogram file … … 394 361 /* create the filename for the histogram file */ 395 362 fName = loc_fname; // use the name of the tree file 396 fName.Remove(fName.Length() - 5); // remove the extension .root 397 fName += "_histo.root"; // add the new extension 363 //fName.Remove(fName.Length() - 5); // remove the extension .root 364 //fName += "_histo.root"; // add the new extension 365 //fName += ".root"; 398 366 399 367 TFile tf( fName, "RECREATE"); // create the histogram file (replace if already existing) … … 407 375 } // end of function: void ana::SaveHistograms( void ) 408 376 409 int FOpenDataFile(fits &datafile){ 410 411 /* cout << "-------------------- Data Header -------------------" << endl; 412 datafile.PrintKeys(); 413 cout << "------------------- Data Columns -------------------" << endl; 414 datafile.PrintColumns(); 415 */ 416 417 //Get the size of the data column 418 data_roi = datafile.GetUInt("NROI"); // Value from header 419 data_px = datafile.GetUInt("NPIX"); 420 data_n = datafile.GetN("Data"); //Size of column "Data" = #Pixel x ROI 421 422 //Set the sizes of the data vectors 423 data.resize(data_n,0); 424 data_offset.resize(data_px,0); 425 426 //Link the data to variables 427 datafile.SetRefAddress("EventNum", data_num); 428 datafile.SetVecAddress("Data", data); 429 datafile.SetVecAddress("StartCellData", data_offset); 430 datafile.GetRow(0); 431 432 cout << "Opening data file successful..." << endl; 433 434 return datafile.GetNumRows() ; 377 size_t FOpenDataFile( 378 const char *datafilename, // path to fits file containing FACT raw data 379 fits * * datafile, // ptr to pointer, where to return the fits object 380 vector<int16_t> &Data, // vector, which will be filled with raw data 381 vector<int16_t> &StartCells, // vector, which will be filled with DRS start positions 382 unsigned int &EventID, // index of the current event 383 UInt_t &RegionOfInterest, // Width of the Region, read out of the DRS 384 UInt_t &NumberOfPixels, // Total number of pixel, read out of the camera 385 size_t &PXLxROI, // Size of column "Data" = #Pixel x ROI 386 // this can be used, to x-check RegionOfInterest and NumberOfPixels 387 int VerbosityLevel // 388 ) { 389 size_t NumberOfEvents; 390 *datafile = new fits(datafilename); 391 if (!(*(*datafile))) { 392 if (VerbosityLevel > 0) 393 cout << "Couldn't properly open the datafile: " << datafilename << endl; 394 return 0; 395 } 396 397 NumberOfEvents = (*datafile)->GetNumRows(); 398 if (NumberOfEvents < 1){ 399 if (VerbosityLevel > 0){ 400 cout << "Warning in FOpenDataFile of file: " << datafilename << endl; 401 cout << "the file contains no events." << endl; 402 } 403 } 404 405 RegionOfInterest = (*datafile)->GetUInt("NROI"); 406 NumberOfPixels = (*datafile)->GetUInt("NPIX"); 407 PXLxROI = (*datafile)->GetN("Data"); 408 409 if ( RegionOfInterest * NumberOfPixels != PXLxROI) // something in the file went wrong 410 { 411 if (VerbosityLevel > 0){ 412 cout << "Warning in FOpenDataFile of file: " << datafilename << endl; 413 cout << "RegionOfInterest * NumberOfPixels != PXLxROI" << endl; 414 cout << "--> " << RegionOfInterest; 415 cout << " * " << NumberOfPixels; 416 cout << " = " << RegionOfInterest * NumberOfPixels; 417 cout << ", but PXLxROI =" << PXLxROI << endl; 418 } 419 return 0; 420 } 421 422 //Set the sizes of the data vectors 423 Data.resize(PXLxROI, 0); 424 StartCells.resize(NumberOfPixels, 0); 425 426 //Link the data to variables 427 (*datafile)->SetRefAddress("EventNum", EventID); 428 (*datafile)->SetVecAddress("Data", Data); 429 (*datafile)->SetVecAddress("StartCellData", StartCells); 430 431 return NumberOfEvents; 435 432 } 436 433
Note:
See TracChangeset
for help on using the changeset viewer.