1 /**************************************************************************
2 * Copyright(c) 2001-2002, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliJetGrid.cxx,v 1.0 07/09/2006 */
18 //=========================================================================
19 // *** 07 September 2006
20 // This class allows to fill a really general grid in (eta,phi)
21 // Two types of grid can be setted :
22 // if fGrid==0 -> the complete acceptance of a rectangular detector acceptance is filled
23 // if fGrid==1 -> the previous grid - an other rectangular detector acceptance is filled
24 // A (eta,phi(rad)) position can be extracted from an index value without looping over all entries
25 // An index position can be extracted from a (eta,phi(rad)) position without looping over all entries
28 // > AliJetGrid *grid = new AliJetGrid((NbinPhi-1),(NbinEta-1),PhiMin,PhiMax,EtaMin,EtaMax);
29 // > grid->SetGridType(...); // 0 or 1 for the moment
30 // > grid->SetMatrixIndexes();
31 // > grid->SetIndexIJ();
33 // Author : magali.estienne@ires.in2p3.fr
34 //=========================================================================
37 #include <Riostream.h>
43 #include "AliJetGrid.h"
48 //__________________________________________________________
49 AliJetGrid::AliJetGrid():
74 // Default constructor
77 //__________________________________________________________
78 AliJetGrid::AliJetGrid(Int_t nphi,Int_t neta,Double_t phiMin,Double_t phiMax,Double_t etaMin,Double_t etaMax):
103 // Standard constructor
104 fPhi = new TArrayD(fNphi+1);
105 fEta = new TArrayD(fNeta+1);
106 fIndexI = new TArrayI((fNeta+1)*(fNphi+1)+1);
107 fIndexJ = new TArrayI((fNeta+1)*(fNphi+1)+1);
109 for(Int_t i=0; i<fNphi+1; i++) (*fPhi)[i] = (phiMax-phiMin)/fNphi*i+phiMin;
110 for(Int_t i=0; i<fNeta+1; i++) (*fEta)[i] = (etaMax-etaMin)/fNeta*i+etaMin;
113 for(Int_t i=0; i<(fNphi+1); i++) cout << (*fPhi)[i] << endl;
114 for(Int_t i=0; i<(fNeta+1); i++) cout << (*fEta)[i] << endl;
117 fIndex = new TMatrixD(fNphi+1,fNeta+1);
121 //__________________________________________________________
122 AliJetGrid::AliJetGrid(const AliJetGrid& grid):TNamed(grid) {
128 fPhiMin = grid.fPhiMin;
129 fPhiMax = grid.fPhiMax;
130 fEtaMin = grid.fEtaMin;
131 fEtaMax = grid.fEtaMax;
132 fEtaBinInTPCAcc = grid.fEtaBinInTPCAcc;
133 fPhiBinInTPCAcc = grid.fPhiBinInTPCAcc;
134 fEtaBinInEMCalAcc = grid.fEtaBinInEMCalAcc;
135 fPhiBinInEMCalAcc = grid.fPhiBinInEMCalAcc;
136 fNbinPhi = grid.fNbinPhi;
137 fMaxPhi = grid.fMaxPhi;
138 fMinPhi = grid.fMinPhi;
139 fMaxEta = grid.fMaxEta;
140 fMinEta = grid.fMinEta;
142 fPhi = new TArrayD(fNphi+1);
143 for(Int_t i=0; i<fNphi+1; i++) (*fPhi)[i] = grid.fPhi->At(i);
144 fEta = new TArrayD(fNeta+1);
145 for(Int_t i=0; i<fNeta+1; i++) (*fEta)[i] = grid.fEta->At(i);
147 fIndex = new TMatrixD(fNphi+1,fNeta+1);
148 for(Int_t i=0; i<fNphi+1; i++) {
149 for(Int_t j=0; j<fNeta+1; j++) (*fIndex)(i,j)=(*grid.fIndex)(i,j);
153 //__________________________________________________________
154 AliJetGrid::~AliJetGrid() {
164 //__________________________________________________________
165 void AliJetGrid::InitParams(Double_t phiMinCal,Double_t phiMaxCal,Double_t etaMinCal,Double_t etaMaxCal)
166 { // To set initial parameters
168 fPhiMin = phiMinCal; // rad
169 fPhiMax = phiMaxCal; // rad
172 fNbinPhi = static_cast<int>(fPhiMin/(2*TMath::Pi()/fNphi));
174 // Define some binning numbers
176 for(Int_t i=0; i<fNphi+1; i++) fPhiBinInTPCAcc++;
177 fPhiBinInEMCalAcc = 0;
179 for(Int_t i=0; i<fNeta+1; i++) fEtaBinInTPCAcc++;
180 fEtaBinInEMCalAcc = 0;
184 for(Int_t i=0; i<fNphi+1; i++) {
186 if(fPhi->At(i) >= fPhiMin &&
187 fPhi->At(i) <= fPhiMax)
190 for(Int_t i=0; i<fNeta+1; i++) {
192 if((fEta->At(i) >= fEtaMin) &&
193 (fEta->At(i) <= fEtaMax))
200 //__________________________________________________________
201 TArrayD* AliJetGrid::GetArrayEta()
202 { // Returns an array with the eta points
208 //__________________________________________________________
209 TArrayD* AliJetGrid::GetArrayPhi()
210 { // Returns an array with the phi points
216 //__________________________________________________________
217 TMatrixD* AliJetGrid::GetIndexObject()
218 { // Returns a pointer to the matrix
224 //__________________________________________________________
225 void AliJetGrid::GetAccParam(Int_t &nphi, Int_t &neta, Float_t &minphi, Float_t &maxphi,
226 Float_t &mineta, Float_t &maxeta)
227 { // Returns EMCAL acceptance initially setted
237 //__________________________________________________________
238 void AliJetGrid::GetBinParam(Int_t &phibintpc, Int_t &etabintpc,
239 Int_t &phibinemc, Int_t &etabinemc, Int_t &nbinphi)
240 { // Returns number of bins in TPC and EMCAL geometry
242 etabintpc = fEtaBinInTPCAcc;
243 phibintpc = fPhiBinInTPCAcc;
244 etabinemc = fEtaBinInEMCalAcc;
245 phibinemc = fPhiBinInEMCalAcc;
249 //__________________________________________________________
250 Int_t AliJetGrid::GetIndexFromEtaPhi(Double_t phi,Double_t eta) const
251 { // Tells the index value of a corresponding (eta,phi) real position
252 // Loop over all entries -> takes time.
253 // Used one time at the begining to fill the grids
255 /* this is how bins are numbered
257 in all TPC or in TPC - EMCAL
260 ... ... . 10 | | | 11
261 ---+---+--- ---------------
262 ^ 6 | 7 | 8 or 8 | | | 9
263 | ---+---+--- ---------------
264 3 | 4 | 5 4 | 5 | 6 | 7
265 phi ---+---+--- ---------------
266 0 | 1 | 2 0 | 1 | 2 | 3
272 Int_t etaBin=0,phiBin=0,absID=0;
273 Int_t etaBin2=0,etaBin3=0;
275 // Fill all the grid in eta/phi (all TPC acceptance)
276 //-----------------------------------------------------
278 if(eta <= fEta->At(0)) {
280 } else if(eta >= fEta->At(fNeta)) {
283 for(Int_t i=0; i<fNeta+1; i++) {
284 if(eta < fEta->At(i)) {
290 if(phi <= fPhi->At(0)) {
292 } else if(phi >= fPhi->At(fNphi)) {
295 for(Int_t i=0; i<fNphi+1; i++) {
296 if(phi < fPhi->At(i)) {
303 // Calculate absolute id
304 absID = phiBin*(fNeta+1) + etaBin;
308 // Fill the grid but do not count id in EMCal acceptance
309 //------------------------------------------------------
310 if((eta >= fEtaMin && eta <= fEtaMax) &&
311 (phi >= fPhiMin && phi <= fPhiMax)){
312 etaBin = etaBin2 = etaBin3 = -1;
318 if(eta <= fEta->At(0)) {
320 } else if(eta >= fEta->At(fNeta)) {
323 for(Int_t i=0; i<fNeta+1; i++) {
324 if(eta < fEta->At(i)) {
332 if((phi>=fPhiMin) && (phi<=fPhiMax)) {
333 if(eta <= fEta->At(0)) {
335 } else if(eta >= fEta->At(fNeta)) {
336 etaBin2 = fNeta-fEtaBinInEMCalAcc;
338 for(Int_t i=0; i<fNeta+1; i++) {
339 if(eta < fEta->At(i) && ((fEta->At(0)<eta && eta<fEtaMin) ||
340 (fEtaMax<eta && eta<fEta->At(fNeta)))) {
341 // cout << "i : " << i << endl;
344 else etaBin2 = i-1-fEtaBinInEMCalAcc;
351 if(eta <= fEta->At(0)) {
353 } else if(eta >= fEta->At(fNeta)) {
356 for(Int_t i=0; i<fNeta+1; i++) {
357 if(eta < fEta->At(i)) {
366 if(phi <= fPhi->At(0)) {
368 } else if(phi >= fPhi->At(fNphi)) {
371 for(Int_t i=0; i<fNphi+1; i++) {
372 if(phi < fPhi->At(i)) {
380 //-------------------------------------------------------
382 absID = phiBin*(fNeta+1) + etaBin;
383 if(phi>=fPhiMin && phi<=fPhiMax) {
384 if(eta >= fEtaMin && eta <= fEtaMax) absID = -1;
386 absID = (fNbinPhi+1)*(fNeta+1)
387 + (phiBin-fNbinPhi-1)*((fEtaBinInTPCAcc-fEtaBinInEMCalAcc))
392 absID = (fNbinPhi+1)*(fNeta+1)
393 + fPhiBinInEMCalAcc*((fEtaBinInTPCAcc-fEtaBinInEMCalAcc))
394 + (phiBin-(fNbinPhi+1+fPhiBinInEMCalAcc))*(fNeta+1)
403 //__________________________________________________________
404 void AliJetGrid::GetEtaPhiFromIndex(Int_t index, Float_t &eta, Float_t &phi)
405 { // Get (eta,phi) position for a given index BUT loop over all entries (takes time)
407 for(Int_t j=0; j<fNphi+1; j++) {
408 for(Int_t i=0; i<fNeta+1; i++) {
411 //-------------------------------------
413 if(j*(fNeta+1)+i == index) {
420 //-------------------------------------
423 if(i>0 && i<(fEtaBinInTPCAcc-fEtaBinInEMCalAcc)/2) ii = i;
424 if(i>=(fEtaBinInTPCAcc+fEtaBinInEMCalAcc)/2 && i<fNeta+1) ii = i-fEtaBinInEMCalAcc;
427 if(j<(fNbinPhi+1) && j*(fNeta+1)+i == index) {
432 if((j>=(fNbinPhi+1) && j<(fNbinPhi+1+fPhiBinInEMCalAcc)) &&
433 ((fNbinPhi+1)*(fNeta+1) + (j-fNbinPhi-1)*(fEtaBinInTPCAcc-fEtaBinInEMCalAcc) + ii)== index ) {
434 if(ii==0) {Int_t ind = 0; eta = fEta->At(ind);}
435 else eta = fEta->At(i);
439 if(j>=(fNbinPhi+1+fPhiBinInEMCalAcc) &&
440 ((fNbinPhi+1)*(fNeta+1)+fPhiBinInEMCalAcc*((fEtaBinInTPCAcc-fEtaBinInEMCalAcc))
441 +(j-(fNbinPhi+1+fPhiBinInEMCalAcc))*(fNeta+1)+i == index)) {
450 //__________________________________________________________
451 Int_t AliJetGrid::GetIndex(Double_t phi, Double_t eta)
452 { // Get index value for a (eta,phi) position - Direct value
454 Int_t ieta = GetIndexJFromEta(eta);
455 Int_t iphi = GetIndexIFromPhi(phi);
457 Int_t index = GetMatrixIndex(iphi,ieta);
460 cout << "(phi,eta) : " << phi << ", " << eta << endl;
461 cout << "index : " << index << endl;
467 //__________________________________________________________
468 Int_t AliJetGrid::GetIndexJFromEta(Double_t eta)
473 Double_t temp = (eta+fMaxEta)/(fMaxEta-fMinEta)*fNeta;
476 cout << "eta : " << eta << endl;
477 cout << "fMaxEta : " << fMaxEta << endl;
478 cout << "fMinEta : " << fMinEta << endl;
479 cout << "fNeta : " << fNeta << endl;
480 cout << "temp eta before cast : " << temp << endl;
482 idEta = static_cast<Int_t>(temp+0.5);
483 if(fDebug>20) cout << "temp eta after cast : " << idEta << endl;
486 //__________________________________________________________
487 Int_t AliJetGrid::GetIndexIFromPhi(Double_t phi)
493 if(fMinPhi==0) temp = phi/(fMaxPhi-fMinPhi)*fNphi;
494 else temp = (phi-fMinPhi)/(fMaxPhi-fMinPhi)*fNphi;
498 cout << "phi : " << phi << endl;
499 cout << "fMaxPhi : " << fMaxPhi << endl;
500 cout << "fMinPhi : " << fMinPhi << endl;
501 cout << "fNphi : " << fNphi << endl;
502 cout << "temp phi before cast : " << temp << endl;
504 idPhi = static_cast<Int_t>(temp+0.5);
505 if(fDebug>20) cout << "temp phi after cast : " << idPhi << endl;
511 //__________________________________________________________
512 void AliJetGrid::SetMatrixIndex(Int_t i,Double_t par)
513 { // Allows to set parameters using only one index (if fGrid==0) !!
516 Int_t iphi = (Int_t)i/fNeta;
517 Int_t ieta = i-iphi*fNeta;
518 SetMatrixIndex(iphi,ieta,par);
523 //__________________________________________________________
524 void AliJetGrid::SetMatrixIndexes()
525 { // Fill the final matrix object with the corresponding index in eta/phi
527 for(Int_t i=0; i<fNphi+1; i++){
528 for(Int_t j=0; j<fNeta+1; j++){
529 (*fIndex)(i,j) = GetIndexFromEtaPhi(fPhi->At(i),fEta->At(j))+1;
531 cout << "(*fIndex)(" << i << "," << j << ") : " << (*fIndex)(i,j) <<
532 ", phi : " << fPhi->At(i) << ", eta : " << fEta->At(j) << endl;
536 printf("##########################################################\n");
537 printf("TMatrix object filled !\n");
538 printf("Size of the object : phi x eta = (fNphi+1) x (fNeta+1) = %d\n",(fNphi+1)*(fNeta+1));
539 printf("##########################################################\n");
542 //__________________________________________________________
543 void AliJetGrid::SetIndexIJ()
546 for(Int_t i=0; i<fNphi+1; i++){
547 for(Int_t j=0; j<fNeta+1; j++){
548 Int_t id = static_cast<Int_t>((*fIndex)(i,j));
558 printf("##########################################################\n");
559 printf(" In SetIndexIJ - Grid indexes setted !\n");
560 printf("##########################################################\n");
563 //__________________________________________________________
564 void AliJetGrid::GetIJFromIndex(Int_t index, Int_t i, Int_t j)
565 { // returns i position id of eta and j position id of phi for a given grid index
566 i = (*fIndexI)[index];
567 j = (*fIndexJ)[index];
570 //__________________________________________________________
571 void AliJetGrid::GetEtaPhiFromIndex2(Int_t index, Float_t &phi, Float_t &eta)
572 { // returns eta, phi values for a given grid index
574 phi = fPhi->At((*fIndexI)[index]);
575 eta = fEta->At((*fIndexJ)[index]);
578 //__________________________________________________________
579 Int_t AliJetGrid::GetNEntries()
580 { // Returns the number of entries of the grid
583 cout << "fMaxPhi : " << fMaxPhi << endl;
584 cout << "fMaxEta : " << fMaxEta << endl;
587 Int_t indexNum = GetIndex(fMaxPhi,fMaxEta);
588 if(fDebug>20) cout << "indexNum : " << indexNum << endl;
593 //__________________________________________________________
594 Int_t AliJetGrid::GetNEntries2()
595 { // Returns the number of entries of the grid
597 Int_t indexNum = GetIndex(fMaxPhi-1.,fMaxEta-0.5);
598 if(fDebug>20) cout << "indexNum : " << indexNum << endl;