]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/macros/CreateCDBFieldIntegrals.C
Coverity Fix for the DptDpt Code
[u/mrichter/AliRoot.git] / HLT / MUON / macros / CreateCDBFieldIntegrals.C
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Artur Szostak <artursz@iafrica.com>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 // $Id: DisplaydHLTData.C 37070 2009-11-20 13:53:08Z aszostak $
18
19 /**
20  * \ingroup macros
21  * \file CreateCDBFieldIntegrals.C
22  * \brief Macro for creating and storing the magnetic field integrals in the CDB.
23  *
24  * This macro calculates the magnetic field integrals for the dipole magnet and
25  * writes them into the CDB under the HLT/ConfigMUON/FieldIntegrals path.
26  * These are then used by the online dHLT reconstruction components during
27  * momentum estimation of the tracks found.
28  * The simplest method to run this macro is with the following command:
29  * \code
30  *   > aliroot -b -q -l CreateCDBFieldIntegrals.C
31  * \endcode
32  *
33  * \author Artur Szostak <artursz@iafrica.com>
34  */
35
36 #if !defined(__CINT__) || defined(__MAKECINT__)
37 #include "AliCDBManager.h"
38 #include "AliCDBStorage.h"
39 #include "AliCDBEntry.h"
40 #include "AliGRPManager.h"
41 #include "AliHLTMUONConstants.h"
42 #include "AliMagF.h"
43 #include "TMap.h"
44 #include "TArrayD.h"
45 #include "TObjString.h"
46 #include "TString.h"
47 #include "TVector3.h"
48 #include "TMath.h"
49 #include "TSystem.h"
50 #include <iostream>
51 using std::cout;
52 using std::cerr;
53 using std::endl;
54 #endif
55
56 /**
57  * Calculates the average magnetic field integral for the dipole magnet given the
58  * L3 solenoid current and dipole magnet current.
59  * \param [in] currentL3  The current in the L3 solenoid magnet.
60  * \param [in] currentDip  The current in the dipole magnet.
61  * \param [out] result  The magnetic field integral result.
62  * \param [in] sqrts  The centre of mass energy for the beams.
63  * \param [in] beamtype  The beam type as given the AliMagF, eg. p-p, A-A or none.
64  * \note The sign of the current indicates the polarity setting for the magnet.
65  * \returns  true if the magnetic field was calculated successfully and false otherwise.
66  */
67 bool CalculateIntegral(
68                 Float_t currentL3, Float_t currentDip, Float_t& result,
69                 Float_t sqrts = 0, const char* beamtype = "none"
70         )
71 {
72         AliMagF* fld = AliMagF::CreateFieldMap(currentL3, currentDip, AliMagF::kConvLHC, kFALSE, sqrts, beamtype);
73         if (fld == NULL) return false;
74         
75         TArrayD totals;
76         for (int theta = 171; theta <= 179; ++theta)
77         for (int phi = 0; phi < 360; phi += 10)
78         {
79                 TVector3 dr;
80                 dr.SetMagThetaPhi(1, theta*TMath::Pi()/180., phi*TMath::Pi()/180.);
81                 Double_t dx = 1e-3 * dr.Mag();
82                 
83                 TVector3 r(0, 0, 0);
84                 int nsteps = 0;
85                 Double_t total = 0;
86                 while (r.Z() > -1700 && nsteps < 10000)
87                 {
88                         Double_t p[3] = {r.X(), r.Y(), r.Z()};
89                         Double_t b[3];
90                         fld->Field(p, b);
91                         total += b[0] * dx;
92                         ++nsteps;
93                         r += dr;
94                 }
95                 
96                 totals.Set(totals.GetSize()+1);
97                 totals[totals.GetSize()-1] = total;
98         }
99         
100         result = - TMath::Mean(totals.GetSize(), totals.GetArray());
101         Float_t rms = TMath::RMS(totals.GetSize(), totals.GetArray());
102         
103         cout << "Integrated field value = " << result
104                 << " +/- " << rms
105                 << ", for L3 current = " << currentL3
106                 << ", dipole current = " << currentDip << endl;
107         return true;
108 }
109
110 /**
111  * Calculates the magnetic field integrals for the dipole magnet and stores them
112  * into the CDB.
113  * \param cdbPath  The path to the local storage.
114  * \param version  The version of the CDB entry.
115  * \param firstRun = The first run number for which the CDB entry is valid.
116  * \param lastRun = The last run number for which the CDB entry is valid.
117  * \param sqrts  The centre of mass energy for the beams.
118  * \param beamtype  The beam type as given the AliMagF, eg. p-p, A-A or none.
119  */
120 void CreateCDBFieldIntegrals(
121                 const char* cdbPath = "local://$ALICE_ROOT/OCDB",
122                 Int_t version = 0,
123                 Int_t firstRun = 0,
124                 Int_t lastRun = AliCDBRunRange::Infinity(),
125                 Float_t sqrts = 0,
126                 const char* beamtype = "none"
127         )
128 {
129         // Get the CDB manager and storage.
130         AliCDBManager* cdbManager = AliCDBManager::Instance();
131         if (cdbManager == NULL)
132         {
133                 cerr << "ERROR: Global CDB manager object does not exist." << endl;
134                 return;
135         }
136         AliCDBStorage* storage = cdbManager->GetStorage(cdbPath);
137         if (storage == NULL)
138         {
139                 cerr << "ERROR: Could not get storage for: " << cdbPath << endl;
140                 return;
141         }
142         
143         const int nL3Current = 5;
144         const int nDipCurrent = 3;
145         Float_t currentL3[nL3Current] = {-30e3, -12e3, 0, 12e3, 30e3};
146         Float_t currentDip[nDipCurrent] = {-6e3, 0, 6e3};
147         
148         // Create and store the configuration parameters for the trigger reconstructor.
149         TMap* params = new TMap;
150         params->SetOwner(kTRUE);
151         for (int i = 0; i < nL3Current; ++i)
152         for (int j = 0; j < nDipCurrent; ++j)
153         {
154                 if (currentL3[i]*currentDip[j] < 0) continue; // Skip invalid combinations.
155                 Float_t bfieldintegral;
156                 if (! CalculateIntegral(currentL3[i], currentDip[j], bfieldintegral, sqrts, beamtype)) continue;
157                 const char* paramName = Form("L3_current=%0.2e;Dipole_current=%0.2e", currentL3[i], currentDip[j]);
158                 const char* paramValue = Form("%8.8f", bfieldintegral);
159                 params->Add(new TObjString(paramName), new TObjString(paramValue));
160         }
161         
162         const char* path = AliHLTMUONConstants::FieldIntegralsCDBPath();
163         AliCDBId id(path, firstRun, lastRun, version);
164         AliCDBMetaData* metaData = new AliCDBMetaData();
165         metaData->SetResponsible("dimuon HLT");
166         metaData->SetComment("Magnetic field integral parameters for dimuon HLT.");
167         storage->Put(params, id, metaData);
168 }