本文整理汇总了C++中TSpectrum::GetPositionX方法的典型用法代码示例。如果您正苦于以下问题:C++ TSpectrum::GetPositionX方法的具体用法?C++ TSpectrum::GetPositionX怎么用?C++ TSpectrum::GetPositionX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSpectrum
的用法示例。
在下文中一共展示了TSpectrum::GetPositionX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_ToF_Calib_Tower
void draw_ToF_Calib_Tower() {
ofstream fout("ToF_Calib_Tower.txt");
TFile* f = new TFile("/phenix/plhf/zji/taxi/Run13pp510MinBias/8328/data/total.root");
TH2I* h_hitmap_tof_energy_PbSc = (TH2I*)f->Get("hitmap_tof_energy_PbSc");
TH2I* h_hitmap_tof_energy_PbGl = (TH2I*)f->Get("hitmap_tof_energy_PbGl");
TH2I* h_hitmap_tof_tower = (TH2I*)f->Get("hitmap_tof_tower");
TCanvas* c = new TCanvas("c", "Canvas", 1800, 600);
gStyle->SetOptStat(1);
gStyle->SetOptFit(1);
c->Divide(3,1);
c->cd(1);
h_hitmap_tof_energy_PbSc->Draw("colz");
c->cd(2);
h_hitmap_tof_energy_PbGl->Draw("colz");
c->cd(3);
fout << "towerid ToF peak" << endl;
for(Int_t id=0; id<25000; id++) {
TH1D* hp_hitmap_tof_tower = (TH1D*)h_hitmap_tof_tower->ProjectionY("_py",id+1,id+1);
TSpectrum* peak = new TSpectrum();
Int_t nfound = peak->Search(hp_hitmap_tof_tower,2.,"nodraw");
if(nfound) {
Float_t peakX = *peak->GetPositionX();
hp_hitmap_tof_tower->Fit("gaus","Q0","",peakX-3.,peakX+3.);
TF1* f_hitmap_tof_tower = hp_hitmap_tof_tower->GetFunction("gaus");
Double_t mean_hitmap_tof_tower = f_hitmap_tof_tower->GetParameter(1);
fout << id << " " << mean_hitmap_tof_tower << endl;
f_hitmap_tof_tower->Delete();
}
else {
fout << id << " " << "-100." << endl;
}
delete peak;
hp_hitmap_tof_tower->Delete();
}
fout.close();
TH1D* hp_hitmap_tof_tower = (TH1D*)h_hitmap_tof_tower->ProjectionY("_py",100,100);
TSpectrum* peak = new TSpectrum();
peak->Search(hp_hitmap_tof_tower,2.,"nodraw");
Float_t peakX = *peak->GetPositionX();
hp_hitmap_tof_tower->Fit("gaus","","",peakX-3.,peakX+3.);
TF1* f_hitmap_tof_tower = hp_hitmap_tof_tower->GetFunction("gaus");
Double_t mean_hitmap_tof_tower = f_hitmap_tof_tower->GetParameter(1);
cout << "peakX=" << peakX << endl;
cout << "ToF mean=" << mean_hitmap_tof_tower << endl;
c->Print("ToF_Calib_Tower.pdf");
}
示例2: getValByKeyword
//Given an input histogram and TSpectrum returns a numeric value based on the input keyword; supported keywords are "AMPLITUDE,MEAN,PEAK,SIGMA"
float AnalyzeResponseUniformity::getValByKeyword(string strInputKeyword, shared_ptr<TH1F> hInput, TSpectrum &specInput){
//Try to automatically assign a value
if (0 == strInputKeyword.compare("AMPLITUDE") ) { //Case: Histo Amplitude
return hInput->GetBinContent( hInput->GetMaximumBin() );
} //End Case: Histo Amplitude
else if (0 == strInputKeyword.compare("MEAN") ) { //Case: Histo Mean
return hInput->GetMean();
} //End Case: Histo Mean
else if ( 0 == strInputKeyword.compare("PEAK") ){ //Case: Histo Peak
Double_t *dPeakPos = specInput.GetPositionX();
return dPeakPos[0];
} //End Case: Histo Peak
else if (0 == strInputKeyword.compare("SIGMA") ) { //Case: Histo RMS
return hInput->GetRMS();
} //End Case: Histo RMS
else{ //Case: manual assignment
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","Error! Input Keyword Not Recognized");
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword", ("\tGiven: " + strInputKeyword ).c_str() );
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","\tRecognized Keywords:\n");
for (int i=0; i < vec_strSupportedKeywords.size(); ++i) {
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword", vec_strSupportedKeywords[i].c_str() );
}
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","\tUndefined Behavior May Occur");
return -1e12;
} //End Case: manual assignment
} //End AnalyzeResponseUniformity::getValByKeyword()
示例3: TSpectrum
TGraph* autogain152(TH1 *hist) {
hist->GetXaxis()->SetRangeUser(200.,16000.);
TSpectrum *s = new TSpectrum();
Int_t nfound = s->Search(hist,6,"",0.08); //This will be dependent on the source used.
printf("Found %d candidate peaks to fit\n",nfound);
if(nfound > 6)
nfound = 6;
std::vector<float> vec;
for(int x=0;x<nfound;x++)
vec.push_back(s->GetPositionX()[x]);
std::sort(vec.begin(),vec.end());
Float_t energies[] = {121.7830, 244.6920, 344.276, 778.903, 964.131, 1408.011};
TGraph* slopefit = new TGraph(nfound, &(vec[0]), energies);
printf("Now fitting: Be patient\n");
slopefit->Fit("pol1");
if(slopefit->GetFunction("pol1")->GetChisquare() > 10.) {
slopefit->RemovePoint(slopefit->GetN()-1);
slopefit->Fit("pol1");
}
TChannel *chan = 0;
slopefit->Draw("AC*");
return slopefit;
}
示例4: while
int e428ana1::MakePara(Double_t thr){
int npeak,nlap;
double threshol,thrmin,thrmax;
TSpectrum *spec;
for (int i=0; i<4; i++) {
for (int j=0; j<127; j++) {
npeak=0;nlap=0;
threshol=thr;
thrmax=1;thrmin=0;
while (npeak!=4 && nlap<100){
spec = new TSpectrum(10);
npeak = spec->Search(hdssd[i][j],2,"",threshol);
if (npeak >3) {
thrmin=threshol;
}else thrmax=threshol;
threshol=(thrmax-thrmin)/2;
nlap++;
// printf("Npeak %d %d %d %f\n",i,j,npeak,threshol);
}
float *xpeak=spec->GetPositionX();
float *ypeak=spec->GetPositionY();
printf("Npeak %d %d %d",i,j,npeak);
for (int i1=0; i1<npeak; i1++) {
printf(" %f %f",xpeak[i1],ypeak[i1]);
}
printf("\n");
}
}
return 0;
}
示例5: peaks
void peaks(Int_t np=10) {
npeaks = TMath::Abs(np);
TH1F *h = new TH1F("h","test",500,0,1000);
//generate n peaks at random
Double_t par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
Int_t p;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1;
par[3*p+3] = 10+gRandom->Rndm()*980;
par[3*p+4] = 3+2*gRandom->Rndm();
}
TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks);
f->SetNpx(1000);
f->SetParameters(par);
TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,900);
c1->Divide(1,2);
c1->cd(1);
h->FillRandom("f",200000);
h->Draw();
TH1F *h2 = (TH1F*)h->Clone("h2");
//Use TSpectrum to find the peak candidates
TSpectrum *s = new TSpectrum(2*npeaks);
Int_t nfound = s->Search(h,2,"",0.10);
printf("Found %d candidate peaks to fit\n",nfound);
//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(h,20,"same");
if (hb) c1->Update();
if (np <0) return;
//estimate linear background using a fitting method
c1->cd(2);
TF1 *fline = new TF1("fline","pol1",0,1000);
h->Fit("fline","qn");
//Loop on all found peaks. Eliminate peaks at the background level
par[0] = fline->GetParameter(0);
par[1] = fline->GetParameter(1);
npeaks = 0;
Double_t *xpeaks = s->GetPositionX();
for (p=0;p<nfound;p++) {
Double_t xp = xpeaks[p];
Int_t bin = h->GetXaxis()->FindBin(xp);
Double_t yp = h->GetBinContent(bin);
if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
printf("Found %d useful peaks to fit\n",npeaks);
printf("Now fitting: Be patient\n");
TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
//we may have more than the default 25 parameters
TVirtualFitter::Fitter(h2,10+3*npeaks);
fit->SetParameters(par);
fit->SetNpx(1000);
h2->Fit("fit");
}
示例6: autogain
TGraph* autogain(TH1 *hist,TNucleus *nuc) { //Display The fits on a TPad
if(!hist || !nuc)
return 0;
nuc->SetSourceData();
if(nuc->GetA() == 152) {
return autogain152(hist);
}
// Search
hist->GetXaxis()->SetRangeUser(200.,16000.);
TSpectrum *s = new TSpectrum();
Int_t nfound = s->Search(hist,6,"",0.1); //This will be dependent on the source used.
printf("Found %d candidate peaks to fit\n",nfound);
// Match
nuc->TransitionList.Sort();
std::vector<float> engvec;
TIter iter(&(nuc->TransitionList));
TObject* obj;
while(obj = iter.Next()) {
if(!obj->InheritsFrom("TGRSITransition"))
continue;
TGRSITransition *tran = (TGRSITransition*)obj;
engvec.push_back(static_cast<float>(tran->energy));
if(engvec.size() == nfound)
break;
}
if(nfound != engvec.size())
return 0;
Float_t *posPeaks = s->GetPositionX();
Float_t *energies = &(engvec[0]);
for(int x=0;x<nfound;x++) {
printf("posPeaks[%i] = %f\t\tenrgies[%i] = %f\n",x,posPeaks[x],x,energies[x]);
}
TGraph *slopefit = new TGraph(nfound,posPeaks,energies );
printf("Now fitting: Be patient\n");
slopefit->Fit("pol1");
slopefit->Draw("AC*");
return slopefit;
}
示例7: Fit
//______________________________________________________________________________
void Fit(Int_t run)
{
// Perform fit.
Char_t tmp[256];
// delete old function
if (gFitFunc) delete gFitFunc;
// create fitting function
if (gFitFunc) delete gFitFunc;
sprintf(tmp, "fGauss_%d", run);
gFitFunc = new TF1(tmp, "expo(0)+gaus(2)");
gFitFunc->SetLineColor(2);
// estimate peak position
TSpectrum s;
s.Search(gH, 10, "goff nobackground", 0.05);
Double_t peak = TMath::MaxElement(s.GetNPeaks(), s.GetPositionX());
// prepare fitting function
gFitFunc->SetRange(gMin, gMax);
gFitFunc->SetParameter(2, gH->GetXaxis()->FindBin(peak));
gFitFunc->SetParLimits(2, 0, 100000);
gFitFunc->SetParameter(3, peak);
gFitFunc->SetParameter(4, 20);
gFitFunc->SetParLimits(4, 18, 100);
for (Int_t i = 0; i < 10; i++)
if (!gH->Fit(gFitFunc, "RBQ0")) break;
// get peak
peak = gFitFunc->GetParameter(3);
// indicator line
gLine->SetX1(peak);
gLine->SetX2(peak);
gLine->SetY1(0);
gLine->SetY2(gH->GetMaximum());
// draw
gCFit->cd();
gH->GetXaxis()->SetRangeUser(0, 2000);
gH->Draw();
gFitFunc->Draw("same");
gLine->Draw("same");
// fill overview histogram
gHOverview->SetBinContent(run+1, peak);
gHOverview->SetBinError(run+1, 0.0001);
}
示例8: FindPeak
void FindPeak(TH1 *hm, int * i, char * namefile){
int np =5, p, max = 0;
int npeaks = TMath::Abs(np);
double par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1;
par[3*p+3] = 10+gRandom->Rndm()*980;
par[3*p+4] = 3+2*gRandom->Rndm();
}
TSpectrum *s = new TSpectrum(2*npeaks,1);
int nfound = s->Search(hm,2,"",0.10);
printf("Found %d candidate peaks to fit\n",nfound);
TH1 *hb = s->Background(hm,20,"same");
if (np <0) return;
// loope over peaks
TF1 *fline = new TF1("fline","pol1",0,1000);
hm->Fit("fline","qn");
par[0] = fline->GetParameter(0);
par[1] = fline->GetParameter(1);
npeaks = 0;
float *xpeaks = s->GetPositionX();
for (p=0;p<nfound;p++) {
float xp = xpeaks[p];
int bin = hm->GetXaxis()->FindBin(xp);
float yp = hm->GetBinContent(bin);
if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
printf("Found %d useful peaks to fit\n",npeaks);
printf("Now fitting: Be patient\n");
if (max < npeaks) max = npeaks;
TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
TVirtualFitter::Fitter(hm,10+3*npeaks);
fit->SetParameters(par);
fit->SetNpx(1000);
hm->Fit("fit");
}
示例9: FindPeaks
//// This version needs thought
void SiCalibrator::FindPeaks() {
Load();
int iterate = 25;
int nbins;
TSpectrum* spec = new TSpectrum(10);
avesigma = 0;
int nsigma = 0;
for (int src=0; src < CalData.size(); src++) {
if (CalData[src].hSource != 0) {
for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) {
TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1);
nbins = hbi->GetNbinsX();
TH1D* hbk1 = (TH1D*) spec->Background(hbi,iterate);
hbi->Add(hbk1,-1);
//Estimate parameters
double lim = 5;
double max = 0;
double peak = 0;
int i = nbins - 1;
while (hbi->GetBinContent(i) < lim && i > 0) {
max = i;
i--;
}
double sigma = (max/CalibSource::sourcelist[src].betas.back().E)*2; //2 keV
if (sigma > 1) {
avesigma += sigma;
nsigma++;
}
gErrorIgnoreLevel = kError;
int npeaks = spec->Search(hbi,sigma,"nodraw ",0.001);
float* adc = spec->GetPositionX();
float* amp = spec->GetPositionY();
for (int i=0; i<npeaks; i++) {
CalData[src].sourcedata[ch].ADC.push_back(adc[i]);
CalData[src].sourcedata[ch].Amp.push_back(amp[i]);
}
}
}
}
avesigma = avesigma/nsigma;
}
示例10: DiffPeak
/*
Finds peak in timing difference spectrum
*/
double DiffPeak(TTree *&tree, TString pidcut = "PID>1000")
{
TSpectrum *spec = new TSpectrum(10); // peak finder
TH1D *diff = new TH1D("diff","diff",200,-5,5);
tree->Project("diff","diff",pidcut.Data());
spec->Search(diff,2,"nodraw",0.7);
double diffpeak = spec->GetPositionX()[0];
// testing
//TCanvas *c_tmp = new TCanvas();
//diff->Draw();
//c_tmp->WaitPrimitive();
//delete c_tmp;
delete diff;
delete spec;
return diffpeak;
} // end DiffPeak()
示例11: laserCalibration
//.........这里部分代码省略.........
Float_t * source = new Float_t[nbins];
Float_t * dest = new Float_t[nbins];
for (int i = 0; i < nbins; ++i){
source[i]=y_max-caen.trace[channel][i];
g->SetPoint(i, i, source[i]);
}
//Use TSpectrum to find the peak candidates
TSpectrum *s = new TSpectrum();
Int_t nfound = s->SearchHighRes(source, dest, nbins, 3, 2, kTRUE, 2, kFALSE, 5);
/**************************************
* Background estimation
**************************************
*/
Int_t ssize = nbins;
Int_t numberIterations = 20;
Int_t direction = s->kBackIncreasingWindow;
Int_t filterOrder = s->kBackOrder2;
bool smoothing = kFALSE;
Int_t smoothWindow = s->kBackSmoothing3;
bool compton = kFALSE;
for (int i = 0; i < nbins; ++i) baseline[i] = source[i];
s->Background(baseline, ssize, numberIterations, direction, filterOrder, smoothing, smoothWindow, compton);
/**************************************
* Peaks and integral estimation
**************************************
*/
Double_t px[2], py[2];
for (int i = 0; i < nbins; ++i) dest[i] = source[i]-baseline[i];
if(nfound==2){
bin = s->GetPositionX()[0];
fPositionX1 = bin;
fPositionY1 = dest[bin];
px[0] = bin;
py[0] = dest[bin];
bin = s->GetPositionX()[1];
fPositionX2 = bin;
fPositionY2 = dest[bin];
px[1] = bin;
py[1] = dest[bin];
}
int posxa=6;
int posxb=9;
switch (filenum){
case 1081:
posxa=6;
posxb=9;
break;
case 1082:
posxa=5;
posxb=7;
break;
case 1083:
posxa=5;
posxb=8;
break;
case 1084:
posxa=5;
posxb=7;
break;
示例12: fit
void fit(){
int range = 1e4;
TFile *f = new TFile("hgrroot.root");
TCanvas *ca = new TCanvas("ca","ca",0,0,1400,900);
ca->Divide(4,4);
TH1F* h[7][4];
TF1* fu[7][4][2];
TF1* fus[7][4][2][3];
double res[7*4];
double det[7*4];
double slope[7*4];
double offset[7*4];
double resolution =5;
TEnv* output = new TEnv("corecal.dat");
for(int d=0;d<7;d++){
for(int c=0;c<4;c++){
h[d][c] = (TH1F*)f->Get(Form("htraceen_b%d_c%d_cr%d_d%d",0,9,c,d+1));
ca->cd(1+c*4);
//h[d][c]->GetXaxis()->SetRangeUser(100,4000);
TSpectrum *sp = new TSpectrum(2,resolution);
sp->SetResolution(resolution);
Int_t nfound = 0;
nfound = sp->Search(h[d][c],resolution,"nobackground",0.5);
Float_t *xpeaks = sp->GetPositionX();
Float_t *ypeaks = sp->GetPositionY();
// for(int p=0;p<nfound;p++){
// cout << xpeaks[p] << "\t" << ypeaks[p] << endl;
// }
if(nfound!=2){
cout << "Found " << nfound << " peaks in spectrum, too many, aborting" << endl;
continue;
}
h[d][c]->DrawCopy();
//check if first peak is lower in energy, otherwise swap them
if(xpeaks[0]>xpeaks[1]){
Float_t temp = xpeaks[1];
xpeaks[1] = xpeaks[0];
xpeaks[0] = temp;
temp = ypeaks[1];
ypeaks[1] = ypeaks[0];
ypeaks[0] = temp;
}
for(int p=0;p<nfound;p++){
ca->cd(1+c*4+1+p);
h[d][c]->GetXaxis()->SetRangeUser(xpeaks[p]-range,xpeaks[p]+range);
h[d][c]->DrawCopy();
fu[d][c][p] = new TF1(Form("fcore_d%d_c%d_p%d",d,c,p),fgammagaussbg,xpeaks[p]-range,xpeaks[p]+range,6);
fu[d][c][p]->SetLineColor(3);
fu[d][c][p]->SetLineWidth(1);
fu[d][c][p]->SetParameter(0,0);//bg const
fu[d][c][p]->SetParameter(1,0);//bg slope
fu[d][c][p]->SetParameter(2,h[d][c]->Integral(xpeaks[p]-range,xpeaks[p]+range));//norm
fu[d][c][p]->SetParameter(3,xpeaks[p]);//mean
fu[d][c][p]->SetParLimits(3,xpeaks[p]-500,xpeaks[p]+500);//mean
fu[d][c][p]->SetParameter(4,100);//sigma
fu[d][c][p]->SetParLimits(4,0.001,1000);//sigma
fu[d][c][p]->SetParameter(5,h[d][c]->GetBinContent(h[d][c]->FindBin(xpeaks[p]-range)));//step
h[d][c]->Fit(fu[d][c][p],"Rqn");
fu[d][c][p]->Draw("same");
fus[d][c][p][0] = new TF1(Form("fcore_d%d_c%d_p%d_bg",d,c,p),fgammabg,xpeaks[p]-range,xpeaks[p]+range,6);
fus[d][c][p][1] = new TF1(Form("fcore_d%d_c%d_p%d_st",d,c,p),fgammastep,xpeaks[p]-range,xpeaks[p]+range,6);
fus[d][c][p][2] = new TF1(Form("fcore_d%d_c%d_p%d_ga",d,c,p),fgammagaus,xpeaks[p]-range,xpeaks[p]+range,6);
fus[d][c][p][0]->SetLineColor(5);
fus[d][c][p][1]->SetLineColor(4);
fus[d][c][p][2]->SetLineColor(2);
for(int k=0;k<3;k++){
fus[d][c][p][k]->SetLineWidth(1);
for(int l=0;l<6;l++)
fus[d][c][p][k]->SetParameter(l,fu[d][c][p]->GetParameter(l));
fus[d][c][p][k]->Draw("same");
}
}//peaks
//res[d*4+c] = 2.35*fu[d][c][1]->GetParameter(4)*(1332.492-1173.228)/(fu[d][c][1]->GetParameter(3)-fu[d][c][0]->GetParameter(3));
slope[d*4+c] = (1332.492-1173.228)/(fu[d][c][1]->GetParameter(3)-fu[d][c][0]->GetParameter(3));
offset[d*4+c] = (1332.492+1173.228)-slope[d*4+c]*(fu[d][c][1]->GetParameter(3)+fu[d][c][0]->GetParameter(3));
offset[d*4+c]*=0.5;
//cout << fu[d][c][0]->GetParameter(3)*slope[d*4+c] + offset[d*4+c] << "\t" << fu[d][c][1]->GetParameter(3)*slope[d*4+c] + offset[d*4+c] << endl;
res[d*4+c] = fu[d][c][1]->GetParameter(2);
det[d*4+c] = d*5+c;
output->SetValue(Form("Slope.d%d.c%d",d,c),slope[d*4+c]);
output->SetValue(Form("Offset.d%d.c%d",d,c),offset[d*4+c]);
//cout << det[d*4+c] <<"\t" << res[d*4+c] << endl;
//cout << fu[d][c][0]->GetParameter(4) <<"\t" << fu[d][c][1]->GetParameter(4) << endl;
//ca->cd(1+c*4+3);
//.........这里部分代码省略.........
示例13: main
//.........这里部分代码省略.........
double meanVal[nPMT][nBinsXY][nBinsXY]; // Holds the mean of the distribution as defined by first fitting the peak
double fitMean[nPMT][nBinsXY][nBinsXY]; // Holds the mean of the low energy peak
double fitSigma[nPMT][nBinsXY][nBinsXY]; // Holds the sigma of the low energy peak
double endpoint[nPMT][nBinsXY][nBinsXY]; // Holds the endpoint
/////// First determine roughly where the low energy peak is
TSpectrum *spec;
for (int p=0; p<nPMT; p++) {
for (int i=0; i<nBinsXY; i++) {
for (int j=0; j<nBinsXY; j++) {
double r = sqrt(power(posmap.getBinCenter(j),2)+power(posmap.getBinCenter(i),2));
// Find bin with maximum content
hisxy[p][i][j]->GetXaxis()->SetRange(2,nBinHist);
maxBin[p][i][j] = hisxy[p][i][j]->GetMaximumBin();
maxCounts[p][i][j] = hisxy[p][i][j]->GetBinContent(maxBin[p][i][j]);
binCenterMax[p][i][j] = hisxy[p][i][j]->GetBinCenter(maxBin[p][i][j]);
if (r<=(50.+2*xyBinWidth))
{
spec = new TSpectrum(20);
Int_t npeaks = spec->Search(hisxy[p][i][j],1.5,"",0.5);
if (npeaks==0)
{
cout << "No peaks identified at PMT" << p << " position " << posmap.getBinCenter(i) << ", " << posmap.getBinCenter(j) << endl;
}
else
{
Float_t *xpeaks = spec->GetPositionX(); // Note that newer versions of ROOT return a pointer to double...
TAxis *xaxis = (TAxis*)(hisxy[p][i][j]->GetXaxis());
Int_t peakBin=0;
Double_t BinSum=0.;
Double_t BinSumHold = 0.;
Int_t maxPeak=0.;
for (int pk=0;pk<npeaks;pk++) {
peakBin = xaxis->FindBin(xpeaks[pk]);
//Sum over 3 center bins of peak and compare to previos BinSum to see which peak is higher
BinSum = hisxy[p][i][j]->GetBinContent(peakBin) + hisxy[p][i][j]->GetBinContent(peakBin-1) + hisxy[p][i][j]->GetBinContent(peakBin+1);
if (BinSum>BinSumHold) {
BinSumHold=BinSum;
maxPeak=pk;
}
}
binCenterMax[p][i][j] = xpeaks[maxPeak];
}
delete spec;
}
xLow[p][i][j] = binCenterMax[p][i][j]*2./3.;
xHigh[p][i][j] = 1.5*binCenterMax[p][i][j];
}
}
}
//////// Now fit the histograms for the peak
for (int p=0; p<nPMT; p++) {
for (int i=0; i<nBinsXY; i++) {
for (int j=0; j<nBinsXY; j++) {
示例14: DrawLEDminCFD
//------------------------------------------------------------------------
void DrawLEDminCFD()
{
Int_t npeaks = 10;
Int_t sigma=10.;
Bool_t down=false;
Int_t index[20];
TCanvas *c1 = new TCanvas("c1", " LED-CFD C side",0,48,1280,951);
c1->Divide(4,3);
Char_t buf1[20];
for (Int_t i=0; i<12; i++)
{
c1->cd(i+1);
sprintf(buf1,"LEDminCFD%i",i+1);
TH1F *cfd = (TH1F*) gFile->Get(buf1);
cfd->Draw();
TSpectrum *s = new TSpectrum(2*npeaks,1);
Int_t nfound = s->Search(cfd,sigma," ",0.2);
cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
if(nfound!=0) {
Float_t *xpeak = s->GetPositionX();
TMath::Sort(nfound, xpeak, index,down);
Float_t xp = xpeak[index[0]];
Int_t xbin = cfd->GetXaxis()->FindBin(xp);
Float_t yp = cfd->GetBinContent(xbin);
cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl;
Float_t hmin=xp-3*sigma;
Float_t hmax =xp+3*sigma;
cfd->GetXaxis()->SetRange(hmin,hmax);
TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
cfd->Fit("g1","RQ");
}
}
TCanvas *c2 = new TCanvas("c2", "LED-CFD A side",0,48,1280,951);
c2->Divide(4,3);
Char_t buf1[20];
for (Int_t i=12; i<24; i++)
{
c2->cd(i+1-12);
sprintf(buf1,"LEDminCFD%i",i+1);
TH1F *cfd = (TH1F*) gFile->Get(buf1);
cfd->Draw();
TSpectrum *s = new TSpectrum(2*npeaks,1);
Int_t nfound = s->Search(cfd,sigma," ",0.2);
cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
if(nfound!=0) {
Float_t *xpeak = s->GetPositionX();
TMath::Sort(nfound, xpeak, index,down);
Float_t xp = xpeak[index[0]];
Int_t xbin = cfd->GetXaxis()->FindBin(xp);
Float_t yp = cfd->GetBinContent(xbin);
cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl;
Float_t hmin=xp-3*sigma;
Float_t hmax =xp+3*sigma;
cfd->GetXaxis()->SetRange(hmin,hmax);
TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
cfd->Fit("g1","RQ");
}
}
/*
TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
c1->Divide(2,2);
Char_t buf1[10];
for (Int_t i=0; i<4; i++)
{
c1->cd(i+1);
sprintf(buf1,"LED-CFD%i",i+1);
TH1F *cfd = (TH1F*) file->Get(buf1);
// cout<<buf1<<" "<<cfd<<endl;
// cfd->Draw();
// cfd->GetXaxis()->SetRange(0,100);
Float_t mean = cfd->GetMean();
Float_t rms = cfd->GetRMS();
Float_t hmin=mean - 3*rms;
Float_t hmax =mean + 3*rms;
cfd->GetXaxis()->SetRange(hmin-10,hmax+10);
cout<<" cfd range "<<mean<<" rms "<<rms<<" "<<hmin<<" "<<hmax<<endl;
// TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
// cfd->Fit("g1","RQ");
cfd->Draw();
}
*/
}
示例15: DrawCFDvsLED
//------------------------------------------------------------------------
void DrawCFDvsLED()
{
Int_t runNumber=1098;
Int_t npeaks = 20;
Int_t sigma=2.;
Char_t buf1[10], buf2[10];
TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
gStyle->SetOptStat(0);
c1->Divide(4,3);
for (Int_t i=0; i<12; i++)
{
c1->cd(i+1);
sprintf(buf1,"T0_C_%i_CFD",i+1);
sprintf(buf2,"CFDvsLED%i",i+1);
TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2);
//qtc_cfd->Draw();
TH1F *cfd = (TH1F*) gFile->Get(buf1);
// cfd->Draw();
TSpectrum *s = new TSpectrum(2*npeaks,1);
Int_t nfound = s->Search(cfd,sigma," ",0.05);
cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
if(nfound!=0){
Double_t max=0.0;
Double_t tabmax[2] = {0.0, 0.0};
Float_t *xpeak = s->GetPositionX();
for(Int_t k=0; k<1 ;k++)
{
Float_t xp = xpeak[k];
Int_t xbin = cfd->GetXaxis()->FindBin(xp);
Float_t yp = cfd->GetBinContent(xbin);
cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[k]<<"\typeak = "<<yp<<endl;
}
Float_t hmin=xp-10*sigma;
Float_t hmax =xp+10*sigma;
cout<<hmin<< " "<<hmax<<endl;
// cfd->GetXaxis()->SetRange(hmin,hmax);
// TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
// cfd->Fit("g1","R");
Int_t hminbin= qtc_cfd->GetXaxis()->GetFirst();
Int_t hmaxbin= qtc_cfd->GetXaxis()->GetLast();
Int_t nbins= qtc_cfd->GetXaxis()->GetNbins();
cout<<" qtc_cfd "<<hminbin<<" "<<hmaxbin<<" "<<nbins<<endl;
qtc_cfd->Draw();
/*TProfile *pr_y = qtc_cfd->ProfileX();
pr_y->SetMaximum(hmax);
pr_y->SetMinimum(hmin);
Int_t np=nbins/20;
Double_t *xx = new Double_t[np];
Double_t *yy = new Double_t[np];
Int_t ng=0;
Double_t yg=0;
for (Int_t ip=1; ip<nbins; ip++)
{
if(ip%20 != 0 ) {
if (pr_y->GetBinContent(ip) !=0)
yg +=pr_y->GetBinContent(ip);
// cout<<ng<<" "<<pr_y->GetBinContent(ip)<<" "<<yg<<endl;
ng++;}
else {
xx[ip/20] = Float_t (ip);
yy[ip/20] = yg/ng;
yg=0;
ng=0;
cout<<ip<<" "<<ip/20<<" "<< xx[ip/20]<<" "<< yy[ip/20]<<endl;
}
}
TH2F *hr = new TH2F("hr"," ",np,0,nbins, np, hmin, hmax);
hr->Draw();
TGraph *gr = new TGraph(np,xx,yy);
gr->SetMinimum(hmin);
gr->SetMaximum(hmax);
gr->Draw("P");
delete [] xx;
delete [] yy;
// pr_y->Rebin(10);
// pr_y->Draw();
*/
}
}
}