]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
Splitting of TRD library (T.Kuhr)
[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
28 #include "AliFieldMap.h"
29 #include "AliMagFMaps.h"
30
31 ClassImp(AliMagFMaps)
32     
33
34 //_______________________________________________________________________
35 AliMagFMaps::AliMagFMaps():
36   fSolenoid(0),
37   fSolenoidUser(0.),
38   fL3Option(0)
39 {
40   //
41   // Default constructor
42   //
43   //
44   // Don't replicate field information in gAlice
45   fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
46 }
47
48 //_______________________________________________________________________
49 AliMagFMaps::AliMagFMaps(const char *name, const char *title, Int_t integ, 
50                          Float_t factor, Float_t fmax, Int_t map, 
51                          Int_t l3):
52   AliMagFC(name,title,integ,factor,fmax),
53   fSolenoid(0),
54   fSolenoidUser(0),
55   fL3Option(l3)
56 {
57   //
58   // Standard constructor
59   //
60   fType         = kConMesh;
61   fFieldMap[0]  = 0;
62   fMap          = map;
63   fL3Option     = l3;
64   ReadField();
65   //
66   // Don't replicate field information in gAlice
67   for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
68   //
69 }
70
71 //_______________________________________________________________________
72 AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
73   AliMagFC(magf),
74   fSolenoid(0),
75   fL3Option(0)
76 {
77   //
78   // Copy constructor
79   //
80   magf.Copy(*this);
81 }
82
83 //_______________________________________________________________________
84 AliMagFMaps::~AliMagFMaps()
85 {
86   //
87   //  Destructor
88   //
89   delete fFieldMap[0];
90   delete fFieldMap[1];
91   delete fFieldMap[2];    
92 }
93
94 //_______________________________________________________________________
95 void AliMagFMaps::ReadField()
96 {
97   //  Read Field Map from file
98   //
99   //  don't read twice
100   //
101     if (!fgReadField) return;
102     fgReadField = 0;
103   //    
104   char* fname;
105   TFile* file = 0;
106   if (fMap == k2kG) {
107       fSolenoid = 2.;
108       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
109       file = new TFile(fname);
110       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
111       file->Close();
112       delete file;
113       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
114       file = new TFile(fname);
115       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
116       file->Close();
117       delete file;;
118       
119       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
120       file = new TFile(fname);
121       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
122       file->Close();
123       delete file;
124   } else if (fMap == k4kG) {
125       fSolenoid = 4.;
126       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
127       file = new TFile(fname);
128       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
129       file->Close();
130       delete file;
131       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
132       file = new TFile(fname);
133       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
134       file->Close();
135       delete file;
136       
137       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
138       file = new TFile(fname);
139       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
140       file->Close();
141       delete file;
142   } else if (fMap == k5kG) {
143       fSolenoid = 5.;
144       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
145       file = new TFile(fname);
146       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
147       file->Close();
148       delete file;
149       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
150       file = new TFile(fname);
151       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
152       file->Close();
153       delete file;
154       
155       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
156       file = new TFile(fname);
157       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
158       file->Close();
159       delete file;
160   }
161
162   if (!fL3Option) fSolenoidUser = fSolenoid;
163
164 }
165
166 //_______________________________________________________________________
167 Float_t AliMagFMaps::SolenoidField() const
168 {
169   //
170   // Returns max. L3 (solenoid) field strength 
171   // according to field map setting 
172   //
173   return fSolenoid;
174 }
175
176 //_______________________________________________________________________
177 void AliMagFMaps::Field(Float_t *x, Float_t *b) const
178 {
179   //
180   // Method to calculate the magnetic field
181   //
182   // --- find the position in the grid ---
183   
184
185     
186  //    if (!fFieldRead) ReadField();
187
188   //
189   // Field Maps have been calculated for the coordinate system in which 
190   // the Muon Spectrometer is placed at z > 0
191   // Transform coordinates corresponingly 
192   //
193   
194   b[0]=b[1]=b[2]=0;
195   Float_t xm[3];
196   xm[0] = - x[0];
197   xm[1] =   x[1];
198   xm[2] = - x[2];
199   
200   AliFieldMap* map = 0;
201   if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
202       map = fFieldMap[0];
203       Float_t r = TMath::Sqrt(xm[0] * xm[0] + xm[1] * xm[1]);
204       
205       if (!fL3Option && TMath::Abs(xm[2]) < 370. && r < 550.) {
206       //
207       //     Constant L3 field , if this option was selected
208       //
209           b[2] = - fSolenoid;
210           return;
211       } 
212   } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
213     map = fFieldMap[1];
214   } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
215     map = fFieldMap[2];
216   }
217   
218   if(map){
219     map->Field(xm,b);
220     b[0] = - b[0];
221     b[2] = - b[2];
222
223   } else {
224       //This is the ZDC part
225       ZDCField(x, b);
226   }
227
228   
229   if(fFactor!=1) {
230       b[0]*=fFactor;
231       b[1]*=fFactor;
232       b[2]*=fFactor;
233   }
234 }
235
236 //_______________________________________________________________________
237 void AliMagFMaps::Copy(TObject & /* magf */) const
238 {
239   //
240   // Copy *this onto magf -- Not implemented
241   //
242   Fatal("Copy","Not implemented!\n");
243 }
244
245 //_______________________________________________________________________
246 void AliMagFMaps::Streamer(TBuffer &R__b)
247 {
248   // Stream an object of class AliMagFMaps.
249   if (R__b.IsReading()) {
250     AliMagFMaps::Class()->ReadBuffer(R__b, this);
251     ReadField();
252   } else {
253     AliMagFMaps::Class()->WriteBuffer(R__b, this);
254   }
255 }