* provided "as is" without express or implied warranty. *
**************************************************************************/
-#include "AliMUONTriggerEfficiencyCells.h"
-#include "AliMpConstants.h"
-#include "AliMpDEManager.h"
+// $Id$
#include "AliLog.h"
+#include "AliMpConstants.h"
-#include "TRandom.h"
-#include "Riostream.h"
-#include "TSystem.h"
-#include "TFile.h"
#include "TH1F.h"
-#include "TMatrixF.h"
+#include "TFile.h"
#include <fstream>
#include <cassert>
+#include "AliMUONTriggerEfficiencyCells.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)
+/// A class to store and give access to the numerator and denominator
+/// histograms for the trigger chamber efficiency calculation.
///
-/// 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.
-///
-///
-/// 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
//__________________________________________________________________________
AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
:
-TObject()
+TObject(),
+fCountHistoList(0x0),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
{
/// Default constructor.
CheckConstants();
- Reset();
+ 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.
CheckConstants();
- Reset();
- ReadFile(filename);
-}
-
-
-//__________________________________________________________________________
-AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
-{
-/// Destructor. Does nothing ;-)
-}
-
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2) const
-{
-/// 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][cell.At(0)][cell.At(1)];
- eff2 = fCellContent[fgkNchambers+chamber][slat][cell.At(0)][cell.At(1)];
- }
-}
-
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2) const
-{
-/// Get the efficiencies of the 2 cathodes at a given local board
-
- Int_t chamber = FindChamberIndex(detElemId);
- eff1 = fBoardContent[chamber][localBoard-1];
- eff2 = fBoardContent[fgkNchambers+chamber][localBoard-1];
+ ResetHistos();
+ ReadFile(filename, listname);
}
-
//__________________________________________________________________________
-void
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2) const
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList)
+:
+TObject(),
+fCountHistoList(countHistoList),
+fNoCountHistoList(0x0),
+fFiredStrips(0x0)
{
-/// 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;
+/// Constructor using a list of histograms with counts.
+ CheckConstants();
+ ResetHistos();
}
-
-//__________________________________________________________________________
-void
-AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2) const
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
+:
+TObject(other),
+fCountHistoList(other.fCountHistoList),
+fNoCountHistoList(other.fNoCountHistoList),
+fFiredStrips(other.fFiredStrips)
{
-/// 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;
-}
+/// Copy constructor
-//__________________________________________________________________________
-TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y) const
-{
-/// Get the efficiencies at a given location.
-
- Int_t chamber = FindChamberIndex(detElemId);
- Int_t slat = FindSlatIndex(detElemId);
- Int_t cell[fgkNcathodes]={-1,-1};
- Float_t maxX = fCellSize[chamber][slat]*((Float_t)fCellNumber[chamber][slat]);
- Float_t maxY = fCellSize[fgkNchambers+chamber][slat]*((Float_t)fCellNumber[fgkNchambers+chamber][slat]);
- if(x>=0 & x<maxX & y>=0 & y<maxY)
- {
- cell[0] = (Int_t)(x/fCellSize[chamber][slat]);
- cell[1] = (Int_t)(y/fCellSize[fgkNchambers+chamber][slat]);
+ for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
+ fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
+ fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
}
- return TArrayI(fgkNcathodes,cell);
}
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
+//_____________________________________________________________________________
+AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
{
-/// Reads a file containing the efficiency map.
-
- TString fileName = gSystem->ExpandPathName(filename);
- if(fileName.EndsWith(".root")){
- ReadHistoBoards(fileName.Data());
- return;
- }
-
- 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()));
+ /// 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];
}
-}
-
-
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFileXY(ifstream &file)
-{
-/// Structure of file (.dat) containing geometrical efficency
- Int_t datInt=0, detEl=0, chamber=0, rpc=0, chCath=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<fgkNcathodes; i++){
- chCath = fgkNchambers*i + chamber;
- file >> datInt;
- fCellNumber[chCath][rpc] = datInt;
- file >> dat;
- }
- for(Int_t i=0; i<fgkNcathodes; i++){
- chCath = fgkNchambers*i + chamber;
- file >> datFloat;
- fCellSize[chCath][rpc] = datFloat;
- if(i==0)file >> dat;
- }
- for(Int_t cath=0; cath<fgkNcathodes; cath++){
- chCath = fgkNchambers*cath + chamber;
- file >> dat;
- file >> datInt;
- for(Int_t iy=0; iy<fCellNumber[fgkNchambers+chamber][rpc]; iy++){
- for(Int_t ix=0; ix<fCellNumber[chamber][rpc]; ix++){
- file >> datFloat;
- fCellContent[chCath][rpc][ix][iy] = datFloat;
- }
- }
- }
- }
-}
-//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
-{
-/// Structure of file (.dat) containing local board efficency
- Int_t datInt=0, detEl=0, chamber=0, chCath=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<fgkNcathodes; cath++){
- chCath = fgkNchambers*cath + chamber;
- file >> dat;
- file >> datInt;
- for(Int_t board=0; board<AliMpConstants::NofLocalBoards(); board++){
- file >> datFloat;
- fBoardContent[chCath][board] = datFloat;
- }
- }
- }
+ fCountHistoList = other.fCountHistoList;
+ fNoCountHistoList = other.fNoCountHistoList;
+ fFiredStrips = other.fFiredStrips;
+
+ return *this;
}
-
//__________________________________________________________________________
-void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const char *filename)
+AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
{
-/// Structure of file (.root) containing local board efficency
- TFile *file = new TFile(filename, "read");
- if(!file) {
- AliWarning(Form("Can't read file %s",filename));
- return;
- }
- char histoName[30];
- char *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
- TH1F *histo = 0x0;
- for(Int_t ch=0; ch<fgkNchambers; ch++){
- for(Int_t cath=0; cath<fgkNcathodes; cath++){
- sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
- histo = (TH1F *)file->Get(histoName);
- if(!(TH1F *)file->Get(histoName)) {
- AliWarning(Form("Can't find histo %s in file %s",histoName, filename));
- continue;
- }
- Int_t chCath = fgkNchambers*cath + ch;
- for(Int_t board=0; board<AliMpConstants::NofLocalBoards(); board++){
- Int_t bin = histo->FindBin(board+1);
- fBoardContent[chCath][board] = histo->GetBinContent(bin);
- }
- }
- }
+/// Destructor.
+ //delete [] fBoardEfficiency;
+ //delete [] fSlatEfficiency;
+ ResetHistos(kTRUE);
+ delete fCountHistoList;
+ delete fNoCountHistoList;
+ delete fFiredStrips;
}
//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId) const
+void
+AliMUONTriggerEfficiencyCells::ResetHistos(Bool_t deleteObjects)
{
-/// From detElemId to chamber number
- Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
- Int_t chamber = iChamber-AliMpConstants::NofTrackingChambers();
- return chamber;
+/// 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;
+ }
}
//__________________________________________________________________________
-Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId) const
+void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename, const Char_t* listname)
{
-/// From detElemId to slat index.
- Int_t slat = detElemId%100;
- return slat;
+/// 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();
+ }
+
+ 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)
+ //
+ /// 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 chCath=0; chCath<fgkNplanes; chCath++){
- fBoardContent[chCath].Set(AliMpConstants::NofLocalBoards());
- fCellSize[chCath].Set(fgkNslats);
- fCellNumber[chCath].Set(fgkNslats);
- for(Int_t slat=0; slat<fgkNslats; slat++){
- fCellContent[chCath][slat].ResizeTo(fgkNcells,fgkNcells);
- }
- }
-
- for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
- fBoardContent[chCath].Reset();
- fCellSize[chCath].Reset();
- fCellNumber[chCath].Reset();
- for(Int_t slat=0; slat<fgkNslats; slat++){
- fCellContent[chCath][slat].Zero();
- }
- }
+ //
+ /// 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;
}
-
-