]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerEfficiencyCells.cxx
Fixing minor bug recognizing diffractive events in simulation
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerEfficiencyCells.cxx
index 12f29960c04490836380f4d71f495e4a88e7338a..db113c64b583861e68920dc6696a430d815aed30 100755 (executable)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-#include <fstream>
-#include <TRandom.h>
-#include "Riostream.h"
+// $Id$
 
 #include "AliMUONTriggerEfficiencyCells.h"
-#include "AliMUONConstants.h"
-#include "AliRun.h"
-#include "AliMpPad.h"
-#include "AliMUON.h"
-#include "AliMpVSegmentation.h"
-#include "AliMpTriggerSegmentation.h"
-#include "AliMpTrigger.h"
+
 #include "AliLog.h"
+#include "AliMpConstants.h"
+
+#include "TH1.h"
+#include "TList.h"
+#include "TFile.h"
+
+#include <fstream>
+#include <cassert>
+
 
-//
-// A class to store and give access to the trigger chamber efficiency.
-//
-// Efficiency is stored per cathode, on "cells" of a given size.
-//
-// The main method of this class is IsTriggered().
-//
-// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency 
-// for each chamber (i.e. DetElement). 
-// The efficiency cells goes from right to left and 
-// from bottom to top of the chamber, namely, the efficiencies tabulated in the 
-// file refers to the following reference frame:
-//
-//x
-//<----------------------------------|
-//                                   |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//  | 0.97 | 0.97 | 0.97 | 0.97 |    |
-//   ---------------------------     |
-//                                   |
-//                                  \/ y
-//
-//  The file can be edited in order to change efficiency in a chosen region
-//  of the chamber.
-//
-// But please note that this object is also available from the CDB 
-// (generated using the MUONCDB.C macro)
-//
+//-----------------------------------------------------------------------------
+/// \class AliMUONTriggerEfficiencyCells
+/// A class to store and give access to the numerator and denominator 
+/// histograms for the trigger chamber efficiency calculation.
+///
+/// \author Diego Stocco; Subatech, Nantes
+//-----------------------------------------------------------------------------
 
+/// \cond CLASSIMP
 ClassImp(AliMUONTriggerEfficiencyCells)
+/// \endcond
 
 //__________________________________________________________________________
 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
 :
-TObject()
+TObject(),
+fCountHistoList(0x0),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
 {
-  // Default ctor.
-  Reset();
+///  Default constructor.
+  CheckConstants();
+  ResetHistos();
 }
 
 //__________________________________________________________________________
-AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const char* filename)
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const Char_t* filename,
+                                                            const Char_t* listname)
 :
-TObject()
+TObject(),
+fCountHistoList(0x0),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
 {
-  // Ctor using an ASCII file.
-  Reset();
-  ReadFile(filename);
+///  Constructor using an ASCII file.
+  CheckConstants();
+  ResetHistos();
+  ReadFile(filename, listname);
 }
 
-
 //__________________________________________________________________________
-AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList)
+:
+TObject(),
+fCountHistoList(countHistoList),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
 {
-  // dtor. Does nothing ;-)
+///  Constructor using a list of histograms with counts.
+  CheckConstants();
+  ResetHistos();
 }
-    
-//__________________________________________________________________________
-Float_t AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
+
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
+:
+TObject(other),
+fCountHistoList(other.fCountHistoList),
+fNoCountHistoList(other.fNoCountHistoList),
+fFiredStrips(other.fFiredStrips)
 {
-  // Get the efficiency at a given position (x,y) for a given cathode
-  
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  TArrayI cell = CellByCoord(detElemId,x,y);
-  Float_t efficiency = 0.0;
-  if (cell.At(0)>=0 && cell.At(1)>=0)
-  {
-    efficiency = fCellContent[chamber][slat][cathode][cell.At(0)][cell.At(1)];
+/// Copy constructor
+
+  for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+    fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
+    fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
   }
-  return efficiency;
 }
 
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2)
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
 {
-  // Get the efficiencies of the 2 cathode at a given location (x,y)
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  TArrayI cell = CellByCoord(detElemId,x,y);
-  eff1 = 0.0;
-  eff2 = 0.0;
-  if(cell.At(0)>=0 && cell.At(1)>=0)
-  {
-    eff1 = fCellContent[chamber][slat][0][cell.At(0)][cell.At(1)];
-    eff2 = fCellContent[chamber][slat][1][cell.At(0)][cell.At(1)];
+  /// Asignment operator
+  // check assignement to self
+  if (this == &other)
+    return *this;
+
+  for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+    fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
+    fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
   }
-}
 
+  fCountHistoList = other.fCountHistoList;
+  fNoCountHistoList = other.fNoCountHistoList;
+  fFiredStrips = other.fFiredStrips;
+    
+  return *this;
+}
 
 //__________________________________________________________________________
