Changeset 12369
- Timestamp:
- 11/04/11 12:45:30 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/fpeak_cdf.C
r12357 r12369 31 31 #include "factfir.C" 32 32 33 33 #include "FOpenDataFile.h" 34 #include "FOpenDataFile.c" 35 36 #include "DrsCalibration.C" 37 #include "DrsCalibration.h" 38 39 bool breakout=false; 40 41 int NEvents; 34 42 vector<int16_t> AllPixelDataVector; 35 43 vector<int16_t> StartCellVector; 36 37 44 unsigned int CurrentEventID; 38 39 bool breakout=false; 40 41 size_t ROIxNOP; 45 size_t PXLxROI; 46 UInt_t RegionOfInterest; 42 47 UInt_t NumberOfPixels; 43 UInt_t RegionOfInterest;44 int NEvents;45 48 46 49 size_t drs_n; … … 49 52 vector<float> drs_triggeroffsetmean; 50 53 51 int FOpenDataFile( fits & );52 53 54 54 vector<float> Ameas(FAD_MAX_SAMPLES); // copy of the data (measured amplitude 55 55 vector<float> N1mean(FAD_MAX_SAMPLES); // mean of the +1 -1 ch neighbors … … 62 62 63 63 64 float getValue( int, int );64 //float getValue( int, int ); 65 65 void computeN1mean( int ); 66 66 void removeSpikes( int ); … … 79 79 TH1F* h; 80 80 TH1F *debugHistos; 81 TH2F* hStartCell; 82 81 TH2F* hStartCell; // id of the DRS physical pipeline cell where readout starts 82 // x = pixel id, y = DRS cell id 83 83 84 84 TH1F *hBaseline[ NPIX ]; // histograms for baseline extraction … … 92 92 93 93 void BookHistos( ); 94 void SaveHistograms( char * ); 95 96 int searchSinglesPeaks = 0; 97 94 void SaveHistograms(const char * ); 95 96 /////////////////////////////////////////////////////////////////////////////// 97 /////////////////////////////////////////////////////////////////////////////// 98 /////////////////////////////////////////////////////////////////////////////// 99 // read FACT raw data 100 // * remove spikes 101 // * calculate baseline 102 // * find peaks (CFD and normal discriminator) 103 // * compute pulse height and pulse integral spektrum of the peaks 98 104 int fpeak( 99 105 char *datafilename = "../../20111011_055.fits.gz", 100 106 const char *drsfilename = "../../20111011_054.drs.fits.gz", 107 const char *OutRootFileName = "./fpeak_cdf.Coutput.root", 108 int firstevent = 0, 101 109 int nevents = -1, 102 int first event= 0,103 int PixelID= -1,110 int firstpixel = 0, 111 int npixel = -1, 104 112 bool spikeDebug = false, 105 113 int verbosityLevel = 1 // different verbosity levels can be implemented here 106 114 ) 107 115 { 116 gStyle->SetPalette(1,0); 117 gROOT->SetStyle("Plain"); 108 118 109 119 // Create (pointer to) Canvases, which are used in every run, … … 130 140 } 131 141 132 gStyle->SetPalette(1,0); 133 gROOT->SetStyle("Plain"); 134 // read FACT raw data 135 // * remove spikes 136 // * calculate baseline 137 // * find peaks (CFD and normal discriminator) 138 // * compute pulse height and pulse integral spektrum of the peaks 139 140 // sliding window filter settings 141 // int k_slide = 16; 142 // vector<double> a_slide(k_slide, 1); 143 // double b_slide = k_slide; 142 144 143 145 144 // CFD filter settings … … 150 149 a_cfd[k_cfd-1]=1.; 151 150 152 // 2nd slinding window filter 153 // int ks2 = 16; 154 // vector<double> as2(ks2, 1); 155 // double bs2 = ks2; 156 157 // Open the data file 158 fits *datafile = new fits( datafilename ); 159 if (!datafile) { 160 printf( "Could not open the file: %s\n", datafilename ); 161 return 1; 151 fits * datafile; 152 NEvents = OpenDataFile( datafilename, &datafile, 153 AllPixelDataVector, StartCellVector, CurrentEventID, 154 RegionOfInterest, NumberOfPixels, PXLxROI, verbosityLevel); 155 if (NEvents == 0){ 156 cout << "return code of FOpenDataFile:" << datafilename<< endl; 157 cout << "is zero -> aborting." << endl; 158 return 1; 162 159 } 163 164 // access data 165 NEvents = FOpenDataFile( *datafile ); 166 printf("number of events in file: %d\n", NEvents); 167 if ( nevents == -1 || nevents > NEvents ) nevents = NEvents; // -1 means all! 168 169 //Get the DRS calibration 160 161 if (verbosityLevel > 0) 162 cout <<"number of events in file: "<< NEvents << "\t"; 163 if ( nevents == -1 || nevents > NEvents ) nevents = NEvents; // -1 means all! 164 if (verbosityLevel > 0) 165 cout <<"of, which "<< nevents << "will be processed"<< endl; 166 167 if (verbosityLevel > 0) 168 cout <<"Totel # of Pixel: "<< NumberOfPixels << "\t"; 169 if ( npixel == -1 || npixel > (int)NumberOfPixels ) npixel = (int)NumberOfPixels; // -1 means all! 170 if (verbosityLevel > 0) 171 cout <<"of, which "<< nevents << "will be processed"<< endl; 172 173 174 175 //Get the DRS calibration 170 176 FOpenCalibFile( drsfilename, 171 177 drs_basemean, … … 174 180 drs_n); 175 181 176 //Check the sizes of the data columns177 if (drs_n != 1474560) {178 cerr << "error: DRS calib file has wrong ...erm...size ... drs_n is: "179 << drs_n << endl;180 cerr << " Aborting." << endl;181 return 1;182 }183 184 if(ROIxNOP != 1474560)185 {186 cout << "warning: data_n should better be 1440x1024=1474560, but is "187 << ROIxNOP << endl;188 cout << "this script is not guaranteed to run under these "189 <<" circumstances....any way ... it is never guaranteed." << endl;190 }191 // Book the histograms192 193 182 BookHistos( ); 194 195 float calibratedVoltage;196 183 197 184 for ( int ev = firstevent; ev < firstevent + nevents; ev++) { … … 199 186 datafile->GetRow( ev ); 200 187 201 for ( int pix = 0; pix < 1440; pix++ ){ 202 203 hStartCell->Fill( pix, StartCellVector[pix] ); 204 205 // this is a stupid hack ... there is more code at the 206 // end of this loop to complete this hack ... 207 // beginning with if (PixelID != -1) as well. 208 if (PixelID != -1) { 209 pix = PixelID; 210 if (verbosityLevel > 0){ 211 cout << "Processing Event number: " << CurrentEventID << "\t" 212 << "Pixel number: "<< pix << endl; 213 } 214 } 215 188 for ( int pix = firstpixel; pix < firstpixel+npixel; pix++ ){ 216 189 if (verbosityLevel > 0){ 217 190 if (pix % 20 ==0){ … … 221 194 } 222 195 223 // compute the DRs calibrated values and put them into Ameas[] 224 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 225 calibratedVoltage = getValue( sl, pix); 226 if (verbosityLevel > 10){ 227 printf("calibratedVoltage = %f\n", calibratedVoltage); 228 } 229 Ameas[ sl ] = calibratedVoltage; 230 231 // in case we want to plot this ... we need to put it into a 232 // Histgramm 233 if (spikeDebug){ 234 debugHistos[Ameas_].SetBinContent(sl, calibratedVoltage); 235 } 236 } 196 applyDrsCalibration( Ameas,pix, 197 drs_basemean, drs_gainmean, drs_triggeroffsetmean, 198 RegionOfInterest, AllPixelDataVector, StartCellVector); 199 237 200 // operates on Ameas[] and writes to N1mean[] 238 201 computeN1mean( RegionOfInterest ); … … 260 223 EnlargeRegion(*zXings, 10, 10); 261 224 findAbsMaxInRegions(*zXings, Vslide); 262 removeMaximaBelow( *zXings, 11.0, 0); 263 removeMaximaAbove( *zXings, 14.0, 0); 264 225 //removeMaximaBelow( *zXings, 11.0, 0); 226 //removeMaximaAbove( *zXings, 14.0, 0); 227 228 // fill maxima in Histogram 265 229 if (zXings->size() != 0 ){ 266 230 for (unsigned int i=0; i<zXings->size(); i++){ … … 280 244 if ( spikeDebug ){ 281 245 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 246 debugHistos[Ameas_].SetBinContent(sl, Ameas[sl]); 282 247 debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] ); 283 248 debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] ); … … 344 309 345 310 delete zXings; 346 347 // this is the 2nd part of the ugly hack in the beginning.348 // this makes sure, that the loop ends349 if (PixelID != -1){350 pix = 1440;351 }352 353 354 311 if (breakout) 355 312 break; … … 373 330 374 331 cTemplate->cd(); 375 hTemp_Array[ PixelID]->GetYaxis()->SetRangeUser(-10,40);376 hTemp_Array[ PixelID]->Draw("COLZ");332 hTemp_Array[firstpixel]->GetYaxis()->SetRangeUser(-10,40); 333 hTemp_Array[firstpixel]->Draw("COLZ"); 377 334 cTemplate->Modified(); 378 335 cTemplate->Update(); … … 385 342 386 343 387 SaveHistograms( datafilename );344 SaveHistograms( OutRootFileName ); 388 345 389 346 return( 0 ); … … 401 358 for ( int i = 0; i < Samples; i++) { 402 359 403 // printf("Vcorr[%d] = %f, Ameas[%d] = %f\n", i, Vcorr[ i ], i, Ameas[ i ] );404 360 405 361 x = Ameas[i] - N1mean[i]; … … 411 367 x3p = Ameas[i+3] - N1mean[i+3]; 412 368 413 // printf("candidates x[%d] = %f; xp = %f; xpp = %f, x3p = %f\n", i, x, xp, xpp, x3p);414 369 415 370 if ( Ameas[i+2] - ( Ameas[i] + Ameas[i+3] )/2. > 10. ){ 416 // printf("double spike candidate\n");417 371 Vcorr[i+1] = ( Ameas[i] + Ameas[i+3] )/2.; 418 372 Vcorr[i+2] = ( Ameas[i] + Ameas[i+3] )/2.; 419 // printf("Vcorr[%d] = %f %f %f %f\n", i, Vcorr[i], Vcorr[i+1], Vcorr[i+2], Vcorr[ i+3 ]);420 // printf("Ameas[%d] = %f %f %f %f\n", i, Ameas[ i ], Ameas[ i+1 ], Ameas[ i+2 ], Ameas[i+3]);421 373 i = i + 3; 422 374 } … … 425 377 if ( ( xp > -2.*x*fract ) && ( xpp < -10. ) ){ 426 378 Vcorr[i+1] = N1mean[i+1]; 427 // printf("Vcorr[%d] = %f %f %f\n", i, Vcorr[i], Vcorr[i+1], Vcorr[i+2]);428 // N1mean[i+1] = (Ameas[i] - Ameas[i+2] / 2.);429 379 N1mean[i+2] = (Ameas[i+1] - Ameas[i+3] / 2.); 430 380 i = i + 2;//do not care about the next sample it was the spike … … 458 408 } // end of computeN1mean computation 459 409 460 float getValue( int slice, int pixel ){461 const float dconv = 2000/4096.0;462 463 float vraw, vcal;464 465 unsigned int pixel_pt;466 unsigned int slice_pt;467 unsigned int cal_pt;468 unsigned int drs_cal_offset;469 470 // printf("pixel = %d, slice = %d\n", slice, pixel);471 472 pixel_pt = pixel * RegionOfInterest;473 slice_pt = pixel_pt + slice;474 drs_cal_offset = ( slice + StartCellVector[ pixel ] )%RegionOfInterest;475 cal_pt = pixel_pt + drs_cal_offset;476 477 vraw = AllPixelDataVector[ slice_pt ] * dconv;478 vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;479 480 return( vcal );481 }482 410 483 411 // booking and parameter settings for all histos … … 487 415 char hTitle[500]; 488 416 417 TString name,title; 418 title = "all events all slices of pixel "; 419 name = "base"; 489 420 TH1F *h; 490 421 491 422 for( int i = 0; i < NPIX; i++ ) { 492 sprintf(&hTitle[0],"all events all slices of pixel %d", i); 493 sprintf(&hName[0],"base%d", i); 494 495 h = new TH1F( hName, hTitle, 400, -99.5 ,100.5 ); 423 title += i; 424 name += i; 425 // sprintf(&hTitle[0],"all events all slices of pixel %d", i); 426 // sprintf(&hName[0],"base%d", i); 427 428 h = new TH1F( name, title, 400, -99.5 ,100.5 ); 496 429 497 430 h->GetXaxis()->SetTitle( "Sample value (mV)" ); … … 530 463 hAmplSpek_discri->GetXaxis()->SetTitle( "amplitude in mV" ); 531 464 hList.Add( hAmplSpek_discri ); 532 533 hStartCell = new TH2F("StartCell", "StartCell", 1440, 0., 1440., 1024, 0., 1024);534 hStartCell->GetXaxis()->SetTitle( "pixel" );535 hStartCell->GetXaxis()->SetTitle( "slice" );536 hList.Add( hStartCell );537 465 538 466 debugHistos = new TH1F[ NumberOfDebugHistoTypes ]; … … 571 499 } 572 500 573 void SaveHistograms( char * loc_fname ){ 574 575 TString fName; // name of the histogram file 576 577 // create the filename for the histogram file 578 fName = loc_fname; // use the name of the tree file 579 // TODO ... next statement doesn't work for ".fits.gz" 580 fName.Remove(fName.Length() - 5); // remove the extension .fits 581 fName += "_discri.root"; // add the new extension 582 501 void SaveHistograms( const char * loc_fname ){ 583 502 // create the histogram file (replace if already existing) 584 TFile tf( fName, "RECREATE");503 TFile tf( loc_fname, "RECREATE"); 585 504 586 505 hList.Write(); // write the major histograms into the top level directory … … 590 509 tf.cd(".."); 591 510 tf.mkdir("PulseTempplates"); 592 tf.cd("PulseTemp plates");511 tf.cd("PulseTemplates"); 593 512 hListTemplates.Write(); // write histos into subdirectory 594 513 595 514 tf.Close(); // close the file 596 } // end of SaveHistograms( char * loc_fname ) 597 598 int FOpenDataFile(fits &datafile){ 599 600 // cout << "-------------------- Data Header -------------------" << endl; 601 // datafile.PrintKeys(); 602 // cout << "------------------- Data Columns -------------------" << endl; 603 // datafile.PrintColumns(); 604 605 //Get the size of the data column 606 RegionOfInterest = datafile.GetUInt("NROI"); 607 NumberOfPixels = datafile.GetUInt("NPIX"); 608 //Size of column "Data" = #Pixel x ROI 609 ROIxNOP = datafile.GetN("Data"); 610 611 //Set the sizes of the data vectors 612 AllPixelDataVector.resize(ROIxNOP,0); 613 StartCellVector.resize(NumberOfPixels,0); 614 615 //Link the data to variables 616 datafile.SetRefAddress("EventNum", CurrentEventID); 617 datafile.SetVecAddress("Data", AllPixelDataVector); 618 datafile.SetVecAddress("StartCellData", StartCellVector); 619 datafile.GetRow(0); 620 621 return datafile.GetNumRows() ; 622 } 515 } // end of SaveHistograms(const char * loc_fname )
Note:
See TracChangeset
for help on using the changeset viewer.