]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDCalibChamberStatus.cxx
Fix
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibChamberStatus.cxx
index 299c3800361164ba3f20f4dc5ba8907284ce5766..08ccbf581cb7eddae21426a79153b15c9c8f01b5 100644 (file)
@@ -17,7 +17,7 @@
 //                                                                        //
 // AliTRDCalibChamberStatus: to determine which half chambers are off     //
 // Produce a AliTRDCalChamberStatus calibration object                    //
-// Check with the AliTRDCalDCSFEE info                                    //
+// Check with the AliTRDCalDCSFEEv2 info                                  //
 //                                                                        //
 //                                                                        //
 // Authors:                                                               //
 
 #include <TDirectory.h>
 #include <TFile.h>
+#include <TAxis.h>
+#include <TH2F.h>
+#include <TStyle.h>
+#include <TCanvas.h>
 
 //AliRoot includes
 #include "AliRawReader.h"
 #include "AliLog.h"
 #include "AliTRDCalibChamberStatus.h"
 #include "AliTRDgeometry.h"
+#include "AliTRDfeeParam.h"
 #include "AliTRDdigitsManager.h"
 #include "AliTRDSignalIndex.h"
-#include "AliTRDrawFastStream.h"
+#include "AliTRDpadPlane.h"
 #include "./Cal/AliTRDCalChamberStatus.h"
-#include "./Cal/AliTRDCalDCS.h"
-#include "./Cal/AliTRDCalDCSFEE.h"
+#include "./Cal/AliTRDCalDCSv2.h"
+#include "./Cal/AliTRDCalDCSFEEv2.h"
+
+#include "AliTRDrawStream.h"
 
 #ifdef ALI_DATE
 #include "event.h"
@@ -65,6 +72,7 @@ AliTRDCalibChamberStatus::AliTRDCalibChamberStatus() : /*FOLD00*/
   fHnSparseEvtDet(0x0),
   fHnSparseDebug(0x0),
   fHnSparseMCM(0x0),
+  fC1(0x0),
   fDebugLevel(0)
 {
     //
@@ -84,6 +92,7 @@ AliTRDCalibChamberStatus::AliTRDCalibChamberStatus(const AliTRDCalibChamberStatu
   fHnSparseEvtDet(ped.fHnSparseEvtDet),
   fHnSparseDebug(ped.fHnSparseDebug),  
   fHnSparseMCM(ped.fHnSparseMCM),
+  fC1(ped.fC1),
   fDebugLevel(ped.fDebugLevel)
 {
     //
@@ -125,7 +134,10 @@ AliTRDCalibChamberStatus::~AliTRDCalibChamberStatus() /*FOLD00*/
   }
   if(fHnSparseMCM) {
    delete fHnSparseMCM;
- }
+  }
+  if(fC1) {
+   delete fC1;
+  }
 }
 
 //_____________________________________________________________________
@@ -225,8 +237,8 @@ void AliTRDCalibChamberStatus::Init()
     thnDimEvtt[1] = 6;
     thnDimEvtt[2] = 5;
     thnDimEvtt[3] = 8;
-    thnDimEvtt[4] = 16;
-    thnDimEvtt[5] = 16;
+    thnDimEvtt[4] = 18;
+    thnDimEvtt[5] = 18;
     //arrays for lower bounds :
     Double_t* binEdgesEvtt[6];
     for(Int_t ivar = 0; ivar < 6; ivar++)
@@ -236,8 +248,8 @@ void AliTRDCalibChamberStatus::Init()
     for(Int_t i=0; i<=thnDimEvtt[1]; i++) binEdgesEvtt[1][i]= 0.0  + (6.0)/thnDimEvtt[1]*(Double_t)i;
     for(Int_t i=0; i<=thnDimEvtt[2]; i++) binEdgesEvtt[2][i]= 0.0  + (5.0)/thnDimEvtt[2]*(Double_t)i;
     for(Int_t i=0; i<=thnDimEvtt[3]; i++) binEdgesEvtt[3][i]= 0.0  + (8.0)/thnDimEvtt[3]*(Double_t)i;
