- //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()->Remove(fHref[iSM]);
- 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) ;
- }
-
- hdata->Paint() ;
-
- // if channels used for average recalculation smaller than the threshold,
- // then too much noise channels or channels didn't work
- if(ratio<= kThreshold && flag >0){
- //fText->SetFillColor(2);
- fHref[iSM]->SetLineColor(2);
- fHref[iSM]->SetLineWidth(2);
- fText->SetFillColor(2);
- fText->AddText(Form("SM %d: NOK = %2.0f %% channels OK!!!",iSM,ratio));
- //fText[iSM]->AddText(Form("SM %d NOT OK, only %5.2f %% works!!!",iSM,flag/nTower));
- }
- else if (flag == -1 || flag == 0 ) { //fitting failed or recalculation didn't call
- fText->SetFillColor(2);
- fHref[iSM]->SetLineColor(2);
- fHref[iSM]->SetLineWidth(2);
- fText->SetFillColor(2);
- fText->AddText(Form("SM %d: NOK Fitting failed",iSM,ratio));
- //fText[iSM]->AddText(Form("SM %d has %5.2f %% towers wok normally",iSM,flag/nTower));
- }