]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPedestal.cxx
Coverity fix
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestal.cxx
index bfa5d2915bdf331770984022f304c21103743e00..b8453640326629f923dadcacd2b820f8aaf89a93 100644 (file)
@@ -27,6 +27,7 @@
 #include <TTree.h>
 #include <TFile.h>
 #include <TH1F.h>
+#include <THashList.h>
 #include <Riostream.h>
 
 #include <sstream>
@@ -50,6 +51,9 @@ ClassImp(AliMUONPedestal)
 AliMUONPedestal::AliMUONPedestal()
 : TObject(),
 //fN(0),
+fNCurrentEvents(0),
+fNEvthreshold(0),
+fSorting(0),
 fNEvents(0),
 fRunNumber(0),
 fNChannel(0),
@@ -96,25 +100,11 @@ void AliMUONPedestal::LoadConfig(const char* dbfile)
   Int_t busPatchId;
 
   ifstream filein(dbfile,ios::in);
-
-  // check if the 1st caracter of the 1st line is # (Config read from the OCDB => OffLine)
-  string line; 
-  getline(filein, line, '\n');
-  cout << " line 1: " << line ;
-  if ( int(line[0]) == 35 )  // ascii code of # character
-    {
-      cout << " ==>  1st caracter = " << line[0] << " (ascii code =" << int(line[0]) << ")" << endl;    
-    }
-  else  
-    { filein.clear();  filein.seekg(0);  // rewind
-      cout << " ==> rewind configuration file: "<< dbfile << endl;           
-    } 
   
   while (!filein.eof())
     { 
       filein >> busPatchId >> manuId;
 
-      AliMUONErrorCounter* manuCounter;
       AliMUONVCalibParam* ped = 
        static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
 
@@ -124,10 +114,10 @@ void AliMUONPedestal::LoadConfig(const char* dbfile)
   ped = new AliMUONCalibParamND(2, AliMpConstants::ManuNofChannels(),busPatchId, manuId, -1.); // put default wise -1, not connected channel
        fPedestalStore ->Add(ped);  
 
-       if (!(manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId))))
+        if ( ! fManuBuspatchTable->FindObject(busPatchId,manuId) )
          {
            // New (buspatch,manu)
-           manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
+           AliMUONErrorCounter* manuCounter = new AliMUONErrorCounter(busPatchId,manuId);
            fManuBuspatchTable->Add(manuCounter);
          }
       }
