]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPainterHelper.cxx
Access to the file analyzed available now in analysis classes through the reader...
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterHelper.cxx
index aa589f08e3897d49769bb5b6568263a0df7fa7db..73b08dfcbdc97b04c439f60648216d55f50732b8 100644 (file)
 #include <cstdlib>
 #include "AliMUONPainterHelper.h"
 
+#include "AliCodeTimer.h"
+#include "AliLog.h"
+#include "AliMUONContour.h"
+#include "AliMUONContourMaker.h"
 #include "AliMUONGeometryDetElement.h"
 #include "AliMUONGeometryTransformer.h"
-#include "AliMUONPainterContour.h"
-#include "AliMUONPainterContourMaker.h"
+#include "AliMUONManuContourMaker.h"
 #include "AliMUONPainterEnv.h"
 #include "AliMUONPainterMatrix.h"
-#include "AliMUONPainterPadStore.h"
 #include "AliMUONPainterRegistry.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVDigit.h"
@@ -44,8 +46,6 @@
 #include "AliMpSlat.h"
 #include "AliMpStationType.h"
 #include "AliMpVPadIterator.h"
-#include "AliCodeTimer.h"
-#include "AliLog.h"
 #include <Riostream.h>
 #include <TArrayI.h>
 #include <TCanvas.h>
@@ -53,8 +53,8 @@
 #include <TCollection.h>
 #include <TFile.h>
 #include <TGLabel.h>
-#include <TGeoMatrix.h>
 #include <TGMsgBox.h>
+#include <TGeoMatrix.h>
 #include <TLine.h>
 #include <TList.h>
 #include <TMap.h>
@@ -67,6 +67,8 @@
 #include <TVirtualPad.h>
 #include <TVirtualX.h>
 
+#include "AliMUONChamberPainter.h"
+
 ///\class AliMUONPainterHelper
 ///
 /// Helper class for painters
@@ -81,16 +83,17 @@ AliMUONPainterHelper* AliMUONPainterHelper::fgInstance(0x0);
 
 //_____________________________________________________________________________
 AliMUONPainterHelper::AliMUONPainterHelper() : 