-    for(Int_t i=0; i<=thnDimEvtt[4]; i++) binEdgesEvtt[4][i]= 0.0  + (16.0)/thnDimEvtt[4]*(Double_t)i;
-    for(Int_t i=0; i<=thnDimEvtt[5]; i++) binEdgesEvtt[5][i]= 0.0  + (16.0)/thnDimEvtt[5]*(Double_t)i;
+    for(Int_t i=0; i<=thnDimEvtt[4]; i++) binEdgesEvtt[4][i]= 0.0  + (18.0)/thnDimEvtt[4]*(Double_t)i;
+    for(Int_t i=0; i<=thnDimEvtt[5]; i++) binEdgesEvtt[5][i]= 0.0  + (18.0)/thnDimEvtt[5]*(Double_t)i;
     
     //create the THnSparse
     fHnSparseMCM = new THnSparseI("MCMerrorDCS","MCMerrorDCS",6,thnDimEvtt);
@@ -255,19 +267,21 @@ void AliTRDCalibChamberStatus::Init()
 void AliTRDCalibChamberStatus::ProcessEvent(AliRawReader * rawReader, Int_t nevents_physics)
 {
   //
-  // Event Processing loop 
+  // Event Processing loop with AliTRDrawStream
   //
   //
   
   Bool_t notEmpty = kFALSE;
     
-  AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
-  rawStream->SetNoErrorWarning();
-  rawStream->SetSharedPadReadout(kFALSE);
-
   AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
   digitsManager->CreateArrays();
   
+  AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
+  rawStream->SetDigitsManager(digitsManager);
+  //  rawStream->SetNoErrorWarning();
+  //  rawStream->SetSharedPadReadout(kFALSE);
+
+  
   Int_t det    = 0;
   while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { 
 
@@ -317,8 +331,8 @@ void AliTRDCalibChamberStatus::ProcessEvent(AliRawReader * rawReader, Int_t neve
 
   if(notEmpty) fCounterEventNotEmpty++;
 
-  if(digitsManager) delete digitsManager;
-  if(rawStream) delete rawStream;
+  delete digitsManager;
+  delete rawStream;
    
 }
 //_____________________________________________________________________
@@ -353,15 +367,15 @@ Bool_t AliTRDCalibChamberStatus::TestEventHisto(Int_t nevent) /*FOLD00*/
 //_____________________________________________________________________
 void AliTRDCalibChamberStatus::AnalyseHisto() /*FOLD00*/
 {
-    //
-    //  Create the AliTRDCalChamberStatus according to the fHnSparseI
-    //
-
+  //
+  //  Create the AliTRDCalChamberStatus according to the fHnSparseI
+  //
+  
   if(fCalChamberStatus) delete fCalChamberStatus;
   fCalChamberStatus = new AliTRDCalChamberStatus();
 
   // Check if enough events to say something
-  if(fCounterEventNotEmpty < 30) {
+  if(fCounterEventNotEmpty < 200) {
     // Say all installed
     for (Int_t ism=0; ism<18; ism++) {
       for (Int_t ipl=0; ipl<6; ipl++) {
@@ -417,16 +431,16 @@ void AliTRDCalibChamberStatus::AnalyseHisto() /*FOLD00*/
 
 }
 //_____________________________________________________________________
-void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
+void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCSv2 *calDCS) /*FOLD00*/
 {
   //
-  //  Correct the AliTRDCalChamberStatus according to the AliTRDCalDCS
+  //  Correct the AliTRDCalChamberStatus according to the AliTRDCalDCSv2
   //  Using globale state of the HalfChamberMerger (HCM)
   //
-  
   for(Int_t det = 0; det < 540; det++) {
-    AliTRDCalDCSFEE* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
-    if(!calDCSFEEEOR) { continue;}
+    AliTRDCalDCSFEEv2* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
+
+    if(!calDCSFEEEOR) continue;
     
     // MCM Global State Machine State Definitions
     //  low_power =  0,
@@ -444,43 +458,44 @@ void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
     Int_t lay  = AliTRDgeometry::GetLayer(det);
     Int_t stac = AliTRDgeometry::GetStack(det);
     
-    Int_t stateA = calDCSFEEEOR->GetMCMGlobalState(4,17); // HCM Side A
-    Int_t stateB = calDCSFEEEOR->GetMCMGlobalState(5,17); // HCM Side B
-    Int_t rphi = -1;
-
-    //printf("DCS: stateA %d \t stateB %d \n",stateA,stateB);
-    if(stateA!=3 && stateA!=9) rphi = 1;
-    Double_t vals[4] = {sm,lay,stac,rphi};
-    if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
-    
-    if(stateB!=3 && stateB!=9) rphi = 2;
-    vals[3] = rphi;
-    if(rphi!=-1) fHnSparseHCM->Fill(&vals[0]);
+    Int_t stateA = 0;   // 0=bad, 1=good state
+    Int_t stateB = 0;
+
+    // loop over all mcm to define DCS-HCS
+    for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
+      for(Int_t i = 0; i < 18; i++) { //MCM loop
+       
+       Int_t side = ii%2;  // 0=sideA, 1=sideB
+       Int_t cstate = calDCSFEEEOR->GetMCMGlobalState(ii,i); //current mcm state
+       
+       if(cstate==3) {
+         switch(side) {
+         case 0: stateA=1; break;
+         case 1: stateB=1; break; 
+         }
+       }
+      }
+    }
 
     //---------//
     //  Debug  //
     if(fDebugLevel > 0) {
-      if( ((fCalChamberStatus->GetStatus(det) <= 1) && (stateA!=3 && stateA!=9)) || 
-         ((fCalChamberStatus->GetStatus(det) <= 1) && (stateB!=3 && stateB!=9)) || 
-         ((fCalChamberStatus->GetStatus(det) == 2) && (stateA==3 || stateA==9)) || 
-         ((fCalChamberStatus->GetStatus(det) == 2) && (stateB==3 || stateB==9)) ||
-         ((fCalChamberStatus->GetStatus(det) == 3) && (stateA==3 || stateA==9)) ||
-          ((fCalChamberStatus->GetStatus(det) == 3) && (stateB!=3 && stateB!=9)) ||
-         ((fCalChamberStatus->GetStatus(det) == 4) && (stateB==3 || stateB==9)) ||
-         ((fCalChamberStatus->GetStatus(det) == 4) && (stateA!=3 && stateA!=9)) )
+      if( ((fCalChamberStatus->GetStatus(det) <= 1) && (stateA==0 || stateB==0)) || 
+         ((fCalChamberStatus->GetStatus(det) == 2) && (stateA==1 || stateB==1)) || 
+         ((fCalChamberStatus->GetStatus(det) == 3) && (stateA==1 || stateB==0)) ||
+         ((fCalChamberStatus->GetStatus(det) == 4) && (stateB==0 || stateB==1))  )
        {
          //printf(" Different half chamber status in DCS and DATA!!\n");
          Double_t val[4] = {sm,lay,stac,1};
          fHnSparseDebug->Fill(&val[0]); 
          
-         if(rphi!=-1) {  // error in DCS information
-           // Fill MCM status map
-           for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
-             for(Int_t i = 0; i < 16; i++) { //MCM loop
-               Double_t valss[6] = {sm,lay,stac,ii,i
-                                    ,calDCSFEEEOR->GetMCMGlobalState(ii,i)};
-               fHnSparseMCM->Fill(&valss[0]);
-             }
+         // Fill MCM status map
+         for(Int_t ii = 0; ii < 8; ii++) { //ROB loop
+           for(Int_t i = 0; i < 18; i++) { //MCM loop
+             Double_t valss[6] = {sm,lay,stac,ii,i
+                                  ,calDCSFEEEOR->GetMCMGlobalState(ii,i)};
+             fHnSparseMCM->Fill(&valss[0]);
+             
            } 
          }
        }
@@ -488,42 +503,34 @@ void AliTRDCalibChamberStatus::CheckEORStatus(AliTRDCalDCS *calDCS) /*FOLD00*/
     //---------//
     //  Debug  //
 
-    //////////////////////////////////////////
+    //---------------------------------------
     // Change the status according to DCS
-    ///////////////////////////////////////////
-
-    // First put bad status if seen by DCS
-    /////////////////////////////////////////
-    if(stateA!=3 && stateA!=9 && stateB!=3 && stateB!=9) {
-      // completely masked from DCS
-      fCalChamberStatus->SetStatus(det,2);
-    }
-    if((stateA!=3 && stateA!=9) && (stateB==3 || stateB==9)) {
-      // Only A side masked from DCS
-      if(fCalChamberStatus->GetStatus(det) != 3) {
-       // But not from Data 
-       if(fCalChamberStatus->GetStatus(det) == 4) fCalChamberStatus->SetStatus(det,2);
-       if(fCalChamberStatus->GetStatus(det) <= 1) fCalChamberStatus->SetStatus(det,3);
-      }
-    }
-    if((stateA==3 || stateA==9) && (stateB!=3 && stateB!=9)) {
-      // Only B side masked from DCS
-      if(fCalChamberStatus->GetStatus(det) != 4) {
-       // But not from Data 
-       if(fCalChamberStatus->GetStatus(det) == 3) fCalChamberStatus->SetStatus(det,2);
-       if(fCalChamberStatus->GetStatus(det) <= 1) fCalChamberStatus->SetStatus(det,4);
+    //---------------------------------------
+    Int_t StatusData = fCalChamberStatus->GetStatus(det);
+    switch(StatusData) 
+      {
+      case 1: 
+       if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
+       if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,4); // Only B side masked from DCS
+       if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,3); // Only A side masked from DCS
+       if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,1);
+       break;
+      case 2: // completely masked from DATA
+       if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
+       break;
+      case 3: // Only A side masked from DATA
+       if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
+       if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,2); // Only B side masked from DCS
+       if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,3); // Only A side masked from DCS
+       if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,3);
+       break;
+      case 4: // Only B side masked from DATA
+       if(stateA==0 && stateB==0) fCalChamberStatus->SetStatus(det,2); // completely masked from DCS
+       if(stateA==1 && stateB==0) fCalChamberStatus->SetStatus(det,4); // Only B side masked from DCS
+       if(stateA==0 && stateB==1) fCalChamberStatus->SetStatus(det,2); // Only A side masked from DCS
+       if(stateA==1 && stateB==1) fCalChamberStatus->SetStatus(det,4);
+       break;
       }
-    }
-
-    // Then release in case of error 3 from DCS
-    /////////////////////////////////////////////
-    if(fCalChamberStatus->GetStatus(det)==2) {
-      if((stateA==3) && (stateB==3)) fCalChamberStatus->SetStatus(det,1);
-      if((stateA==3) && (stateB!=3)) fCalChamberStatus->SetStatus(det,4);
-      if((stateA!=3) && (stateB==3)) fCalChamberStatus->SetStatus(det,3);
-    }
-    if((fCalChamberStatus->GetStatus(det)==3) && (stateA==3)) fCalChamberStatus->SetStatus(det,1);
-    if((fCalChamberStatus->GetStatus(det)==4) && (stateB==3)) fCalChamberStatus->SetStatus(det,1);
     
   }
 
@@ -577,4 +584,129 @@ void AliTRDCalibChamberStatus::DumpToFile(const Char_t *filename, const Char_t *
 
     if ( backup ) backup->cd();
 }
+//_____________________________________________________________________________
+TH2D* AliTRDCalibChamberStatus::PlotSparseI(Int_t sm,Int_t side) 
+{
+  //
+  // Plot number of entries for supermodule sm 
+  // as a function of layer and stack
+  //
+
+  if(!fHnSparseI) return 0x0;
+  
+  fHnSparseI->GetAxis(0)->SetRange(sm+1,sm+1); 
+  fHnSparseI->GetAxis(3)->SetRange(side+1,side+1);  
+  TH2D *h2 = fHnSparseI->Projection(1,2);
+
+  return h2;
+
+}
+//_____________________________________________________________________
+TH2F *AliTRDCalibChamberStatus::MakeHisto2DSmPlEORStatus(AliTRDCalDCSv2 *calDCS, Int_t sm, Int_t pl) /*FOLD00*/
+{
+  //
+  //  Plot globale state of the HalfChamberMerger (HCM)
+  //
+  AliTRDfeeParam *paramfee = AliTRDfeeParam::Instance();
+
+  AliTRDgeometry *trdGeo = new AliTRDgeometry();
+  AliTRDpadPlane *padPlane0 = trdGeo->GetPadPlane(pl,0);        // layer,stack
+  Double_t row0    = padPlane0->GetRow0();
+  Double_t col0    = padPlane0->GetCol0();
+
+  char  name[1000];
+  snprintf(name,1000,"%s DCS status sm %d pl %d",GetTitle(),sm,pl);
+  TH2F * his = new TH2F( name, name, 88,-TMath::Abs(row0),TMath::Abs(row0)
+                                   ,148,-TMath::Abs(col0),TMath::Abs(col0));
+
+
+  // Where we begin
+  Int_t offsetsmpl = 30*sm+pl;
+  Int_t nstack = 5;
+  Int_t ncols = 144;
+
+  for (Int_t k = 0; k < nstack; k++){
+    Int_t det = offsetsmpl+k*6;
+    Int_t stac = AliTRDgeometry::GetStack(det);
+    AliTRDCalDCSFEEv2* calDCSFEEEOR = calDCS->GetCalDCSFEEObj(det);
+    if(!calDCSFEEEOR) { continue;}
+    for (Int_t icol=0; icol<ncols; icol++){
+      Int_t nrows = 16;
+      if(stac==2) nrows = 12;
+      for (Int_t irow=0; irow<nrows; irow++){
+       Int_t binz     = 0;
+       Int_t kb       = 5-1-k;
+       Int_t krow     = nrows-1-irow;
+       Int_t kcol     = ncols-1-icol;
+       if(kb > 2) binz = 16*(kb-1)+12+krow+1+2*(kb+1);
+       else binz = 16*kb+krow+1+2*(kb+1); 
+       Int_t biny = kcol+1+2;
+       // Take the value
+       Int_t mcm = paramfee->GetMCMfromPad(irow,icol);
+       Int_t rob = paramfee->GetROBfromPad(irow,icol);
+       if(mcm < 0) AliWarning("Problem with mcm number");
+       Int_t state = calDCSFEEEOR->GetMCMGlobalState(rob,TMath::Abs(mcm)); 
+               his->SetBinContent(binz,biny,state);
+      }
+    }
+    for(Int_t icol = 1; icol < 147; icol++){
+      for(Int_t l = 0; l < 2; l++){
+       Int_t binz     = 0;
+       Int_t kb       = 5-1-k;
+       if(kb > 2) binz = 16*(kb-1)+12+1+2*(kb+1)-(l+1);
+       else binz = 16*kb+1+2*(kb+1)-(l+1); 
+       his->SetBinContent(binz,icol,16.0);
+      }
+    }
+  }
+  
+  for(Int_t icol = 1; icol < 147; icol++){
+    his->SetBinContent(88,icol,16.0);
+    his->SetBinContent(87,icol,16.0);
+  }
+  for(Int_t irow = 1; irow < 89; irow++){
+    his->SetBinContent(irow,1,16.0);
+    his->SetBinContent(irow,2,16.0);
+    his->SetBinContent(irow,147,16.0);
+    his->SetBinContent(irow,148,16.0);
+  }
+
+  his->SetXTitle("z (cm)");
+  his->SetYTitle("y (cm)");
+  his->SetMaximum(12);
+  his->SetMinimum(0.0);
+  his->SetStats(0);
+
+  return his;
+
+}
+//_____________________________________________________________________________
+TCanvas* AliTRDCalibChamberStatus::PlotHistos2DSmEORStatus(AliTRDCalDCSv2 *calDCS, Int_t sm, const Char_t *name)
+{
+  //
+  // Make 2D graph
+  //
+
+  gStyle->SetPalette(1);
+  fC1 = new TCanvas(name,name,50,50,600,800);
+  fC1->Divide(3,2);
+  fC1->cd(1);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,0)->Draw("colz");
+  fC1->cd(2);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,1)->Draw("colz");
+  fC1->cd(3);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,2)->Draw("colz");
+  fC1->cd(4);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,3)->Draw("colz");
+  fC1->cd(5);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,4)->Draw("colz");
+  fC1->cd(6);
+  MakeHisto2DSmPlEORStatus(calDCS,sm,5)->Draw("colz");
+
+  return fC1;
+
+}
+
+