]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
Pycell configurable.
[u/mrichter/AliRoot.git] / STEER / AliMagFMaps.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 //------------------------------------------------------------------------
19 // Magnetic field composed by 3 maps: the L3 magnet, extended region, and
20 // dipole magnet
21 // Used in the configuration macros (macros/Config.C, etc.)
22 // Author: Andreas Morsch <andreas.morsch@cern.ch>
23 //------------------------------------------------------------------------
24
25 #include <TFile.h>
26 #include <TSystem.h>
27 #include <TVector.h>
28
29 #include "AliFieldMap.h"
30 #include "AliMagFMaps.h"
31
32
33 ClassImp(AliMagFMaps)
34
35 //_______________________________________________________________________
36 AliMagFMaps::AliMagFMaps():
37   fSolenoid(0),
38   fL3Option(0),
39   fFieldRead(0)
40 {
41   //
42   // Default constructor
43   //
44   fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
45 }
46
47 //_______________________________________________________________________
48 AliMagFMaps::AliMagFMaps(const char *name, const char *title, const Int_t integ, 
49                          const Float_t factor, const Float_t fmax, const Int_t map, 
50                          const Int_t l3):
51   AliMagF(name,title,integ,factor,fmax),
52   fSolenoid(0),
53   fL3Option(l3),
54   fFieldRead(0)
55 {
56   //
57   // Standard constructor
58   //
59   fType         = kConMesh;
60   fFieldMap[0]  = 0;
61   fMap          = map;
62   fL3Option     = l3;
63
64   ReadField();
65   fFieldRead = 1;
66   //
67   // Don't replicate field information in gAlice
68   for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
69   //
70 }
71
72 //_______________________________________________________________________
73 AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
74   AliMagF(magf),
75   fSolenoid(0),
76   fL3Option(0),
77   fFieldRead(0)
78 {
79   //
80   // Copy constructor
81   //
82   magf.Copy(*this);
83 }
84
85 //_______________________________________________________________________
86 AliMagFMaps::~AliMagFMaps()
87 {
88   //
89   //  Destructor
90   //
91   delete fFieldMap[0];
92   delete fFieldMap[1];
93   delete fFieldMap[2];    
94 }
95
96 //_______________________________________________________________________
97 void AliMagFMaps::ReadField()
98 {
99   //  Read Field Map from file
100   //
101   //  don't read twice
102   //
103   if (fFieldRead) return;
104   fFieldRead = 1;
105   //    
106   char* fname;
107   TFile* file = 0;
108   if (fMap == k2kG) {
109         if (fL3Option) {
110       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
111       file = new TFile(fname);
112       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
113       file->Close();
114       delete file;
115         }
116         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
117         file = new TFile(fname);
118         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
119         file->Close();
120         delete file;;
121         
122         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
123         file = new TFile(fname);
124         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
125         file->Close();
126         delete file;
127         fSolenoid = 2.;
128   } else if (fMap == k4kG) {
129         if (fL3Option) {
130       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
131       file = new TFile(fname);
132       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
133       file->Close();
134       delete file;
135         }
136         
137         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
138         file = new TFile(fname);
139         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
140         file->Close();
141         delete file;
142         
143         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
144         file = new TFile(fname);
145         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
146         file->Close();
147         delete file;
148         fSolenoid = 4.;
149   } else if (fMap == k5kG) {
150         if (fL3Option) {
151       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
152       file = new TFile(fname);
153       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
154       file->Close();
155       delete file;
156         }
157         
158         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
159         file = new TFile(fname);
160         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
161         file->Close();
162         delete file;
163         
164         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
165         file = new TFile(fname);
166         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
167         file->Close();
168         delete file;
169         
170         fSolenoid = 5.;
171   }
172   
173   if (!fL3Option) {
174     //
175     // Dummy L3 map
176         fFieldMap[0] = new AliFieldMap();
177         fFieldMap[0] -> SetLimits(-800., 800., -800., 800., -700., 700.);
178   }
179 }
180
181 //_______________________________________________________________________
182 Float_t AliMagFMaps::SolenoidField() const
183 {
184   //
185   // Returns max. L3 (solenoid) field strength 
186   // according to field map setting 
187   //
188   return fSolenoid;
189 }
190
191 //_______________________________________________________________________
192 void AliMagFMaps::Field(Float_t *x, Float_t *b)
193 {
194   //
195   // Method to calculate the magnetic field
196   //
197   // --- find the position in the grid ---
198   
199   if (!fFieldRead) ReadField();
200   
201   b[0]=b[1]=b[2]=0;
202   AliFieldMap* map = 0;
203   if (fFieldMap[0]->Inside(x[0], x[1], x[2])) {
204     map = fFieldMap[0];
205     if (!fL3Option) {
206       //
207       //     Constant L3 field, if this option was selected
208       //
209           b[2] = fSolenoid;
210           return;
211     }
212   } else if (fFieldMap[1]->Inside(x[0], x[1], x[2])) {
213     map = fFieldMap[1];
214   } else if (fFieldMap[2]->Inside(x[0], x[1], x[2])) {
215     map = fFieldMap[2];
216   }
217   
218   if(map){
219     map->Field(x,b);
220   } else {
221     //This is the ZDC part
222     Float_t rad2=x[0]*x[0]+x[1]*x[1];
223     if(x[2]>kCORBEG2 && x[2]<kCOREND2){
224           if(rad2<kCOR2RA2){
225         b[0] = kFCORN2;
226           }
227     }
228     else if(x[2]>kZ1BEG && x[2]<kZ1END){  
229           if(rad2<kZ1RA2){
230         b[0] = -kG1*x[1];
231         b[1] = -kG1*x[0];
232           }
233     }
234     else if(x[2]>kZ2BEG && x[2]<kZ2END){  
235           if(rad2<kZ2RA2){
236         b[0] = kG1*x[1];
237         b[1] = kG1*x[0];
238           }
239     }
240     else if(x[2]>kZ3BEG && x[2]<kZ3END){  
241           if(rad2<kZ3RA2){
242         b[0] = kG1*x[1];
243         b[1] = kG1*x[0];
244           }
245     }
246     else if(x[2]>kZ4BEG && x[2]<kZ4END){  
247           if(rad2<kZ4RA2){
248         b[0] = -kG1*x[1];
249         b[1] = -kG1*x[0];
250           }
251     }
252     else if(x[2]>kD1BEG && x[2]<kD1END){ 
253           if(rad2<kD1RA2){
254         b[1] = -kFDIP;
255           }
256     }
257     else if(x[2]>kD2BEG && x[2]<kD2END){
258           if(((x[0]-kXCEN1D2)*(x[0]-kXCEN1D2)+(x[1]-kYCEN1D2)*(x[1]-kYCEN1D2))<kD2RA2
259              || ((x[0]-kXCEN2D2)*(x[0]-kXCEN2D2)+(x[1]-kYCEN2D2)*(x[1]-kYCEN2D2))<kD2RA2){
260         b[1] = kFDIP;
261           }
262     }
263   }
264   if(fFactor!=1) {
265     b[0]*=fFactor;
266     b[1]*=fFactor;
267     b[2]*=fFactor;
268   }
269 }
270
271 //_______________________________________________________________________
272 void AliMagFMaps::Copy(AliMagFMaps & /* magf */) const
273 {
274   //
275   // Copy *this onto magf -- Not implemented
276   //
277   Fatal("Copy","Not implemented!\n");
278 }
279
280 //_______________________________________________________________________
281 void AliMagFMaps::Streamer(TBuffer &R__b)
282 {
283   // Stream an object of class AliMagFMaps.
284   if (R__b.IsReading()) {
285     AliMagFMaps::Class()->ReadBuffer(R__b, this);
286     fFieldRead = 0;
287   } else {
288     AliMagFMaps::Class()->WriteBuffer(R__b, this);
289   }
290 }