1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 // Macro for MUON alignment using physics tracks. The macro uses AliMUONAlignment
20 // class to calculate the alignment parameters.
21 // An array for the alignment parameters is created and can be filled with
22 // initial values that will be used as starting values by the alignment
24 // Ny default the macro run over galice.root in the working directory. If a file list
25 // of galice.root is provided as third argument the macro will run over all files.
26 // The macro loop over the files, events and tracks. For each track
27 // AliMUONAlignment::ProcessTrack(AliMUONTrack * track) and then
28 // AliMUONAlignment::LocalFit(Int_t iTrack, Double_t *lTrackParam, Int_t
29 // lSingleFit) are called. After all tracks have been procesed and fitted
30 // AliMUONAlignment::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls)
31 // is called. The array parameters contains the obatained misalignement parameters.
32 // A realigned geometry is generated in a local CDB.
34 // Authors: B. Becker and J. Castillo
37 #if !defined(__CINT__) || defined(__MAKECINT__)
39 #include "AliMUONAlignment.h"
40 #include "AliMUONTrack.h"
41 #include "AliMUONTrackExtrap.h"
42 #include "AliMUONTrackParam.h"
43 #include "AliMUONGeometryTransformer.h"
44 #include "AliMUONDataInterface.h"
46 #include "AliMagFMaps.h"
47 #include "AliTracker.h"
48 #include "AliCDBManager.h"
49 #include "AliCDBMetaData.h"
53 #include <TGeoManager.h>
56 #include <TGraphErrors.h>
58 #include <TClonesArray.h>
59 #include <Riostream.h>
65 void MUONAlignment(Int_t nEvents = 100000, char* geoFilename = "geometry.root", TString fileName = "galice.root", TString fileList = "")
68 // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
70 TGeoManager::Import(geoFilename);
72 Error("MUONmass_ESD", "getting geometry from file %s failed", geoFilename);
78 // waiting for mag field in CDB
79 printf("Loading field map...\n");
80 AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
81 AliTracker::SetFieldMap(field, kFALSE);
82 // set the magnetic field for track extrapolations
83 AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
85 Double_t parameters[3*156];
86 Double_t errors[3*156];
87 Double_t pulls[3*156];
88 for(Int_t k=0;k<3*156;k++) {
94 Double_t trackParams[8] = {0.,0.,0.,0.,0.,0.,0.,0.};
96 // Set initial values here, good guess may help convergence
99 // parameters[iPar++] = 0.010300 ; parameters[iPar++] = 0.010600 ; parameters[iPar++] = 0.000396 ;
103 if (fileList.Contains(".list")) {
104 cout << "Reading file list: " << fileList.Data() << endl;
107 TString fullListName(".");
109 fullListName +=fileList;
110 sFileList.open(fileList.Data());
113 TH1F *fInvBenMom = new TH1F("fInvBenMom","fInvBenMom",200,-0.1,0.1);
114 TH1F *fBenMom = new TH1F("fBenMom","fBenMom",200,-40,40);
116 AliMUONAlignment* alig = new AliMUONAlignment();
117 alig->InitGlobalParameters(parameters);
119 AliMUONGeometryTransformer *transform = new AliMUONGeometryTransformer(true);
120 transform->ReadGeometryData("volpath.dat", gGeoManager);
121 alig->SetGeometryTransformer(transform);
123 // Set tracking station to use
124 Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
126 // Fix parameters or add constraints here
127 for (Int_t iSt=0; iSt<5; iSt++)
128 if (!bStOnOff[iSt]) alig->FixStation(iSt+1);
130 // Left and right sides of the detector are independent, one can choose to align
132 Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE};
133 alig->FixHalfSpectrometer(bStOnOff,bSpecLROnOff);
135 // Set predifined global constrains: X, Y, P, XvsZ, YvsZ, PvsZ, XvsY, YvsY, PvsY
136 Bool_t bVarXYT[9] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
137 Bool_t bDetTLBR[4] = {kFALSE,kTRUE,kFALSE,kTRUE};
138 alig->AddConstraints(bStOnOff,bVarXYT,bDetTLBR,bSpecLROnOff);
142 AliMUONDataInterface amdi;
144 Int_t lMaxFile = 1000;
147 bool bKeepLoop = kTRUE;
151 while(bKeepLoop && iFile<lMaxFile){
154 sFileList.getline(cFileName,100);
155 if (sFileList.eof()) bKeepLoop = kFALSE;
158 sprintf(cFileName,fileName.Data());
161 if (!strstr(cFileName,"galice.root")) continue;
162 cout << "Using file: " << cFileName << endl;
163 amdi.SetFile(cFileName);
164 Int_t nevents = amdi.NumberOfEvents();
165 cout << "... with " << nevents << endl;
166 for(Int_t event = 0; event < nevents; event++) {
167 amdi.GetEvent(event);
168 if (iEvent >= nEvents){
174 Int_t ntracks = amdi.NumberOfRecTracks();
176 cout << " there are " << ntracks << " tracks in event " << event << endl;
178 AliMUONTrack* track = amdi.RecTrack(iTrack);
180 AliMUONTrackParam trackParam(*((AliMUONTrackParam*)(track->GetTrackParamAtHit()->First())));
181 AliMUONTrackExtrap::ExtrapToVertex(&trackParam,0.,0.,0.);
182 Double_t invBenMom = trackParam.GetInverseBendingMomentum();
183 fInvBenMom->Fill(invBenMom);
184 fBenMom->Fill(1./invBenMom);
185 if (TMath::Abs(invBenMom)<=1.04) {
186 alig->ProcessTrack(track);
187 alig->LocalFit(iTrackOk++,trackParams,0);
191 track = amdi.RecTrack(iTrack);
194 cout << "Processed " << iTrackTot << " Tracks so far." << endl;
196 alig->GlobalFit(parameters,errors,pulls);
198 cout << "Done with GlobalFit " << endl;
201 Double_t DEid[156] = {0};
202 Double_t MSDEx[156] = {0};
203 Double_t MSDEy[156] = {0};
204 Double_t MSDExt[156] = {0};
205 Double_t MSDEyt[156] = {0};
206 Double_t DEidErr[156] = {0};
207 Double_t MSDExErr[156] = {0};
208 Double_t MSDEyErr[156] = {0};
209 Double_t MSDExtErr[156] = {0};
210 Double_t MSDEytErr[156] = {0};
211 Int_t lNDetElem = 4*2+4*2+18*2+26*2+26*2;
212 Int_t lNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26};
213 // Int_t lSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156};
214 Int_t idOffset = 0; // 400
215 Int_t lSDetElemCh = 0;
216 for(Int_t iDE=0; iDE<lNDetElem; iDE++){
218 DEid[iDE] = idOffset+100;
221 for(Int_t iCh=0; iCh<9; iCh++){
222 lSDetElemCh += lNDetElemCh[iCh];
223 if (iDE>=lSDetElemCh) {
225 DEid[iDE] -= lNDetElemCh[iCh];
228 MSDEx[iDE]=parameters[3*iDE+0];
229 MSDEy[iDE]=parameters[3*iDE+1];
230 MSDExt[iDE]=parameters[3*iDE+2];
231 MSDEyt[iDE]=parameters[3*iDE+2];
232 MSDExErr[iDE]=(Double_t)alig->GetParError(3*iDE+0);
233 MSDEyErr[iDE]=(Double_t)alig->GetParError(3*iDE+1);
234 MSDExtErr[iDE]=(Double_t)alig->GetParError(3*iDE+2);
235 MSDEytErr[iDE]=(Double_t)alig->GetParError(3*iDE+2);
238 cout << "Let's create graphs ... " << endl;
240 TGraphErrors *gMSDEx = new TGraphErrors(lNDetElem,DEid,MSDEx,DEidErr,MSDExErr);
241 TGraphErrors *gMSDEy = new TGraphErrors(lNDetElem,DEid,MSDEy,DEidErr,MSDEyErr);
242 TGraphErrors *gMSDExt = new TGraphErrors(lNDetElem,DEid,MSDExt,DEidErr,MSDExtErr);
243 TGraphErrors *gMSDEyt = new TGraphErrors(lNDetElem,DEid,MSDEyt,DEidErr,MSDEytErr);
245 cout << "... graphs created, open file ... " << endl;
247 TFile *hFile = new TFile("measShifts.root","RECREATE");
249 cout << "... file opened ... " << endl;
251 gMSDEx->Write("gMSDEx");
252 gMSDEy->Write("gMSDEy");
253 gMSDExt->Write("gMSDExt");
254 gMSDEyt->Write("gMSDEyt");
259 cout << "... and closed!" << endl;
261 AliMUONGeometryTransformer *newTransform = alig->ReAlign(transform,parameters,true);
262 newTransform->WriteTransformations("transform2ReAlign.dat");
264 // Generate realigned data in local cdb
265 const TClonesArray* array = newTransform->GetMisAlignmentData();
268 AliCDBManager* cdbManager = AliCDBManager::Instance();
269 cdbManager->SetDefaultStorage("local://ReAlignCDB");
271 AliCDBMetaData* cdbData = new AliCDBMetaData();
272 cdbData->SetResponsible("Dimuon Offline project");
273 cdbData->SetComment("MUON alignment objects with residual misalignment");
274 AliCDBId id("MUON/Align/Data", 0, 0);
275 cdbManager->Put(const_cast<TClonesArray*>(array), id, cdbData);