]>
Commit | Line | Data |
---|---|---|
af9df62e | 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 | ||
e54bf126 | 18 | /// \ingroup macros |
19 | /// \file MUONAlignment.C | |
20 | /// \brief Macro for MUON alignment using physics tracks. | |
21 | /// | |
22 | /// The macro uses the AliMUONAlignment class to calculate the alignment parameters. | |
23 | /// An array for the alignment parameters is created and can be filled with | |
24 | /// initial values that will be used as starting values by the alignment | |
25 | /// algorithm. | |
26 | /// | |
27 | /// By default the macro run over galice.root in the working directory. If a file list | |
28 | /// of galice.root is provided as third argument the macro will run over all files. | |
29 | /// The macro loop over the files, events and tracks. For each track | |
30 | /// AliMUONAlignment::ProcessTrack(AliMUONTrack * track) and then | |
31 | /// AliMUONAlignment::LocalFit(Int_t iTrack, Double_t *lTrackParam, Int_t | |
32 | /// lSingleFit) are called. After all tracks have been procesed and fitted | |
33 | /// AliMUONAlignment::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls) | |
34 | /// is called. The array parameters contains the obatained misalignement parameters. | |
35 | /// A realigned geometry is generated in a local CDB. | |
36 | /// | |
37 | /// \author: B. Becker and J. Castillo | |
af9df62e | 38 | |
2688ea9b | 39 | #if !defined(__CINT__) || defined(__MAKECINT__) |
40 | ||
41 | #include "AliMUONAlignment.h" | |
42 | #include "AliMUONTrack.h" | |
43 | #include "AliMUONTrackExtrap.h" | |
44 | #include "AliMUONTrackParam.h" | |
45 | #include "AliMUONGeometryTransformer.h" | |
103e6575 | 46 | #include "AliMUONESDInterface.h" |
47 | ||
61fed964 | 48 | #include "AliESDEvent.h" |
49 | #include "AliESDMuonTrack.h" | |
2688ea9b | 50 | #include "AliMagFMaps.h" |
51 | #include "AliTracker.h" | |
52 | #include "AliCDBManager.h" | |
53 | #include "AliCDBMetaData.h" | |
54 | #include "AliCDBId.h" | |
a02fe82d | 55 | #include "AliGeomManager.h" |
2688ea9b | 56 | |
57 | #include <TString.h> | |
2688ea9b | 58 | #include <TError.h> |
59 | #include <TH1.h> | |
60 | #include <TGraphErrors.h> | |
61 | #include <TFile.h> | |
61fed964 | 62 | #include <TTree.h> |
2688ea9b | 63 | #include <TClonesArray.h> |
64 | #include <Riostream.h> | |
65 | ||
66 | #include <fstream> | |
67 | ||
68 | #endif | |
69 | ||
61fed964 | 70 | void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root", TString esdFileName = "AliESDs.root", TString fileList = "") |
af9df62e | 71 | { |
72 | ||
59830a87 | 73 | // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex) |
a02fe82d | 74 | if ( ! AliGeomManager::GetGeometry() ) { |
75 | AliGeomManager::LoadGeometry(geoFilename); | |
76 | if (! AliGeomManager::GetGeometry() ) { | |
77 | Error("MUONAlignment", "getting geometry from file %s failed", geoFilename); | |
59830a87 | 78 | return; |
79 | } | |
80 | } | |
81 | ||
82 | // set mag field | |
83 | // waiting for mag field in CDB | |
84 | printf("Loading field map...\n"); | |
85 | AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG); | |
86 | AliTracker::SetFieldMap(field, kFALSE); | |
87 | // set the magnetic field for track extrapolations | |
88 | AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap()); | |
89 | ||
af9df62e | 90 | Double_t parameters[3*156]; |
91 | Double_t errors[3*156]; | |
92 | Double_t pulls[3*156]; | |
93 | for(Int_t k=0;k<3*156;k++) { | |
94 | parameters[k]=0.; | |
95 | errors[k]=0.; | |
96 | pulls[k]=0.; | |
97 | } | |
98 | ||
99 | Double_t trackParams[8] = {0.,0.,0.,0.,0.,0.,0.,0.}; | |
100 | ||
af9df62e | 101 | // Set initial values here, good guess may help convergence |
102 | // St 1 | |
2688ea9b | 103 | // Int_t iPar = 0; |
104 | // parameters[iPar++] = 0.010300 ; parameters[iPar++] = 0.010600 ; parameters[iPar++] = 0.000396 ; | |
af9df62e | 105 | |
106 | bool bLoop = kFALSE; | |
107 | ifstream sFileList; | |
108 | if (fileList.Contains(".list")) { | |
109 | cout << "Reading file list: " << fileList.Data() << endl; | |
110 | bLoop = kTRUE; | |
111 | ||
112 | TString fullListName("."); | |
113 | fullListName +="/"; | |
114 | fullListName +=fileList; | |
115 | sFileList.open(fileList.Data()); | |
116 | } | |
117 | ||
118 | TH1F *fInvBenMom = new TH1F("fInvBenMom","fInvBenMom",200,-0.1,0.1); | |
119 | TH1F *fBenMom = new TH1F("fBenMom","fBenMom",200,-40,40); | |
120 | ||
121 | AliMUONAlignment* alig = new AliMUONAlignment(); | |
122 | alig->InitGlobalParameters(parameters); | |
123 | ||
a02fe82d | 124 | AliMUONGeometryTransformer *transform = new AliMUONGeometryTransformer(); |
125 | transform->LoadGeometryData(); | |
af9df62e | 126 | alig->SetGeometryTransformer(transform); |
7f8c1308 | 127 | |
128 | // Do alignment with magnetic field off | |
129 | alig->SetBFieldOn(kFALSE); | |
587965bd | 130 | |
131 | // Set tracking station to use | |
132 | Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; | |
d8ad38e5 | 133 | Bool_t bChOnOff[10] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; |
587965bd | 134 | |
135 | // Fix parameters or add constraints here | |
d8ad38e5 | 136 | // for (Int_t iSt=0; iSt<5; iSt++) |
137 | // if (!bStOnOff[iSt]) alig->FixStation(iSt+1); | |
138 | for (Int_t iCh=0; iCh<10; iCh++) | |
139 | if (!bChOnOff[iCh]) alig->FixChamber(iCh+1); | |
587965bd | 140 | |
141 | // Left and right sides of the detector are independent, one can choose to align | |
142 | // only one side | |
143 | Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE}; | |
d8ad38e5 | 144 | alig->FixHalfSpectrometer(bChOnOff,bSpecLROnOff); |
145 | ||
146 | alig->SetChOnOff(bChOnOff); | |
147 | alig->SetSpecLROnOff(bChOnOff); | |
587965bd | 148 | |
149 | // Set predifined global constrains: X, Y, P, XvsZ, YvsZ, PvsZ, XvsY, YvsY, PvsY | |
150 | Bool_t bVarXYT[9] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; | |
151 | Bool_t bDetTLBR[4] = {kFALSE,kTRUE,kFALSE,kTRUE}; | |
d8ad38e5 | 152 | alig->AddConstraints(bChOnOff,bVarXYT,bDetTLBR,bSpecLROnOff); |
587965bd | 153 | |
af9df62e | 154 | |
155 | char cFileName[100]; | |
7f8c1308 | 156 | |
af9df62e | 157 | Int_t lMaxFile = 1000; |
158 | Int_t iFile = 0; | |
587965bd | 159 | Int_t iEvent = 0; |
af9df62e | 160 | bool bKeepLoop = kTRUE; |
587965bd | 161 | Int_t iTrackTot=0; |
162 | Int_t iTrackOk=0; | |
163 | ||
af9df62e | 164 | while(bKeepLoop && iFile<lMaxFile){ |
165 | iFile++; | |
166 | if (bLoop) { | |
167 | sFileList.getline(cFileName,100); | |
168 | if (sFileList.eof()) bKeepLoop = kFALSE; | |
169 | } | |
170 | else { | |
61fed964 | 171 | sprintf(cFileName,esdFileName.Data()); |
af9df62e | 172 | bKeepLoop = kFALSE; |
173 | } | |
61fed964 | 174 | if (!strstr(cFileName,"AliESDs.root")) continue; |
af9df62e | 175 | cout << "Using file: " << cFileName << endl; |
61fed964 | 176 | |
177 | // load ESD event | |
178 | TFile* esdFile = TFile::Open(cFileName); // open the file | |
179 | if (!esdFile || !esdFile->IsOpen()) { | |
180 | cout << "opening ESD file " << cFileName << "failed" << endl; | |
181 | continue; | |
182 | } | |
183 | TTree* esdTree = (TTree*) esdFile->Get("esdTree"); // get the tree | |
184 | if (!esdTree) { | |
185 | cout << "no ESD tree found" << endl; | |
186 | esdFile->Close(); | |
187 | continue; | |
188 | } | |
189 | AliESDEvent* esdEvent = new AliESDEvent(); // link ESD event to the tree | |
190 | esdEvent->ReadFromTree(esdTree); | |
7f8c1308 | 191 | |
61fed964 | 192 | Int_t nevents = esdTree->GetEntries(); |
587965bd | 193 | cout << "... with " << nevents << endl; |
af9df62e | 194 | for(Int_t event = 0; event < nevents; event++) { |
587965bd | 195 | if (iEvent >= nEvents){ |
196 | bKeepLoop = kFALSE; | |
197 | break; | |
198 | } | |
199 | iEvent++; | |
200 | ||
61fed964 | 201 | if (esdTree->GetEvent(event) <= 0) { |
202 | cout << "fails to read ESD object for event " << event << endl; | |
203 | continue; | |
204 | } | |
7f8c1308 | 205 | |
61fed964 | 206 | Int_t nTracks = Int_t(esdEvent->GetNumberOfMuonTracks()); |
207 | if (!event%100) cout << " there are " << nTracks << " tracks in event " << event << endl; | |
208 | for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) { | |
209 | AliESDMuonTrack* esdTrack = esdEvent->GetMuonTrack(iTrack); | |
210 | if (!esdTrack->ClustersStored()) continue; | |
211 | Double_t invBenMom = esdTrack->GetInverseBendingMomentum(); | |
af9df62e | 212 | fInvBenMom->Fill(invBenMom); |
213 | fBenMom->Fill(1./invBenMom); | |
214 | if (TMath::Abs(invBenMom)<=1.04) { | |
103e6575 | 215 | AliMUONTrack track; |
ad3c6eda | 216 | AliMUONESDInterface::ESDToMUON(*esdTrack, track); |
61fed964 | 217 | alig->ProcessTrack(&track); |
af9df62e | 218 | alig->LocalFit(iTrackOk++,trackParams,0); |
219 | } | |
587965bd | 220 | iTrackTot++; |
af9df62e | 221 | } |
222 | } | |
61fed964 | 223 | delete esdEvent; |
224 | esdFile->Close(); | |
587965bd | 225 | cout << "Processed " << iTrackTot << " Tracks so far." << endl; |
af9df62e | 226 | } |
227 | alig->GlobalFit(parameters,errors,pulls); | |
228 | ||
229 | cout << "Done with GlobalFit " << endl; | |
230 | ||
231 | // Store results | |
232 | Double_t DEid[156] = {0}; | |
233 | Double_t MSDEx[156] = {0}; | |
234 | Double_t MSDEy[156] = {0}; | |
235 | Double_t MSDExt[156] = {0}; | |
236 | Double_t MSDEyt[156] = {0}; | |
237 | Double_t DEidErr[156] = {0}; | |
238 | Double_t MSDExErr[156] = {0}; | |
239 | Double_t MSDEyErr[156] = {0}; | |
240 | Double_t MSDExtErr[156] = {0}; | |
241 | Double_t MSDEytErr[156] = {0}; | |
242 | Int_t lNDetElem = 4*2+4*2+18*2+26*2+26*2; | |
243 | Int_t lNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26}; | |
2688ea9b | 244 | // Int_t lSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156}; |
af9df62e | 245 | Int_t idOffset = 0; // 400 |
246 | Int_t lSDetElemCh = 0; | |
247 | for(Int_t iDE=0; iDE<lNDetElem; iDE++){ | |
248 | DEidErr[iDE] = 0.; | |
249 | DEid[iDE] = idOffset+100; | |
250 | DEid[iDE] += iDE; | |
251 | lSDetElemCh = 0; | |
252 | for(Int_t iCh=0; iCh<9; iCh++){ | |
253 | lSDetElemCh += lNDetElemCh[iCh]; | |
254 | if (iDE>=lSDetElemCh) { | |
255 | DEid[iDE] += 100; | |
256 | DEid[iDE] -= lNDetElemCh[iCh]; | |
257 | } | |
258 | } | |
259 | MSDEx[iDE]=parameters[3*iDE+0]; | |
260 | MSDEy[iDE]=parameters[3*iDE+1]; | |
261 | MSDExt[iDE]=parameters[3*iDE+2]; | |
262 | MSDEyt[iDE]=parameters[3*iDE+2]; | |
263 | MSDExErr[iDE]=(Double_t)alig->GetParError(3*iDE+0); | |
264 | MSDEyErr[iDE]=(Double_t)alig->GetParError(3*iDE+1); | |
265 | MSDExtErr[iDE]=(Double_t)alig->GetParError(3*iDE+2); | |
266 | MSDEytErr[iDE]=(Double_t)alig->GetParError(3*iDE+2); | |
267 | } | |
268 | ||
269 | cout << "Let's create graphs ... " << endl; | |
270 | ||
271 | TGraphErrors *gMSDEx = new TGraphErrors(lNDetElem,DEid,MSDEx,DEidErr,MSDExErr); | |
272 | TGraphErrors *gMSDEy = new TGraphErrors(lNDetElem,DEid,MSDEy,DEidErr,MSDEyErr); | |
273 | TGraphErrors *gMSDExt = new TGraphErrors(lNDetElem,DEid,MSDExt,DEidErr,MSDExtErr); | |
274 | TGraphErrors *gMSDEyt = new TGraphErrors(lNDetElem,DEid,MSDEyt,DEidErr,MSDEytErr); | |
275 | ||
276 | cout << "... graphs created, open file ... " << endl; | |
277 | ||
278 | TFile *hFile = new TFile("measShifts.root","RECREATE"); | |
279 | ||
280 | cout << "... file opened ... " << endl; | |
281 | ||
282 | gMSDEx->Write("gMSDEx"); | |
283 | gMSDEy->Write("gMSDEy"); | |
284 | gMSDExt->Write("gMSDExt"); | |
285 | gMSDEyt->Write("gMSDEyt"); | |
286 | fInvBenMom->Write(); | |
287 | fBenMom->Write(); | |
288 | hFile->Close(); | |
289 | ||
290 | cout << "... and closed!" << endl; | |
291 | // Re Align | |
292 | AliMUONGeometryTransformer *newTransform = alig->ReAlign(transform,parameters,true); | |
293 | newTransform->WriteTransformations("transform2ReAlign.dat"); | |
294 | ||
295 | // Generate realigned data in local cdb | |
2688ea9b | 296 | const TClonesArray* array = newTransform->GetMisAlignmentData(); |
4818a9b7 | 297 | |
298 | // 100 mum residual resolution for chamber misalignments? | |
299 | alig->SetAlignmentResolution(array,-1,0.01,0.01,0.004,0.003); | |
af9df62e | 300 | |
301 | // CDB manager | |
302 | AliCDBManager* cdbManager = AliCDBManager::Instance(); | |
303 | cdbManager->SetDefaultStorage("local://ReAlignCDB"); | |
304 | ||
305 | AliCDBMetaData* cdbData = new AliCDBMetaData(); | |
306 | cdbData->SetResponsible("Dimuon Offline project"); | |
307 | cdbData->SetComment("MUON alignment objects with residual misalignment"); | |
d8ad38e5 | 308 | AliCDBId id("MUON/Align/Data", 0, AliCDBRunRange::Infinity()); |
2688ea9b | 309 | cdbManager->Put(const_cast<TClonesArray*>(array), id, cdbData); |
af9df62e | 310 | |
61fed964 | 311 | } |
312 |