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