From fa7a23994f1d9f2679a254e9e72e6c0a1a7662d2 Mon Sep 17 00:00:00 2001
From: Graeme Stewart <graemes.cern@gmail.com>
Date: Thu, 4 May 2017 15:23:29 +0000
Subject: [PATCH] Merge branch 'master-addingBMGs' into 'master'

Merge: adding BMGs in offline DQ

See merge request !1284
---
 .../src/OccupancyHoleFinder.cxx               |  97 ++++-----
 .../MdtRawDataMonitoring/src/MDTChamber.cxx   |  16 +-
 .../src/MDTRawDataUtils.cxx                   | 186 ++++++++----------
 .../src/MdtRawDataValAlg.cxx                  |  81 ++++----
 4 files changed, 186 insertions(+), 194 deletions(-)

diff --git a/DataQuality/dqm_algorithms/src/OccupancyHoleFinder.cxx b/DataQuality/dqm_algorithms/src/OccupancyHoleFinder.cxx
index 020085f8a396..a5c7c570e2a2 100644
--- a/DataQuality/dqm_algorithms/src/OccupancyHoleFinder.cxx
+++ b/DataQuality/dqm_algorithms/src/OccupancyHoleFinder.cxx
@@ -336,24 +336,21 @@ dqm_algorithms::OccupancyHoleFinder::getMDTChamberName(const TH2* histo, int bin
       }
     }
     else if(name[1] == 'M') {
-      if(etaStat <= 3){
-	if(phiStat%2==0) stat_type = 'S';
-	else stat_type = 'L';
-	if(phiStat == 12 || phiStat == 14) stat_type = 'F';
-      }
-      else if(etaStat <= 5){
-	if(phiStat%2 == 0) stat_type = 'S';
-	else if(phiStat%2 == 1) stat_type = 'L';
-	//fix phiStat
-	if(phiStat>=13) phiStat+=2;
-	if(phiStat==12) { stat_type = 'L'; phiStat++; }
-      }
-      else {
-	if(phiStat%2 == 0) stat_type = 'S';
-	else if(phiStat%2 == 1) stat_type = 'L';
-	if(phiStat == 12) {stat_type = 'L'; phiStat=15;}
-	if(phiStat == 13) {stat_type = 'S'; phiStat=16;}
-      }
+        if(phiStat%2==0) stat_type = 'S';
+        if(phiStat%2==1) stat_type = 'L';
+        if(etaStat==6 && phiStat>12) phiStat = phiStat+1; //there is no phi=13 in eta=6, therefore phi=14,15,16
+                                                          //was moved one bin down in the histogram we are looking at 
+        if(phiStat==12 || phiStat==14){ //BMF and BMG
+            if(etaStat%2==0) stat_type='G';
+            //BMF naming does not correspond to the actual eta station. BMF eta station is 1,3,5 but the chambers are named
+            //BMF1, BMF2, BMF3. We set etaStat such that the proper name comes out at the end.
+            if(etaStat%2==1) {
+                stat_type = 'F';
+                if(etaStat==3) etaStat=2;
+                if(etaStat==5) etaStat=3;
+            }
+        }
+
     }
     else {//'O'
       if( etaStat == 0 ) {
@@ -488,30 +485,34 @@ dqm_algorithms::OccupancyHoleFinder::getMDTChamberNameByCrate(int biny, std::str
   } else if(crate.substr(0,1) == "B" && crate.substr(2,2) == "03"){
 	int cOffset = 0;
 	if (crate.substr(1,1) == "C"){ cOffset = 1;}
-	if( (biny-71 + cOffset) > 0) { // BOS
+	if( (biny-74 + cOffset) > 0) { // BOS
 		chamber_str = "BOS";
-		etaStat = (biny - 71 + cOffset);
+		etaStat = (biny - 74 + cOffset);
 		phiStat =  10;
-	} else if ( (biny-59 + cOffset) > 0){ //BOL
+	} else if ( (biny-62 + cOffset) > 0){ //BOL
 		chamber_str = "BOL";
-		etaStat = (biny+1 - 59 + cOffset)/2;
-		phiStat =  2*(biny - 2*etaStat - 59 + cOffset) + 11;
-	} else if ( (biny - 54 ) > 0){
+		etaStat = (biny+1 - 62 + cOffset)/2;
+		phiStat =  2*(biny - 2*etaStat - 62 + cOffset) + 11;
+	} else if ( (biny - 57 ) > 0){
 		chamber_str = "BOG";
-		etaStat = 2*(biny - 54) - 2 + 2*cOffset;
+		etaStat = 2*(biny - 57) - 2 + 2*cOffset;
 		phiStat = 12;
-	} else if ( (biny-50) > 0){
+	} else if ( (biny-53) > 0){
 		chamber_str = "BOF";
-		etaStat = 2*(biny - 50) - 1;
+		etaStat = 2*(biny - 53) - 1;
 		phiStat = 12;
-	} else if( (biny-44) > 0){ // BMS
+	} else if( (biny-47) > 0){ // BMS
 		chamber_str = "BMS";
-		etaStat = biny - 44;
+		etaStat = biny - 47;
 		phiStat =  10;
-	} else if ( (biny-32) > 0){ //BML
+	} else if ( (biny-35) > 0){ //BML
 		chamber_str = "BML";
-		etaStat = (biny+1 - 32)/2;
-		phiStat =  2*(biny - 2*etaStat - 32) + 11;
+		etaStat = (biny+1 - 35)/2;
+		phiStat =  2*(biny - 2*etaStat - 35) + 11;
+	} else if ( (biny - 32) > 0){ //BMG
+		chamber_str = "BMG";
+		etaStat = (biny - 32)*2 ; //because its BMG2, BMG4, BMG6
+		phiStat = 12;
 	} else if ( (biny - 29) > 0){ //BMF
 		chamber_str = "BMF";
 		etaStat = biny - 29;
@@ -536,34 +537,38 @@ dqm_algorithms::OccupancyHoleFinder::getMDTChamberNameByCrate(int biny, std::str
   } else if(crate.substr(0,1) == "B" && crate.substr(2,2) == "04"){
 	int cOffset = 0;
 	if (crate.substr(1,1) == "C"){ cOffset = 1;}
-	if( (biny-71 + cOffset) > 0) { // BOS
+	if( (biny-74 + cOffset) > 0) { // BOS
 		chamber_str = "BOS";
-		etaStat = (biny - 71 + cOffset);
+		etaStat = (biny - 74 + cOffset);
 		phiStat =  16;
-	} else if ( (biny-58 + cOffset) > 0){ //BOL
+	} else if ( (biny-61 + cOffset) > 0){ //BOL
 		chamber_str = "BOL";
-		etaStat = (biny+1 - 58 + cOffset)/2;
-		phiStat =  2*(biny - 2*etaStat - 58 + cOffset) + 15;
-	} else if ( (biny - 53 ) > 0){
+		etaStat = (biny+1 - 61 + cOffset)/2;
+		phiStat =  2*(biny - 2*etaStat - 61 + cOffset) + 15;
+	} else if ( (biny - 56 ) > 0){
 		chamber_str = "BOG";
-		etaStat = 2*(biny - 53) - 2 + 2*cOffset;
+		etaStat = 2*(biny - 56) - 2 + 2*cOffset;
 		phiStat = 14;
-	} else if ( (biny-49) > 0){
+	} else if ( (biny-52) > 0){
 		chamber_str = "BOF";
-		etaStat = 2*(biny - 49) - 1;
+		etaStat = 2*(biny - 52) - 1;
 		phiStat = 14;
-	} else if( (biny-43) > 0){ // BMS
+	} else if( (biny-46) > 0){ // BMS
 		chamber_str = "BMS";
 		etaStat = biny - 43;
 		phiStat =  16;
-	} else if ( (biny - 42) > 0){
+	} else if ( (biny - 45) > 0){
 		chamber_str = "BML";
 		etaStat = 6;
 		phiStat = 15;
-	} else if ( (biny-32) > 0){ //BML
+	} else if ( (biny-35) > 0){ //BML
 		chamber_str = "BML";
-		etaStat = (biny+1 - 32)/2;
-		phiStat =  2*(biny - 2*etaStat - 32) + 15;
+		etaStat = (biny+1 - 35)/2;
+		phiStat =  2*(biny - 2*etaStat - 35) + 15;
+	} else if ( (biny - 32) > 0){ //BMG
+		chamber_str = "BMG";
+		etaStat = (biny - 32)*2;
+		phiStat = 14;
 	} else if ( (biny - 29) > 0){ //BMF
 		chamber_str = "BMF";
 		etaStat = biny - 29;
diff --git a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTChamber.cxx b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTChamber.cxx
index 4c105597d6a8..920db5a57dff 100755
--- a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTChamber.cxx
+++ b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTChamber.cxx
@@ -91,6 +91,10 @@ MDTChamber::MDTChamber(std::string name) :
     ss >> m_station_phi;
     m_station_phi--;
     ss.clear();
+
+  //First there were only BMF1,2,3, then BMGs were added which are between the BMFs, so doing the eta-station assignment by hand.
+  if( m_hardware_name.substr(0, 4) == "BMF2") m_station_eta = 3; 
+  if( m_hardware_name.substr(0, 4) == "BMF3") m_station_eta = 5; 
     
     //station_phi is used as an iterator, and is thus 1 less than its value (since it always starts at 01, not 00).
 
@@ -173,6 +177,11 @@ void MDTChamber::SetMDTHitsPerChamber_IMO_Bin(TH2F* h){
 	  ecap_layer_IMO = "BC4";
 	  statphi_s = "13";
   }
+  //First there were only BMF1,2,3, then BMGs were added which are between the BMFs, so doing the ecap-layer assignment by hand.
+  if( m_hardware_name.substr(0, 5) == "BMF2A") ecap_layer_IMO  = "BA3";
+  if( m_hardware_name.substr(0, 5) == "BMF3A") ecap_layer_IMO  = "BA5";
+  if( m_hardware_name.substr(0, 5) == "BMF2C") ecap_layer_IMO = "BC3";
+  if( m_hardware_name.substr(0, 5) == "BMF3C") ecap_layer_IMO = "BC5";
 
   std::string statphi_IMO_s = m_hardware_name.substr(1,1)+","+statphi_s;
   //Separate pesky BIR/BIM 11,15
@@ -215,7 +224,12 @@ void MDTChamber::SetMDTHitsPerML_byLayer_Bins(TH2F* h_mdthitspermultilayerLumi,
     if(m_hardware_name == "BME1C14" || m_hardware_name == "BME1C13"){
   	  ecap_layer = "BMC4";
     }
-
+  
+  // Setting BMF by hand because of irregular naming convention. BMF and BMG chambers alternate; historical BMF naming is BMF1,2,3 but BMG it is 2,4,6  
+  if( m_hardware_name.substr(0, 5) == "BMF2A") ecap_layer = "BMA3";
+  if( m_hardware_name.substr(0, 5) == "BMF3A") ecap_layer = "BMA5";
+  if( m_hardware_name.substr(0, 5) == "BMF2C") ecap_layer = "BMC3";
+  if( m_hardware_name.substr(0, 5) == "BMF3C") ecap_layer = "BMC5";
 
   int binx = h_mdthitspermultilayerLumi->GetXaxis()->FindBin(ecap_layer.c_str());
   int biny_m1 = h_mdthitspermultilayerLumi->GetYaxis()->FindBin(statphi_ml1_s.c_str());
diff --git a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTRawDataUtils.cxx b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTRawDataUtils.cxx
index c62f41a71052..a9e5f141d58d 100644
--- a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTRawDataUtils.cxx
+++ b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MDTRawDataUtils.cxx
@@ -91,12 +91,7 @@ StatusCode MdtRawDataValAlg::binMdtGlobal( TH2* &h, char ecap ) {
     putBox(h, 0, 108, 1, 110); putLine(h,1,108,1,110); putLine(h,0,108,1,108); putLine(h,0,110,1,110);
     putBox(h, 0, 112, 2, 116); putLine(h,2,112,2,116); putLine(h,0,112,2,112); 
 
-    putLine(h,2,52,2,74);
-    //BML 12,13,14
-    putBox(h, 2, 74, 5, 76); putLine(h,5,74,5,76);putLine(h,5,78,5,80); putLine(h,2,74,5,74); putLine(h,2,76,5,76);putLine(h,2,76,2,78);
-    //putBox(h, 4, 76, 5, 78);  //putLine(h,4,76,4,78);
-    putBox(h, 2, 78, 5, 80); putLine(h,2,80,5,80); putLine(h,2,78,5,78); //putLine(h,5,74,5,76);
-    putLine(h,2,80,2,106);
+    putLine(h,2,52,2,106);
 
     //Mid Section
     putBox(h, 8, 0, 9, 106); putLine(h,8,0,8,106); putLine(h,8,106,9,106); putLine(h,9,0,9,106);
@@ -119,13 +114,7 @@ StatusCode MdtRawDataValAlg::binMdtGlobal( TH2* &h, char ecap ) {
     putBox(h, 16, 108, 17, 110);   putLine(h,16,108,16,110); putLine(h,16,108,17,108); putLine(h,16,110,17,110);
     putBox(h, 15, 112, 17, 116);   putLine(h,15,112,15,116); putLine(h,15,112,17,112); 			 
 
-    putLine(h,15,52,15,74);
-    //BML 12,13,14
-    putBox(h, 12, 74, 17, 76); putLine(h,12,74,12,76); putLine(h,15,74,12,74); putLine(h,15,76,12,76);
-    putBox(h, 15, 76, 17, 78); //putBox(h, 12, 76, 13, 78);
-    putLine(h,15,76,15,78); //putLine(h,13,76,13,78); putLine(h,12,76,12,78);
-    putBox(h, 12, 78, 17, 80); putLine(h,15,78,12,78); putLine(h,15,80,12,80); putLine(h,12,78,12,80);
-    putLine(h,15,80,15,106);
+    putLine(h,15,52,15,106);
 
     //Draw TickMarks
     for(int i = 0; i < 59; i +=1){
@@ -316,30 +305,6 @@ StatusCode  MdtRawDataValAlg::binMdtRegional( TH2* &h, string &xAxis){
     putLine(h, 1, 48, 1, 52); putLine(h, 0, 48, 1, 48); putLine(h, 0, 52, 1, 52);
     putLine(h, 2, 56, 2, 64); putLine(h, 0, 56, 2, 56);
   }
-  if(xAxis=="BMA") {
-    putBox(h, 3, 44, 6, 48);
-    //putBox(h, 5, 48, 6, 52);
-    putBox(h, 3, 52, 6, 56);  
-    putLine(h, 3, 44, 6, 44);
-    putLine(h, 3, 44, 3, 48);
-    putLine(h, 3, 48, 6, 48);
-    //putLine(h, 5, 48, 5, 52);
-    putLine(h, 3, 52, 6, 52);
-    putLine(h, 3, 52, 3, 56);
-    putLine(h, 3, 56, 6, 56);
-  }
-  if(xAxis=="BMC") {
-    putBox(h, 0, 44, 3, 48);
-    //putBox(h, 0, 48, 1, 52);
-    putBox(h, 0, 52, 3, 56);  
-    putLine(h, 0, 44, 3, 44);
-    putLine(h, 3, 44, 3, 48);
-    putLine(h, 0, 48, 3, 48);
-    //putLine(h, 1, 48, 1, 52);
-    putLine(h, 0, 52, 3, 52);
-    putLine(h, 3, 52, 3, 56);
-    putLine(h, 0, 56, 3, 56);
-  }
   if(xAxis=="BIA") {
     putBox(h, 6, 0, 8, 4); putLine(h, 6, 0, 8, 0); putLine(h, 6, 0, 6, 4); putLine(h, 6, 4, 8, 4); //phi 1
     putBox(h, 7, 6, 8, 8); putLine(h, 7, 6, 8, 6); putLine(h, 7, 6, 7, 8); //phi 2
@@ -1134,17 +1099,12 @@ int MdtRawDataValAlg::get_bin_for_LB_hist(int region, int layer, int phi, int et
     }
 
     else if(layer == 1){ //Middle
-      if(eta < 4 || (eta == 4 && phi < 12)) return 16*(eta-1) + phi;
-      else if( eta == 4 && phi == 12) return 59;
-      else if( eta == 4 && phi == 14) return 60;
-      else if( eta == 4 && phi == 15) return 61;
-      else if( eta == 5 && phi < 12) return 62 + phi;
-      else if( eta == 5 && phi == 12) return 73;
-      else if( eta == 5 && phi == 14) return 74;
-      else if( eta == 5 && phi == 15) return 75;
-      else if( eta == 6 && phi < 12) return 76 + phi;
-      else if( eta == 6 && phi == 14) return 87;
-      else if( eta == 6 && phi == 15) return 88;
+      // 95 = 1 + 16 + 16 + 16 + 16 + 16 + 14   total number of phi sectors (+1)
+      // in the last eta-sector (6) there is no phi-sector 13; ie there are no chambers BML6A13 and BML6C13, so there are only 14 phi sectos
+      // we move the bin of phi=14 directly above phi=12 so there is no white line in the histogram
+      if(eta == 6 && phi > 11 ) return 16*(eta-1) + phi - 1;
+      else return 16*(eta-1) + phi;
+
     }
     else if(layer == 2 && region == 0){ // Outer, side A (must be separated due to presence of eta=0 chambers)
       if(eta == 0 && phi == 11) return 0;
@@ -1240,25 +1200,27 @@ StatusCode MdtRawDataValAlg::binMdtOccVsLB(TH2* &h, int region, int layer){
     }
 
     else if(layer == 1){ //Middle
-      h->SetBins(834,1,2502,89,0,89);
+      h->SetBins(834,1,2502,95,0,95);   // 95 = 1 + 16 + 16 + 16 + 16 + 16 + 14   total number of phi sectors (+1)
+                                        // in the last eta-sector (6) there is no phi-sector 13; ie there arent chambers BML6A13 and BML6C13
+                                        // so there are only 14 phi sectors
       //Add Labels
       h->GetYaxis()->SetBinLabel(1,"BM1");
       h->GetYaxis()->SetBinLabel(17,"BM2");
       h->GetYaxis()->SetBinLabel(33,"BM3");
       h->GetYaxis()->SetBinLabel(49,"BM4");
-      h->GetYaxis()->SetBinLabel(63,"BM5");
-      h->GetYaxis()->SetBinLabel(77,"BM6");
+      h->GetYaxis()->SetBinLabel(65,"BM5");
+      h->GetYaxis()->SetBinLabel(81,"BM6");
       //Add lines
       h->GetYaxis()->SetTickLength(0);
-      for(int i = 1; i < 89; i++){
+      for(int i = 1; i < 95; i++){
 	TLine* l = new TLine(1,i,20,i);
 	h->GetListOfFunctions()->Add(l);
       }
       TLine* l1 = new TLine(1,16,50,16); h->GetListOfFunctions()->Add(l1);
       TLine* l2 = new TLine(1,32,50,32); h->GetListOfFunctions()->Add(l2);
       TLine* l3 = new TLine(1,48,50,48); h->GetListOfFunctions()->Add(l3);
-      TLine* l4 = new TLine(1,62,50,62); h->GetListOfFunctions()->Add(l4);
-      TLine* l5 = new TLine(1,76,50,76); h->GetListOfFunctions()->Add(l5);
+      TLine* l4 = new TLine(1,64,50,64); h->GetListOfFunctions()->Add(l4);
+      TLine* l5 = new TLine(1,80,50,80); h->GetListOfFunctions()->Add(l5);
     }
 
     else if(layer == 2 && region == 0){ //Outer, side A 
@@ -1475,88 +1437,92 @@ StatusCode MdtRawDataValAlg::binMdtOccVsLB_Crate(TH2* &h, int region, int crate)
     }
     else if(crate == 2){ //BA03, BC03
      //Add Labels
-      h->SetBins(834,1,2502,77,0,77);
+      h->SetBins(834,1,2502,80,0,80);
       h->GetYaxis()->SetBinLabel(1,"BIL");
       h->GetYaxis()->SetBinLabel(7,"BIM");
       h->GetYaxis()->SetBinLabel(12,"BIR");
       h->GetYaxis()->SetBinLabel(18,"BIS");
       h->GetYaxis()->SetBinLabel(30,"BMF");
-      h->GetYaxis()->SetBinLabel(33,"BML");
-      h->GetYaxis()->SetBinLabel(45,"BMS");
-      h->GetYaxis()->SetBinLabel(51,"BOF");
-      h->GetYaxis()->SetBinLabel(55,"BOG");
+      h->GetYaxis()->SetBinLabel(33,"BMG");
+      h->GetYaxis()->SetBinLabel(36,"BML");
+      h->GetYaxis()->SetBinLabel(48,"BMS");
+      h->GetYaxis()->SetBinLabel(54,"BOF");
+      h->GetYaxis()->SetBinLabel(58,"BOG");
       if(region == 0){
-        h->GetYaxis()->SetBinLabel(60,"BOL");
-        h->GetYaxis()->SetBinLabel(72,"BOS");
+        h->GetYaxis()->SetBinLabel(63,"BOL");
+        h->GetYaxis()->SetBinLabel(75,"BOS");
       } else if (region == 1){
-        h->GetYaxis()->SetBinLabel(59,"BOL");
-        h->GetYaxis()->SetBinLabel(71,"BOS");    	  
+        h->GetYaxis()->SetBinLabel(62,"BOL");
+        h->GetYaxis()->SetBinLabel(74,"BOS");    	  
       }
       //Add lines
       h->GetYaxis()->SetTickLength(0);
-      for(int i = 0; i < 77; i++){
+      for(int i = 0; i < 80; i++){
 	     TLine* l = new TLine(1,i,20,i);
 	     h->GetListOfFunctions()->Add(l);
-      }
+      } ////change line positions!
       TLine* l2 = new TLine(1,6,50,6); h->GetListOfFunctions()->Add(l2);
       TLine* l3 = new TLine(1,11,50,11);  h->GetListOfFunctions()->Add(l3);
       TLine* l3b = new TLine(1,17,50,17);  h->GetListOfFunctions()->Add(l3b);
-      TLine* l4 = new TLine(1,26,50,26);  h->GetListOfFunctions()->Add(l4);
+      //TLine* l4 = new TLine(1,26,50,26);  h->GetListOfFunctions()->Add(l4); //removed this line because it doesnt correspond to anything
       TLine* l5 = new TLine(1,29,50,29);  h->GetListOfFunctions()->Add(l5);
       TLine* l6 = new TLine(1,32,50,32);  h->GetListOfFunctions()->Add(l6);
-      TLine* l7 = new TLine(1,44,50,44);  h->GetListOfFunctions()->Add(l7);
-      TLine* l8 = new TLine(1,50,50,50);  h->GetListOfFunctions()->Add(l8);
-      TLine* l9 = new TLine(1,54,50,54);  h->GetListOfFunctions()->Add(l9);
+      TLine* l7 = new TLine(1,35,50,35);  h->GetListOfFunctions()->Add(l7);
+      TLine* l8 = new TLine(1,47,50,47);  h->GetListOfFunctions()->Add(l8);
+      TLine* l9 = new TLine(1,53,50,53);  h->GetListOfFunctions()->Add(l9);
+      TLine* l9b = new TLine(1,57,50,57);  h->GetListOfFunctions()->Add(l9b);
       if(region == 0) {
-    	  TLine* l10 = new TLine(1,59,50,59);  h->GetListOfFunctions()->Add(l10);
-          TLine* l11 = new TLine(1,71,50,71);  h->GetListOfFunctions()->Add(l11);
+    	  TLine* l10 = new TLine(1,62,50,62);  h->GetListOfFunctions()->Add(l10);
+          TLine* l11 = new TLine(1,74,50,74);  h->GetListOfFunctions()->Add(l11);
       } else if (region == 1){
-          TLine* l10 = new TLine(1,58,50,58);  h->GetListOfFunctions()->Add(l10);
-          TLine* l11 = new TLine(1,70,50,70);  h->GetListOfFunctions()->Add(l11);
+          TLine* l10 = new TLine(1,61,50,61);  h->GetListOfFunctions()->Add(l10);
+          TLine* l11 = new TLine(1,73,50,73);  h->GetListOfFunctions()->Add(l11);
       }
     }
 
-    else if(crate == 3){ //BA04, BC04
+    else if(crate == 3){ //BA04, BC04 
      //Add Labels
-      h->SetBins(834,1,2502,76,0,76);
+      h->SetBins(834,1,2502,79,0,79);
       h->GetYaxis()->SetBinLabel(1,"BIL");
       h->GetYaxis()->SetBinLabel(7,"BIM");
       h->GetYaxis()->SetBinLabel(12,"BIR");
       h->GetYaxis()->SetBinLabel(18,"BIS");
       h->GetYaxis()->SetBinLabel(30,"BMF");
-      h->GetYaxis()->SetBinLabel(33,"BML");
-      h->GetYaxis()->SetBinLabel(44,"BMS");
-      h->GetYaxis()->SetBinLabel(50,"BOF");
-      h->GetYaxis()->SetBinLabel(54,"BOG");
+      h->GetYaxis()->SetBinLabel(33,"BMG");
+      h->GetYaxis()->SetBinLabel(36,"BML");
+      h->GetYaxis()->SetBinLabel(47,"BMS");
+      h->GetYaxis()->SetBinLabel(53,"BOF");
+      h->GetYaxis()->SetBinLabel(57,"BOG");
       if (region == 0){
-          h->GetYaxis()->SetBinLabel(59,"BOL");
-          h->GetYaxis()->SetBinLabel(72,"BOS");
+          h->GetYaxis()->SetBinLabel(62,"BOL");
+          h->GetYaxis()->SetBinLabel(75,"BOS");
       } else if (region == 1){
-          h->GetYaxis()->SetBinLabel(58,"BOL");
-          h->GetYaxis()->SetBinLabel(71,"BOS");
+          h->GetYaxis()->SetBinLabel(61,"BOL");
+          h->GetYaxis()->SetBinLabel(74,"BOS");
       }
       
       //Add lines
       h->GetYaxis()->SetTickLength(0);
-      for(int i = 0; i < 76; i++){
+      for(int i = 0; i < 79; i++){
 	TLine* l = new TLine(1,i,20,i);
 	h->GetListOfFunctions()->Add(l);
       }
       TLine* l2 = new TLine(1,6,50,6); h->GetListOfFunctions()->Add(l2);
       TLine* l3 = new TLine(1,11,50,11);  h->GetListOfFunctions()->Add(l3);
       TLine* l3b = new TLine(1,17,50,17);  h->GetListOfFunctions()->Add(l3b);
-      TLine* l4 = new TLine(1,26,50,26);  h->GetListOfFunctions()->Add(l4);
+      //TLine* l4 = new TLine(1,26,50,26);  h->GetListOfFunctions()->Add(l4);//removed this line because it doesnt correspond to anything
       TLine* l5 = new TLine(1,29,50,29);  h->GetListOfFunctions()->Add(l5);
       TLine* l6 = new TLine(1,32,50,32);  h->GetListOfFunctions()->Add(l6);
-      TLine* l7 = new TLine(1,43,50,43);  h->GetListOfFunctions()->Add(l7);
-      TLine* l8 = new TLine(1,49,50,49);  h->GetListOfFunctions()->Add(l8);
-      TLine* l9 = new TLine(1,53,50,53);  h->GetListOfFunctions()->Add(l9);
+      TLine* l7 = new TLine(1,35,50,35);  h->GetListOfFunctions()->Add(l7);
+      TLine* l8 = new TLine(1,46,50,46);  h->GetListOfFunctions()->Add(l8);
+      TLine* l9 = new TLine(1,52,50,52);  h->GetListOfFunctions()->Add(l9);
+      TLine* l9b = new TLine(1,56,50,56);  h->GetListOfFunctions()->Add(l9b);
       if(region == 0){
-    	  TLine* l10 = new TLine(1,58,50,58);  h->GetListOfFunctions()->Add(l10);
-          TLine* l11 = new TLine(1,71,50,71);  h->GetListOfFunctions()->Add(l11);
+    	  TLine* l10 = new TLine(1,61,50,61);  h->GetListOfFunctions()->Add(l10);
+          TLine* l11 = new TLine(1,74,50,74);  h->GetListOfFunctions()->Add(l11);
       } else if (region == 1 ){
-    	  TLine* l10 = new TLine(1,57,50,57);  h->GetListOfFunctions()->Add(l10);
-          TLine* l11 = new TLine(1,70,50,70);  h->GetListOfFunctions()->Add(l11);
+    	  TLine* l10 = new TLine(1,60,50,60);  h->GetListOfFunctions()->Add(l10);
+          TLine* l11 = new TLine(1,73,50,73);  h->GetListOfFunctions()->Add(l11);
       }
     }
   }
@@ -1685,14 +1651,15 @@ int MdtRawDataValAlg::get_bin_for_LB_crate_hist(int region, int crate, int phi,
 	else if(chamber.substr(0,3)=="BIM") binNum = 6 + eta;
 	else if(chamber.substr(0,3)=="BIR") binNum = 11 + eta;
 	else if(chamber.substr(0,3)=="BIS") binNum = 17 + 2*eta + (phi-10)/2-1;
-	else if(chamber.substr(0,3)=="BMF") binNum = 29 + eta;
-	else if(chamber.substr(0,3)=="BML") binNum = 32 + 2*eta + (phi-9)/2-1;
-	else if(chamber.substr(0,3)=="BMS") binNum = 44 + eta;
-	else if(chamber.substr(0,3)=="BOF") binNum = 50 + (eta+1)/2;
-	else if(chamber.substr(0,4)=="BOG0" && region == 0 ) binNum = 55;
-	else if(chamber.substr(0,3)=="BOG") binNum = 55 + eta/2 - region;
-	else if(chamber.substr(0,3)=="BOL") binNum = 59 + 2*eta + (phi-9)/2-1 - region;
-	else if(chamber.substr(0,3)=="BOS") binNum = 71 + eta - region;
+	else if(chamber.substr(0,3)=="BMF") binNum = 29 + (eta+1)/2;
+	else if(chamber.substr(0,3)=="BMG") binNum = 32 + eta/2;
+	else if(chamber.substr(0,3)=="BML") binNum = 35 + 2*eta + (phi-9)/2-1;
+	else if(chamber.substr(0,3)=="BMS") binNum = 47 + eta;
+	else if(chamber.substr(0,3)=="BOF") binNum = 53 + (eta+1)/2;
+	else if(chamber.substr(0,4)=="BOG0" && region == 0 ) binNum = 58;
+	else if(chamber.substr(0,3)=="BOG") binNum = 58 + eta/2 - region;
+	else if(chamber.substr(0,3)=="BOL") binNum = 62 + 2*eta + (phi-9)/2-1 - region;
+	else if(chamber.substr(0,3)=="BOS") binNum = 74 + eta - region;
 	else ATH_MSG_INFO("chamber " << chamber << " didn't exist in crate Bx03");
 	return binNum - 1;
     } else if(crate == 4){//BA04, BC04
@@ -1701,15 +1668,16 @@ int MdtRawDataValAlg::get_bin_for_LB_crate_hist(int region, int crate, int phi,
 	else if(chamber.substr(0,3)=="BIM") binNum = 6 + eta;
 	else if(chamber.substr(0,3)=="BIR") binNum = 11 + eta;
 	else if(chamber.substr(0,3)=="BIS") binNum = 17 + 2*eta + (phi-14)/2-1;
-	else if(chamber.substr(0,3)=="BMF") binNum = 29 + eta;
-	else if(chamber.substr(0,3)=="BML" && eta < 6) binNum = 32 + 2*eta + (phi-13)/2-1;
-	else if(chamber.substr(0,7)=="BML6A15" || chamber.substr(0,7)=="BML6C15" ) binNum = 43;
-	else if(chamber.substr(0,3)=="BMS") binNum = 43 + eta;
-	else if(chamber.substr(0,3)=="BOF") binNum = 49 + (eta+1)/2;
-	else if(chamber.substr(0,4)=="BOG0" && region == 0) binNum = 54;
-	else if(chamber.substr(0,3)=="BOG") binNum = 54 + eta/2 - region;
-	else if(chamber.substr(0,3)=="BOL") binNum = 58 + 2*eta + (phi-13)/2-1 - region;
-	else if(chamber.substr(0,3)=="BOS") binNum = 71 + eta - region;
+	else if(chamber.substr(0,3)=="BMF") binNum = 29 + (eta+1)/2;
+	else if(chamber.substr(0,3)=="BMG") binNum = 32 + eta/2;
+	else if(chamber.substr(0,3)=="BML" && eta < 6) binNum = 35 + 2*eta + (phi-13)/2-1;
+	else if(chamber.substr(0,7)=="BML6A15" || chamber.substr(0,7)=="BML6C15" ) binNum = 46;
+	else if(chamber.substr(0,3)=="BMS") binNum = 46 + eta;
+	else if(chamber.substr(0,3)=="BOF") binNum = 52 + (eta+1)/2;
+	else if(chamber.substr(0,4)=="BOG0" && region == 0) binNum = 57;
+	else if(chamber.substr(0,3)=="BOG") binNum = 57 + eta/2 - region;
+	else if(chamber.substr(0,3)=="BOL") binNum = 61 + 2*eta + (phi-13)/2-1 - region;
+	else if(chamber.substr(0,3)=="BOS") binNum = 74 + eta - region;
 	else ATH_MSG_INFO("chamber " << chamber << " didn't exist in crate Bx04");
 	return binNum - 1;
     }
diff --git a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MdtRawDataValAlg.cxx b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MdtRawDataValAlg.cxx
index 6ac8c5f62850..d0a5b69c8a65 100755
--- a/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MdtRawDataValAlg.cxx
+++ b/MuonSpectrometer/MuonValidation/MuonDQA/MuonRawDataMonitoring/MdtRawDataMonitoring/src/MdtRawDataValAlg.cxx
@@ -322,20 +322,20 @@ StatusCode MdtRawDataValAlg::initialize()
 }
 
 /*----------------------------------------------------------------------------------*/
-StatusCode MdtRawDataValAlg::bookHistogramsRecurrent( /*bool isNewEventsBlock, bool newLumiBlock, bool newRun */)
+StatusCode MdtRawDataValAlg::bookHistogramsRecurrent( /*bool isNewEventsBlock, bool newLumiBlockFlag(), bool newRunFlag() */)
 /*----------------------------------------------------------------------------------*/
 {
   //changed for booking unmanaged histograms for MIG2
 
   StatusCode sc = StatusCode::SUCCESS;
 
-  if(newRun || newLowStatInterval){
-    sc = bookMDTSummaryHistograms(/* isNewEventsBlock,*/ newLumiBlock, newRun);
+  if(newRunFlag() || newLowStatIntervalFlag()){
+    sc = bookMDTSummaryHistograms(/* isNewEventsBlock,*/ newLumiBlockFlag(), newRunFlag());
     if(sc.isFailure()) { 
       ATH_MSG_FATAL("Failed to bookMDTSummaryHistograms" );
       return sc;
     }
-    sc = bookMDTOverviewHistograms(/* isNewEventsBlock,*/ newLumiBlock, newRun);
+    sc = bookMDTOverviewHistograms(/* isNewEventsBlock,*/ newLumiBlockFlag(), newRunFlag());
     if(sc.isFailure()) { 
       ATH_MSG_FATAL("Failed to bookMDTOverviewHistograms" );
       return sc;
@@ -343,11 +343,11 @@ StatusCode MdtRawDataValAlg::bookHistogramsRecurrent( /*bool isNewEventsBlock, b
   }
 
   //if(isNewEventsBlock) {}
-  if(newLumiBlock) {}
-  if(newRun) {      
-    ATH_MSG_DEBUG("MDT RawData Monitoring from ESD : newRun" );    
+  if(newLumiBlockFlag()) {}
+  if(newRunFlag()) {      
+    ATH_MSG_DEBUG("MDT RawData Monitoring from ESD : newRunFlag()" );    
     //Book All Chambers
-    //Protection against newRun()
+    //Protection against newRunFlag()()
     clear_hist_map();
     int counter = 0;
       sc= GetTimingInfo();
@@ -385,7 +385,7 @@ StatusCode MdtRawDataValAlg::bookHistogramsRecurrent( /*bool isNewEventsBlock, b
       }
     }
     
-  }//if newRun
+  }//if newRunFlag()
 
   return sc; 
 } 
@@ -504,7 +504,6 @@ StatusCode MdtRawDataValAlg::fillHistograms()
       for (Muon::MdtPrepDataContainer::const_iterator containerIt = mdt_container->begin(); containerIt != mdt_container->end(); ++containerIt) {
         if (containerIt == mdt_container->end() || (*containerIt)->size()==0) continue;  //check if there are counts  
         m_nColl++;
-
         
         bool isHit_above_ADCCut = false;
         // loop over hits
@@ -516,10 +515,9 @@ StatusCode MdtRawDataValAlg::fillHistograms()
             m_nPrdcut++;
             isHit_above_ADCCut = true;
           }
-
           //      Identifier digcoll_id = (*mdtCollection)->identify();
           hardware_name = getChamberName(*mdtCollection);
-           
+
 
           //Relic from cosmic days nolonger relevant      
           //      if (selectChambersRange(hardware_name, m_chamberName, m_mdtIdHelper->stationEta(digcoll_id), m_StationEta, m_mdtIdHelper->stationPhi(digcoll_id), m_StationPhi, m_StationSize) ) 
@@ -544,7 +542,6 @@ StatusCode MdtRawDataValAlg::fillHistograms()
             return sc; 
           }
 
-
           if(m_doChamberHists){
             if(isATLASReady()) sc = fillMDTHistograms(*mdtCollection);
             if(sc.isSuccess()) 
@@ -679,9 +676,9 @@ StatusCode MdtRawDataValAlg::procHistograms(/*bool isEndOfEventsBlock, bool isEn
 
   StatusCode sc = StatusCode::SUCCESS; 
   //if(isEndOfEventsBlock) {}
-  if(endOfLumiBlock) {}
+  if(endOfLumiBlockFlag()) {}
   //Replicate lowStat histograms to run directory if stable beam
-  if( endOfLumiBlock && isATLASReady() && !m_isOnline ){
+  if( endOfLumiBlockFlag() && isATLASReady() && !m_isOnline ){
     //Book tdc adccut per region per lowStat
     sc = regHist((TH1F*) overalltdccut_segm_PR_Lumi[enumBarrelA]->Clone(), mg->mongroup_brA_shift);
     sc = regHist((TH1F*) overalltdccut_segm_PR_Lumi[enumBarrelC]->Clone(), mg->mongroup_brC_shift);
@@ -854,7 +851,7 @@ StatusCode MdtRawDataValAlg::procHistograms(/*bool isEndOfEventsBlock, bool isEn
 
 
 
-  if(endOfRun) {
+  if(endOfRunFlag()) {
 
     ATH_MSG_DEBUG("********Reached Last Event in MdtRawDataValAlg !!!" );   
     ATH_MSG_DEBUG("MdtRawDataValAlg finalize()" );
@@ -897,7 +894,7 @@ StatusCode MdtRawDataValAlg::procHistograms(/*bool isEndOfEventsBlock, bool isEn
       if( mdtchamberstatphislice[j] ) mdtchamberstatphislice[j]->LabelsDeflate("X");
     }
 
-  } // endOfRun
+  } // endOfRunFlag()
 
   return sc;
 }  
@@ -1096,7 +1093,7 @@ StatusCode MdtRawDataValAlg::bookMDTSummaryHistograms(/* bool isNewEventsBlock,
   //if( isNewEventsBlock ){}
   if( newLumiBlock ){}
   //book these histos as lowStat interval if not online monitoring
-  if( (newLowStatInterval && !m_isOnline) || (m_isOnline && newRun) ){
+  if( (newLowStatIntervalFlag() && !m_isOnline) || (m_isOnline && newRun) ){
     //Book tdc adccut per region per lowStat
     sc = bookMDTHisto_overview(overalltdccut_segm_PR_Lumi[enumBarrelA], "MDTTDC_segm_Summary_ADCCut_BA", "[nsec]", "Number of Entries",
         120, 0., 2000.,mg->mongroup_brA_shiftLumi);
@@ -1235,7 +1232,7 @@ StatusCode MdtRawDataValAlg::bookMDTSummaryHistograms(/* bool isNewEventsBlock,
         } // end if(ilayer==0&&(iecap==0||iecap==2) )
       }//layer
     }//ecap
-  }//newLowStatInterval
+  }//newLowStatIntervalFlag()
 
   if(newRun){
     //     //Book t0 tmax tdrift summary plots
@@ -1494,7 +1491,7 @@ StatusCode MdtRawDataValAlg::bookMDTSummaryHistograms(/* bool isNewEventsBlock,
       } // loop in phi
     } // loop in layer
   } // loop in ecap 
-}//newRun
+}//newRunFlag()
 
 ATH_MSG_DEBUG("LEAVING MDTSUMMARYBOOK");
 return sc;
@@ -1506,7 +1503,7 @@ StatusCode MdtRawDataValAlg::bookMDTOverviewHistograms(/* bool isNewEventsBlock,
   //if( isNewEventsBlock ){}
   if( newLumiBlock ){}
   //book these histos as lowStat interval if not online monitoring
-  if( (newLowStatInterval && !m_isOnline) || (m_isOnline && newRun) ){
+  if( (newLowStatIntervalFlag() && !m_isOnline) || (m_isOnline && newRun) ){
     ////////////////////////////////////////////////////////////////////////////////////// 
     //histo path for overall tdccut spectrum
     sc = bookMDTHisto_overview(overalltdccutLumi, "Overall_TDC_ADCCut_spectrum", "[nsec]", "Number of Entries",
@@ -1699,6 +1696,8 @@ StatusCode MdtRawDataValAlg::fillMDTHistograms( const Muon::MdtPrepData* mdtColl
 
 
   float tdc = mdtCollection->tdc()*25.0/32.0;
+  // Note: the BMG is digitized with 200ps which is not same as other MDT chambers with 25/32=781.25ps
+  if(hardware_name.substr(0,3)=="BMG") tdc = mdtCollection->tdc() * 0.2;
   float adc = mdtCollection->adc();
 
   if (chamber->mdttdc) {
@@ -1749,7 +1748,6 @@ StatusCode MdtRawDataValAlg::fillMDTSummaryHistograms( const Muon::MdtPrepData*
     ATH_MSG_ERROR( "Could Not Retrieve MDTChamber w/ ID " << digcoll_idHash );
     return sc;
   }
-
   bool isNoisy = m_masked_tubes->isNoisy( mdtCollection );
 
   int ibarrel = chamber->GetBarrelEndcapEnum();
@@ -1762,8 +1760,11 @@ StatusCode MdtRawDataValAlg::fillMDTSummaryHistograms( const Muon::MdtPrepData*
   bool isBIM = (chambername.at(2)=='M');
 
   float tdc = mdtCollection->tdc()*25.0/32.0;
+  // Note: the BMG is digitized with 200ps which is not same as other MDT chambers with 25/32=781.25ps
+  if(chambername.substr(0,3)=="BMG") tdc = mdtCollection->tdc() * 0.2;
   float adc = mdtCollection->adc();
 
+
   if( mdtChamberHits[iregion][ilayer][stationPhi] && adc > m_ADCCut )
     mdtChamberHits[iregion][ilayer][stationPhi]->Fill(std::abs(stationEta));
 
@@ -1843,6 +1844,8 @@ StatusCode MdtRawDataValAlg::fillMDTOverviewHistograms( const Muon::MdtPrepData*
   float mdt_tube_perp = mdtgPos.perp();
 
   float tdc = mdtCollection->tdc()*25.0/32.0;
+  // Note: the BMG is digitized with 200ps which is not same as other MDT chambers with 25/32=781.25ps
+  if(hardware_name.substr(0,3)=="BMG") tdc = mdtCollection->tdc() * 0.2;
   float adc = mdtCollection->adc();
 
   //Barrel -->Fill MDT Global RZ and YX
@@ -1938,27 +1941,29 @@ StatusCode MdtRawDataValAlg::handleEvent_effCalc(const Trk::SegmentCollection* s
         MDTChamber* chamber = 0;
         m_mdtIdHelper->get_module_hash( tmpid, idHash );  
         sc = getChamber(idHash, chamber);
-
+        std::string chambername = chamber->getName();
         if(overalladc_segm_Lumi) overalladc_segm_Lumi->Fill(mrot->prepRawData()->adc());
         if( store_ROTs.find(tmpid) == store_ROTs.end() ) { // Let's not double-count hits belonging to multiple segments
           store_ROTs.insert(tmpid);   
 
           double tdc = mrot->prepRawData()->tdc()*25.0/32.0;
-          //      double tdc = mrot->driftTime()+500;
-
-          int iregion = chamber->GetRegionEnum();
-          int ilayer = chamber->GetLayerEnum();
-          int statphi = chamber->GetStationPhi();
-          int ibarrel_endcap = chamber->GetBarrelEndcapEnum();
-          if(overalladc_segm_PR_Lumi[iregion]) overalladc_segm_PR_Lumi[iregion]->Fill(mrot->prepRawData()->adc());        
-
-          if(mrot->prepRawData()->adc()>m_ADCCut) { // This is somewhat redundant because this is usual cut for segment-reconstruction, but that's OK
-            if(statphi > 15) {
-              ATH_MSG_ERROR( "MDT StationPhi: " << statphi << " Is too high.  Chamber name: " << chamber->getName() );
-              continue;
-            }
-
-            if( mdttdccut_sector[iregion][ilayer][statphi] ) mdttdccut_sector[iregion][ilayer][statphi]->Fill(tdc);
+          // Note: the BMG is digitized with 200ps which is not same as other MDT chambers with 25/32=781.25ps
+          if(chambername.substr(0,3)=="BMG") tdc = mrot->prepRawData()->tdc() * 0.2;
+              //      double tdc = mrot->driftTime()+500;
+
+              int iregion = chamber->GetRegionEnum();
+              int ilayer = chamber->GetLayerEnum();
+              int statphi = chamber->GetStationPhi();
+              int ibarrel_endcap = chamber->GetBarrelEndcapEnum();
+              if(overalladc_segm_PR_Lumi[iregion]) overalladc_segm_PR_Lumi[iregion]->Fill(mrot->prepRawData()->adc());        
+
+              if(mrot->prepRawData()->adc()>m_ADCCut) { // This is somewhat redundant because this is usual cut for segment-reconstruction, but that's OK
+                if(statphi > 15) {
+                  ATH_MSG_ERROR( "MDT StationPhi: " << statphi << " Is too high.  Chamber name: " << chamber->getName() );
+                  continue;
+                }
+
+                if( mdttdccut_sector[iregion][ilayer][statphi] ) mdttdccut_sector[iregion][ilayer][statphi]->Fill(tdc);
             //Fill Overview Plots
             if(overalltdccut_segm_Lumi) overalltdccut_segm_Lumi->Fill(tdc);
             if(overalltdccut_segm_PR_Lumi[iregion]) overalltdccut_segm_PR_Lumi[iregion]->Fill(tdc);
-- 
GitLab