* provided "as is" without express or implied warranty. *
**************************************************************************/
+// $Id$
+
+#include "AliLog.h"
+#include "AliMpConstants.h"
+
+#include "TH1F.h"
+#include "TFile.h"
+
#include <fstream>
-#include <TRandom.h>
-#include "Riostream.h"
-#include "TSystem.h"
+#include <cassert>
#include "AliMUONTriggerEfficiencyCells.h"
-#include "AliMpConstants.h"
-#include "AliLog.h"
+
+//-----------------------------------------------------------------------------
/// \class AliMUONTriggerEfficiencyCells
-/// A class to store and give access to the trigger chamber efficiency.
-///
-/// Efficiency is stored per cathode on local boards, or, alternatively,
-/// 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).
-///
-/// In the case of local boards, efficiency is stored from left to right
-/// per increasing board number (from 1 to 234)
-///
-/// Otherwise, he 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:
-///
-/// <pre>
-/// 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
-/// </pre>
-///
-/// In both cases, the file can be edited in order to change efficiency
-/// in a chosen local board/region of the chamber.
-///
+/// A class to store and give access to the numerator and denominator
+/// histograms for the trigger chamber efficiency calculation.
///
-/// But please note that this object is also available from the CDB
-/// (generated using the MUONCDB.C macro)
-///
-/// \author Diego Stocco; INFN Torino
+/// \author Diego Stocco; Subatech, Nantes
+//-----------------------------------------------------------------------------
/// \cond CLASSIMP
ClassImp(AliMUONTriggerEfficiencyCells)
//__________________________________________________________________________
AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
:
-TObject()
+TObject(),
+fCountHistoList(0x0),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
{
/// Default constructor.
- Reset();
+ 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)
{
/// Constructor using an ASCII file.
- Reset();
- ReadFile(filename);
+ CheckConstants();
+ ResetHistos();
+ ReadFile(filename, listname);
}
-
//__________________________________________________________________________
-AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList)
+:
+TObject(),
+fCountHistoList(countHistoList),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
{
-/// Destructor. Does nothing ;-)
+/// Constructor using a list of histograms with counts.
+ CheckConstants();
+ ResetHistos();
}
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2)
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
+:
+TObject(other),
+fCountHistoList(other.fCountHistoList),
+fNoCountHistoList(other.fNoCountHistoList),
+fFiredStrips(other.fFiredStrips)
{
-/// Get the efficiencies of the 2 cathodes 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)];
+/// Copy constructor
+
+ for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+ fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
+ fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
}
}
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2)
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
{
-/// Get the efficiencies of the 2 cathodes at a given local board
+ /// 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];
+ }
- Int_t chamber = FindChamberIndex(detElemId);
- eff1 = fBoardContent[chamber][0][localBoard];
- eff2 = fBoardContent[chamber][1][localBoard];
+ fCountHistoList = other.fCountHistoList;
+ fNoCountHistoList = other.fNoCountHistoList;
+ fFiredStrips = other.fFiredStrips;
+
+ return *this;
}
-
//__________________________________________________________________________
-void
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2)
+AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
{
-/// 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;
+/// Destructor.
+ //delete [] fBoardEfficiency;
+ //delete [] fSlatEfficiency;
+ ResetHistos(kTRUE);
+ delete fCountHistoList;
+ delete fNoCountHistoList;
+ delete fFiredStrips;
}
-//__________________________________________________________________________
-void
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2)
+//_____________________________________________________________________________
+void AliMUONTriggerEfficiencyCells::CheckConstants() const
{
-/// Whether or not a given local board has a chance to trig, on each cathode.
-
- Float_t eff1 = 0.0;
- Float_t eff2 = 0.0;
- GetCellEfficiency(detElemId, localBoard, eff1, eff2);
- trig1 = kTRUE;
- trig2 = kTRUE;
- if(gRandom->Rndm()>eff1)trig1 = kFALSE;
- if(gRandom->Rndm()>eff2)trig2 = kFALSE;
-}
+/// Check consistence of redefined constants
-//__________________________________________________________________________
-TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y)
-{
-/// 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);
+ assert(fgkNcathodes == AliMpConstants::NofCathodes());
+ assert(fgkNchambers == AliMpConstants::NofTriggerChambers());
+ assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);
}
+
//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
+void
+AliMUONTriggerEfficiencyCells::ResetHistos(Bool_t deleteObjects)
{
-/// Reads a file containing the efficiency map.
-
- TString fileName = gSystem->ExpandPathName(filename);
- ifstream file(fileName.Data());
- char dat[50];
- if (file.good()){
- file >> dat;
- if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
- else ReadFileXY(file);
- file.close();
- } else {
- AliWarning(Form("Can't read file %s",fileName.Data()));
+/// Sets our internal array contents to zero.
+
+ for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+ if ( deleteObjects ) {
+ delete fBoardEfficiency[chCath];
+ delete fSlatEfficiency[chCath];
+ }
+ fBoardEfficiency[chCath] = 0x0;
+ fSlatEfficiency[chCath] = 0x0;
}
}
//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFileXY(ifstream &file)
+void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename, const Char_t* listname)
{
-/// Structure of file containing geometrical efficency
- Int_t datInt=0, detEl=0, chamber=0, rpc=0;
- Float_t datFloat=0.0;
- char dat[50];
-
- 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;
- }
- }
- }
+/// Structure of file (.root) containing local board efficency
+ TFile *file = new TFile(filename, "read");
+ if(!file || !file->IsOpen()) {
+ AliError(Form("Can't read file %s",filename));
+ return;
}
-}
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
-{
-/// Structure of file containing local board efficency
- Int_t datInt=0, detEl=0, chamber=0;
- Float_t datFloat=0.0;
- char dat[50];
-
- while (file >> dat) {
- file >> detEl;
- chamber = FindChamberIndex(detEl);
- //rpc = FindSlatIndex(detEl);
- for(Int_t cath=0; cath<2; cath++){
- file >> dat;
- file >> datInt;
- for(Int_t board=0; board<fgkNofBoards; board++){
- file >> datFloat;
- fBoardContent[chamber][cath][board] = datFloat;
- }
- }
+ if ( ! fCountHistoList ) {
+ fCountHistoList = new TList();
+ fCountHistoList->SetOwner();
}
-}
-//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId)
-{
-/// From detElemId to chamber number
-
- Int_t offset = 100*(AliMpConstants::NofTrackingChambers()+1);
- Int_t chamber = (detElemId-offset)/100;
- return chamber;
-}
-
-
-//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
-{
-/// From detElemId to slat index.
+ 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
- Int_t offset = 100*(AliMpConstants::NofTrackingChambers()+1);
- Int_t chamber = FindChamberIndex(detElemId);
- Int_t slat = detElemId-offset-(chamber*100);
- return slat;
+ 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)
+ //
+ /// 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);
+ }
- Float_t x1 = x0-x;//reflection of axis
- Float_t y1 = y+y0;
- return TVector2(x1,y1);
+ 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;
- }
- }
- }
- }
- for(Int_t cath=0; cath<2; cath++)
- {
- for(Int_t board=0; board<fgkNofBoards; board++)
- {
- fBoardContent[chamber][cath][board]=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;
}
-