-  TObject(),
-  fPadStore(0x0),
-  fExplodedGlobalTransformations(0x0),
-  fRealGlobalTransformations(0x0),
-  fIsModified(kFALSE),
-  fContourMaker(0x0),
-  fPainterMatrices(0x0),
-  fEnv(0x0)
+TObject(),
+fExplodedGlobalTransformations(0x0),
+fRealGlobalTransformations(0x0),
+fPainterMatrices(0x0),
+fEnv(0x0),
+fAllContours(20000,1)
 {
     /// ctor
+  
+  fAllContours.SetOwnerKeyValue(kTRUE,kTRUE);
+  
     fExplodeFactor[0] = 1.00;
     fExplodeFactor[1] = 1.50;
 
@@ -110,37 +113,19 @@ AliMUONPainterHelper::AliMUONPainterHelper() :
 AliMUONPainterHelper::~AliMUONPainterHelper()
 {
   /// dtor
-  if ( fIsModified ) Save();
   delete fExplodedGlobalTransformations;
   delete fRealGlobalTransformations;
-  delete fPadStore;
-  delete fContourMaker;
   delete fPainterMatrices;
+  fEnv->Save();
   fgInstance = 0;
 }
 
 //_____________________________________________________________________________
-AliMUONPainterContour*
+AliMUONContour*
 AliMUONPainterHelper::GetContour(const char* contourName) const
 {
-  /// Get a contour by name
-  
-  AliCodeTimerAuto("")
-  
-  if ( fContourMaker ) 
-  {
-    return fContourMaker->GetContour(contourName);
-  }
-  return 0x0;
-}
-
-//_____________________________________________________________________________
-Int_t 
-AliMUONPainterHelper::FindPadID(const TArrayI& pads, Double_t x, Double_t y) const
-{
-  /// Find a pad by position
-  
-  return fPadStore->FindPadID(pads,x,y);
+  /// Get a contour by name  
+  return static_cast<AliMUONContour*>(fAllContours.GetValue(contourName));
 }
 
 //_____________________________________________________________________________
@@ -149,6 +134,8 @@ AliMUONPainterHelper::GenerateDefaultMatrices()
 {
   /// Kind of bootstrap method to trigger the generation of all contours
   
+  AliCodeTimerAuto("");
+  
   fPainterMatrices = new TObjArray;
   fPainterMatrices->SetOwner(kFALSE);
   
@@ -159,17 +146,19 @@ AliMUONPainterHelper::GenerateDefaultMatrices()
   att.SetViewPoint(kTRUE,kFALSE);
   att.SetPlane(kFALSE,kFALSE);
   att.SetCathode(kTRUE,kFALSE);
-  
-  AliWarningClass("Should generate back views as well here");
-  
-  attributes.Add(new AliMUONAttPainter(att));  
-  att.SetCathode(kFALSE,kTRUE);
-  attributes.Add(new AliMUONAttPainter(att));
+
   att.SetCathode(kFALSE,kFALSE);
   att.SetPlane(kTRUE,kFALSE);
   attributes.Add(new AliMUONAttPainter(att));
-  att.SetPlane(kFALSE,kTRUE);
-  attributes.Add(new AliMUONAttPainter(att));
+
+// commented the lines below, as it's now fast enough to be created on the fly,
+// only when requested by the user
+//
+//  attributes.Add(new AliMUONAttPainter(att));  
+//  att.SetCathode(kFALSE,kTRUE);
+//  attributes.Add(new AliMUONAttPainter(att));
+//  att.SetPlane(kFALSE,kTRUE);
+//  attributes.Add(new AliMUONAttPainter(att));
   
   TIter next(&attributes);
   AliMUONAttPainter* a;
@@ -180,7 +169,7 @@ AliMUONPainterHelper::GenerateDefaultMatrices()
     
     for ( Int_t i = 0; i < 10; ++i )
     {
-      AliMUONVPainter* painter = AliMUONVPainter::CreatePainter("AliMUONChamberPainter",*a,i,-1);
+      AliMUONVPainter* painter = new AliMUONChamberPainter(*a,i);
       
       painter->SetResponder("Chamber");
       
@@ -209,11 +198,10 @@ AliMUONPainterHelper::GenerateGeometry()
   /// having overlapping detection elements as in the reality, which 
   /// would be inconvenient for a display ;-)
   
-  AliDebug(1,Form(" with explodeFactor=%e,%e",fExplodeFactor[0],fExplodeFactor[1]));
+  AliCodeTimerAuto("");
   
   AliMUONGeometryTransformer transformer;
   transformer.LoadGeometryData("transform.dat");
-//  transformer.LoadGeometryData("geometry.root"); //FIXME: add a protection if geometry.root file does not exist
   fExplodedGlobalTransformations = new AliMpExMap;
   fRealGlobalTransformations = new AliMpExMap;
   AliMpDEIterator deIt;
@@ -253,7 +241,7 @@ AliMUONPainterHelper::GenerateGeometry()
 }
 
 //_____________________________________________________________________________
-AliMUONPainterContour* 
+AliMUONContour* 
 AliMUONPainterHelper::GenerateManuContour(Int_t detElemId,
                                           Int_t manuId,
                                           AliMUONAttPainter viewType,
@@ -261,87 +249,26 @@ AliMUONPainterHelper::GenerateManuContour(Int_t detElemId,
 {
   /// Generate the contour of the list of pads
   
-  if (!fContourMaker) fContourMaker = new AliMUONPainterContourMaker(fExplodedGlobalTransformations);
-  
-  AliMUONPainterContour* contour = 
-    fContourMaker->GenerateManuContour(contourName,detElemId,manuId,viewType);
+  static AliMUONManuContourMaker maker(fExplodedGlobalTransformations);
   
-  if (contour) 
+  if ( viewType.IsBackView() )
   {
-    RegisterContour(contour);
+    AliError("Backview not implemented yet (and will probably never be, after all...)");
+    return 0x0;
   }
   
-  return contour;
-}
-
-//_____________________________________________________________________________
-void
-AliMUONPainterHelper::GeneratePadStore()
-{
-  /// Generate the pad store
+  AliMUONContour* contour = maker.CreateManuContour(detElemId,manuId,contourName);
   
-  AliCodeTimerAuto("")
-  AliDebugClass(1,"Generating pad store");
-  fPadStore = new AliMUONPainterPadStore();
+  if ( !contour ) return 0x0;
   
-  AliMpDEIterator deIt;
+  AliMUONContour* pContour = new AliMUONContour(*contour);
   
-  deIt.First();
-  while ( !deIt.IsDone() )
+  if (pContour) 
   {
-    Int_t detElemId = deIt.CurrentDEId();
-    if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger )
-    {
-      GeneratePadStore(detElemId);
-    }
-    deIt.Next();
-  }
-}
-
-//_____________________________________________________________________________
-void
-AliMUONPainterHelper::GeneratePadStore(Int_t detElemId)
-{
-  /// Generate part of the padstore for one detection element
-  
-  AliMp::CathodType cathode[] = { AliMp::kCath0, AliMp::kCath1 };
-  
-  for ( Int_t i = 0; i < 2; ++i ) 
-  {
-    const AliMpVSegmentation* seg = 
-    AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,cathode[i]);
-    AliMpVPadIterator* it = seg->CreateIterator();
-    it->First();
-    
-    while ( !it->IsDone() )
-    {
-      AliMpPad pad = it->CurrentItem();
-      
-      TVector2 localPosition(pad.Position());
-      Double_t x,y,z;
-      Local2Global(detElemId,localPosition.X(),localPosition.Y(),0,
-                   x,y,z);
-      Int_t manuId = pad.GetLocation().GetFirst();
-      Int_t manuChannel = pad.GetLocation().GetSecond();
-      AliMUONVCalibParam* param = fPadStore->Get(detElemId,manuId);
-      param->SetValueAsDouble(manuChannel,0,x);
-      param->SetValueAsDouble(manuChannel,1,y);
-      param->SetValueAsDouble(manuChannel,2,pad.Dimensions().X());
-      param->SetValueAsDouble(manuChannel,3,pad.Dimensions().Y());
-      it->Next();
-    }          
-    delete it;
+    RegisterContour(pContour);
   }
-}
-
-//_____________________________________________________________________________
-void 
-AliMUONPainterHelper::GetBoundaries(const TArrayI& pads, Double_t& xmin, Double_t& ymin,
-                                    Double_t& xmax, Double_t& ymax) const
-{
-  /// Get the area covered by an array of pads
   
-  return fPadStore->GetBoundaries(pads,xmin,ymin,xmax,ymax);
+  return pContour;
 }
 
 //_____________________________________________________________________________
@@ -358,13 +285,6 @@ AliMUONPainterHelper::GetCathodeType(Int_t detElemId, Int_t manuId) const
   return AliMpDEManager::GetCathod(detElemId,planeType);
 }
 
-//_____________________________________________________________________________
-AliMUONPainterContour* 
-AliMUONPainterHelper::GetLocalManuContour(Int_t detElemId, Int_t manuId) const
-{
-  /// Retrieve a manu contour (in local coordinates)
-  return fContourMaker->FindLocalManuContour(detElemId,manuId);
-}
 
 //_____________________________________________________________________________
 AliMpMotifPosition* 
@@ -450,7 +370,7 @@ AliMUONPainterHelper::GetSector(Int_t detElemId, AliMp::PlaneType planeType) con
 {
   /// Get a given sector
   AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
-  if ( stationType != AliMp::kStation1 && stationType != AliMp::kStation2 ) return 0x0;
+  if ( stationType != AliMp::kStation12 ) return 0x0;
   
   AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
   
@@ -486,51 +406,13 @@ AliMUONPainterHelper::Instance()
   /// Return the global and unique instance of this class
   
   if (fgInstance) return fgInstance;
-  
-  AliMUONPainterEnv env;
-  
-  TString fileName(gSystem->ExpandPathName(env.String("PadStoreFileName","$HOME/padstore.root")));
 
-  if ( gSystem->AccessPathName(fileName.Data(),kFileExists) ) // mind the strange return value of that method...   
-  {
-    // file does NOT exist yet. Create it
-    AliDebugClass(1,"Generating instance");
-    
-    Int_t ret;
-    
-    new TGMsgBox(gClient->GetRoot(),gClient->GetRoot(),"",
-                 Form("File %s not found.\nI will generate it, and this will take a while.\n"
-                      "Click OK (and grab a cup of coffee ;-) ) to proceed,\n or Cancel to quit.",fileName.Data()),
-                 kMBIconQuestion,
-                 kMBOk | kMBCancel,
-                 &ret);
-    if ( ret == kMBCancel ) exit(1);
-    
-    fgInstance = new AliMUONPainterHelper;
-    fgInstance->GenerateGeometry();
-    fgInstance->GeneratePadStore();
-    fgInstance->GenerateDefaultMatrices();
-    fgInstance->Modified(kTRUE);
-    fgInstance->fEnv = new AliMUONPainterEnv;
-    fgInstance->fEnv->Set("PadStoreFileName",fileName.Data());
-    fgInstance->Save();
-    
-  }
-  else
-  {
-    AliDebugClass(1,"Reading instance");
-    TFile f(fileName.Data());
-    fgInstance = static_cast<AliMUONPainterHelper*>(f.Get("AliMUONPainterHelper"));
-    
-    TIter next(fgInstance->fPainterMatrices);
-    AliMUONPainterMatrix* matrix;
-    while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
-    {
-      AliMUONPainterRegistry::Instance()->Register(matrix);
-    }
-    fgInstance->fPainterMatrices->SetOwner(kFALSE);
-    fgInstance->fEnv = new AliMUONPainterEnv;
-  }
+  AliCodeTimerAutoClass("");
+
+  fgInstance = new AliMUONPainterHelper;
+  fgInstance->GenerateGeometry();
+  fgInstance->GenerateDefaultMatrices();
+  fgInstance->fEnv = new AliMUONPainterEnv;
   return fgInstance;
 }
 
@@ -623,18 +505,15 @@ AliMUONPainterHelper::ColorFromValue(Double_t value, Double_t min, Double_t max)
 }
 
 //_____________________________________________________________________________
