]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGain.cxx
coverity warnings fixed
[u/mrichter/AliRoot.git] / MUON / AliMUONGain.cxx
index 8fdeea9ca2a3ef431bd7679ce1286ca027f6fec5..4f821f9bbe5a4ce12cc53b41fbfd372ff989e0e7 100644 (file)
@@ -34,6 +34,7 @@
 #include <Riostream.h>
 
 #include <sstream>
+#include <cstdio>
 
 #define  NFITPARAMS 4
 
@@ -232,7 +233,6 @@ TString AliMUONGain::WriteGainHeader(Int_t nInit, Int_t nEntries, Int_t nbpf2, I
   if(nInit==1)
     stream<<"//  "<< nEntries <<" DAC values  fit: "<< fnbpf1 << " pts (1st order) " << nbpf2 << " pts (2nd order) DAC=0 excluded" << endl;
   stream<<"//   *  nInit = " << nInit << "  *  f1nbp = " << fnbpf1 << "  *  f2nbp = " <<  nbpf2 << endl; 
-  stream<<"//" << endl; 
 
   stream<<"//   RUN     DAC   " << endl;
   stream<<"//-----------------" << endl;
@@ -270,7 +270,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
   Double_t goodA1Max =  2.;
 //   Double_t goodA2Min = -0.5E-03;
 //   Double_t goodA2Max =  1.E-03;
-  Double_t goodA2Min = -0.5E-01; // changed 28/10/2009 (JLC) <=> no condition on a2
+  Double_t goodA2Min = -0.5E-01; // changed 28/10/2009 (JLC) <=> enlarged condition on a2
   Double_t goodA2Max =  1.E-01;
   // Table for uncalibrated  buspatches and manus
   THashList* uncalBuspatchManuTable = new THashList(1000,2);
@@ -398,12 +398,11 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
 
   //  plot out 
 
-  TFile* gainFile = 0x0;
   TTree* tg = 0x0;
   if(fPlotLevel>0)
     {
       fHistoFileName=Form("%s.root",fPrefixDA.Data());
-      gainFile = new TFile(fHistoFileName.Data(),"RECREATE","MUON Tracking gains");
+      new TFile(fHistoFileName.Data(),"RECREATE","MUON Tracking gains");
       tg = new TTree("tg","TTree avec class Manu_DiMu");
 
       tg->Branch("bp",&busPatchId, "busPatchId/I");
@@ -442,10 +441,12 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
   Double_t xp[11], xpErr[11], yp[11], ypErr[11];
 
   Int_t uncalcountertotal=0 ;
+  Int_t unparabolicfit=0;
 
   while ( ( p = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
     {
       ped[0]  = p;
+      unparabolicfit=0;
 
       busPatchId = p->ID0();
       manuId     = p->ID1();
@@ -472,7 +473,6 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
            n++;
          }
 
-
          // print_peak_mean_values
          if(fPrintLevel>1)
            {
@@ -496,15 +496,17 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
 
          Int_t fitproceed=1;
          Int_t nbpf2Dynamic=nbpf2;
+         Int_t adcLimit=4090; // when RMS < 0.5 (in other cases mean values forced to 4095, see DA_PED)
          for (Int_t j = 0; j < nbs; ++j)
            {
              Int_t k = j + fnInit;
              x[j]    = pedMean[k];
              if(x[j]<=0.){fitproceed=0; break;}
-             if(x[j]== ADCMax())
+             //              if(x[j]>= ADCMax())
+             if(x[j]>= adcLimit)
                {
                  if(j < nbs-1){fitproceed=0; break;}
-                 else  nbpf2Dynamic=nbpf2-1;
+                 else { nbpf2Dynamic=nbpf2-1; break;}
                }
              xErr[j] = pedSigma[k];
              y[j]    = injCharge[k];
@@ -541,8 +543,8 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
              a1 = par[1];
 
              // 2. - Translation : new origin (xLim, yLim) + parabolic fit over nbf2 points
-
-             if(nbpf2Dynamic > 1)
+             //checking:         if(busPatchId ==1841 && manuId==4)nbpf2Dynamic=2;
+             if(nbpf2Dynamic > 2)
                {
                  for (Int_t j = 0; j < nbpf2Dynamic; j++)
                    {
@@ -568,6 +570,13 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
                  prChi2P2 = TMath::Prob(chi2P2, nbpf2Dynamic-1);
                  a2 = par[0];
                }
+             else 
+               { 
+                 unparabolicfit++;
+                 (*fFilcout) << " Warning : BP = " << busPatchId << " Manu = " << manuId <<  " Channel = " << channelId <<": parabolic fit not possible (nbpf2=" <<  nbpf2Dynamic  << ") => a2=0 and linear fit OK" << std::endl;
+                 if(unparabolicfit==1) std::cout << " Warning : BP = " << busPatchId << " Manu = " << manuId <<  ": no parabolic fit for some channels (nbpf2=" <<  nbpf2Dynamic  << "), linear fit is OK (see .log for details)" << std::endl;
+                 a2=0. ; prChi2P2=0. ;
+               }
 
              par[0] = a0;
              par[1] = a1;
@@ -616,7 +625,7 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
              char bpmanuname[256];
              AliMUONErrorCounter* uncalcounter;
 
-             sprintf(bpmanuname,"bp%dmanu%d",busPatchId,manuId);
+             snprintf(bpmanuname,256,"bp%dmanu%d",busPatchId,manuId);
              if (!(uncalcounter = (AliMUONErrorCounter*)uncalBuspatchManuTable->FindObject(bpmanuname)))
                {
                  // New buspatch_manu name
@@ -650,14 +659,14 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
 
                      graphErr = new TGraphErrors(nEntries,pedMean,injCharge,pedSigma,injChargeErr);
 
-                     sprintf(graphName,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
+                     snprintf(graphName,256,"BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
 
                      graphErr->SetTitle(graphName);
                      graphErr->SetMarkerColor(3);
                      graphErr->SetMarkerStyle(12);
                      graphErr->Write(graphName);
 
-                     sprintf(graphName,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
+                     snprintf(graphName,256,"f2_BusPatch_%d_Manu_%d_Ch_%d",busPatchId, manuId,channelId);
                      f2Calib->SetTitle(graphName);
                      f2Calib->SetLineColor(4);
                      f2Calib->SetParameters(par);
@@ -668,16 +677,13 @@ void AliMUONGain::MakeGainStore(TString shuttleFile)
                      delete f2Calib;
                    }
                }
-
-
              tg->Fill();
            }
-
-
          pfilew << WriteGainData(busPatchId,manuId,channelId,par[1],par[2],threshold,q);
        }
       nmanu++;
-      if(nmanu % 500 == 0)std::cout << " Nb manu = " << nmanu << std::endl;
+      Int_t step=500;
+      if(nmanu % step == 0)std::cout << " Nb manu = " << nmanu << std::endl;
     }
 
   //      print in logfile