@@ -136,6 +126,7 @@ void AliMUONPedestal::LoadConfig(const char* dbfile)
 //______________________________________________________________________________
 void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, Int_t charge)
 {
+  static Int_t warn=0;
   /// Compute pedestals values
   AliMUONVCalibParam* ped = 
     static_cast<AliMUONVCalibParam*>(fPedestalStore ->FindObject(busPatchId, manuId));
@@ -146,7 +137,10 @@ void AliMUONPedestal::MakePed(Int_t busPatchId, Int_t manuId, Int_t channelId, I
        {  // Fill out_of_config (buspatch,manu) table
          if (!(static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
            fManuBPoutofconfigTable->Add(new AliMUONErrorCounter(busPatchId,manuId));
-         cout << " !!! WARNING  : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
+         if(warn<10) cout << " !!! WARNING  : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl;
+         else if(warn==10) cout << " !!! see .log file for an exhaustive list of (busPatchId, manuId) out of Detector configuration \n" << endl; 
+          warn++;
+          (*fFilcout) << " !!! WARNING  : busPatchId = " << busPatchId << " manuId = " << manuId << " not in the Detector configuration " << endl; 
        }
       else {fNManu++;}
       fNChannel+=64;
@@ -189,6 +183,7 @@ void AliMUONPedestal::Finalize()
   
   Double_t pedMean;
   Double_t pedSigma;
+  Double_t pedSigmalimit=0.5;
   Int_t busPatchId;
   Int_t manuId;
   Int_t channelId;
@@ -196,8 +191,8 @@ void AliMUONPedestal::Finalize()
   // print in logfile
   if (fErrorBuspatchTable->GetSize())
     {
-      cout<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
-      (*fFilcout)<<"\n* Buspatches with less statistics (due to parity errors)"<<endl;
+      cout<<"\nWarning: Buspatches with less statistics (due to parity errors)"<<endl;
+      (*fFilcout)<<"\nWarning: Buspatches with less statistics (due to parity errors)"<<endl;
       TIter nextParityError(fErrorBuspatchTable->CreateIterator());
       AliMUONErrorCounter* parityerror;
       while((parityerror = static_cast<AliMUONErrorCounter*>(nextParityError())))
@@ -207,6 +202,8 @@ void AliMUONPedestal::Finalize()
        }
     }
 
+  Int_t nADC4090=0;
+  Int_t nADCmax=0;
   // iterator over pedestal
   TIter next(fPedestalStore ->CreateIterator());
   AliMUONVCalibParam* ped;
@@ -217,8 +214,8 @@ void AliMUONPedestal::Finalize()
       manuId                  = ped->ID1();
       if(manuId==0)
        {
-         cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << endl;
-         (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << endl;
+         cout << "Warning: ManuId = " << manuId << " !!! in  BP = " << busPatchId << endl;
+         (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in  BP = " << busPatchId << endl;
        }
       Int_t eventCounter;
       // Correct the number of events for buspatch with errors
@@ -231,7 +228,6 @@ void AliMUONPedestal::Finalize()
        {
          eventCounter = fNEvents;
        }
-
       Int_t occupancy=0; // channel missing in raw data or read but rejected (case of parity error)
       // value of (buspatch, manu) occupancy
       AliMUONErrorCounter* manuCounter;
@@ -239,39 +235,45 @@ void AliMUONPedestal::Finalize()
       if(eventCounter>0)occupancy = manuCounter->Events()/64/eventCounter;
       if(occupancy>1)
        {
-         cout << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
-         (*fFilcout) << " !!! BIG WARNING: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
+         cout << "Warning: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy << endl;
+         (*fFilcout) << "Warning: ManuId = " << manuId << " !!! in  BP = " << busPatchId << " occupancy (>1) = " << occupancy <<endl;
        }
 
       for (channelId = 0; channelId < ped->Size() ; ++channelId) 
        {
-         pedMean  = ped->ValueAsDouble(channelId, 0);
+         pedMean  = ped->ValueAsDouble(channelId, 0);
 
-         if (pedMean > 0) // connected channels
+         if (pedMean >= 0) // connected channels
            {
              ped->SetValueAsDouble(channelId, 0, pedMean/(Double_t)eventCounter);
              pedMean  = ped->ValueAsDouble(channelId, 0);
              pedSigma = ped->ValueAsDouble(channelId, 1);
-             ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
-             if(manuId == 0)
-               {
-                 ped->SetValueAsDouble(channelId, 0, ADCMax());
+             ped->SetValueAsDouble(channelId, 1, TMath::Sqrt(TMath::Abs(pedSigma/(Double_t)eventCounter - pedMean*pedMean)));
+
+             if(eventCounter < fNEvthreshold )
+               { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
+                 ped->SetValueAsDouble(channelId, 1, ADCMax());}
+             if( ped->ValueAsDouble(channelId, 1) < pedSigmalimit )
+               { nADC4090++; ped->SetValueAsDouble(channelId, 0, ADCMax()-5);
+                 ped->SetValueAsDouble(channelId, 1, ADCMax()-5);}
+             if(manuId == 0 || occupancy>1)
+               { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
                  ped->SetValueAsDouble(channelId, 1, ADCMax());
-               }
-             if(occupancy>1)
-               {
-                 ped->SetValueAsDouble(channelId, 0, ADCMax());
-                 ped->SetValueAsDouble(channelId, 1, ADCMax());
-                 if(channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);
-               }
+                 if(occupancy>1 && channelId==0)ped->SetValueAsDouble(channelId, 0, ADCMax()+occupancy);}
            }
          else
-           {
-             ped->SetValueAsDouble(channelId, 0, ADCMax());
-             ped->SetValueAsDouble(channelId, 1, ADCMax());
-           }
+           { nADCmax++; ped->SetValueAsDouble(channelId, 0, ADCMax());
+             ped->SetValueAsDouble(channelId, 1, ADCMax());}
        }
     }
+  if(nADCmax>0)
+    { char* detail=Form("Warning: Nb of Channels with bad Pedestal (Ped=4095) = %d over %d",nADCmax,fNChannel);
+      printf("%s\n",detail);
+      (*fFilcout) <<  detail << endl; }
+  if(nADC4090>0)
+    { char* detail=Form("Warning: Nb of Channels with PedSigma<0.5 (Ped=4090) = %d over %d",nADC4090,fNChannel);
+      printf("%s\n",detail);
+      (*fFilcout) <<  detail << endl; }
 }
 //______________________________________________________________________________
 void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
@@ -281,14 +283,18 @@ void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
   out<<"//===========================================================================" << endl;
   out<<"//                 Pedestal file calculated by "<< fPrefixDA.Data() << endl;
   out<<"//===========================================================================" << endl;
-  out<<"//       * Run           : " << fRunNumber << endl; 
-  out<<"//       * Date          : " << fDate->AsString("l") <<endl;
-  out<<"//       * Statictics    : " << fNEvents << endl;
+  out<<"//     * Run           : " << fRunNumber << endl; 
+  out<<"//     * Date          : " << fDate->AsString("l") <<endl;
+  out<<"//     * Statictics    : " << fNEvents << endl;
   if(fConfig)
-    out<<"//       * # of MANUS    : " << fNManuConfig << " read in the Det. config. " << endl;
-  out<<"//       * # of MANUS    : " << fNManu << " read in raw data " << endl;
-  out<<"//       * # of MANUS    : " << fNChannel/64 << " written in pedestal file " << endl;
-  out<<"//       * # of channels : " << fNChannel << endl;
+    out<<"//     * Nb of MANUS   : " << fNManuConfig << " read in the Det. config. " << endl;
+  out<<"//     * Nb of MANUS   : " << fNManu << " read in raw data " << endl;
+  out<<"//     * Nb of MANUS   : " << fNChannel/64 << " written in pedestal file " << endl;
+  out<<"//     * Nb of channels: " << fNChannel << endl;
+  out<<"//"<<endl;
+  out<<"//     * Below " << fNEvthreshold << " events=> Ped.&sig.=4095" << endl;
+  out<<"//     * PedSigma < 0.5 => Ped.&sig.=4090" << endl;
+
   if (fErrorBuspatchTable->GetSize())
     {
       out<<"//"<<endl;
@@ -297,12 +303,12 @@ void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
       AliMUONErrorCounter* parityerror;
       while((parityerror = static_cast<AliMUONErrorCounter*>(next())))
        {
-         out<<"//      BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl;
+         if(fNEvents-parityerror->Events()>fNEvthreshold)
+           { out<<"//      BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<<endl; }
+         else
+           { out<<"//      BusPatch = "<<parityerror->BusPatch()<<"\t Nevents used = "<<fNEvents-parityerror->Events()<< " (Ped.&sig.=4095)" << endl; }
        }
     }  
-
-//   out<<"//"<<endl;
-//   out<<"//    * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;
   Int_t writitle=0;
   Int_t occupancy=1;
   if(occupancy)
@@ -320,10 +326,10 @@ void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
              writitle++;
              if(writitle==1){ 
                out<<"//"<<endl;
-               out<<"//    * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
-             occupancy=pedMean-ADCMax();
+               out<<"//    * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
+             occupancy=TMath::Nint(pedMean-ADCMax());
              ped->SetValueAsDouble(0, 0, ADCMax());
-             out<<"//      BusPatch = "<< busPatchId <<"\t ManuId =  "<< manuId << "\t occupancy = " << occupancy  <<endl;
+             out<<"//      BusPatch = "<< busPatchId <<"\t ManuId =  "<< manuId << "\t occupancy = " << occupancy  << endl;
            }
 
          if (manuId==0 || (fConfig && static_cast<AliMUONErrorCounter*>(fManuBPoutofconfigTable->FindObject(busPatchId,manuId))))
@@ -331,34 +337,56 @@ void AliMUONPedestal::MakeASCIIoutput(ostream& out) const
              writitle++;
              if(writitle==1){ 
                out<<"//"<<endl;
-               out<<"//    * Puzzling (Buspatch,Manu) read in raw data ?"<<endl;}
+               out<<"//    * Puzzling (Buspatch,Manu) read in raw data ? (Ped.&sig.=4095)"<<endl;}
              out<<"//      BusPatch = "<< busPatchId <<"\t ManuId =  "<< manuId << "\t missing in the mapping" << endl;
            }
        }
     }