-Bool_t 
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
+AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
 {
-  // Random decision of whether a given "location" (x,y) trigs or not.
-  Float_t efficiency = GetCellEfficiency(detElemId, cathode, x, y);
-  Bool_t trigger = kTRUE;
-  if(gRandom->Rndm()>efficiency)
-  {
-    trigger = kFALSE;
-  }
-  return trigger;
+///  Destructor.
+  //delete [] fBoardEfficiency;
+  //delete [] fSlatEfficiency;
+  ResetHistos(kTRUE);
+  delete fCountHistoList;
+  delete fNoCountHistoList;
+  delete fFiredStrips;
 }
 
 
-//__________________________________________________________________________
-void 
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2)
+//_____________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::CheckConstants() const
 {
-  // Whether or not a given location (x,y) has a chance to trig, on each cathode.
-  Float_t eff1 = 0.0;
-  Float_t eff2 = 0.0;
-  GetCellEfficiency(detElemId, x, y, eff1, eff2);
-  trig1 = kTRUE; 
-  trig2 = kTRUE;
-  if(gRandom->Rndm()>eff1)trig1 = kFALSE;
-  if(gRandom->Rndm()>eff2)trig2 = kFALSE;
+/// Check consistence of redefined constants 
+
+  assert(fgkNcathodes == AliMpConstants::NofCathodes());    
+  assert(fgkNchambers == AliMpConstants::NofTriggerChambers());    
+  assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);    
 }
 
 
 //__________________________________________________________________________
-TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y)
+void
+AliMUONTriggerEfficiencyCells::ResetHistos(Bool_t deleteObjects)
 {
-  // Get the efficiencies at a given location.
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = FindSlatIndex(detElemId);
-  Int_t cell[2]={-1,-1};
-  Float_t maxX = fCellSize[chamber][slat][0]*((Float_t)fCellNumber[chamber][slat][0]);
-  Float_t maxY = fCellSize[chamber][slat][1]*((Float_t)fCellNumber[chamber][slat][1]);
-  if(x>=0 & x<maxX & y>=0 & y<maxY)
-  {
-    cell[0] = (Int_t)(x/fCellSize[chamber][slat][0]);
-    cell[1] = (Int_t)(y/fCellSize[chamber][slat][1]);
-  }
-  return TArrayI(2,cell);
-}
+///  Sets our internal array contents to zero.
 
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
-{
-  // Reads a file containing the efficiency map.
-  TString fileName = gSystem->ExpandPathName(filename);
-  ifstream file(fileName.Data());
-  Int_t datInt=0, detEl=0, chamber=0, rpc=0;
-  Float_t datFloat=0.0;
-  char dat[50];
-  if (file.good()){
-    while (file >> dat) {
-           file >> detEl;
-           chamber = FindChamberIndex(detEl);
-           rpc = FindSlatIndex(detEl);
-           file >> dat;
-           for(Int_t i=0; i<2; i++){
-        file >> datInt;
-        fCellNumber[chamber][rpc][i] = datInt;
-        file >> dat;
-           }
-           for(Int_t i=0; i<2; i++){
-        file >> datFloat;
-        fCellSize[chamber][rpc][i] = datFloat;
-        if(i==0)file >> dat;
-           }
-           for(Int_t cath=0; cath<2; cath++){
-        file >> dat;
-        file >> datInt;
-        for(Int_t iy=0; iy<fCellNumber[chamber][rpc][1]; iy++){
-          for(Int_t ix=0; ix<fCellNumber[chamber][rpc][0]; ix++){
-            file >> datFloat;
-            fCellContent[chamber][rpc][cath][ix][iy] = datFloat;
-          }
-        }
-           }
+  for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+    if ( deleteObjects ) {
+      delete fBoardEfficiency[chCath];
+      delete fSlatEfficiency[chCath];
     }
-    file.close();
-  } else {
-    AliWarning(Form("Can't read file %s",fileName.Data()));
+    fBoardEfficiency[chCath] = 0x0;
+    fSlatEfficiency[chCath] = 0x0;
   }
 }
 
 
 //__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId)
+void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename, const Char_t* listname)
 {
-  // From detElemId to chamber number
-  Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
-  Int_t chamber = (detElemId-offset)/100;
-  return chamber;
-}
+///  Structure of file (.root) containing local board efficency
+    TFile *file = TFile::Open(filename);
+    if(!file || !file->IsOpen()) {
+      AliError(Form("Can't read file %s",filename));
+      return;
+    }
 
+    if ( ! fCountHistoList ) {
+      fCountHistoList = new TList();
+      fCountHistoList->SetOwner();
+    }
 
