Changeset 12392 for fact/tools/rootmacros/tpeak.C
- Timestamp:
- 11/05/11 13:32:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/tpeak.C
r12366 r12392 42 42 #include "factfir.C" 43 43 44 #include "FOpenDataFile.h" 45 #include "FOpenDataFile.c" 46 47 #include "DrsCalibration.C" 48 #include "DrsCalibration.h" 49 50 #include "SpikeRemoval.h" 51 #include "SpikeRemoval.C" 44 52 45 53 //----------------------------------------------------------------------------- 46 54 // Decleration of variables 47 55 //----------------------------------------------------------------------------- 48 56 bool breakout=false; 57 58 int NEvents; 49 59 vector<int16_t> AllPixelDataVector; 50 60 vector<int16_t> StartCellVector; 51 52 61 unsigned int CurrentEventID; 53 54 bool breakout=false; 55 56 size_t ROIxNOP; 62 size_t PXLxROI; 63 UInt_t RegionOfInterest; 57 64 UInt_t NumberOfPixels; 58 UInt_t RegionOfInterest;59 int NEvents;60 65 61 66 size_t drs_n; … … 64 69 vector<float> drs_triggeroffsetmean; 65 70 66 int FOpenDataFile( fits & );67 68 69 71 vector<float> Ameas(FAD_MAX_SAMPLES); // copy of the data (measured amplitude 70 vector<float> N1mean(FAD_MAX_SAMPLES); // mean of the +1 -1 ch neighbors71 72 vector<float> Vcorr(FAD_MAX_SAMPLES); // corrected Values 72 vector<float> Vdiff(FAD_MAX_SAMPLES); // numerical derivative73 74 73 vector<float> Vslide(FAD_MAX_SAMPLES); // sliding average result 75 74 vector<float> Vcfd(FAD_MAX_SAMPLES); // CDF result 76 75 vector<float> Vcfd2(FAD_MAX_SAMPLES); // CDF result + 2nd sliding average 77 78 79 float getValue( int, int );80 float correctDrsOffset( int slice, int pixel );81 void computeN1mean( int );82 void removeSpikes( int );83 76 84 77 // histograms … … 95 88 TH1F* h; 96 89 TH1F *debugHistos; 97 TH2F* hStartCell; // id of the DRS physical pipeline cell where readout starts98 // x = pixel id, y = DRS cell id99 100 TH1F *hBaseline[ NPIX ]; // histograms for baseline extraction101 TH1F *hMeanBsl, *hpltMeanBsl;102 TH1F *hRmsBsl, *hpltRmsBsl;103 TH2F * hAmplSpek_cfd;104 TH2F * hAmplSpek_discri;105 106 90 TH2F *hPeakOverlay; //histogrammm for overlay of detected Peaks 91 int hPeakOverlayXaxisLeft,hPeakOverlayXaxisRight; 107 92 108 93 TObjArray hList; … … 110 95 111 96 void BookHistos( ); 112 void SaveHistograms( char * ); 113 114 int searchSinglesPeaks = 0; 97 void SaveHistograms( const char * ); 115 98 116 99 //----------------------------------------------------------------------------- 117 100 // Main 118 101 //----------------------------------------------------------------------------- 119 120 102 int tpeak( 121 char *datafilename = "../../20111011_055.fits.gz", 122 const char *drsfilename = "../../20111011_054.drs.fits.gz", 123 int PixelID = -1, 124 int firstevent = 0, 125 int nevents = -1, 126 bool spikeDebug = false, 127 int verbosityLevel = 1 // different verbosity levels can be implemented here 128 ) 103 char *datafilename = "data/20111016_013.fits.gz", 104 const char *drsfilename = "../../20111016_011.drs.fits.gz", 105 const char *OutRootFileName = "../analysis/fpeak_cdf.Coutput.root", 106 int firstevent = 0, 107 int nevents = -1, 108 int firstpixel = 0, 109 int npixel = -1, 110 bool spikeDebug = false, 111 int avg1 = 14, 112 int avg2 = 8, 113 int OverlayWindowLeft = 50, 114 int OverlayWindowRight = 150, 115 int verbosityLevel = 1, // different verbosity levels can be implemented here 116 bool ProduceGraphic = true 117 ) 118 129 119 { 120 hPeakOverlayXaxisLeft = OverlayWindowLeft; 121 hPeakOverlayXaxisRight = OverlayWindowRight; 122 123 gStyle->SetPalette(1,0); 124 gROOT->SetStyle("Plain"); 130 125 131 126 //----------------------------------------------------------------------------- … … 133 128 // also in 'non-debug' runs 134 129 //----------------------------------------------------------------------------- 135 136 TCanvas * cSpektrum;137 TCanvas * cStartCell;138 cSpektrum = new TCanvas("cSpektrum","Amplitude Spektra of different discriminators",10,10,400,400);139 cSpektrum->Divide(1,2);140 cStartCell = new TCanvas("cStartCell ", "The Startcells of this run", 10,410,400,400);141 142 130 // Canvases only need if spike Debug, but I want to deklare 143 131 // the pointers anyway ... 144 TCanvas *cRawAndSpikeRemoval = NULL;145 132 TCanvas *cFiltered = NULL; 146 133 if (spikeDebug){ 147 cRawAndSpikeRemoval = new TCanvas("cRawAndSpikeRemoval","DRS Waveform",410,10,400,400); 148 cRawAndSpikeRemoval->Divide(1, 2); 149 cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms",410,410,400,400); 150 cFiltered->Divide(1, 2); 134 cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms",1,10,400,300); 135 cFiltered->Divide(1, 3); 151 136 } 152 137 // Canvases to show the peak template 153 138 TCanvas *cPeakOverlay = NULL; 154 cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 410, 10, 600, 600); 155 156 gStyle->SetPalette(1,0); 157 gROOT->SetStyle("Plain"); 139 cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 1, 310, 400, 400); 140 158 141 159 142 //----------------------------------------------------------------------------- … … 169 152 // Filter-Settings 170 153 //----------------------------------------------------------------------------- 171 172 // sliding window filter settings173 int k_slide = 16;174 vector<double> a_slide(k_slide, 1); //erzeugt vector der länge k_slide, und füllt die elemente mit 1175 double b_slide = k_slide;176 177 154 // CFD filter settings 178 155 int k_cfd = 10; … … 182 159 a_cfd[k_cfd-1]=1.; 183 160 184 // 2nd slinding window filter185 int ks2 = 16;186 vector<double> as2(ks2, 1);187 double bs2 = ks2;188 189 161 //----------------------------------------------------------------------------- 190 162 // prepare datafile … … 192 164 193 165 // Open the data file 194 fits *datafile = new fits( datafilename ); 195 if (!datafile) { 196 printf( "Could not open the file: %s\n", datafilename ); 197 return 1; 198 } 199 200 // access data 201 NEvents = FOpenDataFile( *datafile ); 202 printf("number of events in file: %d\n", NEvents); 166 167 fits * datafile; 168 // Opens the raw data file and 'binds' the variables given as 169 // Parameters to the data file. So they are filled with 170 // raw data as soon as datafile->GetRow(int) is called. 171 NEvents = OpenDataFile( datafilename, &datafile, 172 AllPixelDataVector, StartCellVector, CurrentEventID, 173 RegionOfInterest, NumberOfPixels, PXLxROI, verbosityLevel); 174 if (NEvents == 0){ 175 cout << "return code of OpenDataFile:" << datafilename<< endl; 176 cout << "is zero -> aborting." << endl; 177 return 1; 178 } 179 180 if (verbosityLevel > 0) 181 cout <<"number of events in file: "<< NEvents << "\t"; 203 182 if ( nevents == -1 || nevents > NEvents ) nevents = NEvents; // -1 means all! 183 if (verbosityLevel > 0) 184 cout <<"of, which "<< nevents << "will be processed"<< endl; 185 186 if (verbosityLevel > 0) 187 cout <<"Total # of Pixel: "<< NumberOfPixels << "\t"; 188 if ( npixel == -1 || npixel > (int)NumberOfPixels ) npixel = (int)NumberOfPixels; // -1 means all! 189 if (verbosityLevel > 0) 190 cout <<"of, which "<< npixel << "will be processed"<< endl; 204 191 205 192 //Get the DRS calibration … … 210 197 drs_n); 211 198 212 //Check the sizes of the data columns213 if (drs_n != 1474560) {214 cerr << "error: DRS calib file has wrong ...erm...size ... drs_n is: "215 << drs_n << endl;216 cerr << " Aborting." << endl;217 return 1;218 }219 220 if(ROIxNOP != 1474560)221 {222 cout << "warning: data_n should better be 1440x1024=1474560, but is "223 << ROIxNOP << endl;224 cout << "this script is not guaranteed to run under these "225 <<" circumstances....any way ... it is never guaranteed." << endl;226 }227 228 199 // Book the histograms 229 230 200 BookHistos( ); 231 201 232 float myTHR = 3.5;233 float calibratedVoltage;234 202 //----------------------------------------------------------------------------- 235 203 // Loops over Every Event and Pixel … … 243 211 //------------------------------------- 244 212 245 for ( int pix = 0; pix < 1440; pix++ ){ 246 247 hStartCell->Fill( pix, StartCellVector[pix] ); 248 249 // this is a stupid hack ... there is more code at the 250 // end of this loop to complete this hack ... 251 // beginning with if (PixelID != -1) as well. 252 if (PixelID != -1) { 253 pix = PixelID; 254 if (verbosityLevel > 0){ 255 cout << "Processing Event number: " << CurrentEventID << "\t" 256 << "Pixel number: "<< pix << endl; 257 } 258 } 259 260 if (verbosityLevel > 0){ 261 if (pix % 20 ==0){ 262 cout << "Processing Event number: " << CurrentEventID << "\t" 263 << "Pixel number: "<< pix << endl; 264 } 265 } 266 267 // compute the DRs calibrated values and put them into Ameas[] 268 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 269 calibratedVoltage = getValue( sl, pix); 270 if (verbosityLevel > 10){ 271 printf("calibratedVoltage = %f\n", calibratedVoltage); 272 } 273 Ameas[ sl ] = calibratedVoltage; 274 275 // in case we want to plot this ... we need to put it into a 276 // Histgramm 277 if (spikeDebug){ 278 debugHistos[Ameas_].SetBinContent(sl, calibratedVoltage); 279 } 280 } 281 // operates on Ameas[] and writes to N1mean[] 282 computeN1mean( RegionOfInterest ); 283 284 // operates on Ameas[] and N1mean[], then writes to Vcorr[] 285 removeSpikes( RegionOfInterest ); 286 287 // filter Vcorr with sliding average using FIR filter function 288 factfir(b_slide , a_slide, k_slide, Vcorr, Vslide); 289 // filter Vslide with CFD using FIR filter function 290 factfir(b_cfd , a_cfd, k_cfd, Vslide, Vcfd); 291 // filter Vcfd with sliding average using FIR filter function 292 factfir(bs2 , as2, ks2, Vcfd, Vcfd2); 293 294 295 vector<Region> *Regions = discriminator( Vslide, myTHR,true , 120); 296 for (unsigned int p=0; p<Regions->size(); p++ ){ 297 hAmplSpek_discri->Fill(pix , Regions->at(p).maxVal); 298 } 213 for ( int pix = firstpixel; pix < firstpixel + npixel; pix++ ){ 214 215 if (verbosityLevel > 0){ 216 if (pix == firstpixel){ 217 cout << "Processing Event: " << CurrentEventID << "/" << nevents << endl; 218 } 219 } 220 221 applyDrsCalibration( Ameas,pix,12,12, 222 drs_basemean, drs_gainmean, drs_triggeroffsetmean, 223 RegionOfInterest, AllPixelDataVector, StartCellVector); 224 225 // finds spikes in the raw data, and interpolates the value 226 // spikes are: 1 or 2 slice wide, positive non physical artifacts 227 removeSpikes (Ameas, Vcorr); 228 229 // filter Vcorr with sliding average using FIR filter function 230 sliding_avg(Vcorr, Vslide, avg1); 231 // filter Vslide with CFD using FIR filter function 232 factfir(b_cfd , a_cfd, k_cfd, Vslide, Vcfd); 233 // filter Vcfd with sliding average using FIR filter function 234 sliding_avg(Vcfd, Vcfd2, avg2); 299 235 300 236 // peaks in Ameas[] are found by searching for zero crossings … … 304 240 vector<Region> * zXings = zerosearch( Vcfd2 , 1 , 1); 305 241 // zXings means "zero cross ings" 306 ShiftRegionBy(*zXings, -ks2/2);307 242 EnlargeRegion(*zXings, 10, 10); 308 243 findAbsMaxInRegions(*zXings, Vslide); 309 310 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 311 // hPixelCellData.Fill( sl, Vcorr[sl] ); 312 hBaseline[pix]->Fill( Vslide[sl] ) ; 313 } 244 removeMaximaBelow( *zXings, 3.0); 245 removeRegionWithMaxOnEdge( *zXings, 2); 246 removeRegionOnFallingEdge( *zXings, 100); 314 247 315 248 //following Code should produce the Overlay of peaks … … 317 250 318 251 for (it = zXings->begin() ; it < zXings->end() ; it++){ 319 int a = it->maxPos-100;320 int b = it->maxPos+100;321 if ( a< 0)322 a=0;323 if ( b>1023)324 b=1023;325 for ( int pos = a; pos <= b; pos++){252 int Left = it->maxPos - OverlayWindowLeft; 253 int Right = it->maxPos + OverlayWindowRight; 254 if (Left < 0) 255 Left =0; 256 if (Right > (int)Vcorr.size() ) 257 Right=Vcorr.size() ; 258 for ( int pos = Left; pos < Right; pos++){ 326 259 327 260 hPeakOverlay->Fill( pos - (it->maxPos), Vcorr[pos]) ; … … 330 263 331 264 332 333 if (zXings->size() != 0 ){334 for (unsigned int i=0; i<zXings->size(); i++){335 if (verbosityLevel > 1){336 cout << zXings->at(i).maxPos << ":\t"337 << zXings->at(i).maxVal <<endl;338 }339 hAmplSpek_cfd->Fill(pix, zXings->at(i).maxVal);340 }341 }342 343 265 if ( spikeDebug ){ 344 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 345 debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] ); 346 debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] ); 347 debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] ); 348 } 349 350 cRawAndSpikeRemoval->cd( 1); 351 gPad->SetGrid(); 352 debugHistos[Ameas_].Draw(); 353 354 cRawAndSpikeRemoval->cd( 2); 266 267 268 // TODO do this correct. The vectors should be the rigt ones... this is just luck 269 debugHistos[Ameas_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5); 270 debugHistos[Vcorr_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5); 271 debugHistos[Vslide_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5); 272 debugHistos[Vcfd_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5); 273 debugHistos[Vcfd2_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5); 274 275 for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){ 276 debugHistos[Ameas_].SetBinContent(sl, Ameas[sl]); 277 debugHistos[Vcorr_].SetBinContent(sl, Vcorr[sl]); 278 debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] ); 279 debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] ); 280 debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] ); 281 } 282 283 284 cFiltered->cd(1); 355 285 gPad->SetGrid(); 356 286 debugHistos[Vcorr_].Draw(); 357 287 358 cFiltered->cd( 1);288 cFiltered->cd(2); 359 289 gPad->SetGrid(); 360 290 debugHistos[Vslide_].Draw(); 361 TLine * thrLine = new TLine(0, myTHR, 1024, myTHR); 362 thrLine->SetLineColor(kRed); 363 thrLine->SetLineWidth(2); 364 thrLine->Draw(); 365 TLine * OneLine; 366 vector<TLine*> MyLines; 367 for (unsigned int p=0; p<Regions->size(); p++ ){ 368 OneLine = new TLine( 369 Regions->at(p).begin , 370 Regions->at(p).maxVal, 371 Regions->at(p).end, 372 Regions->at(p).maxVal); 373 OneLine->SetLineColor(kRed); 374 OneLine->SetLineWidth(2); 375 MyLines.push_back(OneLine); 376 OneLine->Draw(); 377 } 291 378 292 TBox *OneBox; 379 293 vector<TBox*> MyBoxes; … … 392 306 } 393 307 394 cFiltered->cd( 2);308 cFiltered->cd(3); 395 309 gPad->SetGrid(); 396 310 debugHistos[Vcfd2_].Draw(); … … 399 313 zeroline->Draw(); 400 314 401 cRawAndSpikeRemoval->Update();402 315 cFiltered->Update(); 403 316 … … 423 336 }// end of if(spikeDebug) 424 337 425 delete Regions;426 338 delete zXings; 427 428 // this is the 2nd part of the ugly hack in the beginning.429 // this makes sure, that the loop ends430 if (PixelID != -1){431 pix = 2000;432 }433 434 339 if (breakout) 435 340 break; … … 439 344 // end of loop over pixels 440 345 //------------------------------------- 441 if (ev % 50 == 0){ 442 cSpektrum->cd(1); 443 hAmplSpek_cfd->Draw("COLZ"); 444 cSpektrum->cd(2); 445 hAmplSpek_discri->Draw("COLZ"); 446 cSpektrum->Modified(); 447 cSpektrum->Update(); 448 449 // updating seems not to work .. 450 // debug cout 451 cStartCell->cd(); 452 hStartCell->Draw(); 453 cStartCell->Modified(); 454 cStartCell->Update(); 455 346 if (ProduceGraphic){ 347 if (ev % 50 == 0){ 456 348 //OVERLAY PEAKS 457 349 cPeakOverlay->cd(); … … 459 351 cPeakOverlay->Modified(); 460 352 cPeakOverlay->Update(); 461 462 } 463 464 353 } 354 } 465 355 if (breakout) 466 356 break; … … 469 359 // end of loop over Events 470 360 //------------------------------------- 471 472 473 for (int pix = 0; pix < NumberOfPixels; pix++) { 474 //printf("Maximum bin pix[%d] %f\n", pix ,hBaseline[pix]->GetMaximumBin() ); 475 476 float vmaxprob = hBaseline[pix]->GetXaxis()->GetBinCenter( 477 hBaseline[pix]->GetMaximumBin() ); 478 479 printf("%8.3f", vmaxprob ); 480 481 hMeanBsl->Fill( vmaxprob ); 482 hpltMeanBsl->SetBinContent(pix+1, vmaxprob ); 483 484 hRmsBsl->Fill(hBaseline[pix]->GetRMS() ); 485 hpltRmsBsl->SetBinContent( pix+1, hBaseline[pix]->GetRMS() ); 486 } 487 488 489 SaveHistograms( datafilename ); 361 if (ProduceGraphic){ 362 //OVERLAY PEAKS 363 cPeakOverlay->cd(); 364 hPeakOverlay->Draw("COLZ"); 365 cPeakOverlay->Modified(); 366 cPeakOverlay->Update(); 367 } 368 369 SaveHistograms( OutRootFileName ); 490 370 491 371 return( 0 ); 492 372 } 493 373 494 void removeSpikes(int Samples){495 496 const float fract = 0.8;497 float x, xp, xpp, x3p;498 499 // assume that there are no spikes500 for ( int i = 0; i < Samples; i++) Vcorr[i] = Ameas[i];501 502 // find the spike and replace it by mean value of neighbors503 for ( int i = 0; i < Samples; i++) {504 505 // printf("Vcorr[%d] = %f, Ameas[%d] = %f\n", i, Vcorr[ i ], i, Ameas[ i ] );506 507 x = Ameas[i] - N1mean[i];508 509 if ( x < -5. ){ // a spike candidate510 // check consistency with a single channel spike511 xp = Ameas[i+1] - N1mean[i+1];512 xpp = Ameas[i+2] - N1mean[i+2];513 x3p = Ameas[i+3] - N1mean[i+3];514 515 // printf("candidates x[%d] = %f; xp = %f; xpp = %f, x3p = %f\n", i, x, xp, xpp, x3p);516 517 if ( Ameas[i+2] - ( Ameas[i] + Ameas[i+3] )/2. > 10. ){518 // printf("double spike candidate\n");519 Vcorr[i+1] = ( Ameas[i] + Ameas[i+3] )/2.;520 Vcorr[i+2] = ( Ameas[i] + Ameas[i+3] )/2.;521 // printf("Vcorr[%d] = %f %f %f %f\n", i, Vcorr[i], Vcorr[i+1], Vcorr[i+2], Vcorr[ i+3 ]);522 // printf("Ameas[%d] = %f %f %f %f\n", i, Ameas[ i ], Ameas[ i+1 ], Ameas[ i+2 ], Ameas[i+3]);523 i = i + 3;524 }525 else{526 527 if ( ( xp > -2.*x*fract ) && ( xpp < -10. ) ){528 Vcorr[i+1] = N1mean[i+1];529 // printf("Vcorr[%d] = %f %f %f\n", i, Vcorr[i], Vcorr[i+1], Vcorr[i+2]);530 // N1mean[i+1] = (Ameas[i] - Ameas[i+2] / 2.);531 N1mean[i+2] = (Ameas[i+1] - Ameas[i+3] / 2.);532 i = i + 2;//do not care about the next sample it was the spike533 }534 // treatment for the end of the pipeline must be added !!!535 }536 }537 else{538 // do nothing539 }540 } // end of spike search and correction541 for ( int i = 0; i < Samples; i++ ) debugHistos[ Vcorr_ ].SetBinContent( i, Vcorr[i] );542 }543 /*544 void computeN1mean( int Samples ){545 cout << "In compute N1mean" << endl;546 // compute the mean of the left and right neighbors of a channel547 548 for( int i = 0; i < Samples; i++){549 if (i == 0){ // use right sample es mean550 N1mean[i] = Ameas[i+1];551 }552 else if ( i == Samples-1 ){ //use left sample as mean553 N1mean[i] = Ameas[i-1];554 }555 else{556 N1mean[i] = ( Ameas[i-1] + Ameas[i+1] ) / 2.;557 }558 h[tN1mean].SetBinContent(i, Ameas[i] - N1mean[i]);559 }560 } // end of computeN1mean computation561 */562 563 void computeN1mean( int Samples ){564 // compute the mean of the left and right neighbors of a channel565 566 for( int i = 2; i < Samples - 2; i++){567 /* if (i == 0){ // use right sample es mean568 N1mean[i] = Ameas[i+1];569 }570 else if ( i == Samples-1 ){ //use left sample as mean571 N1mean[i] = Ameas[i-1];572 }573 else{574 N1mean[i] = ( Ameas[i-1] + Ameas[i+1] ) / 2.;575 }576 */577 N1mean[i] = ( Ameas[i-1] + Ameas[i+1] ) / 2.;578 }579 } // end of computeN1mean computation580 581 582 583 /*584 // this function takes a vector<float> and tries to apply the DRS calibration to it.585 // therfor it uses a DRS calibration file, which must be given as a parameter.586 // in case the calibration file can not be opened the function generates a warning on cerr587 // and returns an empty vector588 //589 // the function assumes the first parameter conatins the data of all Pixel590 // the RegionOfInterest is deduced from its size().591 592 //593 594 vector<float> * calibrateDrsData(595 vector<float> & AllPixelData,596 vector<float> & AllStartCells,597 const char * DrsCalibFilePath,598 bool ApplyCalibToSourceVector = false)599 {600 vector<float> * CalibratedDRSData;601 602 size_t DrsLengthOfVectors;603 vector<float> DrsOffset;604 vector<float> DrsGain;605 vector<float> DrsOffsetSpecialTrigger;606 607 // the Total Number of Pixel, we have data of608 // is deduced from the size() of AllPixelStartCell609 unsigned int NumberOfPixel = AllStartCells.size();610 //sanity Check:611 if (NumberOfPixel < 1) {612 cerr << "calibrateDrsData - Error: NumberOfPixel=AllStartCells.size() ia:"613 << AllStartCells.size() << " must be >= 1" << endl;614 return CalibratedDRSData615 }616 617 // The RegionOfInterest is deduced from the size() of AllPixel Data618 unsigned int RegionOfInterest = AllPixelData.size() / NumberOfPixel;619 // sanity Check620 if ( RegionOfInterest < 1){621 cerr << "calibrateDrsData - Error: RegionOfInterest = AllPixelData.size() / NumberOfPixel is:"622 << RegionOfInterest << " must be >= 1" << endl;623 return CalibratedDRSData624 }625 626 // now lets see if we can find the drs calib file627 FOpenCalibFile( DrsCalibFilePath,628 DrsOffset,629 DrsGain,630 DrsOffsetSpecialTrigger,631 DrsLengthOfVectors);632 //sanity check is done in FOpenCalibFile, I guess ... check and maybe TODO633 // maybe at least the return code of FOpenCalibFile should be checked here ... TODO634 635 636 637 638 }639 640 */641 642 float getValue( int slice, int pixel ){643 const float dconv = 2000/4096.0;644 645 float vraw, vcal;646 647 unsigned int pixel_pt;648 unsigned int slice_pt;649 unsigned int cal_pt;650 unsigned int drs_cal_offset;651 652 // printf("pixel = %d, slice = %d\n", slice, pixel);653 654 pixel_pt = pixel * RegionOfInterest;655 slice_pt = pixel_pt + slice;656 drs_cal_offset = ( slice + StartCellVector[ pixel ] )%RegionOfInterest;657 cal_pt = pixel_pt + drs_cal_offset;658 659 vraw = AllPixelDataVector[ slice_pt ] * dconv;660 vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;661 662 return( vcal );663 }664 665 // this is a faster version of getValue, that does not do a full calibration666 // was used for a performace test...667 float correctDrsOffset( int slice, int pixel ){668 669 const float dconv = 2000/4096.0;670 671 // here 1024 is not the RegionOfInterest, but really the lenth of the pipeline672 unsigned int physical_slice = ( slice + StartCellVector[ pixel ] ) % 1024;673 674 unsigned int slice_pt;675 unsigned int physical_slice_pt;676 slice_pt = pixel * RegionOfInterest + slice;677 physical_slice_pt = pixel * RegionOfInterest + physical_slice;678 679 float vcal = AllPixelDataVector[ slice_pt ] *680 dconv - drs_basemean[ physical_slice_pt ];681 return( vcal );682 }683 684 374 // booking and parameter settings for all histos 685 375 void BookHistos( ){ 686 // histograms for baseline extraction687 char hName[500];688 char hTitle[500];689 690 TH1F *h;691 692 for( int i = 0; i < NPIX; i++ ) {693 sprintf(&hTitle[0],"all events all slices of pixel %d", i);694 sprintf(&hName[0],"base%d", i);695 696 h = new TH1F( hName, hTitle, 400, -99.5 ,100.5 );697 698 h->GetXaxis()->SetTitle( "Sample value (mV)" );699 h->GetYaxis()->SetTitle( "Entries / 0.5 mV" );700 hListBaseline.Add( h );701 hBaseline[i] = h;702 }703 704 hMeanBsl = new TH1F("histo_mean","Value of maximal probability",400,-99.5,100.5);705 hMeanBsl->GetXaxis()->SetTitle( "max value (mV)" );706 hMeanBsl->GetYaxis()->SetTitle( "Entries / 0.5 mV" );707 hList.Add( hMeanBsl );708 709 hpltMeanBsl = new TH1F("hplt_mean","Value of maximal probability",1440,-0.5,1439.5);710 hpltMeanBsl->GetXaxis()->SetTitle( "pixel" );711 hpltMeanBsl->GetYaxis()->SetTitle( "max value in mV" );712 hList.Add( hpltMeanBsl );713 714 hRmsBsl = new TH1F("histo_rms","RMS in mV",2000,-99.5,100.5);715 hRmsBsl->GetXaxis()->SetTitle( "RMS (mV)" );716 hRmsBsl->GetYaxis()->SetTitle( "Entries / 0.5 mV" );717 hList.Add( hRmsBsl );718 719 hpltRmsBsl = new TH1F("hplt_rms","Value of maximal probability",1440,-0.5,1439.5);720 hpltRmsBsl->GetXaxis()->SetTitle( "pixel" );721 hpltRmsBsl->GetYaxis()->SetTitle( "RMS in mV" );722 hList.Add( hpltRmsBsl );723 724 hAmplSpek_cfd = new TH2F("hAmplSpek_cfd","amplitude spektrum - CFD",1440,-0.5,1439.5, 256, -27.5, 100.5);725 hAmplSpek_cfd->GetXaxis()->SetTitle( "pixel" );726 hAmplSpek_cfd->GetYaxis()->SetTitle( "amplitude in mV" );727 hList.Add( hAmplSpek_cfd );728 729 hAmplSpek_discri = new TH2F("hAmplSpek_discri","amplitude spektrum - std discriminator",1440,-0.5,1439.5, 256, -27.5, 100.5);730 hAmplSpek_discri->GetXaxis()->SetTitle( "pixel" );731 hAmplSpek_discri->GetXaxis()->SetTitle( "amplitude in mV" );732 hList.Add( hAmplSpek_discri );733 734 hStartCell = new TH2F("StartCell", "StartCell", 1440, 0., 1440., 1024, 0., 1024);735 hStartCell->GetXaxis()->SetTitle( "pixel" );736 hStartCell->GetXaxis()->SetTitle( "slice" );737 hList.Add( hStartCell );738 376 739 377 debugHistos = new TH1F[ NumberOfDebugHistoTypes ]; … … 755 393 debugHistos[ type ].GetYaxis()->SetTitle("Amplitude (a.u.)"); 756 394 } 757 hPeakOverlay = new TH2F("hPeakOverlay", "Overlay of detected Peaks", 201, -100.5, 100.5, 1024, -99.5, 100.5); 395 hPeakOverlay = new TH2F("hPeakOverlay", "Overlay of detected Peaks", 396 hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight , (-1*hPeakOverlayXaxisLeft)-0.5, hPeakOverlayXaxisRight-0.5 , 397 4096, -48.5, 1999.5 ); 758 398 hPeakOverlay->GetXaxis()->SetTitle( "Timeslices" ); 759 399 hPeakOverlay->GetYaxis()->SetTitle( "Amplitude [a.u.]" ); 760 //hList.Add( hPeakOverlay h);400 hList.Add( hPeakOverlay ); 761 401 762 402 } 763 403 764 void SaveHistograms( char * loc_fname ){ 765 766 TString fName; // name of the histogram file 767 768 // create the filename for the histogram file 769 fName = loc_fname; // use the name of the tree file 770 // TODO ... next statement doesn't work for ".fits.gz" 771 fName.Remove(fName.Length() - 5); // remove the extension .fits 772 fName += "_discri.root"; // add the new extension 773 404 void SaveHistograms(const char * loc_fname ){ 774 405 // create the histogram file (replace if already existing) 775 TFile tf( fName, "RECREATE");406 TFile tf( loc_fname, "RECREATE"); 776 407 777 408 hList.Write(); // write the major histograms into the top level directory 778 tf.mkdir("BaselineHisto");779 tf.cd("BaselineHisto"); // go to new subdirectory780 hListBaseline.Write(); // write histos into subdirectory781 409 782 410 tf.Close(); // close the file 783 411 } // end of SaveHistograms( char * loc_fname ) 784 412 785 int FOpenDataFile(fits &datafile){786 787 // cout << "-------------------- Data Header -------------------" << endl;788 // datafile.PrintKeys();789 // cout << "------------------- Data Columns -------------------" << endl;790 // datafile.PrintColumns();791 792 //Get the size of the data column793 RegionOfInterest = datafile.GetUInt("NROI");794 NumberOfPixels = datafile.GetUInt("NPIX");795 //Size of column "Data" = #Pixel x ROI796 ROIxNOP = datafile.GetN("Data");797 798 //Set the sizes of the data vectors799 AllPixelDataVector.resize(ROIxNOP,0);800 StartCellVector.resize(NumberOfPixels,0);801 802 //Link the data to variables803 datafile.SetRefAddress("EventNum", CurrentEventID);804 datafile.SetVecAddress("Data", AllPixelDataVector);805 datafile.SetVecAddress("StartCellData", StartCellVector);806 datafile.GetRow(0);807 808 return datafile.GetNumRows() ;809 }810 811 812 /////////////////////////////////////////////////////////////////////////////813 /// old BookHistos814 /*815 void BookHistos( int Samples ){816 // booking and parameter settings for all histos817 818 h = new TH1F[ Ntypes ];819 820 for ( int type = 0; type < Ntypes; type++){821 822 h[ type ].SetBins(Samples, 0, Samples);823 h[ type ].SetLineColor(1);824 h[ type ].SetLineWidth(2);825 826 // set X axis paras827 h[ type ].GetXaxis()->SetLabelSize(0.1);828 h[ type ].GetXaxis()->SetTitleSize(0.1);829 h[ type ].GetXaxis()->SetTitleOffset(1.2);830 h[ type ].GetXaxis()->SetTitle(Form("Time slice (%.1f ns/slice)", 1./2.));831 832 // set Y axis paras833 h[ type ].GetYaxis()->SetLabelSize(0.1);834 h[ type ].GetYaxis()->SetTitleSize(0.1);835 h[ type ].GetYaxis()->SetTitleOffset(0.3);836 h[ type ].GetYaxis()->SetTitle("Amplitude (a.u.)");837 }838 cRawAndSpikeRemoval = new TCanvas("cRawAndSpikeRemoval","DRS Waveform",10,10,800,600);839 cRawAndSpikeRemoval->Divide(1, 3);840 cFilter = new TCanvas("cFilter","filtered DRS Waveforms",10,10,800,600);841 cFilter->Divide(1, 3);842 843 hStartCell = new TH2F("StartCell", "StartCell", 1440, 0., 1440., 1024, 0., 1024);844 845 }846 */847
Note:
See TracChangeset
for help on using the changeset viewer.