Adaption to new fluka common blocks (E. Futo)
[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$
cbc57deb 17Revision 1.7 2002/10/23 07:24:57 alibrary
18Introducing Riostream.h
19
70479d0e 20Revision 1.6 2001/03/20 13:32:37 egangler
21includes cleanup
22
b6ae9e79 23Revision 1.5 2000/10/02 21:28:09 fca
24Removal of useless dependecies via forward declarations
25
94de3818 26Revision 1.4 2000/10/02 16:58:29 egangler
27Cleaning of the code :
28-> coding conventions
29-> void Streamers
30-> some useless includes removed or replaced by "class" statement
31
ecfa008b 32Revision 1.3 2000/06/25 16:47:43 pcrochet
33pow replaced by TMath::Power
34
a9e2aefa 35*/
c1651df4 36
ecfa008b 37#include "AliMUONTriggerCircuit.h"
a9e2aefa 38#include "AliMUONTriggerLut.h"
39#include "TTree.h"
40#include "AliRun.h"
41#include "AliMUON.h"
a9e2aefa 42#include "TMath.h"
43#include "TFile.h"
94de3818 44#include "TROOT.h"
a9e2aefa 45#include "TH3.h"
70479d0e 46#include <Riostream.h>
a9e2aefa 47
48ClassImp(AliMUONTriggerLut)
49
50//----------------------------------------------------------------------
51AliMUONTriggerLut::AliMUONTriggerLut() {
52// constructor
53 fLptPlus = fLptMinu = fLptUnde = 0;
54 fHptPlus = fHptMinu = fHptUnde = 0;
55 fAptPlus = fAptMinu = fAptUnde = 0;
56}
57//----------------------------------------------------------------------
58AliMUONTriggerLut::~AliMUONTriggerLut() {
59// destructor
60 delete fLptPlus;
61 delete fLptMinu;
62 delete fLptUnde;
63 delete fHptPlus;
64 delete fHptMinu;
65 delete fHptUnde;
66 delete fAptPlus;
67 delete fAptMinu;
68 delete fAptUnde;
69 fLptPlus = fLptMinu = fLptUnde = 0;
70 fHptPlus = fHptMinu = fHptUnde = 0;
71 fAptPlus = fAptMinu = fAptUnde = 0;
72}
73
74//----------------------------------------------------------------------
75AliMUONTriggerLut::AliMUONTriggerLut (const AliMUONTriggerLut& MUONTriggerLut)
76{
77// Dummy copy constructor
78}
79
80//----------------------------------------------------------------------
81AliMUONTriggerLut & AliMUONTriggerLut::operator=(const AliMUONTriggerLut& MUONTriggerLut)
82{
83// Dummy assignment operator
84 return *this;
85}
86
87//----------------------------------------------------------------------
88void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
89 Int_t ystrip, Int_t lutLpt[2],
90 Int_t lutHpt[2], Int_t lutApt[2]){
91// return output of LuT for corresponding TH3S
92
93 static TFile *fileLut;
94 static Bool_t first=kTRUE;
95 if(first) {
cbc57deb 96 printf(" opening MUONTriggerLut.root \n");
a9e2aefa 97 fileLut = new TFile("$(ALICE_ROOT)/MUON/MUONTriggerLut.root","READ");
98 first=kFALSE;
99 }
100 fileLut->cd();
101
102// get the pointers to the TH3S objects of the file
103 TH3S *lptPlus = (TH3S*)gROOT->FindObject("LptPlus");
104 TH3S *lptMinu = (TH3S*)gROOT->FindObject("LptMinu");
105 TH3S *lptUnde = (TH3S*)gROOT->FindObject("LptUnde");
106 TH3S *hptPlus = (TH3S*)gROOT->FindObject("HptPlus");
107 TH3S *hptMinu = (TH3S*)gROOT->FindObject("HptMinu");
108 TH3S *hptUnde = (TH3S*)gROOT->FindObject("HptUnde");
109 TH3S *aptPlus = (TH3S*)gROOT->FindObject("AptPlus");
110 TH3S *aptMinu = (TH3S*)gROOT->FindObject("AptMinu");
111 TH3S *aptUnde = (TH3S*)gROOT->FindObject("AptUnde");
112
113 Int_t bin;
114 Short_t binc;
115 Int_t mask = GetMask(ystrip); // get ystrip mask
116
117 // Low pt..............................................
118 bin = lptPlus->GetBin(circuit,xstrip,idev);
119 binc = (Short_t)lptPlus->GetBinContent(bin);
120 if ((binc & mask)!=0) lutLpt[1]=1;
121
122 bin = lptMinu->GetBin(circuit,xstrip,idev);
123 binc = (Short_t)lptMinu->GetBinContent(bin);
124 if ((binc & mask)!=0) lutLpt[0]=1;
125
126 bin = lptUnde->GetBin(circuit,xstrip,idev);
127 binc = (Short_t)lptUnde->GetBinContent(bin);
128 if ((binc & mask)!=0) lutLpt[0]=lutLpt[1]=1;
129
130 // High pt.............................................
131 bin = hptPlus->GetBin(circuit,xstrip,idev);
132 binc = (Short_t)hptPlus->GetBinContent(bin);
133 if ((binc & mask)!=0) lutHpt[1]=1;
134
135 bin = hptMinu->GetBin(circuit,xstrip,idev);
136 binc = (Short_t)hptMinu->GetBinContent(bin);
137 if ((binc & mask)!=0) lutHpt[0]=1;
138
139 bin = hptUnde->GetBin(circuit,xstrip,idev);
140 binc = (Short_t)hptUnde->GetBinContent(bin);
141 if ((binc & mask)!=0) lutHpt[0]=lutHpt[1]=1;
142
143 // All pts.............................................
144 bin = aptPlus->GetBin(circuit,xstrip,idev);
145 binc = (Short_t)aptPlus->GetBinContent(bin);
146 if ((binc & mask)!=0) lutApt[1]=1;
147
148 bin = aptMinu->GetBin(circuit,xstrip,idev);
149 binc = (Short_t)aptMinu->GetBinContent(bin);
150 if ((binc & mask)!=0) lutApt[0]=1;
151
152 bin = aptUnde->GetBin(circuit,xstrip,idev);
153 binc = (Short_t)aptUnde->GetBinContent(bin);
154 if ((binc & mask)!=0) lutApt[0]=lutApt[1]=1;
155
156// get back to the first file
157 TTree *tK = gAlice->TreeK();
158 TFile *file1 = 0;
159 if (tK) file1 = tK->GetCurrentFile();
160 file1->cd();
161}
162
163//----------------------------------------------------------------------
164Int_t AliMUONTriggerLut::GetMask(Int_t ystrip){
165// returns the mask corresponding to ystrip
166 Int_t tabMask[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
167 Int_t mask=0;
168 tabMask[ystrip]=1;
169 for (Int_t i=0; i<16; i++) {
c1651df4 170 mask=mask+Int_t(tabMask[i]*TMath::Power(2,i));
a9e2aefa 171 }
172 return mask;
173}
174
175//----------------------------------------------------------------------
176void AliMUONTriggerLut::LoadLut(){
177// !!!!!!! This is dummy version of the LoadLut method !!!!!!!
178// !!!!!!! calibration to be done !!!!!!!
179// 1) Loop on circuit/Xstrip1/deviation/Ystrip
180// 2) get corresponding ptCal from AliMUONTriggerCircuit
181// 3) fill histos with cuts on deviation, ptLow and ptHigh
182// 4) store histos in a file
183
184 char fileName[60];
185 sprintf(fileName,"$(ALICE_ROOT)/MUON/MUONTriggerLut.root");
cbc57deb 186 printf(" file name is %s\n",fileName);
a9e2aefa 187
188// open output file containing histos
189 TFile *hfile = new TFile(fileName,"RECREATE","Trigger Look Up Table");
190
191 //..........................................circuit/stripX/deviation
192 TH3S *fLptPlus=new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
193 TH3S *fLptMinu=new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
194 TH3S *fLptUnde=new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
195
196 TH3S *fHptPlus=new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
197 TH3S *fHptMinu=new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
198 TH3S *fHptUnde=new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
199
200 TH3S *fAptPlus=new TH3S("AptPlus","AptPlus",234,0,234,31,0,31,31,0,31);
201 TH3S *fAptMinu=new TH3S("AptMinu","AptMinu",234,0,234,31,0,31,31,0,31);
202 TH3S *fAptUnde=new TH3S("AptUnde","AptUnde",234,0,234,31,0,31,31,0,31);
203
204 Float_t lptTreshold=0.75;
205 Float_t hptTreshold=1.75;
206
207 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
208 AliMUONTriggerCircuit* triggerCircuit;
209
210 for (Int_t icirc=0; icirc<234; icirc++) {
cbc57deb 211 printf(" Loading LuT for circuit %d \n",icirc);
a9e2aefa 212 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
213
214 for (Int_t istripX=0; istripX<31; istripX++) {
215 for (Int_t idev=0; idev<31; idev++) {
216
217 Short_t iLptPlus, iLptMinu, iLptUnde;
218 Short_t iHptPlus, iHptMinu, iHptUnde;
219 Short_t iAptPlus, iAptMinu, iAptUnde;
220 iLptPlus = iLptMinu = iLptUnde = 0;
221 iHptPlus = iHptMinu = iHptUnde = 0;
222 iAptPlus = iAptMinu = iAptUnde = 0;
223
224 for (Int_t istripY=0; istripY<16; istripY++) {
225 Float_t pt=triggerCircuit->PtCal(istripX,idev,istripY);
226
227 if (pt>lptTreshold) {
c1651df4 228 if (idev<15) iLptMinu=iLptMinu+Int_t(TMath::Power(2,istripY));
229 else if (idev==15) iLptUnde=iLptUnde+Int_t(TMath::Power(2,istripY));
230 else if (idev>15) iLptPlus=iLptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 231 }
232 if (pt>hptTreshold) {
c1651df4 233 if (idev<15) iHptMinu=iHptMinu+Int_t(TMath::Power(2,istripY));
234 else if (idev==15) iHptUnde=iHptUnde+Int_t(TMath::Power(2,istripY));
235 else if (idev>15) iHptPlus=iHptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 236 }
c1651df4 237 if (idev<15) iAptMinu=iAptMinu+Int_t(TMath::Power(2,istripY));
238 else if (idev==15) iAptUnde=iAptUnde+Int_t(TMath::Power(2,istripY));
239 else if (idev>15) iAptPlus=iAptPlus+Int_t(TMath::Power(2,istripY));
a9e2aefa 240
241 } // loop on istripY
242
243 Int_t bin;
244
245 bin = fLptMinu->GetBin(icirc,istripX,idev);
246 fLptMinu->SetBinContent(bin,iLptMinu);
247 bin = fLptUnde->GetBin(icirc,istripX,idev);
248 fLptUnde->SetBinContent(bin,iLptUnde);
249 bin = fLptPlus->GetBin(icirc,istripX,idev);
250 fLptPlus->SetBinContent(bin,iLptPlus);
251
252 bin = fHptMinu->GetBin(icirc,istripX,idev);
253 fHptMinu->SetBinContent(bin,iHptMinu);
254 bin = fHptUnde->GetBin(icirc,istripX,idev);
255 fHptUnde->SetBinContent(bin,iHptUnde);
256 bin = fHptPlus->GetBin(icirc,istripX,idev);
257 fHptPlus->SetBinContent(bin,iHptPlus);
258
259 bin = fAptMinu->GetBin(icirc,istripX,idev);
260 fAptMinu->SetBinContent(bin,iAptMinu);
261 bin = fAptUnde->GetBin(icirc,istripX,idev);
262 fAptUnde->SetBinContent(bin,iAptUnde);
263 bin = fAptPlus->GetBin(icirc,istripX,idev);
264 fAptPlus->SetBinContent(bin,iAptPlus);
265
266 } // loop on idev
267 } // loop on istripX
268 } // loop on circuit
269
270 hfile->Write();
271 hfile->Close();
272}
273
274
275
276
277
278
279