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