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