New code from Piergiorgio added
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerLut.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15/*
c1651df4 16$Log$
ecfa008b 17Revision 1.3 2000/06/25 16:47:43 pcrochet
18pow replaced by TMath::Power
19
a9e2aefa 20*/
c1651df4 21
ecfa008b 22#include "AliMUONTriggerCircuit.h"
a9e2aefa 23#include "AliMUONTriggerLut.h"
24#include "TTree.h"
25#include "AliRun.h"
26#include "AliMUON.h"
27#include "AliMUONPoints.h"
28#include "TMath.h"
29#include "TFile.h"
30#include "TH3.h"
ecfa008b 31#include <iostream.h>
a9e2aefa 32
33ClassImp(AliMUONTriggerLut)
34
35//----------------------------------------------------------------------
36AliMUONTriggerLut::AliMUONTriggerLut() {
37// constructor
38 fLptPlus = fLptMinu = fLptUnde = 0;
39 fHptPlus = fHptMinu = fHptUnde = 0;
40 fAptPlus = fAptMinu = fAptUnde = 0;
41}
42//----------------------------------------------------------------------
43AliMUONTriggerLut::~AliMUONTriggerLut() {
44// destructor
45 delete fLptPlus;
46 delete fLptMinu;
47 delete fLptUnde;
48 delete fHptPlus;
49 delete fHptMinu;
50 delete fHptUnde;
51 delete fAptPlus;
52 delete fAptMinu;
53 delete fAptUnde;
54 fLptPlus = fLptMinu = fLptUnde = 0;
55 fHptPlus = fHptMinu = fHptUnde = 0;
56 fAptPlus = fAptMinu = fAptUnde = 0;
57}
58
59//----------------------------------------------------------------------
60AliMUONTriggerLut::AliMUONTriggerLut (const AliMUONTriggerLut& MUONTriggerLut)
61{
62// Dummy copy constructor
63}
64
65//----------------------------------------------------------------------
66AliMUONTriggerLut & AliMUONTriggerLut::operator=(const AliMUONTriggerLut& MUONTriggerLut)
67{
68// Dummy assignment operator
69 return *this;
70}
71
72//----------------------------------------------------------------------
73void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
74 Int_t ystrip, Int_t lutLpt[2],
75 Int_t lutHpt[2], Int_t lutApt[2]){
76// return output of LuT for corresponding TH3S
77
78 static TFile *fileLut;
79 static Bool_t first=kTRUE;
80 if(first) {
81 cout << " opening MUONTriggerLut.root " << "\n";
82 fileLut = new TFile("$(ALICE_ROOT)/MUON/MUONTriggerLut.root","READ");
83 first=kFALSE;
84 }
85 fileLut->cd();
86
87// get the pointers to the TH3S objects of the file
88 TH3S *lptPlus = (TH3S*)gROOT->FindObject("LptPlus");
89 TH3S *lptMinu = (TH3S*)gROOT->FindObject("LptMinu");
90 TH3S *lptUnde = (TH3S*)gROOT->FindObject("LptUnde");
91 TH3S *hptPlus = (TH3S*)gROOT->FindObject("HptPlus");
92 TH3S *hptMinu = (TH3S*)gROOT->FindObject("HptMinu");
93 TH3S *hptUnde = (TH3S*)gROOT->FindObject("HptUnde");
94 TH3S *aptPlus = (TH3S*)gROOT->FindObject("AptPlus");
95 TH3S *aptMinu = (TH3S*)gROOT->FindObject("AptMinu");
96 TH3S *aptUnde = (TH3S*)gROOT->FindObject("AptUnde");
97
98 Int_t bin;
99 Short_t binc;
100 Int_t mask = GetMask(ystrip); // get ystrip mask
101
102 // Low pt..............................................
103 bin = lptPlus->GetBin(circuit,xstrip,idev);
104 binc = (Short_t)lptPlus->GetBinContent(bin);
105 if ((binc & mask)!=0) lutLpt[1]=1;
106
107 bin = lptMinu->GetBin(circuit,xstrip,idev);
108 binc = (Short_t)lptMinu->GetBinContent(bin);
109 if ((binc & mask)!=0) lutLpt[0]=1;
110
111 bin = lptUnde->GetBin(circuit,xstrip,idev);
112 binc = (Short_t)lptUnde->GetBinContent(bin);
113 if ((binc & mask)!=0) lutLpt[0]=lutLpt[1]=1;
114
115 // High pt.............................................
116 bin = hptPlus->GetBin(circuit,xstrip,idev);
117 binc = (Short_t)hptPlus->GetBinContent(bin);
118 if ((binc & mask)!=0) lutHpt[1]=1;
119
120 bin = hptMinu->GetBin(circuit,xstrip,idev);
121 binc = (Short_t)hptMinu->GetBinContent(bin);
122 if ((binc & mask)!=0) lutHpt[0]=1;
123
124 bin = hptUnde->GetBin(circuit,xstrip,idev);
125 binc = (Short_t)hptUnde->GetBinContent(bin);
126 if ((binc & mask)!=0) lutHpt[0]=lutHpt[1]=1;
127
128 // All pts.............................................
129 bin = aptPlus->GetBin(circuit,xstrip,idev);
130 binc = (Short_t)aptPlus->GetBinContent(bin);
131 if ((binc & mask)!=0) lutApt[1]=1;
132
133 bin = aptMinu->GetBin(circuit,xstrip,idev);
134 binc = (Short_t)aptMinu->GetBinContent(bin);
135 if ((binc & mask)!=0) lutApt[0]=1;
136
137 bin = aptUnde->GetBin(circuit,xstrip,idev);
138 binc = (Short_t)aptUnde->GetBinContent(bin);
139 if ((binc & mask)!=0) lutApt[0]=lutApt[1]=1;
140
141// get back to the first file
142 TTree *tK = gAlice->TreeK();
143 TFile *file1 = 0;
144 if (tK) file1 = tK->GetCurrentFile();
145 file1->cd();
146}
147
148//----------------------------------------------------------------------
149Int_t AliMUONTriggerLut::GetMask(Int_t ystrip){
150// returns the mask corresponding to ystrip
151 Int_t tabMask[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
152 Int_t mask=0;
153 tabMask[ystrip]=1;
154 for (Int_t i=0; i<16; i++) {
c1651df4 155 mask=mask+Int_t(tabMask[i]*TMath::Power(2,i));
a9e2aefa 156 }
157 return mask;
158}
159
160//----------------------------------------------------------------------
161void AliMUONTriggerLut::LoadLut(){
162// !!!!!!! This is dummy version of the LoadLut method !!!!!!!
163// !!!!!!! calibration to be done !!!!!!!
164// 1) Loop on circuit/Xstrip1/deviation/Ystrip
165// 2) get corresponding ptCal from AliMUONTriggerCircuit
166// 3) fill histos with cuts on deviation, ptLow and ptHigh
167// 4) store histos in a file
168
169 char fileName[60];
170 sprintf(fileName,"$(ALICE_ROOT)/MUON/MUONTriggerLut.root");
171 cout << " file name is " << fileName << "\n";
172
173// open output file containing histos
174 TFile *hfile = new TFile(fileName,"RECREATE","Trigger Look Up Table");
175
176 //..........................................circuit/stripX/deviation
177 TH3S *fLptPlus=new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
178 TH3S *fLptMinu=new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
179 TH3S *fLptUnde=new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
180
181 TH3S *fHptPlus=new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
182 TH3S *fHptMinu=new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
183 TH3S *fHptUnde=new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
184
185 TH3S *fAptPlus=new TH3S("AptPlus","AptPlus",234,0,234,31,0,31,31,0,31);
186 TH3S *fAptMinu=new TH3S("AptMinu","AptMinu",234,0,234,31,0,31,31,0,31);
187 TH3S *fAptUnde=new TH3S("AptUnde","AptUnde",234,0,234,31,0,31,31,0,31);
188
189 Float_t lptTreshold=0.75;
190 Float_t hptTreshold=1.75;
191
192 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
193 AliMUONTriggerCircuit* triggerCircuit;
194
195 for (Int_t icirc=0; icirc<234; icirc++) {
196 cout << " Loading LuT for circuit " << icirc << " of 234 " << "\n";
197 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
198
199 for (Int_t istripX=0; istripX<31; istripX++) {
200 for (Int_t idev=0; idev<31; idev++) {
201
202 Short_t iLptPlus, iLptMinu, iLptUnde;
203 Short_t iHptPlus, iHptMinu, iHptUnde;
204 Short_t iAptPlus, iAptMinu, iAptUnde;
205 iLptPlus = iLptMinu = iLptUnde = 0;
206 iHptPlus = iHptMinu = iHptUnde = 0;
207 iAptPlus = iAptMinu = iAptUnde = 0;
208
209 for (Int_t istripY=0; istripY<16; istripY++) {
210 Float_t pt=triggerCircuit->PtCal(istripX,idev,istripY);
211
212 if (pt>lptTreshold) {
c1651df4 213 if (idev<15) iLptMinu=iLptMinu+Int_t(TMath::Power(2,istripY));
214 else if (idev==15) iLptUnde=iLptUnde+Int_t(TMath::Power(2,istripY));
215 else if (idev>15) iLptPlus=iLptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 216 }
217 if (pt>hptTreshold) {
c1651df4 218 if (idev<15) iHptMinu=iHptMinu+Int_t(TMath::Power(2,istripY));
219 else if (idev==15) iHptUnde=iHptUnde+Int_t(TMath::Power(2,istripY));
220 else if (idev>15) iHptPlus=iHptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 221 }
c1651df4 222 if (idev<15) iAptMinu=iAptMinu+Int_t(TMath::Power(2,istripY));
223 else if (idev==15) iAptUnde=iAptUnde+Int_t(TMath::Power(2,istripY));
224 else if (idev>15) iAptPlus=iAptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 225
226 } // loop on istripY
227
228 Int_t bin;
229
230 bin = fLptMinu->GetBin(icirc,istripX,idev);
231 fLptMinu->SetBinContent(bin,iLptMinu);
232 bin = fLptUnde->GetBin(icirc,istripX,idev);
233 fLptUnde->SetBinContent(bin,iLptUnde);
234 bin = fLptPlus->GetBin(icirc,istripX,idev);
235 fLptPlus->SetBinContent(bin,iLptPlus);
236
237 bin = fHptMinu->GetBin(icirc,istripX,idev);
238 fHptMinu->SetBinContent(bin,iHptMinu);
239 bin = fHptUnde->GetBin(icirc,istripX,idev);
240 fHptUnde->SetBinContent(bin,iHptUnde);
241 bin = fHptPlus->GetBin(icirc,istripX,idev);
242 fHptPlus->SetBinContent(bin,iHptPlus);
243
244 bin = fAptMinu->GetBin(icirc,istripX,idev);
245 fAptMinu->SetBinContent(bin,iAptMinu);
246 bin = fAptUnde->GetBin(icirc,istripX,idev);
247 fAptUnde->SetBinContent(bin,iAptUnde);
248 bin = fAptPlus->GetBin(icirc,istripX,idev);
249 fAptPlus->SetBinContent(bin,iAptPlus);
250
251 } // loop on idev
252 } // loop on istripX
253 } // loop on circuit
254
255 hfile->Write();
256 hfile->Close();
257}
258
259
260
261
262
263
264