]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
TRD included in the ESD chain (Yu.Belikov)
[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, const Int_t integ, 
49                          const Float_t factor, const Float_t fmax, const Int_t map, 
50                          const 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       if (fL3Option) {
110           fSolenoid = 2.;
111           fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
112           file = new TFile(fname);
113           fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
114           file->Close();
115           delete file;
116       }
117       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
118       file = new TFile(fname);
119       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
120       file->Close();
121       delete file;;
122       
123       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
124       file = new TFile(fname);
125       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
126       file->Close();
127       delete file;
128   } else if (fMap == k4kG) {
129       if (fL3Option) {
130           fSolenoid = 4.;
131           fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
132           file = new TFile(fname);
133           fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
134           file->Close();
135           delete file;
136       }
137       
138       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
139       file = new TFile(fname);
140       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
141       file->Close();
142       delete file;
143       
144       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
145       file = new TFile(fname);
146       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
147       file->Close();
148       delete file;
149   } else if (fMap == k5kG) {
150       if (fL3Option) {
151           fSolenoid = 5.;
152           fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
153           file = new TFile(fname);
154           fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
155           file->Close();
156           delete file;
157       }
158       
159       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
160       file = new TFile(fname);
161       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
162       file->Close();
163       delete file;
164       
165       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
166       file = new TFile(fname);
167       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
168       file->Close();
169       delete file;
170       
171   }
172   
173   if (!fL3Option) {
174       //
175       // Dummy L3 map
176       fFieldMap[0] = new AliFieldMap();
177       fFieldMap[0] -> SetLimits(-800., 800., -800., 800., -700., 700.);
178       switch(fMap) {
179       case k2kG:
180           fSolenoid = 2.;
181           break;
182       case k4kG:
183           fSolenoid = 4.;
184           break;
185       case k5kG:
186           fSolenoid = 5.;
187           break;
188       }
189       fSolenoidUser = fSolenoid;
190   }
191 }
192
193 //_______________________________________________________________________
194 Float_t AliMagFMaps::SolenoidField() const
195 {
196   //
197   // Returns max. L3 (solenoid) field strength 
198   // according to field map setting 
199   //
200   return fSolenoid;
201 }
202
203 //_______________________________________________________________________
204 void AliMagFMaps::Field(Float_t *x, Float_t *b)
205 {
206   //
207   // Method to calculate the magnetic field
208   //
209   // --- find the position in the grid ---
210   
211
212     
213     if (!fFieldRead) ReadField();
214
215   //
216   // Field Maps have been calculated for the coordinate system in which 
217   // the Muon Spectrometer is placed at z > 0
218   // Transform coordinates corresponingly 
219   //
220   
221   b[0]=b[1]=b[2]=0;
222   Float_t xm[3];
223   xm[0] = - x[0];
224   xm[1] =   x[1];
225   xm[2] = - x[2];
226   
227   AliFieldMap* map = 0;
228   if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
229       map = fFieldMap[0];
230       if (!fL3Option) {
231       //
232       //     Constant L3 field, if this option was selected
233       //
234           b[2] = fSolenoidUser;
235           return;
236     }
237   } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
238     map = fFieldMap[1];
239   } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
240     map = fFieldMap[2];
241   }
242   
243   if(map){
244     map->Field(xm,b);
245     b[0] = - b[0];
246     b[2] = - b[2];
247
248   } else {
249       //This is the ZDC part
250       ZDCField(x, b);
251   }
252
253   
254   if(fFactor!=1) {
255       b[0]*=fFactor;
256       b[1]*=fFactor;
257       b[2]*=fFactor;
258   }
259 }
260
261 //_______________________________________________________________________
262 void AliMagFMaps::Copy(AliMagFMaps & /* magf */) const
263 {
264   //
265   // Copy *this onto magf -- Not implemented
266   //
267   Fatal("Copy","Not implemented!\n");
268 }
269
270 //_______________________________________________________________________
271 void AliMagFMaps::Streamer(TBuffer &R__b)
272 {
273   // Stream an object of class AliMagFMaps.
274   if (R__b.IsReading()) {
275     AliMagFMaps::Class()->ReadBuffer(R__b, this);
276     fFieldRead = 0;
277   } else {
278     AliMagFMaps::Class()->WriteBuffer(R__b, this);
279   }
280 }