]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONStatusMap.C
PMD info on da/amore updated
[u/mrichter/AliRoot.git] / MUON / MUONStatusMap.C
index 000668517504ab7af5c00e2a0c376d650539f907..75605e423569534663a845a65dc8fb7fb716e0dc 100644 (file)
 
 /* $Id$ */
 
-/// Macro to check/test pad status and pad status map makers
+/// \ingroup macros
+/// \file MUONStatusMap.C
+/// \brief Macro to check/test pad status and pad status map makers
 ///
-// Laurent Aphecetche
+/// \author Laurent Aphecetche
 
 #if !defined(__CINT__) || defined(__MAKECINT__)
 #include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+#include "AliLog.h"
+#include "AliMpCDB.h"
+#include "AliMpDEManager.h"
+#include "AliMUONCDB.h"
 #include "AliMUONCalibrationData.h"
 #include "AliMUONPadStatusMaker.h"
 #include "AliMUONPadStatusMapMaker.h"
+#include "AliMUONRecoParam.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVStore.h"
-#include "AliMpCDB.h"
 #include "AliMpConstants.h"
 #include "AliMpDDLStore.h"
 #include "AliMpDetElement.h"
-#include "AliMpIntPair.h"
 #include "AliMpManuIterator.h"
 #include "Riostream.h"
+#include "TAxis.h"
+#include "TCanvas.h"
+#include "TLegend.h"
+#include "TFile.h"
+#include "TGraph.h"
+#include "TBox.h"
+#include "TH2F.h"
+#include "TStyle.h"
+#include "TText.h"
+#include <vector>
 #endif
 