-//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
-{
-  // From detElemId to slat index.
-  Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
-  Int_t chamber = FindChamberIndex(detElemId);
-  Int_t slat = detElemId-offset-(chamber*100);
-  return slat;
+    TH1F *histo = 0x0;
+    const Char_t* histoName;
+
+    TList* listInFile = 0x0;
+    TString listNameString(listname);
+    if ( ! listNameString.IsNull() )
+      listInFile = (TList*)file->FindObjectAny(listname);
+
+    for ( Int_t ide=0; ide<=kHchamberCount; ide++){
+      for(Int_t ich=0; ich<fgkNchambers; ich++){
+
+       // Efficiency per chamber is provided by 1 histogram only
+       if ( ide == kHchamberCount ) ich = fgkNchambers;
+
+       for(Int_t hType=0; hType<kNcounts; hType++){
+         histoName = GetHistoName(ide, hType, ich);
+         histo = ( listInFile ) ? (TH1F*)listInFile->FindObject(histoName) : (TH1F*)file->Get(histoName);
+         if ( ! histo ) {
+           AliWarning(Form("Cannot find %s in file. Skip histogram", histoName));
+           continue;
+         }
+         histo->SetDirectory(0);
+         fCountHistoList->Add(histo);
+
+         AliDebug(5,Form("Adding histogram %s\n",histoName));
+
+         // Do not fill efficiency per chamber histos
+         if ( ide == kHchamberCount )
+           continue;
+
+         // Fill old historgrams for consistency
+         if ( hType < kBothPlanesEff ){
+           TString newName = histoName;
+           newName.ReplaceAll("Counts","Eff");
+           TH1F* auxHisto = (TH1F*)histo->Clone(newName.Data());
+           auxHisto->SetDirectory(0);
+           if ( ide == kHboardCount )
+             fBoardEfficiency[fgkNchambers*hType+ich] = auxHisto;
+           else if ( ide == kHslatCount )
+             fSlatEfficiency[fgkNchambers*hType+ich] = auxHisto;
+
+           AliDebug(5,Form("Creating histogram %s\n",auxHisto->GetName()));
+         }
+         else if ( hType == kAllTracks ){
+           for ( Int_t icath=0; icath<2; icath++){
+             if ( ide == kHboardCount )
+               fBoardEfficiency[fgkNchambers*icath+ich]->Divide(histo);
+             else if ( ide == kHslatCount )
+               fSlatEfficiency[fgkNchambers*icath+ich]->Divide(histo);
+           }
+         }
+       } // loop on count types
+      } // loop on chambers
+    } // loop on detection element type
+
+    file->Close();
 }
 
 
 //__________________________________________________________________________
-TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t y, Float_t x0, Float_t y0)
+const Char_t*
+AliMUONTriggerEfficiencyCells::GetHistoName(Int_t histoType, Int_t countType, 
+                                           Int_t chamber)
 {
-    //(x0,y0) position of the local reference frame (center of the chamber)
-    Float_t x1 = x0-x;//reflection of axis
-    Float_t y1 = y+y0;
-    return TVector2(x1,y1);
+  //
+  /// Return the name of the histogram for efficiency calculation
+  //
+  TString histoTypeName[kNcounts] = {"bendPlane", "nonBendPlane", "bothPlanes", "allTracks"};
+
+  switch ( histoType ) {
+  case kHchamberCount:
+    return Form("%sCountChamber", histoTypeName[countType].Data());
+  case kHslatCount:
+    return Form("%sCountSlatCh%i", histoTypeName[countType].Data(), 11+chamber);
+  case kHboardCount:
+    return Form("%sCountBoardCh%i", histoTypeName[countType].Data(), 11+chamber);
+  }
+
+  return 0x0;
 }
 
 //__________________________________________________________________________
-void
-AliMUONTriggerEfficiencyCells::Reset()
+TH1F* AliMUONTriggerEfficiencyCells::GetOldEffHisto(Int_t histoType,
+                                                   Int_t ich, Int_t icath) const
 {
   //
-  // Sets our internal array contents to zero.
-  //
-  for(Int_t chamber=0; chamber<4; chamber++)
-  {
-    for(Int_t slat=0; slat<18; slat++)
-    {
-           for(Int_t cath=0; cath<2; cath++)
-      {
-        fCellSize[chamber][slat][cath]=0.0;
-        fCellNumber[chamber][slat][cath]=0;
-        for(Int_t ix=0; ix<fgkNofCells; ix++)
-        {
-          for(Int_t iy=0; iy<fgkNofCells; iy++)
-          {
-            fCellContent[chamber][slat][cath][ix][iy]=0.0;
-          }
-        }
-           }
-    }
+  /// Compatibility with old class
+  /// Gets the efficiency from the array
+  /// (which are empty in the new implementation)
+
+  switch ( histoType ) {
+  case kHboardCount:
+    return fBoardEfficiency[fgkNchambers*icath+ich];
+  case kHslatCount:
+    return fSlatEfficiency[fgkNchambers*icath+ich];
   }
+  return 0x0;
 }
-