.so cleanup: more gSystem->Load()
[u/mrichter/AliRoot.git] / PWG / muon / buildMuonTrackCutsOADB.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include "Riostream.h"
3 #include "TString.h"
4 #include "TROOT.h"
5 #include "TSystem.h"
6
7 #include "AliOADBContainer.h"
8 #include "AliOADBMuonTrackCutsParam.h"
9 #endif
10
11 // Needed libraries:
12 // gSystem->Load("libANALYSIS");gSystem->Load("libOADB");gSystem->Load("libANALYSISalice");gSystem->Load("libCORRFW");gSystem->Load("libPWGmuon");
13
14 //________________________________________________________
15 AliOADBMuonTrackCutsParam* CreateOADBObject ( TString periodName, Double_t meanDcaX, Double_t meanDcaY, Double_t meanDcaZ, Double_t meanPCorr23, Double_t meanPCorr310, Double_t sigmaPdca23, Double_t sigmaPdca310, Double_t nSigmaPdca, Double_t chi2NormCut, Double_t relPResolution, Double_t slopeResolution, Double_t sharpPtApt, Double_t sharpPtLpt, Double_t sharpPtHpt )
16 {
17   AliOADBMuonTrackCutsParam* oadbObj = new AliOADBMuonTrackCutsParam ( periodName.Data() );
18   oadbObj->SetMeanDCA ( meanDcaX, meanDcaY, meanDcaZ );
19   oadbObj->SetMeanPCorr ( meanPCorr23, meanPCorr310 );
20   oadbObj->SetSigmaPdca ( sigmaPdca23, sigmaPdca310 );
21   oadbObj->SetNSigmaPdca ( nSigmaPdca );
22   oadbObj->SetChi2NormCut ( chi2NormCut );
23   oadbObj->SetRelPResolution ( relPResolution );
24   oadbObj->SetSlopeResolution ( slopeResolution );
25   oadbObj->SetSharpPtCut ( sharpPtApt, sharpPtLpt, sharpPtHpt );
26
27   return oadbObj;
28 }
29
30 //________________________________________________________
31 Bool_t HasDefault ( AliOADBContainer* container )
32 {
33   return ( container->GetDefaultList()->GetEntries() > 0 );
34 }
35
36 //________________________________________________________
37 void AddParams ( AliOADBContainer* container, AliOADBMuonTrackCutsParam* oadbObj, Int_t firstRun, Int_t lastRun, TString passName, AliOADBContainer* defaultContainer = 0x0 )
38 {
39   TString oadbObjName = oadbObj->GetName();
40   if ( ! oadbObjName.Contains(passName.Data()) ) oadbObjName += "_" + passName;
41   oadbObj->SetName(oadbObjName.Data());
42   container->AppendObject ( oadbObj, firstRun, lastRun, passName );
43   if ( ! defaultContainer ) return;
44   defaultContainer->AppendObject ( oadbObj->Clone(), firstRun, lastRun );
45 }
46
47 enum {kData, kDataDef, kMC, kMCDef, kNcontainers};
48 AliOADBContainer* containers[kNcontainers] = {0x0};
49
50 //________________________________________________________
51 void FillDataAndMC ( AliOADBMuonTrackCutsParam* oadbObj, Int_t firstRun, Int_t lastRun, TString passName, Bool_t isDefault, Bool_t resetDCAforMC = kTRUE )
52 {
53   AliOADBContainer* defContainer = ( isDefault ) ? containers[kDataDef] : 0x0;
54   AddParams ( containers[kData], oadbObj, firstRun, lastRun, passName, defContainer );
55   AliOADBMuonTrackCutsParam* oadbObjMC = static_cast<AliOADBMuonTrackCutsParam*>(oadbObj->Clone());
56   if ( resetDCAforMC ) oadbObjMC->SetMeanDCA ( 0., 0., 0. );
57   defContainer = ( isDefault ) ? containers[kMCDef] : 0x0;
58   AddParams ( containers[kMC], oadbObjMC, firstRun, lastRun, passName, defContainer );
59 }
60
61 //________________________________________________________
62 void buildMuonTrackCutsOADB ( )
63 {
64   Double_t defMeanPCorr23 = 2.*1.5;
65   Double_t defMeanPCorr310 = 2.*1.2;
66   Double_t defSigmaPdca23 = 99.;
67   Double_t defSigmaPdca310 = 54.;
68   Double_t defNSigmaPdca = 6.;
69   Double_t defChi2NormCut = 1.e6;
70   Double_t lut4 = 4.2;
71   Double_t lut2 = 1.7;
72   Double_t lut1 = 1.0;
73   Double_t lut05 = 0.5;
74
75   AliOADBMuonTrackCutsParam* oadbObj = 0x0;
76
77   TString baseContName = "MuonTrackCutsParam";
78   TString contNameSuffix[kNcontainers] = {"data","data_def","MC","MC_def"};
79
80
81   for ( Int_t icont=0; icont<kNcontainers; icont++ ) {
82     containers[icont] = new AliOADBContainer(Form("%s_%s",baseContName.Data(),contNameSuffix[icont].Data()));
83     oadbObj = CreateOADBObject ( "default",
84                                 0., 0., 0.,
85                                 defMeanPCorr23, defMeanPCorr310,
86                                 defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
87                                 defChi2NormCut,
88                                 5.e-4, 6.e-4,
89                                 0., lut1, lut4 );
90     containers[icont]->AddDefaultObject(oadbObj);
91   }
92
93
94
95   oadbObj = CreateOADBObject ( "LHC12hi",
96                               0.18943, -0.250591, 0.,
97                               defMeanPCorr23, defMeanPCorr310,
98                               80., defSigmaPdca310, defNSigmaPdca,
99                               defChi2NormCut,
100                               4.e-4, 5.e-4,
101                               0., lut1, lut4 );
102   FillDataAndMC ( oadbObj, 189576, 193341, "muon_calo_pass2", kTRUE );
103
104
105   oadbObj = CreateOADBObject ( "LHC13def",
106                               0.18943, -0.250591, 0.,
107                               defMeanPCorr23, defMeanPCorr310,
108                               80., defSigmaPdca310, defNSigmaPdca,
109                               defChi2NormCut,
110                               4.e-4, 5.e-4,
111                               0., lut05, lut4 );
112   FillDataAndMC ( oadbObj, 195682, 197388, "muon_pass2", kTRUE );
113
114
115   oadbObj = CreateOADBObject ( "LHC13f",
116                               0.18943, -0.250591, 0.,
117                               defMeanPCorr23, defMeanPCorr310,
118                               80., defSigmaPdca310, defNSigmaPdca,
119                               defChi2NormCut,
120                               4.e-4, 5.e-4,
121                               0., lut05, lut4 );
122   FillDataAndMC ( oadbObj, 196433, 197388, "muon_calo", kFALSE );
123
124
125   oadbObj = CreateOADBObject ( "LHC11h_2",
126                               -1.118002, -1.175119, 0.,
127                               defMeanPCorr23, defMeanPCorr310,
128                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
129                               defChi2NormCut,
130                               5.e-4, 6.e-4,
131                               0., lut1, lut4 );
132   FillDataAndMC ( oadbObj, 167706, 170593, "pass2", kFALSE );
133
134
135   oadbObj = CreateOADBObject ( "LHC11c3defgh",
136                               0.296514, -0.229262, 0.,
137                               defMeanPCorr23, defMeanPCorr310,
138                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
139                               defChi2NormCut,
140                               4.e-4, 5.e-4,
141                               0., lut1, lut4 );
142   FillDataAndMC ( oadbObj, 154726, 170593, "pass2_muon", kTRUE );
143
144
145   oadbObj = CreateOADBObject ( "LHC11c2",
146                               0.296514, -0.229262, 0.,
147                               defMeanPCorr23, defMeanPCorr310,
148                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
149                               defChi2NormCut,
150                               4.e-4, 5.e-4,
151                               0., lut1, lut2 );
152   FillDataAndMC ( oadbObj, 153059, 154495, "pass2_muon", kTRUE );
153
154
155   oadbObj = CreateOADBObject ( "LHC11c1",
156                                0.296514, -0.229262, 0.,
157                                defMeanPCorr23, defMeanPCorr310,
158                                defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
159                                defChi2NormCut,
160                                4.e-4, 5.e-4,
161                                0., lut05, lut1 );
162   FillDataAndMC ( oadbObj, 151661, 152935, "pass2_muon", kTRUE );
163
164
165   oadbObj = CreateOADBObject ( "LHC11h",
166                               -1.118002, -1.175119, 0.,
167                               defMeanPCorr23, defMeanPCorr310,
168                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
169                               defChi2NormCut,
170                               5.e-4, 6.e-4,
171                               0., lut1, lut4 );
172   FillDataAndMC ( oadbObj, 167706, 170593, "pass1_muon", kFALSE );
173
174
175   oadbObj = CreateOADBObject ( "LHC11def",
176                               -1.146336, -1.130535, 0.,
177                               defMeanPCorr23, defMeanPCorr310,
178                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
179                               defChi2NormCut,
180                               5.e-4, 6.e-4,
181                               0., lut1, lut4 );
182   FillDataAndMC ( oadbObj, 156620, 162717, "pass1", kFALSE );
183
184
185   oadbObj = CreateOADBObject ( "LHC11a",
186                               -1.146336, -1.130535, 0.,
187                               defMeanPCorr23, defMeanPCorr310,
188                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
189                               defChi2NormCut,
190                               5.e-4, 6.e-4,
191                               0., lut05, lut1 );
192   FillDataAndMC ( oadbObj, 146688, 146860, "pass1", kTRUE );
193
194
195   oadbObj = CreateOADBObject ( "LHC10h",
196                               -0.4599, -0.9172, 0.,
197                               defMeanPCorr23, defMeanPCorr310,
198                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
199                               3.5,
200                               5.e-4, 6.e-4,
201                               0., lut05, lut1 );
202   FillDataAndMC ( oadbObj, 137135, 139513, "pass1", kTRUE );
203
204
205   oadbObj = CreateOADBObject ( "LHC10pp",
206                               -0.4599, -0.9172, 0.,
207                               defMeanPCorr23, defMeanPCorr310,
208                               defSigmaPdca23, defSigmaPdca310, defNSigmaPdca,
209                               defChi2NormCut,
210                               5.e-4, 6.e-4,
211                               0., lut05, lut1 );
212   FillDataAndMC ( oadbObj, 114783, 136376, "pass1", kTRUE );
213
214
215   TString oadbFilename = "$ALICE_ROOT/OADB/PWG/MUON/MuonTrackCuts.root";
216   if ( ! gSystem->AccessPathName(gSystem->ExpandPathName(oadbFilename.Data())) ) {
217     gSystem->Exec(Form("rm %s", oadbFilename.Data()));
218   }
219
220   for ( Int_t icont=0; icont<kNcontainers; icont++ ) {
221     containers[icont]
222     ->WriteToFile ( oadbFilename.Data() );
223   }
224 }