-
- //Double_t size = 0.24 ;
- //fText[iSM] = new TPaveText(0.1+size*iSM,0.7,size*(iSM+1),0.9,"NDC");
- for(Int_t iTower = iSM*nTower ; iTower<(iSM+1)*nTower ; iTower++){
- proj->Fill(hdata->GetBinContent(iTower)-aver);
- }
- proj->Fit("gaus","","QNO");
- mean=proj->GetFunction("gaus")->GetParameter(1);
- width=proj->GetFunction("gaus")->GetParameter(2);
- AliInfo(Form("aver = %f, mean = %f, sigma =%f\n",aver,mean, width));
- //if mean or sigma is too huge from the fitting, fitting failed
- if(aver < 0 || width/aver >2.) flag = -1 ;
- else { //recalculate the average if the fitting didn't give the initial average
- aver+=mean;
- init=TMath::Abs(mean/aver);
- while(init>0.01){
- if(flag) flag = 0 ;
- for(Int_t iTower = iSM*nTower ; iTower < (iSM+1)*nTower ; iTower++){
- if(hdata->GetBinContent(iTower)>(aver-width) && hdata->GetBinContent(iTower)<(aver+width)){
- flag++ ;
- recal += hdata->GetBinContent(iTower);
- }
- }
- recal/=flag;
- aver =(aver+recal)/2 ;
- init=(aver-recal)/(aver+recal) ;
- } //recalculate the average
- if(flag)ratio=100.0*flag/nTower ; //counting how many towers used for average recalculation
- rv+=TMath::Abs((aver-recal)/(aver+recal)) ;
- AliInfo(Form("SM %d has %2.2f %% chanhel works \n", iSM, ratio));
- }
- fHref[iSM] = dynamic_cast<TLine*>(hdata->GetListOfFunctions()->FindObject(fHref[iSM]));
- if(!fHref[iSM]) {
- fHref[iSM] = new TLine(iSM*nTower,aver,(iSM+1)*nTower,aver);
- hdata->GetListOfFunctions()->Add(fHref[iSM]);
- list[specie]->AddAt(hdata, kTowerHG) ;
- }
- else {
- fHref[iSM]->Clear() ;
- fHref[iSM]->SetX1(iSM*nTower) ;
- fHref[iSM]->SetY1(aver) ;
- fHref[iSM]->SetX2((iSM+1)*nTower) ;
- fHref[iSM]->SetY2(aver) ;
- }
+ //filling the histogram with the difference and fitting with gaus function to obtain mean and sigma
+ for(Int_t iTower = iSM*nTower ; iTower<(iSM+1)*nTower ; iTower++){
+ proj->Fill(hdata->GetBinContent(iTower)-aver);
+ }
+ proj->Fit("gaus","","QNO");
+ mean=proj->GetFunction("gaus")->GetParameter(1); // ! mean should be peaked at 0 in principal
+ width=proj->GetFunction("gaus")->GetParameter(2);
+ AliInfo(Form("aver = %f, mean = %f, sigma =%f\n",aver,mean, width));
+
+ if(aver) init=TMath::Abs(mean/aver); //calculate the divation from the average
+
+ //if mean or sigma is too huge or the sigma is too small, the fitting failed
+ if((aver+mean) < 1. || width/aver >2. || width < 1.e-3)
+ flag = -1 ;
+ else { //recalculate the average if the fitting didn't give the initial average
+ aver+=mean; //average corrected after fitting is fitting works
+ //if(aver <= 1. ) break ;
+ // if divation is too large, we conside to recalate the average by excluding channels too far from the average
+ while(init>0.01 && aver >= 1.){
+ if(flag) flag = 0 ; //for each time recalculation, reset flag
+ for(Int_t iTower = iSM*nTower ; iTower < (iSM+1)*nTower ; iTower++){
+ if(hdata->GetBinContent(iTower)>(aver-width) && hdata->GetBinContent(iTower)<(aver+width)){
+ flag++ ;
+ recal += hdata->GetBinContent(iTower);
+ }
+ } //end of channels loop
+
+ if(flag == 0 || recal < 1.) {
+ flag = -1 ;
+ break ;
+ }
+ else {
+ recal/=flag ;
+ init=(aver-recal)/(aver+recal) ; //difference between the new average and the pervious one
+ aver =(aver+recal)/2 ; //recalculate the average by the last two values
+ }
+ } //out of while condition
+
+ ratio=100.0*flag/nTower ; //counting how many towers used for average recalculation
+ AliInfo(Form("SM %d has %2.2f %% chanhel works \n", iSM, ratio));
+ } // end of recalculation
+
+ rv+=init ; //define the deviation from the final average
+
+ //define the average line on each SM
+ fHref[iSM] = dynamic_cast<TLine*>(hdata->GetListOfFunctions()->FindObject(fHref[iSM]));
+ if(!fHref[iSM]) {
+ fHref[iSM] = new TLine(iSM*nTower,aver,(iSM+1)*nTower,aver);
+ hdata->GetListOfFunctions()->Add(fHref[iSM]);
+ list[specie]->AddAt(hdata, kTowerHG) ;
+ }
+ else {
+ fHref[iSM]->Clear() ;
+ fHref[iSM]->SetX1(iSM*nTower) ;
+ fHref[iSM]->SetY1(aver) ;
+ fHref[iSM]->SetX2((iSM+1)*nTower) ;
+ fHref[iSM]->SetY2(aver) ;
+ }
+