-
-
   out<<"//"<<endl;
   out<<"//---------------------------------------------------------------------------" << endl;
   out<<"//---------------------------------------------------------------------------" << endl;
   out<<"//      BP     MANU     CH.      MEAN    SIGMA"<<endl;
   out<<"//---------------------------------------------------------------------------" << endl;
 
-  // iterator over pedestal
-  TIter next(fPedestalStore ->CreateIterator());
-  AliMUONVCalibParam* ped;
-  
-  while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
-    {
-      Int_t busPatchId = ped->ID0();
-      Int_t manuId = ped->ID1();
+  TIter next(fPedestalStore->CreateIterator());
+  AliMUONVCalibParam* ped;  
 
-      for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId ) 
+  // Sorting 
+  if  (fSorting)
+    {
+      cout << " ..... sorting pedestal values ....."  << endl;
+      THashList pedtable(100,2);
+      while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
+      {
+        pedtable.Add(ped);
+      }
+      pedtable.Sort();
+      //      iterator over sorted pedestal
+      TIter nextSorted(&pedtable);
+      while ( (ped = (AliMUONVCalibParam*)(nextSorted()) ) )
+      {
+        Int_t busPatchId = ped->ID0();
+        Int_t manuId = ped->ID1();
+        for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId ) 
+        {
+          Double_t pedMean  = ped->ValueAsDouble(channelId, 0);
+          Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
+          out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
+        }
+      }
+    }
+  else
+    {
+      while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
        {
-         Double_t pedMean  = ped->ValueAsDouble(channelId, 0);
-         Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
-
-         out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
+         Int_t busPatchId = ped->ID0();
+         Int_t manuId = ped->ID1();
+         for ( Int_t channelId = 0; channelId < ped->Size(); ++channelId ) 
+           {
+             Double_t pedMean  = ped->ValueAsDouble(channelId, 0);
+             Double_t pedSigma = ped->ValueAsDouble(channelId, 1);
+             out << "\t" << busPatchId << "\t" << manuId <<"\t"<< channelId << "\t" << pedMean <<"\t"<< pedSigma << endl;
+           }
        }
     }
 }
