Changeset 14477
- Timestamp:
- 10/15/12 14:29:05 (12 years ago)
- Location:
- fact/tools/rootmacros/PulseTemplates
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/PulseTemplates/templateextractors.C
r14081 r14477 1 1 #include <iostream> 2 2 #include <fstream> 3 #include <stdlib.h> 3 4 4 5 #include "templateextractors.h" 5 #include <stdlib.h>6 6 7 7 using namespace std; … … 15 15 ) 16 16 { 17 if (verbosityLevel > 2) cout << endl 18 << "...calculating slieces value of max. propability" 19 << endl; 20 21 float max_value_of_slice = 0; 22 TH1D* hTempHisto = NULL; 23 int nbins = inputHisto->GetXaxis()->GetNbins(); 24 25 if (verbosityLevel > 2) cout << "...generating projections" << endl; 26 27 for (Int_t TimeSlice = 1; TimeSlice <= nbins; TimeSlice++) 28 { 29 if (verbosityLevel > 2) cout << "...Timeslice: " << TimeSlice; 30 31 //put maximumvalue of every Y-projection of every timeslice into vector 32 hTempHisto = inputHisto->ProjectionY( "", TimeSlice,TimeSlice); 33 max_value_of_slice = hTempHisto->GetBinCenter( hTempHisto->GetMaximumBin() ); 34 35 if (verbosityLevel > 2) cout << " with max value " 36 << max_value_of_slice << endl; 37 38 outputHisto->SetBinContent(TimeSlice, max_value_of_slice ); 39 } 40 41 if (verbosityLevel > 2) cout << "\t...done" << endl; 17 if (verbosityLevel > 2) 18 cout << endl 19 << "...calculating slieces value of max. propability" 20 << endl; 21 22 float sliceMax = 0; 23 TH1D* hTemp = NULL; 24 int nbins = inputHisto->GetXaxis()->GetNbins(); 25 26 if (verbosityLevel > 2) 27 cout << "...generating projections" << endl; 28 29 for (Int_t slice = 1; slice <= nbins; slice++) 30 { 31 if (verbosityLevel > 2) 32 cout << "...slice: " << slice; 33 34 //put maximumvalue of every Y-projection of every slice into vector 35 hTemp = inputHisto->ProjectionY( "", slice,slice); 36 sliceMax = hTemp->GetBinCenter( hTemp->GetMaximumBin() ); 37 38 if (verbosityLevel > 2) 39 cout << " with max value " 40 << sliceMax << endl; 41 42 outputHisto->SetBinContent(slice, sliceMax ); 43 } 44 45 if (verbosityLevel > 2) 46 cout << "\t...done" << endl; 42 47 } 43 48 // end of CalcMaxPropabilityOfSlice … … 442 447 } 443 448 444 void 445 FitFallingEdge( 446 TString name, 447 TH1F* histo, 448 double xMin, 449 double xMax, 450 double* parameters 451 ) 452 { 453 TF1* polExpFit = new TF1(name, PolExp, xMin, xMax, 3 ); 454 polExpFit->SetParNames("Pol0", "Slope", "Shift"); 455 polExpFit->SetLineColor(kRed); 456 histo->Fit(polExpFit, "RWM"); 457 polExpFit->GetParameters(parameters); 458 } 459 460 void 461 FitRisingEdge( 462 TString name, 463 TH1F* histo, 464 double xMin, 465 double xMax, 466 double* parameters 467 ) 468 { 469 TF1* polExpFit = new TF1(name, NegPolExp, xMin, xMax, 3 ); 470 polExpFit->SetParNames("Pol0", "Slope", "Shift"); 471 polExpFit->SetLineColor(kRed); 472 histo->Fit(polExpFit, "RWM"); 473 polExpFit->GetParameters(parameters); 474 } 475 476 double 477 NegPolExp( 478 double* x, 479 double* par 480 ) 481 { 482 return par[0]+(-1)*TMath::Exp(par[1]+par[2]*x[0]); 483 } 484 485 double 486 PolExp( 487 double* x, 488 double* par 489 ) 490 { 491 return par[0]+TMath::Exp(par[1]+par[2]*x[0]); 492 } 493 494 double 495 ChargeDiode( 496 double* time, 497 double* chargeVoltage, 498 double* impedance, 499 double* capacity, 500 ) 501 { 502 return chargeVoltage*(1 - TMath::Exp(time/(impedance*capacity))); 503 } 504 505 double 506 UnChargeDiode( 507 double* time, 508 double* chargeVoltage, 509 double* impedance, 510 double* capacity, 511 ) 512 { 513 return chargeVoltage*(TMath::Exp(time/(impedance*capacity))); 514 } 515 516 double 517 template_function( 518 double* input_x, 519 double* par) 520 { 521 double returnval = 0.0; 522 523 // I introduce a few names 524 // double shift = par[0]; 525 double bsl = par[0]; 526 double beginOfRisingEdge = par[1]; 527 double p0RisingEdge = par[6]; 528 double p1RisingEdge = par[7]; 529 double p2RisingEdge = par[8]; 530 double p3RisingEdge = par[9]; 531 double endOfRisingEdge = par[2]; 532 // double pOFallingEdge = par[3]; 533 // double expPar1FallingEdge = par[4]; 534 // double expPar1FallingEdge = par[5]; 535 /* 536 bool couted_once = false; 537 if not couted_once 538 { 539 couted_once = true; 540 cout << "shift:" << shift << endl; 541 cout << "bsl:" << bsl << endl; 542 cout << "expars:" << endl; 543 cout << "\t factor:" << exppar[0] << endl; 544 cout << "\t tau:" << exppar[1] << endl; 545 cout << "\t t0:" << exppar[2] << endl; 546 cout << "pol3pars:" << endl; 547 cout << "p[0] + x p[1] + x^2 p[2] + x^3 p[3]" << endl; 548 cout << pol3par[0] << "\t" << pol3par[1] << "\t" << pol3par[2] << "\t" << pol3par[3] << endl; 549 cout << "ranges:" << endl; 550 cout << "begin of pol3: " << range[0] << endl; 551 cout << "begin of exp: " << range[1] << endl; 552 } 553 */ 554 double x = input_x[0]; 555 556 // the baseline is added everywhere. 557 returnval += bsl; 558 559 if ( (x > beginOfRisingEdge) && (x <= endOfRisingEdge) ) 560 { 561 // from this point on the pol3 is added 562 returnval += p0RisingEdge; 563 returnval += p1RisingEdge * x; 564 returnval += p2RisingEdge * x*x; 565 returnval += p3RisingEdge * x*x*x; 566 } 567 else if ( x > endOfRisingEdge ) 568 { 569 // from this point on the exp-func is added 570 // returnval += exppar[0] * TMath::Exp( exppar[1] * ( x - exppar[2] ) ); 571 returnval += PolExp(input_x, par+3); 572 } 573 574 return returnval; 575 } 576 577 double 578 PulseFunction( 579 double* time, 580 double* baseline, 581 double* risingChargeVoltage, 582 double* risingImpedance, 583 double* risingCapacity, 584 double* fallingChargeVoltage, 585 double* fallingImpedance, 586 double* fallingCapacity 587 ) 588 { 589 double returnValue = 0.0; 590 returnValue += baseline; 591 returnValue += ChargeDiode( 592 time, 593 risingChargeVoltage, 594 risingImpedance, 595 risingCapacity); 596 returnValue += UnChargeDiode( 597 time, 598 fallingChargeVoltage, 599 fallingImpedance, 600 fallingCapacity); 601 return returnValue; 602 } 603 604 void 605 FitPulse( 606 TString name, 607 TH1F* histo, 608 double xMin, 609 double xMax, 610 double* parameters 611 ) 612 { 613 TF1* pulseFunction = new TF1(name, PulseFunction, xMin, xMax, 7 ); 614 pulseFunction->SetParNames( 615 "Baseline", 616 "Charge-Voltage of rising Edge", 617 "Impedance for rising Edge", 618 "Capacity for rising Edge", 619 "Charge-Voltage of falling Edge", 620 "Impedance for falling Edge", 621 "Capacity for falling Edge" 622 ); 623 pulseFunction->SetLineColor(kRed); 624 histo->Fit(pulseFunction, "RWM"); 625 pulseFunction->GetParameters(parameters); 626 return 0; 627 } 449 //void 450 //FitFallingEdge( 451 // TString name, 452 // TH1F* histo, 453 // double xMin, 454 // double xMax, 455 // double* parameters 456 // ) 457 //{ 458 // TF1* polExpFit = new TF1(name, PolExp, xMin, xMax, 3 ); 459 // polExpFit->SetParNames("Pol0", "Slope", "Shift"); 460 // polExpFit->SetLineColor(kGreen); 461 // histo->Fit(polExpFit, "+RWM"); 462 // polExpFit->GetParameters(parameters); 463 //} 464 465 //void 466 //FitRisingEdge( 467 // TString name, 468 // TH1F* histo, 469 // double xMin, 470 // double xMax, 471 // double* parameters 472 // ) 473 //{ 474 // TF1* polExpFit = new TF1(name, NegPolExp, xMin, xMax, 3 ); 475 // polExpFit->SetParNames("Pol0", "Slope", "Shift"); 476 // polExpFit->SetLineColor(kRed); 477 // histo->Fit(polExpFit, "+RWWM"); 478 // polExpFit->GetParameters(parameters); 479 //} 480 481 //double 482 //NegPolExp( 483 // double* x, 484 // double* par 485 // ) 486 //{ 487 // return par[0]+(-1)*TMath::Exp(par[1]+par[2]*x[0]); 488 //} 489 490 //double 491 //PolExp( 492 // double* x, 493 // double* par 494 // ) 495 //{ 496 // return 497 //// par[0]+ 498 // TMath::Exp(par[1]+par[2]*x[0]); 499 //} 500 501 //double 502 //ChargeDiode( 503 // double time, 504 // double chargeVoltage, 505 // double impedance, 506 // double capacity 507 // ) 508 //{ 509 // return chargeVoltage*(1 - TMath::Exp(time/(impedance*capacity))); 510 //} 511 512 //double 513 //UnChargeDiode( 514 // double* time, 515 // double* chargeVoltage, 516 // double* timeConstant 517 // ) 518 //{ 519 // return chargeVoltage[0]+TMath::Exp(chargeVoltage[1]+timeConstant[2]*time[0]); 520 //// return chargeVoltage[0] * (TMath::Exp(time[0]/timeConstant[0])); 521 //} 522 523 //double 524 //template_function( 525 // double* input_x, 526 // double* par) 527 //{ 528 // double returnval = 0.0; 529 530 // // I introduce a few names 531 // // double shift = par[0]; 532 // double bsl = par[0]; 533 // double beginOfRisingEdge = par[1]; 534 // double p0RisingEdge = par[6]; 535 // double p1RisingEdge = par[7]; 536 // double p2RisingEdge = par[8]; 537 // double p3RisingEdge = par[9]; 538 // double endOfRisingEdge = par[2]; 539 //// double pOFallingEdge = par[3]; 540 //// double expPar1FallingEdge = par[4]; 541 //// double expPar1FallingEdge = par[5]; 542 // /* 543 // bool couted_once = false; 544 // if not couted_once 545 // { 546 // couted_once = true; 547 // cout << "shift:" << shift << endl; 548 // cout << "bsl:" << bsl << endl; 549 // cout << "expars:" << endl; 550 // cout << "\t factor:" << exppar[0] << endl; 551 // cout << "\t tau:" << exppar[1] << endl; 552 // cout << "\t t0:" << exppar[2] << endl; 553 // cout << "pol3pars:" << endl; 554 // cout << "p[0] + x p[1] + x^2 p[2] + x^3 p[3]" << endl; 555 // cout << pol3par[0] << "\t" << pol3par[1] << "\t" << pol3par[2] << "\t" << pol3par[3] << endl; 556 // cout << "ranges:" << endl; 557 // cout << "begin of pol3: " << range[0] << endl; 558 // cout << "begin of exp: " << range[1] << endl; 559 // } 560 // */ 561 // double x = input_x[0]; 562 563 // // the baseline is added everywhere. 564 // returnval += bsl; 565 566 // if ( (x > beginOfRisingEdge) && (x <= endOfRisingEdge) ) 567 // { 568 // // from this point on the pol3 is added 569 // returnval += p0RisingEdge; 570 // returnval += p1RisingEdge * x; 571 // returnval += p2RisingEdge * x*x; 572 // returnval += p3RisingEdge * x*x*x; 573 // } 574 // else if ( x > endOfRisingEdge ) 575 // { 576 // // from this point on the exp-func is added 577 //// returnval += exppar[0] * TMath::Exp( exppar[1] * ( x - exppar[2] ) ); 578 // returnval += PolExp(input_x, par+3); 579 // } 580 581 // return returnval; 582 //} -
fact/tools/rootmacros/PulseTemplates/templateextractors.h
r14082 r14477 88 88 ); 89 89 90 void91 FitMaxPropabilityPuls(92 TH1F* hMaximumTemp,93 int verbosityLevel94 );90 //void 91 //FitMaxPropabilityPuls( 92 // TH1F* hMaximumTemp, 93 // int verbosityLevel 94 // ); 95 95 96 double97 PolExp(98 double* x,99 double* par100 );96 //double 97 //PolExp( 98 // double* x, 99 // double* par 100 // ); 101 101 102 void103 FitFallingEdge(104 TString name,105 TH1F* histo,106 double xMin,107 double xMax,108 double* parameters109 );102 //void 103 //FitFallingEdge( 104 // TString name, 105 // TH1F* histo, 106 // double xMin, 107 // double xMax, 108 // double* parameters 109 // ); 110 110 111 double112 template_function(113 double* input_x,114 double* par);111 //double 112 //template_function( 113 // double* input_x, 114 // double* par); 115 115 116 double117 NegPolExp(118 double* x,119 double* par120 );116 //double 117 //NegPolExp( 118 // double* x, 119 // double* par 120 // ); 121 121 122 void123 FitRisingEdge(124 TString name,125 TH1F* histo,126 double xMin,127 double xMax,128 double* parameters129 );122 //void 123 //FitRisingEdge( 124 // TString name, 125 // TH1F* histo, 126 // double xMin, 127 // double xMax, 128 // double* parameters 129 // ); 130 130 131 double132 ChargeDiode(133 double*time,134 double*chargeVoltage,135 double*impedance,136 double*capacity137 );131 //double 132 //ChargeDiode( 133 // double time, 134 // double chargeVoltage, 135 // double impedance, 136 // double capacity 137 // ); 138 138 139 double 140 UnChargeDiode( 141 double* time, 142 double* chargeVoltage, 143 double* impedance, 144 double* capacity 145 ); 146 147 double 148 PulseFunction( 149 double* time, 150 double* baseline, 151 double* risingChargeVoltage, 152 double* risingImpedance, 153 double* risingCapacity, 154 double* fallingChargeVoltage, 155 double* fallingImpedance, 156 double* fallingCapacity 157 ); 158 159 void 160 FitPulse( 161 TString name, 162 TH1F* histo, 163 double xMin, 164 double xMax, 165 double* parameters 166 ); 139 //double 140 //UnChargeDiode( 141 // double* time, 142 // double* chargeVoltage, 143 // double* timeConstant 144 // ); 167 145 168 146 #endif // TEMPLATEEXTRACTORS_H
Note:
See TracChangeset
for help on using the changeset viewer.