-AliMUONPainterContour* 
+AliMUONContour* 
 AliMUONPainterHelper::MergeContours(const TObjArray& contours, 
                                     const char* contourName)
 {
   /// Merge a set of contours (delegating to the contour maker)
-  if (!fContourMaker) 
-  {
-    fContourMaker = new AliMUONPainterContourMaker(fExplodedGlobalTransformations);
-  }
   
-  AliMUONPainterContour* contour = fContourMaker->MergeContours(contours,
-                                                                contourName);
+  AliMUONContourMaker maker;
+  
+  AliMUONContour* contour = maker.MergeContour(contours,contourName);
   
   if (contour) 
   {
@@ -655,36 +534,15 @@ AliMUONPainterHelper::Print(Option_t* opt) const
   if ( sopt.Length() == 0 )
   {
     cout << Form("ExplodeFactor=%e,%e",fExplodeFactor[0],fExplodeFactor[1]) << endl;
-    cout << Form("PadStore=%x",fPadStore);
-    if ( fPadStore ) cout << Form(" with %d pads",fPadStore->GetSize());
     cout << endl;
     cout << Form("GlobalTransformations=%x",fExplodedGlobalTransformations);
     if ( fExplodedGlobalTransformations ) cout << Form(" with %d transformations",fExplodedGlobalTransformations->GetSize());
     cout << endl;
-    if ( fContourMaker ) 
-    {
-      cout << Form(" with %d contours",fContourMaker->Size());
-    }
-    else
-    {
-      cout << "No contour";
-    }
+    cout << Form("Contour map : collisions = %5.3f size = %d capacity = %d", 
+                 fAllContours.AverageCollisions(),
+                 fAllContours.GetSize(),
+                 fAllContours.Capacity()) << endl;
     cout << endl;
-    cout << "Modified=";
-    if ( IsModified() ) 
-    {
-    cout << "YES";
-  }
-  else
-  {
-    cout << "NO";
-  }
-  cout << endl;
-  }
-  
-  if ( sopt.Contains("CONTOUR") || sopt.Contains("FULL") )
-  {
-    fContourMaker->Print(opt);
   }
   
   if ( sopt.Contains("MATRI") || sopt.Contains("FULL") )
@@ -695,46 +553,18 @@ AliMUONPainterHelper::Print(Option_t* opt) const
 
 //_____________________________________________________________________________
 void
-AliMUONPainterHelper::RegisterContour(AliMUONPainterContour* contour)
+AliMUONPainterHelper::RegisterContour(AliMUONContour* contour)
 {
   /// contour is adopted by contourMaker
   AliCodeTimerAuto("")
   AliDebug(1,contour->GetName());
-  if ( fContourMaker->HasContour(contour->GetName()) ) 
+  if ( fAllContours.GetValue(contour->GetName()) ) 
   {
     AliError(Form("Contour with name %s is already there",contour->GetName()));
 //    Print("CONTOUR");
     return;
   }
-  fContourMaker->Add(contour);
-  Modified(kTRUE);
-}
-
-//_____________________________________________________________________________
-void
-AliMUONPainterHelper::Save()
-{
-  /// Save to disk
-  
-  if (!IsModified()) return;
-
-  Modified(kFALSE);
-
-  AliInfo("");
-
-  fgInstance->Print();
-  
-  fgInstance->Env()->Save();
-  
-  TString fileName(gSystem->ExpandPathName(fgInstance->Env()->String("PadStoreFileName")));
-
-  AliInfo(Form("Saving to %s",fileName.Data()));
-          
-  TFile f(fileName,"RECREATE");
-
-  fgInstance->Write("");
-  
-  f.Close();
+  fAllContours.Add(new TObjString(contour->GetName()),contour);
 }
 
 //_____________________________________________________________________________
@@ -762,9 +592,9 @@ AliMUONPainterHelper::PadByExplodedPosition(Int_t detElemId, Int_t manuId,
 
   const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
   
-  AliDebug(1,Form("dx,dy=%7.3f,%7.3f",seg->Dimensions().X(),seg->Dimensions().Y()));
+  AliDebug(1,Form("dx,dy=%7.3f,%7.3f",seg->GetDimensionX(),seg->GetDimensionY()));
   
-  return seg->PadByPosition(TVector2(xl,yl));
+  return seg->PadByPosition(xl,yl);
 }
 
 //_____________________________________________________________________________
@@ -899,3 +729,4 @@ AliMUONPainterHelper::FormatValue(const char* name, Double_t value) const
   
   return Form("%s = %e",name,value);
 }
+