+//______________________________________________________________________
+void AliTRDCalibraFit::RemoveOutliers(Int_t type, Bool_t perdetector){
+ //
+ // Remove the results too far from the mean value and rms
+ // type: 0 gain, 1 vdrift
+ // perdetector
+ //
+
+ Int_t loop = (Int_t) fVectorFit.GetEntriesFast();
+ if(loop != 540) {
+ AliInfo("The Vector Fit is not complete!");
+ return;
+ }
+ Int_t detector = -1;
+ Int_t sector = -1;
+ Float_t value = 0.0;
+
+ /////////////////////////////////
+ // Calculate the mean values
+ ////////////////////////////////
+ // Initialisation
+ ////////////////////////
+ Double_t meanAll = 0.0;
+ Double_t rmsAll = 0.0;
+ Int_t countAll = 0;
+ ////////////
+ // compute
+ ////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
+ sector = GetSector(detector);
+ if(perdetector){
+ value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[0];
+ if(value > 0.0) {
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+ }
+ else {
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
+ if(value > 0.0) {
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+
+ } // Col
+ } // Row
+ }
+ }
+ if(countAll > 0) {
+ meanAll = meanAll/countAll;
+ rmsAll = TMath::Sqrt(TMath::Abs(rmsAll/countAll - (meanAll*meanAll)));
+ }
+ //printf("RemoveOutliers: meanAll %f and rmsAll %f\n",meanAll,rmsAll);
+ /////////////////////////////////////////////////
+ // Remove outliers
+ ////////////////////////////////////////////////
+ Double_t defaultvalue = -1.0;
+ if(type==1) defaultvalue = -1.5;
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
+ sector = GetSector(detector);
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
+
+ // remove the results too far away
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = coef[(Int_t)(col*rowMax+row)];
+ if((value > 0.0) && (rmsAll > 0.0) && (TMath::Abs(value-meanAll) > (2*rmsAll))) {
+ coef[(Int_t)(col*rowMax+row)] = defaultvalue;
+ }
+ } // Col
+ } // Row
+ }
+}
+//______________________________________________________________________
+void AliTRDCalibraFit::RemoveOutliers2(Bool_t perdetector){
+ //
+ // Remove the results too far from the mean and rms
+ // perdetector
+ //
+
+ Int_t loop = (Int_t) fVectorFit2.GetEntriesFast();
+ if(loop != 540) {
+ AliInfo("The Vector Fit is not complete!");
+ return;
+ }
+ Int_t detector = -1;
+ Int_t sector = -1;
+ Float_t value = 0.0;
+
+ /////////////////////////////////
+ // Calculate the mean values
+ ////////////////////////////////
+ // Initialisation
+ ////////////////////////
+ Double_t meanAll = 0.0;
+ Double_t rmsAll = 0.0;
+ Int_t countAll = 0;
+ /////////////
+ // compute
+ ////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
+ sector = GetSector(detector);
+ if(perdetector){
+ value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[0];
+ if(value < 70.0) {
+ meanAll += value;
+ rmsAll += value*value;
+ countAll++;
+ }
+ }
+ else {
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
+ if(value < 70.0) {
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+ } // Col
+ } // Row
+ }
+ }
+ if(countAll > 0) {
+ meanAll = meanAll/countAll;
+ rmsAll = TMath::Sqrt(TMath::Abs(rmsAll/countAll - (meanAll*meanAll)));
+ }
+ //printf("Remove outliers 2: meanAll %f, rmsAll %f\n",meanAll,rmsAll);
+ /////////////////////////////////////////////////
+ // Remove outliers
+ ////////////////////////////////////////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
+ sector = GetSector(detector);
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ Float_t *coef = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef();
+
+ // remove the results too far away
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = coef[(Int_t)(col*rowMax+row)];
+ if((value < 70.0) && (rmsAll > 0.0) && (TMath::Abs(value-meanAll) > (2.5*rmsAll))) {
+ //printf("value outlier %f\n",value);
+ coef[(Int_t)(col*rowMax+row)] = 100.0;
+ }
+ } // Col
+ } // Row
+ }
+}
+//______________________________________________________________________
+void AliTRDCalibraFit::PutMeanValueOtherVectorFit(Int_t ofwhat, Bool_t perdetector){
+ //
+ // ofwhat is equaled to 0: mean value of all passing detectors
+ // ofwhat is equaled to 1: mean value of the detector, otherwise supermodule, otherwise all
+ //
+
+ Int_t loop = (Int_t) fVectorFit.GetEntriesFast();
+ if(loop != 540) {
+ AliInfo("The Vector Fit is not complete!");
+ return;
+ }
+ Int_t detector = -1;
+ Int_t sector = -1;
+ Float_t value = 0.0;
+
+ /////////////////////////////////
+ // Calculate the mean values
+ ////////////////////////////////
+ // Initialisation
+ ////////////////////////
+ Double_t meanAll = 0.0;
+ Double_t meanSupermodule[18];
+ Double_t meanDetector[540];
+ Double_t rmsAll = 0.0;
+ Double_t rmsSupermodule[18];
+ Double_t rmsDetector[540];
+ Int_t countAll = 0;
+ Int_t countSupermodule[18];
+ Int_t countDetector[540];
+ for(Int_t sm = 0; sm < 18; sm++){
+ rmsSupermodule[sm] = 0.0;
+ meanSupermodule[sm] = 0.0;
+ countSupermodule[sm] = 0;
+ }
+ for(Int_t det = 0; det < 540; det++){
+ rmsDetector[det] = 0.0;
+ meanDetector[det] = 0.0;
+ countDetector[det] = 0;
+ }
+ ////////////
+ // compute
+ ////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
+ sector = GetSector(detector);
+ if(perdetector){
+ value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[0];
+ if(value > 0.0) {
+ rmsDetector[detector] += value*value;
+ meanDetector[detector] += value;
+ countDetector[detector]++;
+ rmsSupermodule[sector] += value*value;
+ meanSupermodule[sector] += value;
+ countSupermodule[sector]++;
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+ }
+ else {
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
+ if(value > 0.0) {
+ rmsDetector[detector] += value*value;
+ meanDetector[detector] += value;
+ countDetector[detector]++;
+ rmsSupermodule[sector] += value*value;
+ meanSupermodule[sector] += value;
+ countSupermodule[sector]++;
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+
+ } // Col
+ } // Row
+ }
+ }
+ if(countAll > 0) {
+ meanAll = meanAll/countAll;
+ rmsAll = TMath::Abs(rmsAll/countAll - (meanAll*meanAll));
+ }
+ for(Int_t sm = 0; sm < 18; sm++){
+ if(countSupermodule[sm] > 0) {
+ meanSupermodule[sm] = meanSupermodule[sm]/countSupermodule[sm];
+ rmsSupermodule[sm] = TMath::Abs(rmsSupermodule[sm]/countSupermodule[sm] - (meanSupermodule[sm]*meanSupermodule[sm]));
+ }
+ }
+ for(Int_t det = 0; det < 540; det++){
+ if(countDetector[det] > 0) {
+ meanDetector[det] = meanDetector[det]/countDetector[det];
+ rmsDetector[det] = TMath::Abs(rmsDetector[det]/countDetector[det] - (meanDetector[det]*meanDetector[det]));
+ }
+ }
+ //printf("Put mean value, meanAll %f, rmsAll %f\n",meanAll,rmsAll);
+ ///////////////////////////////////////////////
+ // Put the mean value for the no-fitted
+ /////////////////////////////////////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
+ sector = GetSector(detector);
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ Float_t *coef = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
+
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = coef[(Int_t)(col*rowMax+row)];
+ if(value < 0.0) {
+ if((ofwhat == 0) && (meanAll > 0.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanAll);
+ if(ofwhat == 1){
+ if((meanDetector[detector] > 0.0) && (countDetector[detector] > 20)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanDetector[detector]);
+ else if((meanSupermodule[sector] > 0.0) && (countSupermodule[sector] > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanSupermodule[sector]);
+ else if((meanAll > 0.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = -TMath::Abs(meanAll);
+ }
+ }
+ // Debug
+ if(fDebugLevel > 1){
+
+ if ( !fDebugStreamer ) {
+ //debug stream
+ TDirectory *backup = gDirectory;
+ fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
+ if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
+ }
+
+ Float_t coefnow = coef[(Int_t)(col*rowMax+row)];
+
+ (* fDebugStreamer) << "PutMeanValueOtherVectorFit"<<
+ "detector="<<detector<<
+ "sector="<<sector<<
+ "row="<<row<<
+ "col="<<col<<
+ "before="<<value<<
+ "after="<<coefnow<<
+ "\n";
+ }
+ } // Col
+ } // Row
+ }
+}
+//______________________________________________________________________
+void AliTRDCalibraFit::PutMeanValueOtherVectorFit2(Int_t ofwhat, Bool_t perdetector){
+ //
+ // ofwhat is equaled to 0: mean value of all passing detectors
+ // ofwhat is equaled to 1: mean value of the detector, otherwise supermodule, otherwise all
+ //
+
+ Int_t loop = (Int_t) fVectorFit2.GetEntriesFast();
+ if(loop != 540) {
+ AliInfo("The Vector Fit is not complete!");
+ return;
+ }
+ Int_t detector = -1;
+ Int_t sector = -1;
+ Float_t value = 0.0;
+
+ /////////////////////////////////
+ // Calculate the mean values
+ ////////////////////////////////
+ // Initialisation
+ ////////////////////////
+ Double_t meanAll = 0.0;
+ Double_t rmsAll = 0.0;
+ Double_t meanSupermodule[18];
+ Double_t rmsSupermodule[18];
+ Double_t meanDetector[540];
+ Double_t rmsDetector[540];
+ Int_t countAll = 0;
+ Int_t countSupermodule[18];
+ Int_t countDetector[540];
+ for(Int_t sm = 0; sm < 18; sm++){
+ rmsSupermodule[sm] = 0.0;
+ meanSupermodule[sm] = 0.0;
+ countSupermodule[sm] = 0;
+ }
+ for(Int_t det = 0; det < 540; det++){
+ rmsDetector[det] = 0.0;
+ meanDetector[det] = 0.0;
+ countDetector[det] = 0;
+ }
+ // compute
+ ////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
+ sector = GetSector(detector);
+ if(perdetector){
+ value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[0];
+ if(value < 70.0) {
+ rmsDetector[detector] += value*value;
+ meanDetector[detector] += value;
+ countDetector[detector]++;
+ rmsSupermodule[sector] += value*value;
+ meanSupermodule[sector] += value;
+ countSupermodule[sector]++;
+ meanAll += value;
+ rmsAll += value*value;
+ countAll++;
+ }
+ }
+ else {
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
+ if(value < 70.0) {
+ rmsDetector[detector] += value*value;
+ meanDetector[detector] += value;
+ countDetector[detector]++;
+ rmsSupermodule[sector] += value*value;
+ meanSupermodule[sector] += value;
+ countSupermodule[sector]++;
+ rmsAll += value*value;
+ meanAll += value;
+ countAll++;
+ }
+
+ } // Col
+ } // Row
+ }
+ }
+ if(countAll > 0) {
+ meanAll = meanAll/countAll;
+ rmsAll = TMath::Abs(rmsAll/countAll - (meanAll*meanAll));
+ }
+ for(Int_t sm = 0; sm < 18; sm++){
+ if(countSupermodule[sm] > 0) {
+ meanSupermodule[sm] = meanSupermodule[sm]/countSupermodule[sm];
+ rmsSupermodule[sm] = TMath::Abs(rmsSupermodule[sm]/countSupermodule[sm] - (meanSupermodule[sm]*meanSupermodule[sm]));
+ }
+ }
+ for(Int_t det = 0; det < 540; det++){
+ if(countDetector[det] > 0) {
+ meanDetector[det] = meanDetector[det]/countDetector[det];
+ rmsDetector[det] = TMath::Abs(rmsDetector[det]/countDetector[det] - (meanDetector[det]*meanDetector[det]));
+ }
+ }
+ //printf("Put mean value 2: meanAll %f, rmsAll %f\n",meanAll,rmsAll);
+ ////////////////////////////////////////////
+ // Put the mean value for the no-fitted
+ /////////////////////////////////////////////
+ for (Int_t k = 0; k < loop; k++) {
+ detector = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetDetector();
+ sector = GetSector(detector);
+ Int_t rowMax = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+ Int_t colMax = fGeo->GetColMax(GetLayer(detector));
+ Float_t *coef = ((AliTRDFitInfo *) fVectorFit2.At(k))->GetCoef();
+
+ for (Int_t row = 0; row < rowMax; row++) {
+ for (Int_t col = 0; col < colMax; col++) {
+ value = coef[(Int_t)(col*rowMax+row)];
+ if(value > 70.0) {
+ if((ofwhat == 0) && (meanAll > -3.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = meanAll+100.0;
+ if(ofwhat == 1){
+ if((meanDetector[detector] > -3.0) && (countDetector[detector] > 20)) coef[(Int_t)(col*rowMax+row)] = meanDetector[detector]+100.0;
+ else if((meanSupermodule[sector] > -3.0) && (countSupermodule[sector] > 15)) coef[(Int_t)(col*rowMax+row)] = meanSupermodule[sector]+100.0;
+ else if((meanAll > -3.0) && (countAll > 15)) coef[(Int_t)(col*rowMax+row)] = meanAll+100.0;
+ }
+ }
+ // Debug
+ if(fDebugLevel > 1){
+
+ if ( !fDebugStreamer ) {
+ //debug stream
+ TDirectory *backup = gDirectory;
+ fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
+ if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
+ }
+
+ Float_t coefnow = coef[(Int_t)(col*rowMax+row)];
+
+ (* fDebugStreamer) << "PutMeanValueOtherVectorFit2"<<
+ "detector="<<detector<<
+ "sector="<<sector<<
+ "row="<<row<<
+ "col="<<col<<
+ "before="<<value<<
+ "after="<<coefnow<<
+ "\n";
+ }
+ } // Col
+ } // Row
+ }
+
+}