-void FindBad(AliMUONPadStatusMaker& statusMaker, Int_t mask, Int_t& nBadPads, Int_t& nPads)
+namespace
+{
+  Int_t NTOTALNUMBEROFPADS(1064008);
+}
+
+//______________________________________________________________________________
+void ReadIntegers(const char* filename, std::vector<int>& integers)
 {
+  /// Read integers from filename, where integers are either
+  /// separated by "," or by return carriage
+  ifstream in(gSystem->ExpandPathName(filename));
+  int i;
+  
+  char line[10000];
+  
+  in.getline(line,10000,'\n');
+  
+  TString sline(line);
+  
+  if (sline.Contains(","))
+  {
+    TObjArray* a = sline.Tokenize(",");
+    TIter next(a);
+    TObjString* s;
+    while ( ( s = static_cast<TObjString*>(next()) ) )
+    {
+      integers.push_back(s->String().Atoi());
+    }
+  }
+  else
+  {
+    integers.push_back(sline.Atoi());
+    
+    while ( in >> i )
+    {
+      integers.push_back(i);
+    }
+  }
+  
+  std::sort(integers.begin(),integers.end());
+}
+
+
+//______________________________________________________________________________
+void MUONStatusMap(AliMUONVStore*& vstatus,
+                   AliMUONVStore*& vstatusMap,
+                   const char* cdbStorage = "alien://folder=/alice/data/2011/OCDB",
+                   Int_t runNumber=145292)
+{  
+
+  AliCDBManager::Instance()->SetDefaultStorage(cdbStorage);
+  AliCDBManager::Instance()->SetRun(runNumber);
+  
+  AliMUONCDB::LoadMapping();
+  
+  AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
+  
+  AliMUONCalibrationData cd(runNumber);
+  
+  AliMUONPadStatusMaker statusMaker(cd);
+  
+  statusMaker.SetLimits(*recoParam);
+  
+  UInt_t mask = recoParam->PadGoodnessMask();
+
+  statusMaker.Report(mask);
+  
+  vstatus = static_cast<AliMUONVStore*>(statusMaker.StatusStore()->Clone());
+  
+  const Bool_t deferredInitialization = kFALSE;
+  
+  AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
+    
+  vstatusMap = static_cast<AliMUONVStore*>(statusMapMaker.StatusMap()->Clone());
+}
+
+//______________________________________________________________________________
+Int_t GetBadChannels(Int_t runNumber,
+                     Int_t& nbadped,
+                     Int_t& nbadhv,
+                     Int_t& nbadgain,
+                     Int_t& nbadocc,
+                     Int_t& nmissing,
+                     Int_t& nreco,
+                     Int_t chamber=-1)
+{
+  if (!AliCDBManager::Instance()->IsDefaultStorageSet())
+  {
+//    AliCDBManager::Instance()->SetDefaultStorage("alien://folder=/alice/data/2011/OCDB?cacheFold=/local/cdb");
+    AliCDBManager::Instance()->SetDefaultStorage("raw://");
+  }
+  
+  AliCDBManager::Instance()->SetRun(runNumber);
+  
+  AliMpCDB::LoadDDLStore();
+  
+  AliMUONCalibrationData cd(runNumber,true);
+  
+  AliMUONPadStatusMaker statusMaker(cd);
+  
+  AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
+
+  statusMaker.SetLimits(*recoParam);
+  
   AliMpManuIterator it;
+  Int_t detElemId, manuId;
   
-  nBadPads = nPads = 0;
+  Int_t pedCheck = ( 
+                     AliMUONPadStatusMaker::kPedMeanZero |
+                     AliMUONPadStatusMaker::kPedMeanTooLow |
+                     AliMUONPadStatusMaker::kPedMeanTooHigh |
+                     AliMUONPadStatusMaker::kPedSigmaTooLow |
+                     AliMUONPadStatusMaker::kPedSigmaTooHigh );
+     
+  Int_t hvCheck = ( 
+                   AliMUONPadStatusMaker::kHVError |
+                   AliMUONPadStatusMaker::kHVTooLow |
+                   AliMUONPadStatusMaker::kHVTooHigh |
+                   AliMUONPadStatusMaker::kHVChannelOFF |
+                   AliMUONPadStatusMaker::kHVSwitchOFF );
+
   
-  Int_t detElemId;
-  Int_t manuId;
+  Int_t occCheck = (
+                    AliMUONPadStatusMaker::kManuOccupancyTooHigh 
+                   );
+                    
+  Int_t ntotal(0);
+  Int_t nbad(0);
+  nbadped=0;
+  nbadocc=0;
+  nbadgain=0;
+  nbadhv=0;
+  nmissing=0;
+  nreco=0;
   
   while ( it.Next(detElemId,manuId) )
   {
-    Bool_t bad(kFALSE);
-    
     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
     
-    Int_t nb(0);
-    Int_t n(0);
-
-    for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
+    if ( chamber >= 0 && AliMpDEManager::GetChamberId(detElemId) != chamber ) continue;
+    
+    for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
     {
-      if ( de->IsConnectedChannel(manuId,i) )
+      if ( de->IsConnectedChannel(manuId,manuChannel) )
       {
-        ++n;
-        ++nPads;
-        Int_t status = statusMaker.PadStatus(detElemId,manuId,i);
-        if ( ( status & mask) || (!mask && status) )
+        ++ntotal;
+        
+        UInt_t status = statusMaker.PadStatus(detElemId, manuId, manuChannel);
+        
+        if (!status) continue;
+        
+        bool bad(false);
+        
+        if ( status & AliMUONPadStatusMaker::BuildStatus(pedCheck,0,0,0) ) 
         {
-          bad = kTRUE;
-          ++nBadPads;
-          ++nb;
+          ++nbadped;
+          bad=true;
         }
+        
+        if ( status & AliMUONPadStatusMaker::BuildStatus(0,hvCheck,0,0) ) 
+        {
+          ++nbadhv;
+          bad=true;
+        }
+        
+        if ( status & AliMUONPadStatusMaker::BuildStatus(0,0,0,occCheck) ) 
+        {
+          ++nbadocc;
+          bad=true;
+        }
+        
+        if ( status & recoParam->PadGoodnessMask() ) 
+        {
+          ++nreco;
+        }
+        
+        if ( status & AliMUONPadStatusMaker::BuildStatus(AliMUONPadStatusMaker::kMissing,0,0,AliMUONPadStatusMaker::kMissing) )
+        {
+          bad=true;
+          ++nmissing;
+        }
+        
+        if (bad) ++nbad;
       }
     }
-    
-    if (bad)
+  }
+  
+  if ( chamber<0 && ntotal!=NTOTALNUMBEROFPADS)
+  {
+    cerr << Form("ERROR ! NOT THE EXPECTED NUMBER OF CHANNELS (%d vs 1064008) FOR RUN %09d",
+                 ntotal,runNumber) << endl;
+  }
+  else
+  {
+    cout << Form("Chamber %d - %d channels",chamber,ntotal) << endl;
+    cout << Form("nbadped %5d nbadhv %5d nbadgain %5d nbadocc %5d nmissing %5d nreco %5d",
+                 nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco) << endl;
+  }
+  
+  AliCDBManager::Instance()->ClearCache(); 
+  return nbad;
+}
+
+//______________________________________________________________________________
+void Draw(TFile* f, const char* gname, TLegend* l, Bool_t normalized)
+{
+  if (!f) return;
+  
+  TGraph* g = static_cast<TGraph*>(f->Get(gname));
+  
+  if (!g) return;
+  
+  if ( normalized ) 
+  {
+    g = static_cast<TGraph*>(g->Clone());
+    for ( Int_t i = 0; i < g->GetN(); ++i ) 
     {
-      cout << Form("DE %4d ManuId %4d %2d bad pads over %2d pads",
-                   detElemId,manuId,nb,n) << endl;
+      Double_t y = g->GetY()[i];
+      g->SetPoint(i,g->GetX()[i],y/NTOTALNUMBEROFPADS);
     }
   }
+  
+  g->Draw("lp");
+  g->GetXaxis()->SetNdivisions(505);
+  g->GetXaxis()->SetNoExponent();
+  
+  if (l) l->AddEntry(g,gname,"LP");
 }
 