@@ -371,6 +399,7 @@ void AliMUONPedestal::MakeControlHistos()
 
   Double_t pedMean;
   Double_t pedSigma;
+  Double_t evt;
   Int_t busPatchId;
   Int_t manuId;
   Int_t channelId;
@@ -384,22 +413,16 @@ void AliMUONPedestal::MakeControlHistos()
   fHistoFileName=Form("%s.root",fPrefixDA.Data());
   histoFile = new TFile(fHistoFileName,"RECREATE","MUON Tracking pedestals");
 
-  Char_t name[255];
-  Char_t title[255];
-  sprintf(name,"pedmean_allch");
-  sprintf(title,"Pedestal mean all channels");
   Int_t nx = ADCMax()+1;
   Int_t xmin = 0;
   Int_t xmax = ADCMax(); 
-  pedMeanHisto = new TH1F(name,title,nx,xmin,xmax);
+  pedMeanHisto = new TH1F("pedmean_allch","Pedestal mean all channels",nx,xmin,xmax);
   pedMeanHisto->SetDirectory(histoFile);
 
-  sprintf(name,"pedsigma_allch");
-  sprintf(title,"Pedestal sigma all channels");
   nx = 201;
   xmin = 0;
   xmax = 200; 
-  pedSigmaHisto = new TH1F(name,title,nx,xmin,xmax);
+  pedSigmaHisto = new TH1F("pedsigma_allch","Pedestal sigma all channels",nx,xmin,xmax);
   pedSigmaHisto->SetDirectory(histoFile);
 
   tree = new TTree("t","Pedestal tree");
@@ -408,10 +431,12 @@ void AliMUONPedestal::MakeControlHistos()
   tree->Branch("channel",&channelId,",channel/I");
   tree->Branch("pedMean",&pedMean,",pedMean/D");
   tree->Branch("pedSigma",&pedSigma,",pedSigma/D");
+  tree->Branch("nevt",&evt,",evt/D");
 
   // iterator over pedestal
   TIter next(fPedestalStore ->CreateIterator());
   AliMUONVCalibParam* ped;
+  AliMUONErrorCounter* manuCounter;
   
   while ( ( ped = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
   {
@@ -422,6 +447,8 @@ void AliMUONPedestal::MakeControlHistos()
     {
       pedMean  = ped->ValueAsDouble(channelId, 0);
       pedSigma = ped->ValueAsDouble(channelId, 1);
+      manuCounter = static_cast<AliMUONErrorCounter*>(fManuBuspatchTable->FindObject(busPatchId,manuId));
+      evt = manuCounter->Events()/64;
           
       pedMeanHisto->Fill(pedMean);
       pedSigmaHisto->Fill(pedSigma);