]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
aa43984d1c3aef1fe61d4cc13a9cfbe907cc6c36
[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 ClassImp(AliMagFMaps)
33
34 //_______________________________________________________________________
35 AliMagFMaps::AliMagFMaps():
36   fSolenoid(0),
37   fSolenoidUser(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, Int_t integ, 
49                          Float_t factor, Float_t fmax, Int_t map, 
50                          Int_t l3):
51   AliMagFC(name,title,integ,factor,fmax),
52   fSolenoid(0),
53   fSolenoidUser(0),
54   fL3Option(l3),
55   fFieldRead(0)
56 {
57   //
58   // Standard constructor
59   //
60   fType         = kConMesh;
61   fFieldMap[0]  = 0;
62   fMap          = map;
63   fL3Option     = l3;
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   AliMagFC(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       fSolenoid = 2.;
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       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
116       file = new TFile(fname);
117       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
118       file->Close();
119       delete file;;
120       
121       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
122       file = new TFile(fname);
123       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
124       file->Close();
125       delete file;
126   } else if (fMap == k4kG) {
127       fSolenoid = 4.;
128       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
129       file = new TFile(fname);
130       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
131       file->Close();
132       delete file;
133       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
134       file = new TFile(fname);
135       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
136       file->Close();
137       delete file;
138       
139       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
140       file = new TFile(fname);
141       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
142       file->Close();
143       delete file;
144   } else if (fMap == k5kG) {
145       fSolenoid = 5.;
146       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
147       file = new TFile(fname);
148       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
149       file->Close();
150       delete file;
151       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
152       file = new TFile(fname);
153       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
154       file->Close();
155       delete file;
156       
157       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
158       file = new TFile(fname);
159       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
160       file->Close();
161       delete file;
162   }
163
164   if (!fL3Option) fSolenoidUser = fSolenoid;
165
166 }
167
168 //_______________________________________________________________________
169 Float_t AliMagFMaps::SolenoidField() const
170 {
171   //
172   // Returns max. L3 (solenoid) field strength 
173   // according to field map setting 
174   //
175   return fSolenoid;
176 }
177
178 //_______________________________________________________________________
179 void AliMagFMaps::Field(Float_t *x, Float_t *b)
180 {
181   //
182   // Method to calculate the magnetic field
183   //
184   // --- find the position in the grid ---
185   
186
187     
188     if (!fFieldRead) ReadField();
189
190   //
191   // Field Maps have been calculated for the coordinate system in which 
192   // the Muon Spectrometer is placed at z > 0
193   // Transform coordinates corresponingly 
194   //
195   
196   b[0]=b[1]=b[2]=0;
197   Float_t xm[3];
198   xm[0] = - x[0];
199   xm[1] =   x[1];
200   xm[2] = - x[2];
201   
202   AliFieldMap* map = 0;
203   if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
204       map = fFieldMap[0];
205       Float_t r = TMath::Sqrt(xm[0] * xm[0] + xm[1] * xm[1]);
206       
207       if (!fL3Option && TMath::Abs(xm[2]) < 370. && r < 550.) {
208       //
209       //     Constant L3 field , if this option was selected
210       //
211           b[2] = - fSolenoid;
212           return;
213       } 
214   } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
215     map = fFieldMap[1];
216   } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
217     map = fFieldMap[2];
218   }
219   
220   if(map){
221     map->Field(xm,b);
222     b[0] = - b[0];
223     b[2] = - b[2];
224
225   } else {
226       //This is the ZDC part
227       ZDCField(x, b);
228   }
229
230   
231   if(fFactor!=1) {
232       b[0]*=fFactor;
233       b[1]*=fFactor;
234       b[2]*=fFactor;
235   }
236 }
237
238 //_______________________________________________________________________
239 void AliMagFMaps::Copy(TObject & /* magf */) const
240 {
241   //
242   // Copy *this onto magf -- Not implemented
243   //
244   Fatal("Copy","Not implemented!\n");
245 }
246
247 //_______________________________________________________________________
248 void AliMagFMaps::Streamer(TBuffer &R__b)
249 {
250   // Stream an object of class AliMagFMaps.
251   if (R__b.IsReading()) {
252     AliMagFMaps::Class()->ReadBuffer(R__b, this);
253     fFieldRead = 0;
254   } else {
255     AliMagFMaps::Class()->WriteBuffer(R__b, this);
256   }
257 }