Remove the dollar-id-dollar in the responsible name which interfere with CDB_MD metad...
[u/mrichter/AliRoot.git] / MUON / AliMUONAlignmentCompareDialog.cxx
CommitLineData
301ca128 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#include "AliMUONAlignmentCompareDialog.h"
19
20/// \class AliMUONAlignmentCompareDialog
21///
22/// Widget to select 2 alignments objects from the OCDB (A1,A2) to be compared
23///
24/// \author Philippe Pillot, Laurent Aphecetche
25///
26
27#include "AliCDBManager.h"
28#include "AliGeomManager.h"
29#include "AliLog.h"
30#include "AliMUON2DMap.h"
31#include "AliMUONCalibParamND.h"
32#include "AliMUONConstants.h"
33#include "AliMUONGeometryTransformer.h"
34#include "AliMUONPainterDataRegistry.h"
35#include "AliMUONTrackerData.h"
36#include "AliMUONTrackerDataWrapper.h"
37#include "AliMpConstants.h"
38#include "AliMpDDLStore.h"
39#include "AliMpDEIterator.h"
40#include "AliMpDetElement.h"
41#include "AliMpManuIterator.h"
42#include "AliMpPad.h"
43#include "AliMpSegmentation.h"
44#include "AliMpVPadIterator.h"
45#include "AliMpVSegmentation.h"
46#include <TGComboBox.h>
47#include <TGLabel.h>
48#include <TGNumberEntry.h>
49#include <TGTextEntry.h>
50#include <TGeoManager.h>
51#include <TTimer.h>
52
53/// \cond CLASSIMP
54ClassImp(AliMUONAlignmentCompareDialog)
55/// \endcond
56
57namespace
58{
59
60#define PRECISION 1E-12
61
62 Double_t Difference(Double_t v1, Double_t v2)
63 {
64 Double_t d = v1-v2;
65 return TMath::Abs(d) < PRECISION ? 0.0 : d;
66 }
67}
68
69//_____________________________________________________________________________
70AliMUONAlignmentCompareDialog::AliMUONAlignmentCompareDialog(const TGWindow* p, const TGWindow* main, UInt_t w, UInt_t h)
71: TGTransientFrame(p,main,w,h),
72fF1(new TGVerticalFrame(this)),
73fOCDBPath1(0x0),
74fRun1(0x0),
75fF2(new TGVerticalFrame(this)),
76fOCDBPath2(0x0),
77fRun2(0x0),
78fF3(new TGHorizontalFrame(this)),
79fBasename(new TGTextEntry(fF3)),
80fButtonFrame(new TGHorizontalFrame(this)),
81fOK(new TGTextButton(fButtonFrame,"OK")),
82fCancel(new TGTextButton(fButtonFrame,"Cancel"))
83{
84 /// ctor
85
86 SetCleanup(kDeepCleanup);
87
88 AddInput(fF1,"First alignment",fOCDBPath1,fRun1);
89 AddInput(fF2,"Second alignment",fOCDBPath2,fRun2);
90
91 fF3->AddFrame(new TGLabel(fF3,"Output basename"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
92 fF3->AddFrame(fBasename,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
93
94 AddFrame(fF1,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
95 AddFrame(fF2,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
96 AddFrame(fF3,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
97
98 fButtonFrame->AddFrame(fOK,new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
99 fButtonFrame->AddFrame(fCancel,new TGLayoutHints(kLHintsRight|kLHintsTop,5,5,5,5));
100
101 AddFrame(fButtonFrame,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
102
103 fOK->Connect("Clicked()", "AliMUONAlignmentCompareDialog",this,"DoOK()");
104 fCancel->Connect("Clicked()","AliMUONAlignmentCompareDialog",this,"DoCancel()");
105}
106
107//_____________________________________________________________________________
108AliMUONAlignmentCompareDialog::~AliMUONAlignmentCompareDialog()
109{
110 /// dtor
111}
112
113//_____________________________________________________________________________
114void AliMUONAlignmentCompareDialog::AddInput(TGCompositeFrame* frame, const char* msg,
115 TGTextEntry*& text, TGNumberEntry*& run)
116{
117
118 TGHorizontalFrame* hf1 = new TGHorizontalFrame(frame);
119
120 hf1->AddFrame(new TGLabel(hf1,TString(msg) + " ocdb path"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
121
122 text = new TGTextEntry(hf1,"alien://folder=/alice/data/2012/OCDB");
123
124 hf1->AddFrame(text,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
125
126 TGHorizontalFrame* hf2 = new TGHorizontalFrame(frame);
127
128 hf2->AddFrame(new TGLabel(hf2,TString(msg) + " run number"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
129
130 run = new TGNumberEntry(hf2);
131
132 hf2->AddFrame(run,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
133
134 frame->AddFrame(hf1,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
135 frame->AddFrame(hf2,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
136}
137
138//______________________________________________________________________________
139void
140AliMUONAlignmentCompareDialog::DoOK()
141{
142 /// Do the job.
143
144 AliMUONVTrackerData* d = CompareAlignment(fOCDBPath1->GetText(),fRun1->GetNumber(),
145 fOCDBPath2->GetText(),fRun2->GetNumber());
146
147 if (!d) return;
148
149 TString basename = fBasename->GetText();
150
151 AliMUONVTrackerDataMaker* dw = new AliMUONTrackerDataWrapper(d);
152
153 AliMUONPainterDataRegistry::Instance()->Register(dw);
154
155 TTimer::SingleShot(150,"AliMUONAlignmentCompareDialog",this,"CloseWindow()");
156}
157
158//______________________________________________________________________________
159void
160AliMUONAlignmentCompareDialog::DoCancel()
161{
162 /// Kills the dialog
163 TTimer::SingleShot(150,"AliMUONAlignmentCompareDialog",this,"CloseWindow()");
164}
165
166//______________________________________________________________________________
167AliMUONVTrackerData*
168AliMUONAlignmentCompareDialog::CompareAlignment(const char* ocdbPathForAlign1, Int_t run1,
169 const char* ocdbPathForAlign2, Int_t run2)
170{
171 // ocdb access
172 AliCDBManager* cdbm = AliCDBManager::Instance();
173 cdbm->SetDefaultStorage("raw://");
174
175 // get geometry transformers
176 AliMUONGeometryTransformer geoTransformer[2];
177
178 const char* align[2] = {
179 ocdbPathForAlign1,
180 ocdbPathForAlign2
181 };
182
183 Int_t runs[] = {
184 run1,run2
185 };
186
187 for (Int_t i = 0; i < 2; i++)
188 {
189 cdbm->UnloadFromCache("GRP/Geometry/Data");
190 cdbm->UnloadFromCache("MUON/Align/Data");
191 AliGeomManager::GetGeometry()->UnlockGeometry();
192 AliGeomManager::LoadGeometry();
193 if (!AliGeomManager::GetGeometry()) return 0x0;
194 cdbm->SetSpecificStorage("MUON/Align/Data",align[i]);
195 cdbm->SetRun(runs[i]);
196 AliGeomManager::ApplyAlignObjsFromCDB("MUON");
197 geoTransformer[i].LoadGeometryData();
198 }
199
200 // store for cluster shifts
201 AliMUON2DMap shiftStore(kTRUE);
202
203 // loop over chamber
204 for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
205
206 // loop over DEs
207 AliMpDEIterator nextDE;
208 nextDE.First(iCh);
209 while (!nextDE.IsDone()) {
210
211 Int_t deId = nextDE.CurrentDE()->GetId();
212
213 // loop over cathods
214 for (Int_t icath = 0; icath < 2; icath++) {
215
216 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(deId,AliMp::GetCathodType(icath));
217
218 // loop over pads
219 AliMpVPadIterator *nextPad = seg->CreateIterator();
220 nextPad->First();
221 while (!nextPad->IsDone()) {
222
223 AliMpPad pad = nextPad->CurrentItem();
224 Int_t manuId = pad.GetManuId();
225 Int_t manuChannel = pad.GetManuChannel();
226
227 // local position
228 Double_t xl = pad.GetPositionX();
229 Double_t yl = pad.GetPositionY();
230 Double_t zl = 0.;
231
232 // position with first alignment
233 Double_t x1, y1, z1;
234 geoTransformer[0].Local2Global(deId,xl,yl,zl,x1,y1,z1);
235
236 // position with second alignment
237 Double_t x2, y2, z2;
238 geoTransformer[1].Local2Global(deId,xl,yl,zl,x2,y2,z2);
239
240 // pad shift
241 Double_t dx = ::Difference(x2,x1);
242 Double_t dy = ::Difference(y2,y1);
243 Double_t dz = ::Difference(z2,z1);
244
245 // store pad shifts
246 AliMUONVCalibParam* p = static_cast<AliMUONVCalibParam*>(shiftStore.FindObject(deId,manuId));
247 if (!p) {
248 p = new AliMUONCalibParamND(3,AliMpConstants::ManuNofChannels(),deId,manuId,0.);
249 shiftStore.Add(p);
250 }
251 p->SetValueAsDouble(manuChannel,0,dx);
252 p->SetValueAsDouble(manuChannel,1,dy);
253 p->SetValueAsDouble(manuChannel,2,dz);
254
255 nextPad->Next();
256 }
257
258 delete nextPad;
259
260 }
261
262 nextDE.Next();
263 }
264
265 }
266
267 // create tracker data
268 AliMUONTrackerData* data = new AliMUONTrackerData(fBasename->GetText(),fBasename->GetText(),3,kTRUE);
269 data->SetDimensionName(0,"dx"); // max shift in x
270 data->SetDimensionName(1,"dy"); // max shift in y
271 data->SetDimensionName(2,"dz"); // max shift in z
272 data->Add(shiftStore);
273
274 return data;
275}