Reset static data member fgReadField in destructor.
[u/mrichter/AliRoot.git] / STEER / AliMagFMaps.cxx
CommitLineData
84737f5e 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
acd84897 16/* $Id$ */
84737f5e 17
5d8718b8 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.)
84737f5e 22// Author: Andreas Morsch <andreas.morsch@cern.ch>
5d8718b8 23//------------------------------------------------------------------------
84737f5e 24
25#include <TFile.h>
26#include <TSystem.h>
e2afb3b6 27
594d8990 28#include "AliLog.h"
84737f5e 29#include "AliFieldMap.h"
30#include "AliMagFMaps.h"
31
84737f5e 32ClassImp(AliMagFMaps)
a0201063 33
84737f5e 34
e2afb3b6 35//_______________________________________________________________________
36AliMagFMaps::AliMagFMaps():
37 fSolenoid(0),
02b50693 38 fSolenoidUser(0.),
a0201063 39 fL3Option(0)
e2afb3b6 40{
41 //
42 // Default constructor
43 //
10eca208 44 //
45 // Don't replicate field information in gAlice
e2afb3b6 46 fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
47}
48
49//_______________________________________________________________________
d0f1ee3b 50AliMagFMaps::AliMagFMaps(const char *name, const char *title, Int_t integ,
51 Float_t factor, Float_t fmax, Int_t map,
52 Int_t l3):
57754f18 53 AliMagFC(name,title,integ,factor,fmax),
e2afb3b6 54 fSolenoid(0),
02b50693 55 fSolenoidUser(0),
a0201063 56 fL3Option(l3)
84737f5e 57{
58 //
59 // Standard constructor
60 //
61 fType = kConMesh;
62 fFieldMap[0] = 0;
c2b548d6 63 fMap = map;
64 fL3Option = l3;
c2b548d6 65 ReadField();
e2afb3b6 66 //
67 // Don't replicate field information in gAlice
7b6cddfa 68 for (Int_t i = 0; i < 3; i++) fFieldMap[i]->SetWriteEnable(0);
e2afb3b6 69 //
84737f5e 70}
71
e2afb3b6 72//_______________________________________________________________________
73AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
57754f18 74 AliMagFC(magf),
e2afb3b6 75 fSolenoid(0),
a0201063 76 fL3Option(0)
84737f5e 77{
78 //
79 // Copy constructor
80 //
81 magf.Copy(*this);
82}
83
e2afb3b6 84//_______________________________________________________________________
84737f5e 85AliMagFMaps::~AliMagFMaps()
86{
e2afb3b6 87 //
88 // Destructor
89 //
90 delete fFieldMap[0];
91 delete fFieldMap[1];
92 delete fFieldMap[2];
3ce3918c 93 fgReadField = kTRUE;
84737f5e 94}
95
e2afb3b6 96//_______________________________________________________________________
c2b548d6 97void AliMagFMaps::ReadField()
98{
e2afb3b6 99 // Read Field Map from file
100 //
101 // don't read twice
102 //
a0201063 103 if (!fgReadField) return;
104 fgReadField = 0;
e2afb3b6 105 //
106 char* fname;
107 TFile* file = 0;
108 if (fMap == k2kG) {
b6ee07d3 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;
177a7fab 115 fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
e2afb3b6 116 file = new TFile(fname);
177a7fab 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"));
e2afb3b6 124 file->Close();
125 delete file;
e2afb3b6 126 } else if (fMap == k4kG) {
b6ee07d3 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;
177a7fab 133 fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
e2afb3b6 134 file = new TFile(fname);
177a7fab 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"));
e2afb3b6 142 file->Close();
143 delete file;
e2afb3b6 144 } else if (fMap == k5kG) {
b6ee07d3 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;
177a7fab 151 fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
e2afb3b6 152 file = new TFile(fname);
177a7fab 153 fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
e2afb3b6 154 file->Close();
155 delete file;
177a7fab 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;
e2afb3b6 162 }
b6ee07d3 163
164 if (!fL3Option) fSolenoidUser = fSolenoid;
165
c2b548d6 166}
167
e2afb3b6 168//_______________________________________________________________________
84737f5e 169Float_t AliMagFMaps::SolenoidField() const
170{
e2afb3b6 171 //
172 // Returns max. L3 (solenoid) field strength
173 // according to field map setting
174 //
175 return fSolenoid;
84737f5e 176}
177
e2afb3b6 178//_______________________________________________________________________
6f3038e9 179void AliMagFMaps::Field(Float_t *x, Float_t *b) const
84737f5e 180{
181 //
182 // Method to calculate the magnetic field
183 //
84737f5e 184 // --- find the position in the grid ---
185
57754f18 186
187
6f3038e9 188 // if (!fFieldRead) ReadField();
57754f18 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 //
e2afb3b6 195
84737f5e 196 b[0]=b[1]=b[2]=0;
57754f18 197 Float_t xm[3];
198 xm[0] = - x[0];
199 xm[1] = x[1];
200 xm[2] = - x[2];
201
84737f5e 202 AliFieldMap* map = 0;
57754f18 203 if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
177a7fab 204 map = fFieldMap[0];
0ae44e30 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.) {
e2afb3b6 208 //
b6ee07d3 209 // Constant L3 field , if this option was selected
e2afb3b6 210 //
81e97e0d 211 b[2] = (- fSolenoid)*fFactor;
84737f5e 212 return;
b6ee07d3 213 }
57754f18 214 } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
88cb7938 215 map = fFieldMap[1];
57754f18 216 } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
88cb7938 217 map = fFieldMap[2];
84737f5e 218 }
219
220 if(map){
57754f18 221 map->Field(xm,b);
222 b[0] = - b[0];
223 b[2] = - b[2];
224
84737f5e 225 } else {
57754f18 226 //This is the ZDC part
227 ZDCField(x, b);
84737f5e 228 }
57754f18 229
230
84737f5e 231 if(fFactor!=1) {
57754f18 232 b[0]*=fFactor;
233 b[1]*=fFactor;
234 b[2]*=fFactor;
84737f5e 235 }
236}
237
e2afb3b6 238//_______________________________________________________________________
6c4904c2 239void AliMagFMaps::Copy(TObject & /* magf */) const
84737f5e 240{
241 //
242 // Copy *this onto magf -- Not implemented
243 //
594d8990 244 AliFatal("Not implemented!");
84737f5e 245}
246
e2afb3b6 247//_______________________________________________________________________
ee4f31cd 248void AliMagFMaps::Streamer(TBuffer &R__b)
249{
e2afb3b6 250 // Stream an object of class AliMagFMaps.
251 if (R__b.IsReading()) {
252 AliMagFMaps::Class()->ReadBuffer(R__b, this);
10eca208 253 ReadField();
e2afb3b6 254 } else {
255 AliMagFMaps::Class()->WriteBuffer(R__b, this);
256 }
ee4f31cd 257}