In test script:
[u/mrichter/AliRoot.git] / MUON / MUONSurveyCh1.C
CommitLineData
ba8b0266 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/// \ingroup macros
19/// \file MUONSurveyCh8L.C
20/// \brief Macro to process survey and photogrammetry data of chamber 1
21///
22/// Macro loads the survey data from .txt file using AliSurveyObj.
23/// Macro uses AliMUONSurvey... classes.
24/// The transformations of the detection elements or chambers can be obtained
25/// in three ways:
26/// - A: Fit of local to global transformation using the fixed button targets.
27/// - B: Fit a plane to the sticker targets -> psi, theta
28/// Use above psi and theta and fit remaining 4 parameters using the fixed
29/// button targets
30/// - C: Fit a plane to the sticker targets -> psi, theta
31/// Use above psi and theta to calculate xc, yc, zc and phi by solving
32/// the equations from a local to global transformation of the fixed button
33/// targets
34///
35/// Methods A and B are prefered to C, and B is better if sticker targets are
36/// available and lie on a plane!
37/// For slats only methods B and C can be used.
38/// Various histograms are filled and printed for monitoring.
39/// MisAlignment object is then created.
40///
41/// \author Javier Castillo
42
43#if !defined(__CINT__) || defined(__MAKECINT__)
44
45#include "AliMUONGeometryTransformer.h"
46#include "AliMUONGeometryModuleTransformer.h"
47#include "AliMUONGeometryDetElement.h"
48#include "AliMUONGeometryMisAligner.h"
49#include "AliMUONSurveyChamber.h"
50#include "AliMUONSurveyDetElem.h"
51#include "AliMUONSurveyUtil.h"
52
53#include "AliSurveyObj.h"
54#include "AliSurveyPoint.h"
55#include "AliGeomManager.h"
56#include "AliCDBManager.h"
57#include "AliCDBMetaData.h"
58#include "AliCDBId.h"
59#include "AliAlignObjMatrix.h"
60#include "AliAlignObj.h"
61
62#include <TROOT.h>
63#include <TGeoManager.h>
64#include <TClonesArray.h>
65#include <TObjArray.h>
66#include <TArrayD.h>
67#include <TMath.h>
68#include <TString.h>
69#include <TFitter.h>
70#include <TH2.h>
71#include <TF2.h>
72#include <TGraphErrors.h>
73#include <TCanvas.h>
74#include <TPad.h>
75#include <TLine.h>
76#include <TPostScript.h>
77#include <TPaveLabel.h>
78#include <TStyle.h>
79#include <TFile.h>
80#include <TMatrixDSym.h>
81
82#include <fstream>
83
84#endif
85
86void MUONSurveyCh1() {
87
88 TString str;
89 TString title;
90
91 Bool_t bMonitor = kTRUE;
92 Bool_t bOCDB = kTRUE;
93 Bool_t saveps = kFALSE;
94 const int cWidth = (int)(700*(29./21.));
95 const int cHeight = 700;
96 const int filetype = 112; // landscape
97
98 Int_t chId = 0;
99 Int_t nChs = 2;
100 Int_t nDetElems = 4;
101 Int_t nDetElemsI = 2;
102 // Int_t nDetElemsO = 2;
103 Int_t iDetElemToDetElemId[4] = {100,101,102,103};
104 Int_t iDetElemPseudoIdToDetElem[4] = {0,1,2,3};
105 Int_t iDetElemsOfChamber[2][2] = {{0,3},
106 {1,2}};
107
108 TObjArray *myChamberArray = new TObjArray();
109 myChamberArray->Add(new AliMUONSurveyChamber(chId));
110 myChamberArray->Add(new AliMUONSurveyChamber(chId));
111
112 AliMUONSurveyChamber *myChamberI = 0x0;
113 AliMUONSurveyChamber *myChamberO = 0x0;
114 AliMUONSurveyChamber *myChamber = 0x0;
115 AliMUONSurveyDetElem *myDetElem = 0x0;
116
117 myChamberI = (AliMUONSurveyChamber*)myChamberArray->At(0);
118 myChamberI->GetSurveyObj()->FillFromLocalFile("~/phgwrk/Reports/AliceSt1_TC1_1171d.txt");
119 myChamberO = (AliMUONSurveyChamber*)myChamberArray->At(1);
120 myChamberO->GetSurveyObj()->FillFromLocalFile("~/phgwrk/Reports/AliceSt1_TC1_1171d.txt");
121
122 myChamber = myChamberI;
123 myChamber->PrintSurveyReport();
124
125 // Chamber & DetElems button targets local coordinates
126 AliSurveyObj *lSO = new AliSurveyObj();
127 lSO->FillFromLocalFile("$ALICE_ROOT/MUON/data/MUONTrackingTargetsLocal.txt");
128
129 // Set survey targets for chambers
130 myChamberI->AddGButtonTargets(TString("T4_520"),3);
131 myChamberI->AddStickerTargets(TString("T4_620"),6);
132 myChamberI->AddLButtonTargets(lSO->GetData(),Form("%d_520",chId+1),3);
133 myChamberI->AddGButtonTargets(TString("T4_510"),3);
134 myChamberI->AddStickerTargets(TString("T4_610"),6);
135 myChamberI->AddLButtonTargets(lSO->GetData(),Form("%d_510",chId+1),3);
136 myChamberO->AddGButtonTargets(TString("T4_520"),3);
137 myChamberO->AddStickerTargets(TString("T4_620"),6);
138 myChamberO->AddLButtonTargets(lSO->GetData(),Form("%d_520",chId+1),3);
139 myChamberO->AddGButtonTargets(TString("T4_510"),3);
140 myChamberO->AddStickerTargets(TString("T4_610"),6);
141 myChamberO->AddLButtonTargets(lSO->GetData(),Form("%d_510",chId+1),3);
142
143 // Set survey targets for detection elements
144 for (int iCh =0; iCh<=1; iCh++) {
145 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
146 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
147 Int_t iDetElem = iDetElemsOfChamber[iCh][iDetElemI];
148 myChamber->AddSurveyDetElem(iDetElemToDetElemId[iDetElem]);
149 TString baseName;
150 myDetElem = myChamber->GetDetElem(iDetElemI);
151 if (myDetElem) {
152 baseName = Form("T4_53%d",iDetElem+1);
153 myDetElem->AddGButtonTargets(baseName,3);
154 baseName = Form("%d_53%d",chId+1,iDetElem+1);
155 myDetElem->AddLButtonTargets(lSO->GetData(),baseName,3);
156 }
157 }
158 }
159 printf("All targets added! \n");
160
161 Double_t **lCenDetElem = new Double_t*[nDetElems+nChs];
162 Double_t **lRotDetElem = new Double_t*[nDetElems+nChs];
163 Double_t **lDiffCenDetElem0 = new Double_t*[nDetElems+nChs];
164 Double_t **lDiffRotDetElem0 = new Double_t*[nDetElems+nChs];
165 Double_t **lDiffThCenDetElem0 = new Double_t*[nDetElems+nChs];
166 Double_t **lDiffThRotDetElem0 = new Double_t*[nDetElems+nChs];
167 Double_t **lDeltaDiffCenDetElem0 = new Double_t*[nDetElems+nChs];
168 Double_t **lDeltaDiffRotDetElem0 = new Double_t*[nDetElems+nChs];
169
170 for (int iDetElem=0; iDetElem<nDetElems+nChs; iDetElem++) {
171 lCenDetElem[iDetElem] = new Double_t[3];
172 lRotDetElem[iDetElem] = new Double_t[3];
173 lDiffCenDetElem0[iDetElem] = new Double_t[3];
174 lDiffRotDetElem0[iDetElem] = new Double_t[3];
175 lDiffThCenDetElem0[iDetElem] = new Double_t[3];
176 lDiffThRotDetElem0[iDetElem] = new Double_t[3];
177 lDeltaDiffCenDetElem0[iDetElem] = new Double_t[3];
178 lDeltaDiffRotDetElem0[iDetElem] = new Double_t[3];
179 }
180
181 TGeoCombiTrans dtrfDetElem[nDetElems+nChs];
182 TGeoCombiTrans localTrfDetElem[nDetElems+nChs];
183 TGeoCombiTrans localTrfThDetElem[nDetElems+nChs];
184
185 // Import TGeo geometry
186 char* geoFilename = "geometry.root";
187 if ( ! AliGeomManager::GetGeometry() ) {
188 AliGeomManager::LoadGeometry(geoFilename);
189 if (! AliGeomManager::GetGeometry() ) {
190 printf("MUONSurveyCh%d: getting geometry from file %s failed\n", chId+1,geoFilename);
191 return;
192 }
193 cout << "geometry imported" << endl;
194 }
195
196 AliMUONGeometryTransformer *transform = new AliMUONGeometryTransformer();
197 transform->LoadGeometryData();
198
199 TGeoCombiTrans trfThChamber;
200 TGeoCombiTrans trfThDetElem;
201
202 for (int iCh =0; iCh<=1; iCh++) {
203 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
204
205 trfThChamber = TGeoCombiTrans(*transform->GetModuleTransformerByDEId(iDetElemToDetElemId[iCh*nDetElemsI])->GetTransformation());
206 trfThChamber.SetTranslation(trfThChamber.GetTranslation()[0]*10,
207 trfThChamber.GetTranslation()[1]*10,
208 trfThChamber.GetTranslation()[2]*10);
209 trfThChamber.Print();
210 myChamber->SetLocalTransformation(new TGeoCombiTrans(trfThChamber),kTRUE);
211
212 // Set Chamber plane function
213 cout << "Setting plane for Chamber" << iCh+1 << " ..." << endl;
214 myChamber->SetPlane(Form("fChamber%d",iCh+1));
215 myChamber->SetPlaneParameters(0.,0.,0.);
216
217 // Fit a plane to sticker targets
218 Double_t lCChi2 = myChamber->FitPlane();
219 cout << "... chi2 = " << lCChi2 << " ..." << endl;
220
221 // Get best transformation from fitting method
222 // (local to global transformation)
223 cout << "Trying fitting method for chamber " << iCh << endl;
224 myChamber->SurveyToAlign();
225 // myChamber->SurveyToAlign(myChamber->GetPlane()->GetParameter(0),myChamber->GetPlane()->GetParameter(1),myChamber->GetPlane()->GetParError(0),myChamber->GetPlane()->GetParError(1));
226
227 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
228 myDetElem = myChamber->GetDetElem(iDetElemI);
229 Int_t iDetElem = iDetElemsOfChamber[iCh][iDetElemI];
230
231 trfThDetElem.Clear();
232 trfThDetElem = TGeoCombiTrans(*transform->GetDetElement(iDetElemToDetElemId[iDetElem])->GetLocalTransformation());
233 trfThDetElem.SetTranslation(trfThDetElem.GetTranslation()[0]*10,
234 trfThDetElem.GetTranslation()[1]*10,
235 trfThDetElem.GetTranslation()[2]*10);
236 trfThDetElem.Print();
237
238 myDetElem->SetLocalTransformation(new TGeoCombiTrans(trfThDetElem),kTRUE);
239
240 for (int iCor=0; iCor<3; iCor++){
241 lCenDetElem[iDetElem][iCor] = 0;
242 lRotDetElem[iDetElem][iCor] = 0;
243 }
244
245 if (bMonitor){
246 // MONITOR: Draw graph with sticker targets for plane fitting
247 myDetElem->DrawSTargets();
248 gPad->Update();
249 }
250
251 // Get DetElem transformation.
252 // Psi and Theta are obtained by fitting a plane to the sticker targets.
253 // Then Xc, Yc, Zc and Phi are obtained by solving the equations to the ref.
254 // syst. transformation of the button targets
255
256 // Set DetElem plane function
257 cout << "Setting plane for DetElem" << iDetElem+1 << " ..." << endl;
258 myDetElem->SetPlane(Form("fDetElem%d",iDetElem+1));
259 myDetElem->SetPlaneParameters(0.,0.,30.)
260;
261 // Fit a plane to sticker targets
262 Double_t lChi2 = myDetElem->FitPlane();
263 cout << "... chi2 = " << lChi2 << " ..." << endl;
264
265 lRotDetElem[iDetElem][0]=TMath::ATan(myDetElem->GetPlane()->GetParameter(0));
266 lRotDetElem[iDetElem][1]=TMath::ATan(myDetElem->GetPlane()->GetParameter(1));
267
268 // Calculate Mean transformation using previous plane fit
269 // and pairs of button targets
270 myDetElem->CalculateMeanTransf(lCenDetElem[iDetElem],lRotDetElem[iDetElem]);
271
272 cout << "DetElem" << iDetElem+1 << " : mycen(" << lCenDetElem[iDetElem][0] << "," << lCenDetElem[iDetElem][1] << "," << lCenDetElem[iDetElem][2] << "); rot(" << lRotDetElem[iDetElem][0] << "," << lRotDetElem[iDetElem][1] << "," << lRotDetElem[iDetElem][2] << ")" << endl;
273
274
275 // Get best transformation from fitting method
276 // (local to global transformation)
277 cout << "Trying fitting method for DetElemId " << iDetElemToDetElemId[iDetElem] << endl;
278 myDetElem->SurveyToAlign();
279 // myDetElem->SurveyToAlign(lRotDetElem[iDetElem][0],lRotDetElem[iDetElem][1],myDetElem->GetPlane()->GetParError(0),myDetElem->GetPlane()->GetParError(1));
280 }
281 }
282
283 // Print found transformation of Detection Element (plane fit + loop)
284 for (int iCh =0; iCh<=1; iCh++) {
285 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
286 Int_t iDetElem = iDetElemsOfChamber[iCh][iDetElemI];
287 cout << "DetElem" << iDetElem+1 << " : mycen(" << lCenDetElem[iDetElem][0] << "," << lCenDetElem[iDetElem][1] << "," << lCenDetElem[iDetElem][2] << "); rot(" << lRotDetElem[iDetElem][0] << "," << lRotDetElem[iDetElem][1] << "," << lRotDetElem[iDetElem][2] << ")" << endl;
288 }
289 }
290
291 // Print Theoretical transformation of Detection Element
292 for (int iCh =0; iCh<=1; iCh++) {
293 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
294 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
295 myChamber->GetDetElem(iDetElemI)->PrintLocalTrf();
296 }
297 }
298
299 // Print found delta transformation of Detection Element
300 for (int iCh =0; iCh<=1; iCh++) {
301 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
302 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
303 myChamber->GetDetElem(iDetElemI)->PrintAlignTrf();
304 }
305 }
306
307 //
308 // Compare transformations to expected ones
309 //
310 Int_t iDetElemToPos[18] = {0, 1, 2, 3};
311
312 TGraphErrors *gDeltaDiffCenXDetElem0 = new TGraphErrors(nDetElems);
313 TGraphErrors *gDeltaDiffCenYDetElem0 = new TGraphErrors(nDetElems);
314 TGraphErrors *gDeltaDiffCenZDetElem0 = new TGraphErrors(nDetElems);
315 TGraphErrors *gDeltaDiffPsiDetElem0 = new TGraphErrors(nDetElems);
316 TGraphErrors *gDeltaDiffThtDetElem0 = new TGraphErrors(nDetElems);
317 TGraphErrors *gDeltaDiffPhiDetElem0 = new TGraphErrors(nDetElems);
318
319 for (int iCh =0; iCh<=1; iCh++) {
320 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
321 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
322 myChamber->GetDetElem(iDetElemI)->GetAlignTrf()->Print();
323 }
324 }
325
326 for (int iCh =0; iCh<=1; iCh++) {
327 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
328 // Store delta transformations to use for CDB entry creation
329 dtrfDetElem[nDetElems+iCh].Clear();
330 dtrfDetElem[nDetElems+iCh] = *(myChamber->GetAlignTrf());
331
332 // Those are for checks and visualizations
333 localTrfDetElem[nDetElems+iCh].Clear();
334 localTrfDetElem[nDetElems+iCh] = (*(myChamber->GetLocalTrf())*(*(myChamber->GetAlignTrf())));
335 localTrfDetElem[nDetElems+iCh].Print();
336 lDiffCenDetElem0[nDetElems+iCh] = (Double_t*)localTrfDetElem[nDetElems+iCh].GetTranslation();
337 AliMUONSurveyUtil::MatrixToAngles(localTrfDetElem[nDetElems+iCh].GetRotationMatrix(),lDiffRotDetElem0[nDetElems+iCh]);
338
339 localTrfThDetElem[nDetElems+iCh].Clear();
340 localTrfThDetElem[nDetElems+iCh] = (*(myChamber->GetLocalTrf()));
341 localTrfThDetElem[nDetElems+iCh].Print();
342 lDiffThCenDetElem0[nDetElems+iCh] = (Double_t*)localTrfThDetElem[nDetElems+iCh].GetTranslation();
343 AliMUONSurveyUtil::MatrixToAngles(localTrfThDetElem[nDetElems+iCh].GetRotationMatrix(),lDiffThRotDetElem0[nDetElems+iCh]);
344
345 for (int iCor=0; iCor<3; iCor++){
346 lDeltaDiffCenDetElem0[nDetElems+iCh][iCor] = lDiffCenDetElem0[nDetElems+iCh][iCor]-lDiffThCenDetElem0[nDetElems+iCh][iCor];
347 lDeltaDiffRotDetElem0[nDetElems+iCh][iCor] = lDiffRotDetElem0[nDetElems+iCh][iCor]-lDiffThRotDetElem0[nDetElems+iCh][iCor];
348 if (lDeltaDiffRotDetElem0[nDetElems+iCh][iCor]>TMath::Pi()) lDeltaDiffRotDetElem0[nDetElems+iCh][iCor]-=TMath::TwoPi();
349 if (lDeltaDiffRotDetElem0[nDetElems+iCh][iCor]<-TMath::Pi()) lDeltaDiffRotDetElem0[nDetElems+iCh][iCor]+=TMath::TwoPi();
350 }
351
352 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
353 Int_t iDetElem = iDetElemsOfChamber[iCh][iDetElemI];
354 myDetElem = myChamber->GetDetElem(iDetElemI);
355 // Store delta transformations to use for CDB entry creation
356 dtrfDetElem[iDetElem].Clear();
357 dtrfDetElem[iDetElem] = *(myDetElem->GetAlignTrf());
358
359 // Those are for checks and visualizations
360 localTrfDetElem[iDetElem].Clear();
361 localTrfDetElem[iDetElem] = (*(myDetElem->GetLocalTrf())*(*(myDetElem->GetAlignTrf())));
362 // localTrfDetElem[iDetElem] = (*(myDetElem->GetBaseTrf())*(*(myDetElem->GetAlignTrf())));
363 localTrfDetElem[iDetElem].Print();
364 lDiffCenDetElem0[iDetElem] = (Double_t*)localTrfDetElem[iDetElem].GetTranslation();
365 AliMUONSurveyUtil::MatrixToAngles(localTrfDetElem[iDetElem].GetRotationMatrix(),lDiffRotDetElem0[iDetElem]);
366// lDiffCenDetElem0[iDetElem] = lCenDetElem[iDetElem];
367// lDiffRotDetElem0[iDetElem] = lRotDetElem[iDetElem];
368
369 localTrfThDetElem[iDetElem].Clear();
370 localTrfThDetElem[iDetElem] = (*(myDetElem->GetLocalTrf()));
371 // localTrfThDetElem[iDetElem] = (*(myDetElem->GetBaseTrf()));
372 localTrfThDetElem[iDetElem].Print();
373 lDiffThCenDetElem0[iDetElem] = (Double_t*)localTrfThDetElem[iDetElem].GetTranslation();
374 AliMUONSurveyUtil::MatrixToAngles(localTrfThDetElem[iDetElem].GetRotationMatrix(),lDiffThRotDetElem0[iDetElem]);
375
376 for (int iCor=0; iCor<3; iCor++){
377 lDeltaDiffCenDetElem0[iDetElem][iCor] = lDiffCenDetElem0[iDetElem][iCor]-lDiffThCenDetElem0[iDetElem][iCor];
378 lDeltaDiffRotDetElem0[iDetElem][iCor] = lDiffRotDetElem0[iDetElem][iCor]-lDiffThRotDetElem0[iDetElem][iCor];
379 if (lDeltaDiffRotDetElem0[iDetElem][iCor]>TMath::Pi()) lDeltaDiffRotDetElem0[iDetElem][iCor]-=TMath::TwoPi();
380 if (lDeltaDiffRotDetElem0[iDetElem][iCor]<-TMath::Pi()) lDeltaDiffRotDetElem0[iDetElem][iCor]+=TMath::TwoPi();
381 }
382
383 gDeltaDiffCenXDetElem0->SetPoint(iDetElem,lDeltaDiffCenDetElem0[iDetElem][0],iDetElemToPos[iDetElem]+1);
384 gDeltaDiffCenYDetElem0->SetPoint(iDetElem,lDeltaDiffCenDetElem0[iDetElem][1],iDetElemToPos[iDetElem]+1);
385 gDeltaDiffCenZDetElem0->SetPoint(iDetElem,lDeltaDiffCenDetElem0[iDetElem][2],iDetElemToPos[iDetElem]+1);
386 gDeltaDiffPsiDetElem0->SetPoint(iDetElem,1e3*lDeltaDiffRotDetElem0[iDetElem][0],iDetElemToPos[iDetElem]+1);
387 gDeltaDiffThtDetElem0->SetPoint(iDetElem,1e3*lDeltaDiffRotDetElem0[iDetElem][1],iDetElemToPos[iDetElem]+1);
388 gDeltaDiffPhiDetElem0->SetPoint(iDetElem,1e3*lDeltaDiffRotDetElem0[iDetElem][2],iDetElemToPos[iDetElem]+1);
389 gDeltaDiffCenXDetElem0->SetPointError(iDetElem,myDetElem->GetFitter()->GetParError(0),0.);
390 gDeltaDiffCenYDetElem0->SetPointError(iDetElem,myDetElem->GetFitter()->GetParError(1),0.);
391 gDeltaDiffCenZDetElem0->SetPointError(iDetElem,myDetElem->GetFitter()->GetParError(2),0.);
392 gDeltaDiffPsiDetElem0->SetPointError(iDetElem,1e3*myDetElem->GetFitter()->GetParError(3),0.);
393 gDeltaDiffThtDetElem0->SetPointError(iDetElem,1e3*myDetElem->GetFitter()->GetParError(4),0.);
394 gDeltaDiffPhiDetElem0->SetPointError(iDetElem,1e3*myDetElem->GetFitter()->GetParError(5),0.);
395 }
396 }
397
398 // Apply the found misalignments to the geometry
399 AliMUONGeometryTransformer *newTransform = AliMUONSurveyUtil::ReAlign(transform,chId,nDetElems,iDetElemPseudoIdToDetElem,dtrfDetElem,true);
400 newTransform->WriteTransformations(Form("transform2ReAlignSurveyCh%d.dat",chId+1));
401
402 if(bOCDB){
403 // Generate realigned data in local cdb
404 const TClonesArray* array = newTransform->GetMisAlignmentData();
405
406 // Set the alignment resolution in the align objects for this chamber
407 Double_t chResX = 0.1*myChamberI->GetAlignResX();
408 Double_t chResY = 0.1*myChamberI->GetAlignResY();
409 Double_t deResX = 0.1*(myChamberI->GetMeanDetElemAlignResX()+myChamberO->GetMeanDetElemAlignResX())/2.;
410 Double_t deResY = 0.1*(myChamberI->GetMeanDetElemAlignResY()+myChamberO->GetMeanDetElemAlignResY())/2.;
411 printf("Chamber alignment resolutions: resX=%f , resY=%f\n",chResX,chResY);
412 printf("Detection Elements alignment resolutions: resX=%f , resY=%f\n",deResX,deResY);
413 chResX = TMath::Sqrt(0.1*0.1+chResX*chResX);
414 chResY = TMath::Sqrt(0.1*0.1+chResY*chResY);
415 AliMUONSurveyUtil::SetAlignmentResolution(array,chId,chResX,chResY,deResX,deResY);
416
417 // CDB manager
418 AliCDBManager* cdbManager = AliCDBManager::Instance();
419 cdbManager->SetDefaultStorage(Form("local://ReAlignSurveyCh%dCDB",chId+1));
420
421 AliCDBMetaData* cdbData = new AliCDBMetaData();
422 cdbData->SetResponsible("Dimuon Offline project");
423 cdbData->SetComment("MUON alignment objects with survey realignment");
424 AliCDBId id("MUON/Align/Data", 0, AliCDBRunRange::Infinity());
425 cdbManager->Put(const_cast<TClonesArray*>(array), id, cdbData);
426 }
427
428 for(Int_t iCor=0; iCor<3; iCor++){
429 for(Int_t iDetElem=0; iDetElem<nDetElems; iDetElem++){
430 cout << lDeltaDiffCenDetElem0[iDetElem][iCor] << " " << lDiffCenDetElem0[iDetElem][iCor] << " " << lDiffThCenDetElem0[iDetElem][iCor] << endl;
431 }
432 cout << endl;
433 }
434 cout << endl;
435 for(Int_t iCor=0; iCor<3; iCor++){
436 for(Int_t iDetElem=0; iDetElem<nDetElems; iDetElem++){
437 cout << lDeltaDiffRotDetElem0[iDetElem][iCor] << " " << lDiffRotDetElem0[iDetElem][iCor] << " " << lDiffThRotDetElem0[iDetElem][iCor] << endl;
438 }
439 cout << endl;
440 }
441
442 TH1F *myDetElemDeltaDiffCenX = new TH1F("myDetElemDeltaDiffCenX","myDetElemDeltaDiffCenX",100,-10,10);
443 myDetElemDeltaDiffCenX->SetMaximum(nDetElems+1);
444 myDetElemDeltaDiffCenX->SetMinimum(0);
445 TH1F *myDetElemDeltaDiffCenY = new TH1F("myDetElemDeltaDiffCenY","myDetElemDeltaDiffCenY",100,-10,10);
446 myDetElemDeltaDiffCenY->SetMaximum(nDetElems+1);
447 myDetElemDeltaDiffCenY->SetMinimum(0);
448 TH1F *myDetElemDeltaDiffCenZ = new TH1F("myDetElemDeltaDiffCenZ","myDetElemDeltaDiffCenZ",100,-20,20);
449 myDetElemDeltaDiffCenZ->SetMaximum(nDetElems+1);
450 myDetElemDeltaDiffCenZ->SetMinimum(0);
451
452 TH1F *myDetElemDeltaDiffRotX = new TH1F("myDetElemDeltaDiffRotX","myDetElemDeltaDiffRotX",100,-15,15);
453 myDetElemDeltaDiffRotX->SetMaximum(nDetElems+1);
454 myDetElemDeltaDiffRotX->SetMinimum(0);
455 TH1F *myDetElemDeltaDiffRotY = new TH1F("myDetElemDeltaDiffRotY","myDetElemDeltaDiffRotY",100,-15,15);
456 myDetElemDeltaDiffRotY->SetMaximum(nDetElems+1);
457 myDetElemDeltaDiffRotY->SetMinimum(0);
458 TH1F *myDetElemDeltaDiffRotZ = new TH1F("myDetElemDeltaDiffRotZ","myDetElemDeltaDiffRotZ",100,-5,5);
459 myDetElemDeltaDiffRotZ->SetMaximum(nDetElems+1);
460 myDetElemDeltaDiffRotZ->SetMinimum(0);
461
462 //
463 // ******** Starting plots
464 //
465 TCanvas *canvas;
466 TPad *pad;
467 TPaveLabel *theTitle;
468 gStyle->SetPalette(1);
469
470 TPostScript *ps = 0;
471
472 if( saveps ){
473 ps = new TPostScript(Form("surveyChamber%d",chId+1),filetype);
474 ps->NewPage();
475 }
476
477 // Observed misalignments
478 str = Form("Chamber %d",chId+1);
479 TCanvas *cvn2 = new TCanvas("cvn2",str,cWidth,cHeight);
480 canvas = cvn2;
481 canvas->Range(0,0,21,29);
482
483 title = Form(" MisAlignments Chamber %d - L2G - In Single Frame ",chId+1);
484 TPaveLabel *theTitle2 = new TPaveLabel(3,27.0,18,28.5,title,"br");
485 theTitle = theTitle2;
486 theTitle->SetFillColor(18);
487 theTitle->SetTextFont(32);
488 theTitle->SetTextSize(0.4);
489 theTitle->SetTextColor(1);
490 theTitle->Draw();
491
492 TPad *pad2 = new TPad("pad2","pad2",0.01,0.01,0.98,0.91,0);
493 pad = pad2;
494 pad->Draw();
495 TLine *ch0Line = new TLine(0,1,0,2);
496 TLine *ch1Line = new TLine(0,1,0,2);
497 ch1Line->SetLineStyle(2);
498 pad->Divide(3,2);
499
500 pad->cd(1);
501 myDetElemDeltaDiffCenX->Draw();
502 myDetElemDeltaDiffCenX->SetXTitle("#Delta[xc_{i}^{m}-xc_{i}^{th}] (mm)");
503 myDetElemDeltaDiffCenX->SetYTitle("DetElem arbitrary ordering");
504 gDeltaDiffCenXDetElem0->SetMarkerStyle(20);
505 gDeltaDiffCenXDetElem0->Draw("P");
506 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][0],0.5,lDeltaDiffCenDetElem0[nDetElems+0][0],1.5);
507 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][0],3.5,lDeltaDiffCenDetElem0[nDetElems+0][0],4.5);
508 ch1Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+1][0],1.5,lDeltaDiffCenDetElem0[nDetElems+1][0],3.5);
509
510 pad->cd(2);
511 myDetElemDeltaDiffCenY->Draw();
512 myDetElemDeltaDiffCenY->SetXTitle("#Delta[yc_{i}^{m}-yc_{i}^{th}] (mm)");
513 myDetElemDeltaDiffCenY->SetYTitle("DetElem arbitrary ordering");
514 gDeltaDiffCenYDetElem0->SetMarkerStyle(20);
515 gDeltaDiffCenYDetElem0->Draw("P");
516 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][1],0.5,lDeltaDiffCenDetElem0[nDetElems+0][1],1.5);
517 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][1],3.5,lDeltaDiffCenDetElem0[nDetElems+0][1],4.5);
518 ch1Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+1][1],1.5,lDeltaDiffCenDetElem0[nDetElems+1][1],3.5);
519
520 pad->cd(3);
521 myDetElemDeltaDiffCenZ->Draw();
522 myDetElemDeltaDiffCenZ->SetXTitle("#Delta[zc_{i}^{m}-zc_{i}^{th}] (mm)");
523 myDetElemDeltaDiffCenZ->SetYTitle("DetElem arbitrary ordering");
524 gDeltaDiffCenZDetElem0->SetMarkerStyle(20);
525 gDeltaDiffCenZDetElem0->Draw("P");
526 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][2],0.5,lDeltaDiffCenDetElem0[nDetElems+0][2],1.5);
527 ch0Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+0][2],3.5,lDeltaDiffCenDetElem0[nDetElems+0][2],4.5);
528 ch1Line->DrawLine(lDeltaDiffCenDetElem0[nDetElems+1][2],1.5,lDeltaDiffCenDetElem0[nDetElems+1][2],3.5);
529
530 pad->cd(4);
531 myDetElemDeltaDiffRotX->Draw();
532 myDetElemDeltaDiffRotX->SetXTitle("#Delta[#psi_{i}^{m}-#psi_{i}^{th}] (mrad)");
533 myDetElemDeltaDiffRotX->SetYTitle("DetElem arbitrary ordering");
534 gDeltaDiffPsiDetElem0->SetMarkerStyle(20);
535 gDeltaDiffPsiDetElem0->Draw("P");
536 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][0],0.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][0],1.5);
537 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][0],3.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][0],4.5);
538 ch1Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+1][0],1.5,1e3*lDeltaDiffRotDetElem0[nDetElems+1][0],3.5);
539
540 pad->cd(5);
541 myDetElemDeltaDiffRotY->Draw();
542 myDetElemDeltaDiffRotY->SetXTitle("#Delta[#theta_{i}^{m}-#theta_{i}^{th}] (mrad)");
543 myDetElemDeltaDiffRotY->SetYTitle("DetElem arbitrary ordering");
544 gDeltaDiffThtDetElem0->SetMarkerStyle(20);
545 gDeltaDiffThtDetElem0->Draw("P");
546 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][1],0.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][1],1.5);
547 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][1],3.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][1],4.5);
548 ch1Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+1][1],1.5,1e3*lDeltaDiffRotDetElem0[nDetElems+1][1],3.5);
549
550 pad->cd(6);
551 myDetElemDeltaDiffRotZ->Draw();
552 myDetElemDeltaDiffRotZ->SetXTitle("#Delta[#phi_{i}^{m}-#phi_{i}^{th}] (mrad)");
553 myDetElemDeltaDiffRotZ->SetYTitle("DetElem arbitrary ordering");
554 gDeltaDiffPhiDetElem0->SetMarkerStyle(20);
555 gDeltaDiffPhiDetElem0->Draw("P");
556 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][2],0.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][2],1.5);
557 ch0Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+0][2],3.5,1e3*lDeltaDiffRotDetElem0[nDetElems+0][2],4.5);
558 ch1Line->DrawLine(1e3*lDeltaDiffRotDetElem0[nDetElems+1][2],1.5,1e3*lDeltaDiffRotDetElem0[nDetElems+1][2],3.5);
559
560 pad->Update();
561
562 if(bMonitor){
563 // MONITOR: Histograms for monitoring
564 TH2F *hCPSTa = new TH2F("hCPSTa","hCPSTa",100,-2000,2000,100,-2000,2000);
565 TH2F *hCPSTc = new TH2F("hCPSTc","hCPSTc",100,-2000,2000,100,-2000,2000);
566 TH2F *hSSTa = new TH2F("hSSTa","hSSTa",100,-2000,2000,100,-2000,2000);
567 TH2F *hSSTc = new TH2F("hSSTc","hSSTc",100,-2000,2000,100,-2000,2000);
568 TH2F *hSSTap = new TH2F("hSSTap","hSSTap",800,-2000,2000,800,-2000,2000);
569 TH2F *hSSTcp = new TH2F("hSSTcp","hSSTcp",800,-2000,2000,800,-2000,2000);
570
571 // MONITOR: Fill histograms with chambers and slats sticker target positions
572 for (int iCh =0; iCh<=1; iCh++) {
573 myChamber = (AliMUONSurveyChamber*)myChamberArray->At(iCh);
574 cout << "Filling histograms of sticker target for chamber" << iCh+1 << " ..." << endl;
575 myChamber->FillCPSTHistograms(Form("T4_6%d",2-iCh),hCPSTc);
576 // myChamber->FillDESTHistograms(TString("T4_46"),hSSTc);
577
578 for (int iDetElemI=0; iDetElemI<nDetElemsI; iDetElemI++){
579 // Int_t iDetElem = iDetElemsOfChamber[iCh][iDetElemI];
580 myDetElem = myChamber->GetDetElem(iDetElemI);
581 // MONITOR: Fill slat plane for fit monitor.
582 Double_t pl[3] = {0};
583 Double_t pg[3] = {0};
584 AliSurveyPoint *pointSBT0 = myDetElem->GetLButtonTarget(0);
585 AliSurveyPoint *pointSBT1 = myDetElem->GetLButtonTarget(1);
586 if(pointSBT0&&pointSBT1) {
587 if (pointSBT0->GetX()>pointSBT1->GetX()){
588 pointSBT0=myDetElem->GetLButtonTarget(1);
589 pointSBT1=myDetElem->GetLButtonTarget(0);
590 }
591 Double_t lX = pointSBT0->GetX();
592 while(lX<pointSBT1->GetX()){
593 Double_t lY = pointSBT0->GetY()-200;
594 while(lY<pointSBT0->GetY()+200){
595 pl[0] = lX; pl[1] = lY; pl[2] = 0.;
596 (TGeoCombiTrans((*(myDetElem->GetBaseTrf()))*(*(myDetElem->GetAlignTrf())))).LocalToMaster(pl,pg);
597 if(myDetElem->GetGButtonTarget(0)->GetPointName().Contains("A")){
598 hSSTap->Fill(pg[0],pg[1],-pg[2]);
599 }
600 else {
601 hSSTcp->Fill(pg[0],pg[1],-pg[2]);
602 }
603 lY+=hSSTap->GetYaxis()->GetBinWidth(1);
604 }
605 lX+=hSSTap->GetXaxis()->GetBinWidth(1);
606 }
607 }
608 }
609 }
610
611 if( saveps ){
612 ps->NewPage();
613 }
614
615 // View from side A
616 str = Form("Chamber %d - side A",chId+1);
617 TCanvas *cvn0 = new TCanvas("cvn0",str,cWidth,cHeight);
618 canvas = cvn0;
619 canvas->Range(0,0,21,29);
620
621 title = Form(" Deformations of chamber %d - View from side A ",chId+1);
622 TPaveLabel *theTitle0 = new TPaveLabel(3,27.0,18,28.5,title,"br");
623 theTitle = theTitle0;
624 theTitle->SetFillColor(18);
625 theTitle->SetTextFont(32);
626 theTitle->SetTextSize(0.4);
627 theTitle->SetTextColor(1);
628 theTitle->Draw();
629
630 TPad *pad0 = new TPad("pad0","pad0",0.01,0.01,0.98,0.91,0);
631 pad = pad0;
632 pad->Draw();
633 pad->Divide(2,2);
634
635 pad->cd(1);
636 hCPSTa->SetMinimum(9500);
637 hCPSTa->SetMaximum(9750);
638 hCPSTa->Draw("lego2z");
639
640 pad->cd(2);
641 hSSTa->SetMinimum(9500);
642 hSSTa->SetMaximum(9800);
643 hSSTa->Draw("lego2z");
644
645 pad->cd(3);
646
647 pad->cd(4);
648 hSSTap->SetMinimum(9500);
649 hSSTap->SetMaximum(9800);
650 hSSTap->Draw("surf2z");
651
652 pad->Update();
653 if(saveps){
654 ps->NewPage();
655 }
656
657 // Inv Mass, Multiplicity
658 str = Form("Chamber %d - side C",chId+1);
659 TCanvas *cvn1 = new TCanvas("cvn1",str,cWidth,cHeight);
660 canvas = cvn1;
661 canvas->Range(0,0,21,29);
662
663 title = Form(" Deformations of chamber %d - View from side C ",chId+1);
664 TPaveLabel *theTitle1 = new TPaveLabel(3,27.0,18,28.5,title,"br");
665 theTitle = theTitle1;
666 theTitle->SetFillColor(18);
667 theTitle->SetTextFont(32);
668 theTitle->SetTextSize(0.4);
669 theTitle->SetTextColor(1);
670 theTitle->Draw();
671
672 TPad *pad1 = new TPad("pad1","pad1",0.01,0.01,0.98,0.91,0);
673 pad = pad1;
674 pad->Draw();
675 pad->Divide(2,2);
676
677 pad->cd(1);
678 hCPSTc->SetMinimum(5300);
679 hCPSTc->SetMaximum(5330);
680 hCPSTc->Draw("lego2z");
681
682 pad->cd(2);
683 hSSTc->SetMinimum(6930);
684 hSSTc->SetMaximum(7030);
685 hSSTc->Draw("lego2z");
686
687 pad->cd(3);
688
689 pad->cd(4);
690 hSSTcp->SetMinimum(9600);
691 hSSTcp->SetMaximum(9850);
692 hSSTcp->Draw("surf2z");
693 }
694
695 pad->Update();
696 if( saveps ){
697 ps->Close();
698 }
699
700 TFile *hFile = new TFile(Form("spCH%d_L2G_ISF.root",chId+1),"RECREATE");
701 gDeltaDiffCenXDetElem0->Write("gDeltaDiffCenXDetElem0");
702 gDeltaDiffCenYDetElem0->Write("gDeltaDiffCenYDetElem0");
703 gDeltaDiffCenZDetElem0->Write("gDeltaDiffCenZDetElem0");
704 gDeltaDiffPsiDetElem0->Write("gDeltaDiffPsiDetElem0");
705 gDeltaDiffThtDetElem0->Write("gDeltaDiffThtDetElem0");
706 gDeltaDiffPhiDetElem0->Write("gDeltaDiffPhiDetElem0");
707 myDetElemDeltaDiffCenX->Write();
708 myDetElemDeltaDiffCenY->Write();
709 myDetElemDeltaDiffCenZ->Write();
710 myDetElemDeltaDiffRotX->Write();
711 myDetElemDeltaDiffRotY->Write();
712 myDetElemDeltaDiffRotZ->Write();
713 hFile->Close();
714 hFile->Delete();
715}