* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-/*
-$Log$
-Revision 1.7 2002/10/23 07:24:57 alibrary
-Introducing Riostream.h
-
-Revision 1.6 2001/03/20 13:32:37 egangler
-includes cleanup
-
-Revision 1.5 2000/10/02 21:28:09 fca
-Removal of useless dependecies via forward declarations
-Revision 1.4 2000/10/02 16:58:29 egangler
-Cleaning of the code :
--> coding conventions
--> void Streamers
--> some useless includes removed or replaced by "class" statement
+/* $Id$ */
+
+//-----------------------------------------------------------------------------
+/// \class AliMUONTriggerLut
+///
+/// Local Trigger Look Up Table
+/// reading interface LUT data is stored into TH3S histograms and readout
+/// from the Local Trigger algorithm
+///
+/// Histograms structure is :
+/// X 234 bins, 1 to 235 = local board number
+/// Y 31 bins, 0 to 31 = x strip
+/// Z 31 bins, 0 to 31 = x deviation
+/// content = Short_t = y strip mask
+///
+/// overflow bin is used !
+///
+/// \author Philippe Crochet
+//-----------------------------------------------------------------------------
-Revision 1.3 2000/06/25 16:47:43 pcrochet
-pow replaced by TMath::Power
+#include "AliMUONTriggerLut.h"
-*/
+#include "AliLog.h"
-#include "AliMUONTriggerCircuit.h"
-#include "AliMUONTriggerLut.h"
-#include "TTree.h"
-#include "AliRun.h"
-#include "AliMUON.h"
-#include "TMath.h"
-#include "TFile.h"
-#include "TROOT.h"
-#include "TH3.h"
-#include <Riostream.h>
+#include <TFile.h>
+#include <TH3.h>
+#include <TMap.h>
+#include <TObjString.h>
+/// \cond CLASSIMP
ClassImp(AliMUONTriggerLut)
+/// \endcond
//----------------------------------------------------------------------
-AliMUONTriggerLut::AliMUONTriggerLut() {
-// constructor
- fLptPlus = fLptMinu = fLptUnde = 0;
- fHptPlus = fHptMinu = fHptUnde = 0;
- fAptPlus = fAptMinu = fAptUnde = 0;
+AliMUONTriggerLut::AliMUONTriggerLut()
+ : TNamed(),
+ fLptPlus(0),
+ fLptMinu(0),
+ fLptUnde(0),
+ fHptPlus(0),
+ fHptMinu(0),
+ fHptUnde(0),
+ fAptPlus(0),
+ fAptMinu(0),
+ fAptUnde(0),
+ fMap(0x0)
+{
+/// ctor
}
+
//----------------------------------------------------------------------
-AliMUONTriggerLut::~AliMUONTriggerLut() {
-// destructor
+AliMUONTriggerLut::~AliMUONTriggerLut()
+{
+/// Destructor
+
delete fLptPlus;
delete fLptMinu;
delete fLptUnde;
delete fAptPlus;
delete fAptMinu;
delete fAptUnde;
- fLptPlus = fLptMinu = fLptUnde = 0;
- fHptPlus = fHptMinu = fHptUnde = 0;
- fAptPlus = fAptMinu = fAptUnde = 0;
+ delete fMap;
}
//----------------------------------------------------------------------
-AliMUONTriggerLut::AliMUONTriggerLut (const AliMUONTriggerLut& MUONTriggerLut)
+Int_t
+AliMUONTriggerLut::Compare(TH3* h1, TH3* h2) const
{
-// Dummy copy constructor
+/// Return 0 if both histograms are strictly equal (at the bin-by-bin level)
+
+ AliDebug(1,Form("h1 %s h2 %s",h1 ? h1->GetName() : "null", h2 ? h2->GetName() : "null"));
+
+ if (!h1 || !h2)
+ {
+ return 0;
+ }
+ Int_t bin;
+ for ( Int_t ix = 0; ix <= h1->GetNbinsX()+1; ix++ )
+ for ( Int_t iy = 0; iy <= h1->GetNbinsY()+1; iy++ )
+ for ( Int_t iz = 0; iz <= h1->GetNbinsZ()+1; iz++ )
+ {
+ {
+ {
+ bin = h1->GetBin(ix,iy,iz);
+ Double_t x1 = h1->GetBinContent(bin);
+ Double_t x2 = h2->GetBinContent(bin);
+ if ( x1 != x2 ) return 0;
+ }
+ }
+ }
+
+ AliDebug(1,"same");
+
+ return 1;
}
//----------------------------------------------------------------------
-AliMUONTriggerLut & AliMUONTriggerLut::operator=(const AliMUONTriggerLut& MUONTriggerLut)
+Int_t
+AliMUONTriggerLut::Compare(const TObject* object) const
{
-// Dummy assignment operator
- return *this;
+/// Return 0 if the two luts are strictly equal
+
+ const AliMUONTriggerLut* lut = static_cast<const AliMUONTriggerLut*>(object);
+
+ Int_t rvLpt(0);
+
+ rvLpt += Compare(fLptPlus,lut->fLptPlus);
+ rvLpt += Compare(fLptMinu,lut->fLptMinu);
+ rvLpt += Compare(fLptUnde,lut->fLptUnde);
+
+ Int_t rvHpt(0);
+
+ rvHpt += Compare(fHptPlus,lut->fHptPlus);
+ rvHpt += Compare(fHptMinu,lut->fHptMinu);
+ rvHpt += Compare(fHptUnde,lut->fHptUnde);
+
+ Int_t rv(0);
+
+ rv += Compare(fAptPlus,lut->fAptPlus);
+ rv += Compare(fAptMinu,lut->fAptMinu);
+ rv += Compare(fAptUnde,lut->fAptUnde);
+
+ AliDebug(1,Form("Same Lpt %d Hpt %d Apt %d",rvLpt,rvHpt,rv));
+
+ if ( rvLpt == 3 && rvHpt == 3 )
+ {
+ return 0;
+ }
+
+ return 1;
}
//----------------------------------------------------------------------
-void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
- Int_t ystrip, Int_t lutLpt[2],
- Int_t lutHpt[2], Int_t lutApt[2]){
-// return output of LuT for corresponding TH3S
-
- static TFile *fileLut;
- static Bool_t first=kTRUE;
- if(first) {
- printf(" opening MUONTriggerLut.root \n");
- fileLut = new TFile("$(ALICE_ROOT)/MUON/MUONTriggerLut.root","READ");
- first=kFALSE;
+void AliMUONTriggerLut::ReadFromFile(const char* filename)
+{
+/// Return output of LuT for corresponding TH3S
+
+ TFile f(filename);
+
+ if ( f.IsZombie() )
+ {
+ AliFatal(Form("Could not open file %s",filename));
}
- fileLut->cd();
-
-// get the pointers to the TH3S objects of the file
- TH3S *lptPlus = (TH3S*)gROOT->FindObject("LptPlus");
- TH3S *lptMinu = (TH3S*)gROOT->FindObject("LptMinu");
- TH3S *lptUnde = (TH3S*)gROOT->FindObject("LptUnde");
- TH3S *hptPlus = (TH3S*)gROOT->FindObject("HptPlus");
- TH3S *hptMinu = (TH3S*)gROOT->FindObject("HptMinu");
- TH3S *hptUnde = (TH3S*)gROOT->FindObject("HptUnde");
- TH3S *aptPlus = (TH3S*)gROOT->FindObject("AptPlus");
- TH3S *aptMinu = (TH3S*)gROOT->FindObject("AptMinu");
- TH3S *aptUnde = (TH3S*)gROOT->FindObject("AptUnde");
+
+ AliDebug(1,Form("filename=%s",filename));
+
+ fLptPlus = (TH3*)(f.Get("LptPlus"));
+ fLptMinu = (TH3*)(f.Get("LptMinu"));
+ fLptUnde = (TH3*)(f.Get("LptUnde"));
+ fHptPlus = (TH3*)(f.Get("HptPlus"));
+ fHptMinu = (TH3*)(f.Get("HptMinu"));
+ fHptUnde = (TH3*)(f.Get("HptUnde"));
+ fAptPlus = (TH3*)(f.Get("AptPlus"));
+ fAptMinu = (TH3*)(f.Get("AptMinu"));
+ fAptUnde = (TH3*)(f.Get("AptUnde"));
+
+ // insure we "detach" those histograms from file f
+ fLptPlus->SetDirectory(0);
+ fLptMinu->SetDirectory(0);
+ fLptUnde->SetDirectory(0);
+ fHptPlus->SetDirectory(0);
+ fHptMinu->SetDirectory(0);
+ fHptUnde->SetDirectory(0);
+ fAptPlus->SetDirectory(0);
+ fAptMinu->SetDirectory(0);
+ fAptUnde->SetDirectory(0);
+
+ RegisterHistos();
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::RegisterHistos()
+{
+/// Add histos to our internal map
+
+ Add(fLptPlus);
+ Add(fLptMinu);
+ Add(fLptUnde);
+
+ Add(fHptPlus);
+ Add(fHptMinu);
+ Add(fHptUnde);
+ Add(fAptPlus);
+ Add(fAptMinu);
+ Add(fAptUnde);
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::Add(TH3* h)
+{
+ /// Update internal map
+ if (!fMap)
+ {
+ fMap = new TMap;
+ fMap->SetOwner(kTRUE);
+ }
+
+ if (h) fMap->Add(new TObjString(h->GetName()),h);
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::SetContent(const char* hname, Int_t icirc, UChar_t istripX,
+ UChar_t idev, Short_t value)
+{
+ /// Set the content of one bin of one histogram
+
+ if (!fMap)
+ {
+ //..........................................circuit/stripX/deviation
+ fLptPlus = new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
+ fLptMinu = new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
+ fLptUnde = new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
+
+ fHptPlus = new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
+ fHptMinu = new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
+ fHptUnde = new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
+
+ fAptPlus = new TH3S("AptPlus","AptPlus",234,0,234,31,0,31,31,0,31);
+ fAptMinu = new TH3S("AptMinu","AptMinu",234,0,234,31,0,31,31,0,31);
+ fAptUnde = new TH3S("AptUnde","AptUnde",234,0,234,31,0,31,31,0,31);
+
+ RegisterHistos();
+ }
+
+ TH3* h = static_cast<TH3*>(fMap->GetValue(hname));
+
+ Int_t bin = h->GetBin(icirc,istripX,idev);
+ h->SetBinContent(bin,value);
+}
+
+//----------------------------------------------------------------------
+void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
+ Int_t ystrip, Int_t lutLpt[2],
+ Int_t lutHpt[2]) const
+{
+/// Return output of LuT for corresponding TH3S
+
+ if ( !fLptPlus )
+ {
+ AliError("LUT not initialized");
+// ReadFromFile("$(ALICE_ROOT)/MUON/data/MUONTriggerLut.root");
+ }
+
Int_t bin;
Short_t binc;
Int_t mask = GetMask(ystrip); // get ystrip mask
// Low pt..............................................
- bin = lptPlus->GetBin(circuit,xstrip,idev);
- binc = (Short_t)lptPlus->GetBinContent(bin);
+ bin = fLptPlus->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fLptPlus->GetBinContent(bin);
if ((binc & mask)!=0) lutLpt[1]=1;
- bin = lptMinu->GetBin(circuit,xstrip,idev);
- binc = (Short_t)lptMinu->GetBinContent(bin);
+ bin = fLptMinu->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fLptMinu->GetBinContent(bin);
if ((binc & mask)!=0) lutLpt[0]=1;
- bin = lptUnde->GetBin(circuit,xstrip,idev);
- binc = (Short_t)lptUnde->GetBinContent(bin);
+ bin = fLptUnde->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fLptUnde->GetBinContent(bin);
if ((binc & mask)!=0) lutLpt[0]=lutLpt[1]=1;
// High pt.............................................
- bin = hptPlus->GetBin(circuit,xstrip,idev);
- binc = (Short_t)hptPlus->GetBinContent(bin);
+ bin = fHptPlus->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fHptPlus->GetBinContent(bin);
if ((binc & mask)!=0) lutHpt[1]=1;
- bin = hptMinu->GetBin(circuit,xstrip,idev);
- binc = (Short_t)hptMinu->GetBinContent(bin);
+ bin = fHptMinu->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fHptMinu->GetBinContent(bin);
if ((binc & mask)!=0) lutHpt[0]=1;
- bin = hptUnde->GetBin(circuit,xstrip,idev);
- binc = (Short_t)hptUnde->GetBinContent(bin);
+ bin = fHptUnde->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fHptUnde->GetBinContent(bin);
if ((binc & mask)!=0) lutHpt[0]=lutHpt[1]=1;
-
+/*
// All pts.............................................
- bin = aptPlus->GetBin(circuit,xstrip,idev);
- binc = (Short_t)aptPlus->GetBinContent(bin);
+ bin = fAptPlus->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fAptPlus->GetBinContent(bin);
if ((binc & mask)!=0) lutApt[1]=1;
- bin = aptMinu->GetBin(circuit,xstrip,idev);
- binc = (Short_t)aptMinu->GetBinContent(bin);
+ bin = fAptMinu->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fAptMinu->GetBinContent(bin);
if ((binc & mask)!=0) lutApt[0]=1;
- bin = aptUnde->GetBin(circuit,xstrip,idev);
- binc = (Short_t)aptUnde->GetBinContent(bin);
+ bin = fAptUnde->GetBin(circuit,xstrip,idev);
+ binc = (Short_t)fAptUnde->GetBinContent(bin);
if ((binc & mask)!=0) lutApt[0]=lutApt[1]=1;
-
-// get back to the first file
- TTree *tK = gAlice->TreeK();
- TFile *file1 = 0;
- if (tK) file1 = tK->GetCurrentFile();
- file1->cd();
+*/
}
//----------------------------------------------------------------------
-Int_t AliMUONTriggerLut::GetMask(Int_t ystrip){
-// returns the mask corresponding to ystrip
- Int_t tabMask[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- Int_t mask=0;
- tabMask[ystrip]=1;
- for (Int_t i=0; i<16; i++) {
- mask=mask+Int_t(tabMask[i]*TMath::Power(2,i));
- }
- return mask;
+Int_t AliMUONTriggerLut::GetMask(Int_t ystrip) const
+{
+/// Return the mask corresponding to ystrip
+
+ return (Int_t)(1<<ystrip);
}
//----------------------------------------------------------------------
-void AliMUONTriggerLut::LoadLut(){
-// !!!!!!! This is dummy version of the LoadLut method !!!!!!!
-// !!!!!!! calibration to be done !!!!!!!
-// 1) Loop on circuit/Xstrip1/deviation/Ystrip
-// 2) get corresponding ptCal from AliMUONTriggerCircuit
-// 3) fill histos with cuts on deviation, ptLow and ptHigh
-// 4) store histos in a file
-
- char fileName[60];
- sprintf(fileName,"$(ALICE_ROOT)/MUON/MUONTriggerLut.root");
- printf(" file name is %s\n",fileName);
-
-// open output file containing histos
- TFile *hfile = new TFile(fileName,"RECREATE","Trigger Look Up Table");
-
- //..........................................circuit/stripX/deviation
- TH3S *fLptPlus=new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
- TH3S *fLptMinu=new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
- TH3S *fLptUnde=new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
-
- TH3S *fHptPlus=new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
- TH3S *fHptMinu=new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
- TH3S *fHptUnde=new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
-
- TH3S *fAptPlus=new TH3S("AptPlus","AptPlus",234,0,234,31,0,31,31,0,31);
- TH3S *fAptMinu=new TH3S("AptMinu","AptMinu",234,0,234,31,0,31,31,0,31);
- TH3S *fAptUnde=new TH3S("AptUnde","AptUnde",234,0,234,31,0,31,31,0,31);
-
- Float_t lptTreshold=0.75;
- Float_t hptTreshold=1.75;
+void AliMUONTriggerLut::SetLutCode(const UChar_t lutCode)
+{
+/// Set the LUT code for the pair of cuts
+/// see AliMUONTriggerIO::ReadLUT for the definitions
- AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
- AliMUONTriggerCircuit* triggerCircuit;
-
- for (Int_t icirc=0; icirc<234; icirc++) {
- printf(" Loading LuT for circuit %d \n",icirc);
- triggerCircuit = &(pMUON->TriggerCircuit(icirc));
-
- for (Int_t istripX=0; istripX<31; istripX++) {
- for (Int_t idev=0; idev<31; idev++) {
-
- Short_t iLptPlus, iLptMinu, iLptUnde;
- Short_t iHptPlus, iHptMinu, iHptUnde;
- Short_t iAptPlus, iAptMinu, iAptUnde;
- iLptPlus = iLptMinu = iLptUnde = 0;
- iHptPlus = iHptMinu = iHptUnde = 0;
- iAptPlus = iAptMinu = iAptUnde = 0;
-
- for (Int_t istripY=0; istripY<16; istripY++) {
- Float_t pt=triggerCircuit->PtCal(istripX,idev,istripY);
-
- if (pt>lptTreshold) {
- if (idev<15) iLptMinu=iLptMinu+Int_t(TMath::Power(2,istripY));
- else if (idev==15) iLptUnde=iLptUnde+Int_t(TMath::Power(2,istripY));
- else if (idev>15) iLptPlus=iLptPlus+Int_t(TMath::Power(2,istripY));
- }
- if (pt>hptTreshold) {
- if (idev<15) iHptMinu=iHptMinu+Int_t(TMath::Power(2,istripY));
- else if (idev==15) iHptUnde=iHptUnde+Int_t(TMath::Power(2,istripY));
- else if (idev>15) iHptPlus=iHptPlus+Int_t(TMath::Power(2,istripY));
- }
- if (idev<15) iAptMinu=iAptMinu+Int_t(TMath::Power(2,istripY));
- else if (idev==15) iAptUnde=iAptUnde+Int_t(TMath::Power(2,istripY));
- else if (idev>15) iAptPlus=iAptPlus+Int_t(TMath::Power(2,istripY));
-
- } // loop on istripY
-
- Int_t bin;
-
- bin = fLptMinu->GetBin(icirc,istripX,idev);
- fLptMinu->SetBinContent(bin,iLptMinu);
- bin = fLptUnde->GetBin(icirc,istripX,idev);
- fLptUnde->SetBinContent(bin,iLptUnde);
- bin = fLptPlus->GetBin(icirc,istripX,idev);
- fLptPlus->SetBinContent(bin,iLptPlus);
-
- bin = fHptMinu->GetBin(icirc,istripX,idev);
- fHptMinu->SetBinContent(bin,iHptMinu);
- bin = fHptUnde->GetBin(icirc,istripX,idev);
- fHptUnde->SetBinContent(bin,iHptUnde);
- bin = fHptPlus->GetBin(icirc,istripX,idev);
- fHptPlus->SetBinContent(bin,iHptPlus);
-
- bin = fAptMinu->GetBin(icirc,istripX,idev);
- fAptMinu->SetBinContent(bin,iAptMinu);
- bin = fAptUnde->GetBin(icirc,istripX,idev);
- fAptUnde->SetBinContent(bin,iAptUnde);
- bin = fAptPlus->GetBin(icirc,istripX,idev);
- fAptPlus->SetBinContent(bin,iAptPlus);
-
- } // loop on idev
- } // loop on istripX
- } // loop on circuit
-
- hfile->Write();
- hfile->Close();
-}
-
+ if (!fMap) {
+ AliWarning("Nothing registered in the map ?... ");
+ return;
+ }
+ TH3* h = static_cast<TH3*>(fMap->GetValue("LptPlus"));
+ h->SetTitle(Form("LptPlus 0x%02x",lutCode));
+}
+//----------------------------------------------------------------------
+void AliMUONTriggerLut::PrintLutCode()
+{
+/// Print out the LUT code for the pair of cuts
+/// see AliMUONTriggerIO::ReadLUT for the definitions
+
+ TString lutCode = fLptPlus->GetTitle();
+ lutCode.Remove(0,8);
+ if (lutCode.Length() == 0) {
+ AliInfo("No code stored (older version).");
+ } else {
+ AliInfo(lutCode.Data());
+
+ AliInfo("---------------------------------");
+ AliInfo("1st/2nd cut code pt cut [GeV/c]");
+ AliInfo(" ");
+ AliInfo(" 0 0.5 (a.k.a. Apt)");
+ AliInfo(" 1 1.0 (a.k.a. Lpt)");
+ AliInfo(" 2 1.7 (a.k.a. Hpt)");
+ AliInfo(" 3 4.2 (a.k.a. infinity)");
+ AliInfo(" 4 free");
+ AliInfo(" .");
+ AliInfo(" .");
+ AliInfo(" .");
+ AliInfo("15 default (for backward compatibility)");
+ AliInfo("---------------------------------------");
+ }
+}