Adding a tool to mchview to compare alignments (Philippe P. ; Laurent)
authorlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 11 Apr 2012 14:35:43 +0000 (14:35 +0000)
committerlaphecet <laphecet@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 11 Apr 2012 14:35:43 +0000 (14:35 +0000)
MUON/AliMUONAlignmentCompareDialog.cxx [new file with mode: 0644]
MUON/AliMUONAlignmentCompareDialog.h [new file with mode: 0644]
MUON/AliMUONMchViewApplication.cxx
MUON/AliMUONMchViewApplication.h
MUON/AliMUONPainterDataSourceFrame.cxx
MUON/CMakelibMUONgraphics.pkg
MUON/MUONgraphicsLinkDef.h

diff --git a/MUON/AliMUONAlignmentCompareDialog.cxx b/MUON/AliMUONAlignmentCompareDialog.cxx
new file mode 100644 (file)
index 0000000..2ec215d
--- /dev/null
@@ -0,0 +1,275 @@
+/**************************************************************************
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+// $Id$
+
+#include "AliMUONAlignmentCompareDialog.h"
+
+/// \class AliMUONAlignmentCompareDialog
+///
+/// Widget to select 2 alignments objects from the OCDB (A1,A2) to be compared
+///
+/// \author Philippe Pillot, Laurent Aphecetche
+///
+
+#include "AliCDBManager.h"
+#include "AliGeomManager.h"
+#include "AliLog.h"
+#include "AliMUON2DMap.h"
+#include "AliMUONCalibParamND.h"
+#include "AliMUONConstants.h"
+#include "AliMUONGeometryTransformer.h"
+#include "AliMUONPainterDataRegistry.h"
+#include "AliMUONTrackerData.h"
+#include "AliMUONTrackerDataWrapper.h"
+#include "AliMpConstants.h"
+#include "AliMpDDLStore.h"
+#include "AliMpDEIterator.h"
+#include "AliMpDetElement.h"
+#include "AliMpManuIterator.h"
+#include "AliMpPad.h"
+#include "AliMpSegmentation.h"
+#include "AliMpVPadIterator.h"
+#include "AliMpVSegmentation.h"
+#include <TGComboBox.h>
+#include <TGLabel.h>
+#include <TGNumberEntry.h>
+#include <TGTextEntry.h>
+#include <TGeoManager.h>
+#include <TTimer.h>
+
+/// \cond CLASSIMP
+ClassImp(AliMUONAlignmentCompareDialog)
+/// \endcond
+
+namespace
+{
+  
+#define PRECISION 1E-12
+  
+  Double_t Difference(Double_t v1, Double_t v2)
+  {
+    Double_t d = v1-v2;
+    return TMath::Abs(d) < PRECISION ? 0.0 : d;
+  }  
+}
+
+//_____________________________________________________________________________
+AliMUONAlignmentCompareDialog::AliMUONAlignmentCompareDialog(const TGWindow* p, const TGWindow* main, UInt_t w, UInt_t h)
+: TGTransientFrame(p,main,w,h),
+fF1(new TGVerticalFrame(this)),
+fOCDBPath1(0x0),
+fRun1(0x0),
+fF2(new TGVerticalFrame(this)),
+fOCDBPath2(0x0),
+fRun2(0x0),
+fF3(new TGHorizontalFrame(this)),
+fBasename(new TGTextEntry(fF3)),
+fButtonFrame(new TGHorizontalFrame(this)),
+fOK(new TGTextButton(fButtonFrame,"OK")),
+fCancel(new TGTextButton(fButtonFrame,"Cancel"))
+{
+  /// ctor
+  
+  SetCleanup(kDeepCleanup);
+    
+  AddInput(fF1,"First alignment",fOCDBPath1,fRun1);
+  AddInput(fF2,"Second alignment",fOCDBPath2,fRun2);
+    
+  fF3->AddFrame(new TGLabel(fF3,"Output basename"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
+  fF3->AddFrame(fBasename,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
+
+  AddFrame(fF1,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+  AddFrame(fF2,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+  AddFrame(fF3,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+  
+  fButtonFrame->AddFrame(fOK,new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
+  fButtonFrame->AddFrame(fCancel,new TGLayoutHints(kLHintsRight|kLHintsTop,5,5,5,5));
+
+  AddFrame(fButtonFrame,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+  
+  fOK->Connect("Clicked()", "AliMUONAlignmentCompareDialog",this,"DoOK()");
+  fCancel->Connect("Clicked()","AliMUONAlignmentCompareDialog",this,"DoCancel()");
+}
+
+//_____________________________________________________________________________
+AliMUONAlignmentCompareDialog::~AliMUONAlignmentCompareDialog()
+{
+  /// dtor
+}
+
+//_____________________________________________________________________________
+void AliMUONAlignmentCompareDialog::AddInput(TGCompositeFrame* frame, const char* msg,
+                                             TGTextEntry*& text, TGNumberEntry*& run)
+{
+    
+    TGHorizontalFrame* hf1 = new TGHorizontalFrame(frame);
+    
+    hf1->AddFrame(new TGLabel(hf1,TString(msg) + " ocdb path"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
+    
+    text = new TGTextEntry(hf1,"alien://folder=/alice/data/2012/OCDB");
+    
+    hf1->AddFrame(text,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
+    
+    TGHorizontalFrame* hf2 = new TGHorizontalFrame(frame);
+    
+    hf2->AddFrame(new TGLabel(hf2,TString(msg) + " run number"),new TGLayoutHints(kLHintsLeft|kLHintsTop,5,5,5,5));
+    
+    run = new TGNumberEntry(hf2);
+    
+    hf2->AddFrame(run,new TGLayoutHints(kLHintsRight|kLHintsExpandX|kLHintsTop,5,5,5,5));
+    
+    frame->AddFrame(hf1,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+    frame->AddFrame(hf2,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsTop,5,5,5,5));
+}
+
+//______________________________________________________________________________
+void
+AliMUONAlignmentCompareDialog::DoOK()
+{
+  /// Do the job.
+  
+  AliMUONVTrackerData* d = CompareAlignment(fOCDBPath1->GetText(),fRun1->GetNumber(),
+                                            fOCDBPath2->GetText(),fRun2->GetNumber());
+                   
+  if (!d) return;
+  
+  TString basename = fBasename->GetText(); 
+  
+  AliMUONVTrackerDataMaker* dw = new AliMUONTrackerDataWrapper(d);
+  
+  AliMUONPainterDataRegistry::Instance()->Register(dw);
+  
+  TTimer::SingleShot(150,"AliMUONAlignmentCompareDialog",this,"CloseWindow()");
+}
+
+//______________________________________________________________________________
+void
+AliMUONAlignmentCompareDialog::DoCancel()
+{
+  /// Kills the dialog
+  TTimer::SingleShot(150,"AliMUONAlignmentCompareDialog",this,"CloseWindow()");
+}
+
+//______________________________________________________________________________
+AliMUONVTrackerData*
+AliMUONAlignmentCompareDialog::CompareAlignment(const char* ocdbPathForAlign1, Int_t run1,
+                                                const char* ocdbPathForAlign2, Int_t run2)
+{
+  // ocdb access
+  AliCDBManager* cdbm = AliCDBManager::Instance();
+  cdbm->SetDefaultStorage("raw://");
+  
+  // get geometry transformers
+  AliMUONGeometryTransformer geoTransformer[2];
+
+  const char* align[2] = {
+    ocdbPathForAlign1,
+    ocdbPathForAlign2
+  };
+  
+  Int_t runs[] = {
+     run1,run2
+  };
+  
+  for (Int_t i = 0; i < 2; i++) 
+  {
+    cdbm->UnloadFromCache("GRP/Geometry/Data");
+    cdbm->UnloadFromCache("MUON/Align/Data");
+    AliGeomManager::GetGeometry()->UnlockGeometry();
+    AliGeomManager::LoadGeometry();
+    if (!AliGeomManager::GetGeometry()) return 0x0;
+    cdbm->SetSpecificStorage("MUON/Align/Data",align[i]);
+    cdbm->SetRun(runs[i]);
+    AliGeomManager::ApplyAlignObjsFromCDB("MUON");
+    geoTransformer[i].LoadGeometryData();
+  }
+  
+  // store for cluster shifts
+  AliMUON2DMap shiftStore(kTRUE);
+  
+  // loop over chamber
+  for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
+    
+    // loop over DEs
+    AliMpDEIterator nextDE;
+    nextDE.First(iCh);
+    while (!nextDE.IsDone()) {
+      
+      Int_t deId = nextDE.CurrentDE()->GetId();
+      
+      // loop over cathods
+      for (Int_t icath = 0; icath < 2; icath++) {
+        
+        const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(deId,AliMp::GetCathodType(icath));
+        
+        // loop over pads
+        AliMpVPadIterator *nextPad = seg->CreateIterator();
+        nextPad->First();
+        while (!nextPad->IsDone()) {
+          
+          AliMpPad pad = nextPad->CurrentItem();
+          Int_t manuId = pad.GetManuId();
+          Int_t manuChannel = pad.GetManuChannel();
+          
+          // local position
+          Double_t xl = pad.GetPositionX();
+          Double_t yl = pad.GetPositionY();
+          Double_t zl = 0.;
+          
+          // position with first alignment
+          Double_t x1, y1, z1;
+          geoTransformer[0].Local2Global(deId,xl,yl,zl,x1,y1,z1);
+          
+          // position with second alignment
+          Double_t x2, y2, z2;
+          geoTransformer[1].Local2Global(deId,xl,yl,zl,x2,y2,z2);
+          
+          // pad shift
+          Double_t dx = ::Difference(x2,x1);
+          Double_t dy = ::Difference(y2,y1);
+          Double_t dz = ::Difference(z2,z1);
+          
+          // store pad shifts
+          AliMUONVCalibParam* p = static_cast<AliMUONVCalibParam*>(shiftStore.FindObject(deId,manuId));
+          if (!p) {
+            p = new AliMUONCalibParamND(3,AliMpConstants::ManuNofChannels(),deId,manuId,0.);
+            shiftStore.Add(p);
+          }
+          p->SetValueAsDouble(manuChannel,0,dx);
+          p->SetValueAsDouble(manuChannel,1,dy);
+          p->SetValueAsDouble(manuChannel,2,dz);
+          
+          nextPad->Next();
+        }
+        
+        delete nextPad;
+        
+      }
+      
+      nextDE.Next();
+    }
+    
+  }
+  
+  // create tracker data
+  AliMUONTrackerData* data = new AliMUONTrackerData(fBasename->GetText(),fBasename->GetText(),3,kTRUE);
+  data->SetDimensionName(0,"dx"); // max shift in x
+  data->SetDimensionName(1,"dy"); // max shift in y
+  data->SetDimensionName(2,"dz"); // max shift in z
+  data->Add(shiftStore);
+  
+  return data;
+}
\ No newline at end of file
diff --git a/MUON/AliMUONAlignmentCompareDialog.h b/MUON/AliMUONAlignmentCompareDialog.h
new file mode 100644 (file)
index 0000000..f2d0a90
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef ALIMUONALIGNMENTCOMPAREDIALOG_H
+#define ALIMUONALIGNMENTCOMPAREDIALOG_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup graphics
+/// \class AliMUONAlignmentCompareDialog
+/// \brief
+/// 
+/// Authors Philippe Pillot, Laurent Aphecetche, Subatech
+
+#ifndef ROOT_TGFrame
+#  include "TGFrame.h"
+#endif
+
+class AliMUONVTrackerData;
+class TGButtonGroup;
+class TGNumberEntry;
+class TGCompositeFrame;
+class TGTextEntry;
+
+class AliMUONAlignmentCompareDialog : public TGTransientFrame
+{
+public:
+  AliMUONAlignmentCompareDialog(const TGWindow* p = 0, const TGWindow* main = 0, UInt_t w = 1, UInt_t h = 1);
+  virtual ~AliMUONAlignmentCompareDialog();
+
+  void DoOK();
+  void DoCancel();
+  
+private:
+  
+    /// not defined
+    AliMUONAlignmentCompareDialog(const AliMUONAlignmentCompareDialog& rhs);
+    /// not defined
+    AliMUONAlignmentCompareDialog& operator=(const AliMUONAlignmentCompareDialog& rhs);
+
+    AliMUONVTrackerData* CompareAlignment(const char* ocdbPathForAlign1, Int_t run1,
+                                          const char* ocdbPathForAlign2, Int_t run2);
+  
+    void AddInput(TGCompositeFrame* frame, const char* msg, TGTextEntry*& text, TGNumberEntry*&     run);
+
+private:
+
+  TGCompositeFrame* fF1; ///< frame for align 1 selection
+  TGTextEntry* fOCDBPath1; ///< to select first alignment path
+  TGNumberEntry* fRun1; ///< to select first run
+  TGCompositeFrame* fF2; ///< frame for align 2 selection
+  TGTextEntry* fOCDBPath2; ///< to select second alignment path
+  TGNumberEntry* fRun2; ///< to select second run
+  TGCompositeFrame* fF3; ///< frame for difference type selection
+  TGTextEntry* fBasename; ///< basename of resulting (diff-ed) data
+  TGCompositeFrame* fButtonFrame; ///< to hold OK and Cancel buttons
+  TGTextButton* fOK; ///< ok button
+  TGTextButton* fCancel; ///< cancel button
+    
+  ClassDef(AliMUONAlignmentCompareDialog,1) // Dialog to select two data sources to compare
+};
+
+#endif
index b5ffc60..ba4a637 100644 (file)
@@ -20,6 +20,7 @@
 #include "AliCDBManager.h"
 #include "AliCodeTimer.h"
 #include "AliLog.h"
+#include "AliMUONAlignmentCompareDialog.h"
 #include "AliMUONChamberPainter.h"
 #include "AliMUONDEPainter.h"
 #include "AliMUONPainterDataRegistry.h"
@@ -66,6 +67,7 @@ const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
 const Int_t AliMUONMchViewApplication::fgkFILEPRINTAS(4);
 const Int_t AliMUONMchViewApplication::fgkABOUT(5);
 const Int_t AliMUONMchViewApplication::fgkCOMPAREDATA(6);
+const Int_t AliMUONMchViewApplication::fgkCOMPAREALIGNMENTS(7);
 
 const char* AliMUONMchViewApplication::fgkFileTypes[] = { 
   "ROOT files",    "*.root", 
@@ -250,6 +252,28 @@ AliMUONMchViewApplication::GenerateStartupMatrix()
 
 //______________________________________________________________________________
 void
+AliMUONMchViewApplication::CompareAlignments()
+{
+  /// Launch compare data dialog
+  TGTransientFrame* t = new AliMUONAlignmentCompareDialog(gClient->GetRoot(),
+                                                          gClient->GetRoot(),
+                                                          400,400);
+  
+  t->MapSubwindows();
+  t->Resize();
+  t->MapWindow();
+  t->CenterOnParent();
+  
+  // set names
+  
+  t->SetWindowName("mchview compare alignments tool");
+  t->SetIconName("mchview compare alignments tool");
+  
+  t->MapRaised();  
+}
+
+//______________________________________________________________________________
+void
 AliMUONMchViewApplication::CompareData()
 {
   /// Launch compare data dialog
@@ -287,6 +311,7 @@ AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
   
   TGPopupMenu* tools = new TGPopupMenu(gClient->GetRoot());
   tools->AddEntry("&Compare data",fgkCOMPAREDATA);
+  tools->AddEntry("&Compare alignments",fgkCOMPAREALIGNMENTS);
   
   TGPopupMenu* about = new TGPopupMenu(gClient->GetRoot());  
   about->AddEntry(FullVersion(),fgkABOUT);
@@ -330,7 +355,10 @@ AliMUONMchViewApplication::HandleMenu(Int_t i)
     case fgkCOMPAREDATA:
       CompareData();
       break;
-    default:
+    case fgkCOMPAREALIGNMENTS:
+      CompareAlignments();
+      break;
+      default:
       break;
     }
 }
@@ -467,6 +495,11 @@ AliMUONMchViewApplication::ReleaseNotes()
   
   TGTextView* rn = new TGTextView(t);
 
+  rn->AddLine("1.11");
+  rn->AddLine("");
+  rn->AddLine("Adding [Compare alignments] in the Tools menu + make default OCDB be 2012's version");
+  rn->AddLine("");
+  
   rn->AddLine("1.10");
   rn->AddLine("");
   rn->AddLine("Make the raw OCDB more obvious in the data source tab");
index 695bdbd..4423488 100644 (file)
@@ -32,7 +32,7 @@ public:
   void HandleMenu(Int_t i);
 
   /// Return the version number of the mchview application
-  static const char* Version() { return "1.10"; }
+  static const char* Version() { return "1.11"; }
   
   /// Return the SVN revision  and version number of the mchview application
   static const char* FullVersion() { return Form("mchview Version %s ($Id$)",Version()); }
@@ -46,6 +46,7 @@ private:
   AliMUONMchViewApplication& operator=(const AliMUONMchViewApplication& rhs);
   
   void CompareData();  
+  void CompareAlignments();
   void CreateMenuBar(UInt_t w);
   void Save();
   void Save(const char* filename);
@@ -66,6 +67,7 @@ private:
   static const Int_t fgkFILEPRINTAS; ///< File/Print As... menu
   static const Int_t fgkABOUT; ///< About menu
   static const Int_t fgkCOMPAREDATA; ///< Tools/Compare Data menu
+  static const Int_t fgkCOMPAREALIGNMENTS; ///< Tools/Compare Alignments menu
   
   static const char* fgkFileTypes[]; ///< For the open menu
   
index 60bc223..6a2c8b2 100644 (file)
@@ -82,11 +82,11 @@ AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p,
   fEventRangeButton(new TGCheckButton(fRawSelector23,"Event range")),
   fEventMin(new TGNumberEntry(fRawSelector23,-1,10)),
   fEventMax(new TGNumberEntry(fRawSelector23,-1,10)),
-  fRawOCDBPath(new TGTextEntry(fRawSelector24,"alien://folder=/alice/data/2011/OCDB")),
+  fRawOCDBPath(new TGTextEntry(fRawSelector24,"alien://folder=/alice/data/2012/OCDB")),
   fOCDBSelector(new TGGroupFrame(this,"OCDB Path",kHorizontalFrame)),
   fDataReaders(new TGGroupFrame(this,"Data sources")),
   fFilePath(new TGTextEntry(fRawSelector21,"")),
-  fOCDBPath(new TGTextEntry(fOCDBSelector,"alien://folder=/alice/data/2011/OCDB")),
+  fOCDBPath(new TGTextEntry(fOCDBSelector,"alien://folder=/alice/data/2012/OCDB")),
   fRunSelector(new TGNumberEntry(fOCDBSelector,0,10)),
   fOCDBTypes(new TGComboBox(fOCDBSelector)),
   fRecentSources(new TGComboBox(fRecentSourceSelector)),
index bb6d951..df7ebc3 100644 (file)
@@ -67,6 +67,7 @@ set ( SRCS
     AliMUONPointWithRef.cxx 
     AliMUONContourMakerTest.cxx 
     AliMUONContourHandler.cxx
+    AliMUONAlignmentCompareDialog.cxx
     )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
index 0892429..0999a31 100644 (file)
@@ -47,6 +47,7 @@
 #pragma link C++ class AliMUONPointWithRef+;
 #pragma link C++ class AliMUONContourMakerTest+;
 #pragma link C++ class AliMUONContourHandler+;
+#pragma link C++ class AliMUONAlignmentCompareDialog+;
 
 
 #endif