-AliMUONVStore* MUONStatusMap(const TString& cdbStorage = "local://$ALICE_ROOT",
-                             Int_t runNumber=0, Bool_t statusOnly=kFALSE, 
-                             Int_t mask=0x8080)
-{  
-  AliCDBManager::Instance()->SetDefaultStorage(cdbStorage.Data());
-  AliCDBManager::Instance()->SetRun(runNumber);
+//______________________________________________________________________________
+void DrawPeriod(double run1, double run2, double ymin, double ymax, const char* label)
+{
+  TBox* b = new TBox(run1,ymin,run2,ymax);
+  b->SetFillColor(5);
+  b->Draw();
+  TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
+  text->SetTextAlign(22);
+  text->SetTextSize(0.02);
+  text->Draw();
+}
 
-  AliMpCDB::LoadDDLStore();
+//______________________________________________________________________________
+void DrawEvolution(const char* file, bool normalized=true)
+{
+
+  TFile* f = TFile::Open(gSystem->ExpandPathName(file));
   
-  AliMUONCalibrationData cd(runNumber);
+  if (!f) return;
   
-  AliMUONPadStatusMaker statusMaker(cd);
+  TCanvas* c = new TCanvas("mch-status-evolution","mch-status-evolution");
+  
+  c->SetGridy();
+  c->SetTicky();
+  
+  c->Draw();
+  
+  TLegend* l = new TLegend(0.1,0.7,0.3,0.95,"ch evolution");
+
+  TGraph* g = static_cast<TGraph*>(f->Get("nbad"));
+  if (!g) return;
+  
+  int runmin = TMath::Nint(g->GetX()[0]);
+  int runmax = TMath::Nint(g->GetX()[g->GetN()-1]);
+  
+  cout << Form("Run range found in file %s = %d - %d",file,runmin,runmax) << endl;
+  
+  double ymax(0.4);
+  
+  TH2* h = new TH2F("hframe","hframe;Run number;Fraction of dead channels",100,runmin-200,runmax+200,100,0,ymax);
+
+  gStyle->SetOptStat(kFALSE);
+  h->Draw();
+  h->GetXaxis()->SetNoExponent();
+  h->GetXaxis()->SetNdivisions(505);
+
+  gStyle->SetOptTitle(kFALSE);
+
+  DrawPeriod(115881,117222,0,ymax,"10b"); 
+
+  DrawPeriod(119159,120824,0,ymax,"10c");
+
+  DrawPeriod(122374,126424,0,ymax,"10d");
+
+  DrawPeriod(127724,130850,0,ymax,"10e");
+
+  DrawPeriod(133005,134929,0,ymax,"10f");
+
+  DrawPeriod(135658,136376,0,ymax,"10g");
+
+  DrawPeriod(137133,139513,0,ymax,"10h");
+  
+  DrawPeriod(143856,146860,0,ymax,"11a");
+
+  DrawPeriod(148370,150702,0,ymax,"11b");
+
+  DrawPeriod(151566,154583,0,ymax,"11c");
+
+  DrawPeriod(158084,159606,0,ymax,"11d");
+
+  DrawPeriod(160677,162717,0,ymax,"11e");
+
+  DrawPeriod(162933,165744,0,ymax,"11f");
+
+  DrawPeriod(167703,170593,0,ymax,"11h");
+
+  // 2012
+    
+    DrawPeriod(176661,177295,0,ymax,"12a");
+
+    DrawPeriod(177384,178053,0,ymax,"12b");
+
+    DrawPeriod(179603,180569,0,ymax,"12c");
+
+    DrawPeriod(183913,186320,0,ymax,"12d");
+    
+    DrawPeriod(186365,186602,0,ymax,"12e");
+    
+    DrawPeriod(186668,188123,0,ymax,"12f");
+    
+    DrawPeriod(188362,188503,0,ymax,"12g");
+    
+    DrawPeriod(189122,190110,0,ymax,"12h");
+  
+  // 2013
+  
+  DrawPeriod(195344,195483,0,ymax,"LHC13b");
+  DrawPeriod(195529,195677,0,ymax,"LHC13c");
+  DrawPeriod(195681,195873,0,ymax,"LHC13d");
+  DrawPeriod(195949,196311,0,ymax,"LHC13e");
+  DrawPeriod(196433,197388,0,ymax,"LHC13f");
   
-//  statusMaker.SetPedMeanLimits(50,200);
-//  statusMaker.SetPedSigmaLimits(0.5,2);
+  Draw(f,"nbad",l,normalized);
+  Draw(f,"nbadped",l,normalized);
+  Draw(f,"nbadocc",l,normalized);
+  Draw(f,"nbadhv",l,normalized);
+  Draw(f,"nmissing",l,normalized);
+  Draw(f,"nreco",l,normalized);
   
-  Int_t nbad;
-  Int_t ntotal;
+  h->Draw("same");
+
+  c->RedrawAxis("g");
+  
+  l->Draw();
+}
+
+//______________________________________________________________________________
+void MUONStatusMapEvolution(const char* runlist, const char* outfile)
+{
+  // Compute the number of bad pads (because of bad ped, bad hv, bad occupancy
+  // or missing in configuration)
+  //
+  // output a root file with the different graphs.
+  //
+  // output can be then plotted using the DrawEvolution function
+  //
+  // Note that the output of different runlists can then be merged simply using
+  // the hadd program, and so then the DrawEvolution can be used over
+  // a huge period, e.g. a full year, while this method is better restricted
+  // to a period or even less (depending on your success of accessing the OCDB)
+  //
   
-  FindBad(statusMaker,mask,nbad,ntotal);
+  std::vector<int> runs;
 
-  if (ntotal<=0) 
+  ReadIntegers(runlist,runs);
+  
+  if ( runs.empty() ) 
   {
-    cout << "Error : got no pad at all ?!" << endl;
-    return 0x0;
-  }  
+    cout << "No runs to process..." << endl;
+    return;    
+  }
   
-  cout << Form("Nbad = %6d over %6d pads (%7.2f %%)",
-               nbad,ntotal,100.0*nbad/ntotal) << endl;
+  int year(2013);
   
-  if ( statusOnly ) return statusMaker.StatusStore();
+  if ( runs[0] <= 139699 ) year=2010;
   
-  const Bool_t deferredInitialization = kFALSE;
+  if ( runs[0] <= 176000 ) year=2011;
   
-  AliMUONPadStatusMapMaker statusMapMaker(cd,mask,deferredInitialization);
+  if ( runs[0] <= 195344 ) year = 2012;
+      
+  AliCDBManager::Instance()->SetDefaultStorage(Form("alien://folder=/alice/data/%d/OCDB?cacheFold=/local/cdb",year));
+
+//  AliCDBManager::Instance()->SetDefaultStorage("local:///Users/laurent/Alice/OCDBcopy2013");
+//
+  TList glist;
+  
+  glist.SetOwner(kTRUE);
+  
+  TGraph* gnbad = new TGraph(runs.size());
+  gnbad->SetName("nbad");
+  glist.Add(gnbad);
+  
+  TGraph* gnbadped = new TGraph(runs.size());
+  gnbadped->SetName("nbadped");
+  glist.Add(gnbadped);
+  
+  TGraph* gnbadocc = new TGraph(runs.size());
+  gnbadocc->SetName("nbadocc");
+  glist.Add(gnbadocc);
+  
+  TGraph* gnbadhv = new TGraph(runs.size());
+  gnbadhv->SetName("nbadhv");
+  glist.Add(gnbadhv);
+  
+  TGraph* gnmissing = new TGraph(runs.size());
+  gnmissing->SetName("nmissing");
+  glist.Add(gnmissing);
+
+  TGraph* gnreco = new TGraph(runs.size());
+  gnreco->SetName("nreco");
+  glist.Add(gnreco);
+  
+  for ( std::vector<int>::size_type i = 0; i < runs.size(); ++i ) 
+  {
+    Int_t runNumber = runs[i];
+    Int_t nbadped;
+    Int_t nbadhv;
+    Int_t nbadgain;
+    Int_t nbadocc;
+    Int_t nmissing;
+    Int_t nreco;
+    
+    Int_t nbad = GetBadChannels(runNumber,nbadped,nbadhv,nbadgain,nbadocc,nmissing,nreco);
     
-  return statusMapMaker.StatusMap();
+    gnbad->SetPoint(i,runNumber,nbad);
+    gnbadped->SetPoint(i,runNumber,nbadped);
+    gnbadhv->SetPoint(i,runNumber,nbadhv);
+    gnbadocc->SetPoint(i,runNumber,nbadocc);
+    gnmissing->SetPoint(i,runNumber,nmissing);
+    gnreco->SetPoint(i,runNumber,nreco);
+  }
+  
+  TIter next(&glist);
+  TGraph* g;
+  Int_t index(0);
+
+  TFile f(outfile,"recreate");
+  Int_t  color[] = {  1 ,  2 ,  3 ,  4,  6, 8 };
+  Int_t marker[] = { 28 , 24 , 23 , 26, 30, 5 };
+
+  while ( ( g = static_cast<TGraph*>(next() ) ) )
+  {
+    g->GetXaxis()->SetNdivisions(505);
+    g->GetXaxis()->SetNoExponent();
+    g->SetMinimum(0);
+    g->GetYaxis()->SetNoExponent();
+    g->SetLineColor(color[index]);
+    g->SetMarkerStyle(marker[index]);
+    g->SetMarkerColor(color[index]);
+    g->SetMarkerSize(1.0);
+    ++index;
+    g->Write();
+  }
+    
+  f.Close();
+  
+  
 }