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 **************************************************************************/
18 #include "AliMUONTrackerDataCompareDialog.h"
20 /// \class AliMUONTrackerDataCompareDialog
22 /// Widget to select 2 VTrackerData objects (D1,D2) to be compared
24 /// The type of differences that can be used are :
26 /// - Difference = plain difference D1-D2
27 /// - Absolute difference = absolute value of the preceeding = |D1-D2|
28 /// - Relative difference = relative difference = (D1-D2)/D1
29 /// - Absolute relative difference = absolute value of preceeding = |(D1-D2)/D1|
31 /// \author Laurent Aphecetche, Subatech
35 #include "AliMUON2DMap.h"
36 #include "AliMUONCalibParamND.h"
37 #include "AliMUONPainterDataRegistry.h"
38 #include "AliMUONTrackerData.h"
39 #include "AliMUONTrackerDataWrapper.h"
40 #include "AliMUONVTrackerData.h"
41 #include "AliMpConstants.h"
42 #include "AliMpDDLStore.h"
43 #include "AliMpDetElement.h"
44 #include "AliMpManuIterator.h"
45 #include <TGComboBox.h>
47 #include <TGTextEntry.h>
51 ClassImp(AliMUONTrackerDataCompareDialog)
54 const Int_t AliMUONTrackerDataCompareDialog::fgkDifference(1);
55 const Int_t AliMUONTrackerDataCompareDialog::fgkAbsoluteDifference(2);
56 const Int_t AliMUONTrackerDataCompareDialog::fgkRelativeDifference(3);
57 const Int_t AliMUONTrackerDataCompareDialog::fgkAbsoluteRelativeDifference(4);
58 const Int_t AliMUONTrackerDataCompareDialog::fgkAll(5);
63 #define PRECISION 1E-12
65 Double_t Difference(Double_t v1, Double_t v2)
68 return TMath::Abs(d) < PRECISION ? 0.0 : d;
71 Double_t AbsoluteDifference(Double_t v1, Double_t v2)
73 return TMath::Abs(Difference(v1,v2));
77 Double_t RelativeDifference(Double_t v1, Double_t v2)
79 if ( TMath::Abs(v1) < PRECISION ) return 0.0;
83 Double_t AbsoluteRelativeDifference(Double_t v1, Double_t v2)
85 return TMath::Abs(RelativeDifference(v1,v2));
90 //_____________________________________________________________________________
91 AliMUONTrackerDataCompareDialog::AliMUONTrackerDataCompareDialog(const TGWindow* p, const TGWindow* main, UInt_t w, UInt_t h)
92 : TGTransientFrame(p,main,w,h),
93 fF1(new TGHorizontalFrame(this)),
94 fData1(new TGComboBox(fF1)),
95 fF2(new TGHorizontalFrame(this)),
96 fData2(new TGComboBox(fF2)),
97 fF3(new TGHorizontalFrame(this)),
98 fDiffType(new TGComboBox(fF3)),
99 fF4(new TGHorizontalFrame(this)),
100 fBasename(new TGTextEntry(fF4)),
101 fButtonFrame(new TGHorizontalFrame(this)),
102 fOK(new TGTextButton(fButtonFrame,"OK")),
103 fCancel(new TGTextButton(fButtonFrame,"Cancel"))
107 SetCleanup(kDeepCleanup);
109 AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
111 for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
113 AliMUONVTrackerData* data = reg->DataSource(i);
114 fData1->AddEntry(data->GetName(),i);
115 fData2->AddEntry(data->GetName(),i);
118 fDiffType->AddEntry("Difference",fgkDifference);
119 fDiffType->AddEntry("Absolute difference",fgkAbsoluteDifference);
120 fDiffType->AddEntry("Relative difference",fgkRelativeDifference);
121 fDiffType->AddEntry("Absolute relative difference",fgkAbsoluteRelativeDifference);
122 fDiffType->AddEntry("All four",fgkAll);
126 fDiffType->Select(4);
128 fF1->AddFrame(new TGLabel(fF1,"First data"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
129 fF1->AddFrame(fData1,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
131 fF2->AddFrame(new TGLabel(fF2,"Second data"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
132 fF2->AddFrame(fData2,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
134 fF3->AddFrame(new TGLabel(fF3,"Difference type"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
135 fF3->AddFrame(fDiffType,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
137 fF4->AddFrame(new TGLabel(fF4,"Output basename"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
138 fF4->AddFrame(fBasename,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
140 AddFrame(fF1,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
141 AddFrame(fF2,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
142 AddFrame(fF3,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
143 AddFrame(fF4,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
145 fButtonFrame->AddFrame(fOK,new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
146 fButtonFrame->AddFrame(fCancel,new TGLayoutHints(kLHintsRight|kLHintsTop,5,5,5,5));
148 AddFrame(fButtonFrame,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
150 fData1->Resize(200,20);
151 fData2->Resize(200,20);
152 fDiffType->Resize(200,20);
154 fOK->Connect("Clicked()", "AliMUONTrackerDataCompareDialog",this,"DoOK()");
155 fCancel->Connect("Clicked()","AliMUONTrackerDataCompareDialog",this,"DoCancel()");
158 //_____________________________________________________________________________
159 AliMUONTrackerDataCompareDialog::~AliMUONTrackerDataCompareDialog()
164 //______________________________________________________________________________
166 AliMUONTrackerDataCompareDialog::DoOK()
170 TGTextLBEntry* t1 = static_cast<TGTextLBEntry*>(fData1->GetSelectedEntry());
171 TString s1 = t1->GetText()->GetString();
172 TGTextLBEntry* t2 = static_cast<TGTextLBEntry*>(fData2->GetSelectedEntry());
173 TString s2 = t2->GetText()->GetString();
175 Int_t nd = fDiffType->GetSelected();
179 CompareData(s1.Data(),s2.Data(),fgkDifference);
180 CompareData(s1.Data(),s2.Data(),fgkRelativeDifference);
181 CompareData(s1.Data(),s2.Data(),fgkAbsoluteDifference);
182 CompareData(s1.Data(),s2.Data(),fgkAbsoluteRelativeDifference);
186 CompareData(s1.Data(),s2.Data(),nd);
189 TTimer::SingleShot(150,"AliMUONTrackerDataCompareDialog",this,"CloseWindow()");
192 //______________________________________________________________________________
194 AliMUONTrackerDataCompareDialog::DoCancel()
197 TTimer::SingleShot(150,"AliMUONTrackerDataCompareDialog",this,"CloseWindow()");
200 //______________________________________________________________________________
202 AliMUONTrackerDataCompareDialog::CompareData(const char* d1name,
204 Int_t difftype) const
206 /// Compare two data sources
208 AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
210 AliMUONVTrackerData* d1 = reg->DataSource(d1name);
213 AliError(Form("Cannot find data source %s",d1name));
216 AliMUONVTrackerData* d2 = reg->DataSource(d2name);
219 AliError(Form("Cannot find data source %s",d2name));
222 Double_t (*difffunction)(Double_t,Double_t)=0x0;
223 TString suffix("unknown");
225 if ( difftype == fgkDifference )
227 difffunction = Difference;
230 if ( difftype == fgkAbsoluteDifference )
232 difffunction = AbsoluteDifference;
235 if ( difftype == fgkRelativeDifference )
237 difffunction = RelativeDifference;
240 if ( difftype == fgkAbsoluteRelativeDifference )
242 difffunction = AbsoluteRelativeDifference;
246 TString basename = fBasename->GetText();
248 AliMUONVTrackerData* d = CompareData(*d1,*d2,Form("%s:%s",basename.Data(),suffix.Data()),difffunction);
250 AliMUONVTrackerDataMaker* dw = new AliMUONTrackerDataWrapper(d);
252 AliMUONPainterDataRegistry::Instance()->Register(dw);
255 //______________________________________________________________________________
257 AliMUONTrackerDataCompareDialog::CompareData(const AliMUONVTrackerData& d1,
258 const AliMUONVTrackerData& d2,
260 Double_t(*diff)(Double_t,Double_t)) const
262 /// Compare two data objects, using the diff method
264 if ( d1.NumberOfDimensions() != d2.NumberOfDimensions() )
266 AliError("Cannot compare data of incompatible dimensions");
270 AliMpManuIterator it;
271 Int_t detElemId, manuId;
273 AliMUONVStore* store = new AliMUON2DMap(kTRUE);
275 while ( it.Next(detElemId,manuId) )
277 if ( d1.HasDetectionElement(detElemId) && d2.HasDetectionElement(detElemId) &&
278 d1.HasManu(detElemId,manuId) && d2.HasManu(detElemId,manuId) )
280 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
282 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
286 param = new AliMUONCalibParamND(d1.ExternalDimension(),64,detElemId,manuId,
287 AliMUONVCalibParam::InvalidFloatValue());
291 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
293 if ( de->IsConnectedChannel(manuId,i) )
295 for ( Int_t k = 0; k < d1.ExternalDimension(); ++k )
298 Double_t d = diff(d1.Channel(detElemId,manuId,i,k),
299 d2.Channel(detElemId,manuId,i,k));
301 param->SetValueAsDouble(i,k,d);
308 AliMUONVTrackerData* d = new AliMUONTrackerData(outname,outname,d1.ExternalDimension(),kTRUE);
309 for ( Int_t k = 0; k < d1.ExternalDimension(); ++k )
311 d->SetDimensionName(k,Form("D:%s",d1.ExternalDimensionName(k).Data()));