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