b00c84de37a470a00f24287c00a493edd2dfb547
[u/mrichter/AliRoot.git] / HLT / MUON / macros / CreateHitRecoLookupTables.C
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Indranil Das <indra.das@saha.ac.in>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          * 
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /*********************************************
18 Purpose:  A macro to generate LookupTable
19           in the following form
20 detElemId+manuid+channelId  buspatchId Ix  IY  X  Y  B/NB
21
22 Created:  7/10/2005
23 Modified: 22/12/2005
24 Modified: 09/02/2006
25 Modified: 09/04/2007
26 Modified: 24/08/2007 (To adopt to AliRoot v4-06-Release)
27
28 Run Info: To run this code copy "rootlogon.C" 
29           in the current directory from $ALICE_ROOT/MUON 
30           and specify the 
31           transformFileName as "geometry.root" of the 
32           simulation directory.Then compile and run using
33           .L generateLookupTable.C++
34
35 Author:   Indranil Das, HEP, SINP, Kolkata
36 Email:    indra.das@saha.ac.in
37 ***********************************************/
38
39 #include <iostream> 
40
41 //STEER 
42 #include "AliCDBManager.h"
43
44 //MUON
45 #include "AliMUONGeometryTransformer.h"
46
47 //MUON/mapping 
48 #include "AliMpPad.h"
49 #include "AliMpSegmentation.h"
50 #include "AliMpDDLStore.h"
51 #include "AliMpDEIterator.h"
52 #include "AliMpVSegmentation.h"
53 #include "AliMpDEManager.h"
54
55 class AliMpDDLStore ;
56
57 using namespace std;
58
59
60 Bool_t CreateHitRecoLookupTables(TString transformFileName = "geometry.root")
61 {
62   Char_t filename1[20], filename2[20];
63   Int_t chamberId;
64   
65   AliMpSegmentation *mpSegFactory = AliMpSegmentation::ReadData(); 
66
67   AliMpDDLStore* fDDLStore = AliMpDDLStore::ReadData();
68   
69   AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer();
70   chamberGeometryTransformer->LoadGeometryData(transformFileName);
71   
72   for(Int_t iCh = 0; iCh < 4; iCh++){ // max 4
73     
74     sprintf(filename1,"Lut%d.dat",2*(6+iCh)+1);
75     FILE *fout1 = fopen(filename1,"w");
76
77     sprintf(filename2,"Lut%d.dat",2*(6+iCh)+2);
78     FILE *fout2 = fopen(filename2,"w");
79
80     chamberId = iCh + 6;
81
82     AliMpDEIterator it;
83     for ( it.First(chamberId); ! it.IsDone(); it.Next() ) {
84     
85       Int_t detElemId = it.CurrentDEId();
86       
87       cout<<"Running for detElemId :"<<detElemId<<endl;
88       
89       for(Int_t iPlane = 0 ; iPlane <= 1 ; iPlane++){
90         
91         AliMp::CathodType cath;
92
93         if(iPlane == 0)
94           cath = AliMp::kCath0 ;
95         else
96           cath = AliMp::kCath1 ;
97         
98         AliMpVSegmentation* seg = mpSegFactory->CreateMpSegmentation(detElemId, cath);
99         
100         Int_t maxIX = seg->MaxPadIndexX();  
101         Int_t maxIY = seg->MaxPadIndexY(); 
102         Int_t idManuChannel, manuId, channelId,idetElemId;
103         Int_t busPatchId;
104         Double_t realX, realY, realZ;
105         Double_t localX, localY, localZ;
106         Double_t padSizeX, padSizeY;
107         Int_t pcbType;
108
109         //Pad Info of a segment
110         for(Int_t iX = 0; iX<= maxIX ; iX++){
111           for(Int_t iY = 0; iY<= maxIY ; iY++){
112             if(seg->HasPad(AliMpIntPair(iX,iY))){
113               AliMpPad pad = seg->PadByIndices(AliMpIntPair(iX,iY),kFALSE);
114               
115               // Getting Manu id
116               manuId = pad.GetLocation().GetFirst();
117               manuId &= 0x7FF; // 11 bits 
118               
119               busPatchId = fDDLStore->GetBusPatchId(detElemId,manuId);
120               
121               // Getting channel id
122               channelId =  pad.GetLocation().GetSecond();
123               channelId &= 0x3F; // 6 bits
124               
125               idetElemId = detElemId%100;
126               
127               idManuChannel &= 0x0;
128               idManuChannel = (idManuChannel|idetElemId)<<11;  
129               idManuChannel = (idManuChannel|manuId)<<6 ;
130               idManuChannel |= channelId ;
131               
132               localX = pad.Position().X();
133               localY = pad.Position().Y();
134               localZ = 0.0;
135
136               chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ,
137                                                        realX,realY,realZ);
138
139               padSizeX = 2.0*pad.Dimensions().X();
140               padSizeY = 2.0*pad.Dimensions().Y();
141
142               if(iPlane == 0 ){
143                 if(padSizeX==2.5)
144                   pcbType = 0;
145                 else if(padSizeX==5.0)
146                   pcbType = 1;
147                 else
148                   pcbType = 2;
149               }
150               else{
151                 if(padSizeY==2.5)
152                   pcbType = 0;
153                 else if(padSizeY==5.0)
154                   pcbType = 1;
155                 else
156                   pcbType = 2;
157               }
158                 
159               if(idetElemId<7 || idetElemId > 19){
160                 fprintf(fout2,"%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",idManuChannel,iX,iY,realX,realY,realZ,pcbType,iPlane);
161               }
162               else{
163                 fprintf(fout1,"%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",idManuChannel,iX,iY,realX,realY,realZ,pcbType,iPlane);
164               }// HasPad Condn
165               
166             }
167           }// iY loop
168         }// iX loop
169         
170       }// iPlane
171
172     } // detElemId loop
173
174     fclose(fout1);
175     fclose(fout2);
176   }// ichamber loop
177   
178   return kTRUE;
179 }