]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliEvent.cxx
Change place of CalibData class from sim to base and add Alignment class
[u/mrichter/AliRoot.git] / RALICE / AliEvent.cxx
index 68af58307dbdb8389fd5837db69f621573b3099e..541d0ddf3a9aef3848844c8fc87fe34b18d33b95 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-// $Id: AliEvent.cxx,v 1.22 2004/06/29 11:29:37 nick Exp $
+// $Id: AliEvent.cxx,v 1.25 2004/10/20 10:49:44 nick Exp $
 
 ///////////////////////////////////////////////////////////////////////////
 // Class AliEvent
 // Order and investigate all the hits of all the TOF devices
 //
 //        TObjArray* hits=evt.GetHits("AliTOF");
-//        TObjArray orderedtofs=evt.SortHits(hits);
-//        Int_t nhits=orderedtofs.GetEntries();
+//        TObjArray* orderedtofs=evt.SortHits(hits);
+//        Int_t nhits=0;
+//        if (orderedtofs) nhits=orderedtofs->GetEntries();
 //        for (Int_t i=0; i<nhits; i++)
 //        {
-//         AliSignal* sx=(AliSignal*)orderedtofs.At(i);
+//         AliSignal* sx=(AliSignal*)orderedtofs->At(i);
 //         if (sx) sx->Data();
 //        }
 //
 // Order and investigate all the hits of all the calorimeter devices
 //
 //        TObjArray* hits=evt.GetHits("AliCalorimeter");
-//        TObjArray orderedcals=evt.SortHits(hits);
-//        Int_t nhits=orderedcals.GetEntries();
+//        TObjArray* orderedcals=evt.SortHits(hits);
+//        Int_t nhits=0;
+//        if (orderedcals) nhits=orderedcals->GetEntries();
 //        for (Int_t i=0; i<nhits; i++)
 //        {
-//         AliSignal* sx=(AliSignal*)orderedcals.At(i);
+//         AliSignal* sx=(AliSignal*)orderedcals->At(i);
 //         if (sx) sx->Data();
 //        }
 //
 // Note : All quantities are in GeV, GeV/c or GeV/c**2
 //
 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
-//- Modified: NvE $Date: 2004/06/29 11:29:37 $ UU-SAP Utrecht
+//- Modified: NvE $Date: 2004/10/20 10:49:44 $ UU-SAP Utrecht
 ///////////////////////////////////////////////////////////////////////////
 
 #include "AliEvent.h"
  
 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
  
-AliEvent::AliEvent() : AliVertex()
+AliEvent::AliEvent() : AliVertex(),AliTimestamp()
 {
 // Default constructor.
 // All variables initialised to default values.
- fDaytime.Set();
  fRun=0;
  fEvent=0;
  fAproj=0;
@@ -268,9 +269,12 @@ AliEvent::AliEvent() : AliVertex()
  fDevices=0;
  fDevCopy=0;
  fHits=0;
+ fOrdered=0;
+ fDisplay=0;
+ fDevs=0;
 }
 ///////////////////////////////////////////////////////////////////////////
-AliEvent::AliEvent(Int_t n) : AliVertex(n)
+AliEvent::AliEvent(Int_t n) : AliVertex(n),AliTimestamp()
 {
 // Create an event to hold initially a maximum of n tracks
 // All variables initialised to default values
@@ -278,7 +282,6 @@ AliEvent::AliEvent(Int_t n) : AliVertex(n)
  {
   cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
  }
- fDaytime.Set();
  fRun=0;
  fEvent=0;
  fAproj=0;
@@ -292,6 +295,9 @@ AliEvent::AliEvent(Int_t n) : AliVertex(n)
  fDevices=0;
  fDevCopy=0;
  fHits=0;
+ fOrdered=0;
+ fDisplay=0;
+ fDevs=0;
 }
 ///////////////////////////////////////////////////////////////////////////
 AliEvent::~AliEvent()
@@ -307,12 +313,26 @@ AliEvent::~AliEvent()
   delete fHits;
   fHits=0;
  }
+ if (fOrdered)
+ {
+  delete fOrdered;
+  fOrdered=0;
+ }
+ if (fDisplay)
+ {
+  delete fDisplay;
+  fDisplay=0;
+ }
+ if (fDevs)
+ {
+  delete fDevs;
+  fDevs=0;
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
-AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt)
+AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt),AliTimestamp(evt)
 {
 // Copy constructor.
- fDaytime=evt.fDaytime;
  fRun=evt.fRun;
  fEvent=evt.fEvent;
  fAproj=evt.fAproj;
@@ -325,6 +345,11 @@ AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt)
  fIdTarg=evt.fIdTarg;
  fDevCopy=evt.fDevCopy;
 
+ fHits=0;
+ fOrdered=0;
+ fDisplay=0;
+ fDevs=0;
+
  fDevices=0;
  Int_t ndevs=evt.GetNdevices();
  if (ndevs)
@@ -347,21 +372,6 @@ AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt)
    }
   }
  }
-
- fHits=0;
- if (evt.fHits)
- {
-  Int_t nhits=evt.fHits->GetEntries();
-  if (nhits)
-  {
-   fHits=new TObjArray(nhits);
-   for (Int_t ih=0; ih<nhits; ih++)
-   {
-    AliSignal* sx=(AliSignal*)evt.fHits->At(ih);
-    fHits->Add(sx);
-   }
-  }
- }
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::Reset()
@@ -369,11 +379,11 @@ void AliEvent::Reset()
 // Reset all variables to default values
 // The max. number of tracks is set to the initial value again
 // The max. number of vertices is set to the default value again
-// Note : The CalCopy mode is maintained as it was set by the user before.
+// Note : The DevCopy mode is maintained as it was set by the user before.
 
  AliVertex::Reset();
 
fDaytime.Set();
+ Set();
  fRun=0;
  fEvent=0;
  fAproj=0;
@@ -395,6 +405,21 @@ void AliEvent::Reset()
   delete fHits;
   fHits=0;
  }
+ if (fOrdered)
+ {
+  delete fOrdered;
+  fOrdered=0;
+ }
+ if (fDisplay)
+ {
+  delete fDisplay;
+  fDisplay=0;
+ }
+ if (fDevs)
+ {
+  delete fDevs;
+  fDevs=0;
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetOwner(Bool_t own)
@@ -431,7 +456,15 @@ void AliEvent::SetDayTime(TTimeStamp& stamp)
 // Set the date and time stamp for this event.
 // An exact copy of the entered date/time stamp will be saved with an
 // accuracy of 1 nanosecond.
- fDaytime=stamp;
+//
+// Note : Since the introduction of the more versatile class AliTimestamp
+//        and the fact that AliEvent has now been derived from it,
+//        this memberfunction has become obsolete.
+//        It is recommended to use the corresponding AliTimestamp
+//        functionality directly for AliEvent instances.
+//        This memberfunction is only kept for backward compatibility.
+
+ Set(stamp.GetDate(),stamp.GetTime(),0,kTRUE,0);
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetDayTime(TDatime& stamp)
@@ -439,11 +472,13 @@ void AliEvent::SetDayTime(TDatime& stamp)
 // Set the date and time stamp for this event.
 // The entered date/time will be interpreted as being the local date/time
 // and the accuracy is 1 second.
+//
 // This function with the TDatime argument is mainly kept for backward
-// compatibility reasons. It is recommended to use the corresponding
-// function with the TTimeStamp argument.
+// compatibility reasons.
+// It is recommended to use the corresponding AliTimestamp functionality
+// directly for AliEvent instances.
 
fDaytime.Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
+ Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetRunNumber(Int_t run)
@@ -461,7 +496,15 @@ void AliEvent::SetEventNumber(Int_t evt)
 TTimeStamp AliEvent::GetDayTime() const
 {
 // Provide the date and time stamp for this event
- return fDaytime;
+//
+// Note : Since the introduction of the more versatile class AliTimestamp
+//        and the fact that AliEvent has now been derived from it,
+//        this memberfunction has become obsolete.
+//        It is recommended to use the corresponding AliTimestamp
+//        functionality directly for AliEvent instances.
+//        This memberfunction is only kept for backward compatibility.
+
+ return (TTimeStamp)(*this);
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetRunNumber() const
@@ -544,28 +587,34 @@ Int_t AliEvent::GetTargetId() const
  return fIdTarg;
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::HeaderData() const
+void AliEvent::HeaderData()
 {
 // Provide event header information
  const char* name=GetName();
  const char* title=GetTitle();
- Int_t ndevs=GetNdevices();
  cout << " *" << ClassName() << "::Data*";
  if (strlen(name))  cout << " Name : " << GetName();
  if (strlen(title)) cout << " Title : " << GetTitle();
  cout << endl;
- cout << "  " << fDaytime.AsString() << endl;
- cout << "  Run : " << fRun << " Event : " << fEvent
-      << " Number of devices : " << ndevs << endl;
-
- if (ndevs) ShowDevices();
+ Date(1);
+ cout << "  Run : " << fRun << " Event : " << fEvent << endl;
+ ShowDevices(0);
+ ShowTracks(0);
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::Data(TString f)
+void AliEvent::Data(TString f,TString u)
 {
 // Provide event information within the coordinate frame f
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+//     "deg" : angles provided in degrees
+//
+// The defaults are f="car" and u="rad".
+
  HeaderData();
- AliVertex::Data(f);
+ AliVertex::Data(f,u);
 } 
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetNdevices() const
@@ -716,21 +765,56 @@ TObject* AliEvent::GetDevice(TString name) const
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliEvent::ShowDevices() const
+TObject* AliEvent::GetIdDevice(Int_t id) const
+{
+// Return the device with unique identifier "id".
+ if (!fDevices || id<0) return 0;
+
+ Int_t idx=0;
+ for (Int_t i=0; i<GetNdevices(); i++)
+ {
+  TObject* dev=fDevices->At(i);
+  if (dev)
+  {
+   idx=dev->GetUniqueID();
+   if (idx==id) return dev;
+  }
+ }
+ return 0; // No matching id found
+}
+///////////////////////////////////////////////////////////////////////////
+void AliEvent::ShowDevices(Int_t mode) const
 {
 // Provide an overview of the available devices.
+// The argument mode determines the amount of information as follows :
+// mode = 0 ==> Only printout of the number of devices
+//        1 ==> Provide a listing with 1 line of info for each device
+//
+// The default is mode=1.
+//
  Int_t ndevs=GetNdevices();
  if (ndevs)
  {
-  cout << " The following " << ndevs << " devices are available :" << endl; 
-  for (Int_t i=1; i<=ndevs; i++)
+  if (!mode)
   {
-   TObject* dev=GetDevice(i);
-   if (dev)
+   cout << " There are " << ndevs << " devices available." << endl; 
+  }
+  else
+  {
+   cout << " The following " << ndevs << " devices are available :" << endl; 
+   for (Int_t i=1; i<=ndevs; i++)
    {
-    cout << " Device number : " << i
-         << " Class : " << dev->ClassName()
-         << " Name : " << dev->GetName() << endl;
+    TObject* dev=GetDevice(i);
+    if (dev)
+    {
+     const char* name=dev->GetName();
+     cout << " Device number : " << i;
+     cout << " Class : " << dev->ClassName() << " Id : " << dev->GetUniqueID();
+     if (strlen(name)) cout << " Name : " << name;
+     if (dev->InheritsFrom("AliDevice")) cout << " Nhits : " << ((AliDevice*)dev)->GetNhits();
+     if (dev->InheritsFrom("AliSignal")) cout << " Nwaveforms : " << ((AliSignal*)dev)->GetNwaveforms();
+     cout << endl;
+    }
    }
   }
  }
@@ -740,6 +824,27 @@ void AliEvent::ShowDevices() const
  }
 }
 ///////////////////////////////////////////////////////////////////////////
+TObjArray* AliEvent::GetDevices(const char* classname)
+{
+// Provide the references to the various devices derived from the
+// specified class.
+ if (fDevs) fDevs->Clear();
+
+ Int_t ndev=GetNdevices();
+ for (Int_t idev=1; idev<=ndev; idev++)
+ {
+  TObject* obj=GetDevice(idev);
+  if (!obj) continue;
+
+  if (obj->InheritsFrom(classname))
+  {
+   if (!fDevs) fDevs=new TObjArray();
+   fDevs->Add(obj);
+  }
+ }
+ return fDevs;
+}
+///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetNhits(const char* classname)
 {
 // Provide the number of hits registered to the specified device class.
@@ -765,6 +870,28 @@ TObjArray* AliEvent::GetHits(const char* classname)
  return fHits;
 }
 ///////////////////////////////////////////////////////////////////////////
+AliSignal* AliEvent::GetIdHit(Int_t id,const char* classname)
+{
+// Return the hit with unique identifier "id" for the specified device class.
+ if (id<0) return 0;
+
+ Int_t nhits=GetNhits(classname);
+ if (!nhits) return 0;
+
+ AliSignal* sx=0;
+ Int_t sid=0;
+ for (Int_t i=0; i<nhits; i++)
+ {
+  sx=(AliSignal*)fHits->At(i);
+  if (sx)
+  {
+   sid=sx->GetUniqueID();
+   if (id==sid) return sx;
+  }
+ }
+ return 0; // No matching id found
+}
+///////////////////////////////////////////////////////////////////////////
 void AliEvent::LoadHits(const char* classname)
 {
 // Load the references to the various hits registered to the specified
@@ -795,11 +922,10 @@ void AliEvent::LoadHits(const char* classname)
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-TObjArray AliEvent::SortHits(TObjArray* hits,Int_t idx,Int_t mode) const
+TObjArray* AliEvent::SortHits(const char* classname,Int_t idx,Int_t mode,Int_t mcal)
 {
-// Order the references to an array of hits by looping over the input array "hits"
-// and checking the signal value. The ordered array is returned as a TObjArray.
-// Note that the input array is not modified.
+// Order the references to the various hits registered to the specified
+// device class. The ordered array is returned as a TObjArray.
 // A "hit" represents an abstract object which is derived from AliSignal.
 // The user can specify the index of the signal slot to perform the sorting on.
 // By default the slotindex will be 1.
@@ -807,26 +933,202 @@ TObjArray AliEvent::SortHits(TObjArray* hits,Int_t idx,Int_t mode) const
 // order (mode=-1) or ordering in increasing order (mode=1).
 // The default is mode=-1.
 // Signals which were declared as "Dead" will be rejected.
-// The gain etc... corrected signals will be used in the ordering process.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
+
+ if (idx<=0 || abs(mode)!=1) return 0;
+
+ LoadHits(classname);
+
+ AliDevice dev;
+ TObjArray* ordered=dev.SortHits(idx,mode,fHits,mcal);
+
+ if (fHits)
+ {
+  delete fHits;
+  fHits=0;
+ } 
+ if (ordered) fHits=new TObjArray(*ordered);
+ return fHits;
+}
+///////////////////////////////////////////////////////////////////////////
+TObjArray* AliEvent::SortHits(const char* classname,TString name,Int_t mode,Int_t mcal)
+{
+// Order the references to the various hits registered to the specified
+// device class. The ordered array is returned as a TObjArray.
+// A "hit" represents an abstract object which is derived from AliSignal.
+// The user can specify the name of the signal slot to perform the sorting on.
+// In case no matching slotname is found, the signal will be skipped.
+// Via the "mode" argument the user can specify ordering in decreasing
+// order (mode=-1) or ordering in increasing order (mode=1).
+// The default is mode=-1.
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
  
- if (idx<=0 || abs(mode)!=1 || !hits)
+ if (abs(mode)!=1) return 0;
+
+ LoadHits(classname);
+
+ AliDevice dev;
+ TObjArray* ordered=dev.SortHits(name,mode,fHits,mcal);
+
+ if (fHits)
  {
-  TObjArray ordered;
-  return ordered;
+  delete fHits;
+  fHits=0;
+ } 
+ if (ordered) fHits=new TObjArray(*ordered);
+ return fHits;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,Int_t idx,Int_t mode)
+{
+// Provide the min. and max. signal values of the various hits registered
+// to the specified device class.
+// The input argument "idx" denotes the index of the signal slots to be investigated.
+// The default is idx=1;
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the process as specified
+// by the  "mode" argument. The definition of this "mode" parameter corresponds to
+// the description provided in the GetSignal memberfunction of class AliSignal.
+// The default is mode=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
+
+ if (idx<=0) return;
+
+ LoadHits(classname);
+
+ AliDevice dev;
+ dev.GetExtremes(vmin,vmax,idx,fHits,mode);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,TString name,Int_t mode)
+{
+// Provide the min. and max. signal values of the various hits registered
+// to the specified device class.
+// The input argument "name" denotes the name of the signal slots to be investigated.
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the process as specified
+// by the  "mode" argument. The definition of this "mode" parameter corresponds to
+// the description provided in the GetSignal memberfunction of class AliSignal.
+// The default is mode=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
+
+ LoadHits(classname);
+
+ AliDevice dev;
+ dev.GetExtremes(vmin,vmax,name,fHits,mode);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliEvent::DisplayHits(const char* classname,Int_t idx,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
+{
+// 3D color display of the various hits registered to the specified device class.
+// The user can specify the index (default=1) of the signal slot to perform the display for.
+// The marker size will indicate the absolute value of the signal (specified by the slotindex)
+// as a percentage of the input argument "scale".
+// In case scale<0 the maximum absolute signal value encountered in the hit array will be used
+// to define the 100% scale. The default is scale=-1.
+// In case dp=1 the owning device position will be used, otherwise the hit position will
+// be used in the display. The default is dp=0.
+// Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
+// The default is mcol=blue.
+// Signals which were declared as "Dead" will not be displayed.
+// The gain etc... corrected signals will be used to determine the marker size.
+// The gain correction is performed according to "mode" argument. The definition of this
+// "mode" parameter corresponds to the description provided in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mode=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
+//
+// Note :
+// ------
+// Before any display activity, a TCanvas and a TView have to be initiated
+// first by the user like for instance
+// 
+// TCanvas* c1=new TCanvas("c1","c1");
+// TView* view=new TView(1);
+// view->SetRange(-1000,-1000,-1000,1000,1000,1000);
+// view->ShowAxis();
+
+ if (idx<=0) return;
+
+ LoadHits(classname);
+
+ AliDevice* dev=new AliDevice();
+ dev->DisplayHits(idx,scale,fHits,dp,mode,mcol);
+
+ if (fDisplay)
+ {
+  delete fDisplay;
+  fDisplay=0;
  }
- else
+ fDisplay=dev;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliEvent::DisplayHits(const char* classname,TString name,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
+{
+// 3D color display of the various hits registered to the specified device class.
+// The user can specify the name of the signal slot to perform the display for.
+// The marker size will indicate the absolute value of the signal (specified by the slotname)
+// as a percentage of the input argument "scale".
+// In case scale<0 the maximum absolute signal value encountered in the hit array will be used
+// to define the 100% scale. The default is scale=-1.
+// In case dp=1 the owning device position will be used, otherwise the hit position will
+// be used in the display. The default is dp=0.
+// The marker size will indicate the percentage of the maximum encountered value
+// of the absolute value of the name-specified input signal slots.
+// Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
+// The default is mcol=blue.
+// Signals which were declared as "Dead" will not be displayed.
+// The gain etc... corrected signals will be used to determine the marker size.
+// The gain correction is performed according to "mode" argument. The definition of this
+// "mode" parameter corresponds to the description provided in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mode=1 (for backward compatibility reasons).
+//
+// For more extended functionality see class AliDevice.
+//
+// Note :
+// ------
+// Before any display activity, a TCanvas and a TView have to be initiated
+// first by the user like for instance
+// 
+// TCanvas* c1=new TCanvas("c1","c1");
+// TView* view=new TView(1);
+// view->SetRange(-1000,-1000,-1000,1000,1000,1000);
+// view->ShowAxis();
+
+ LoadHits(classname);
+
+ AliDevice* dev=new AliDevice();
+ dev->DisplayHits(name,scale,fHits,dp,mode,mcol);
+
+ if (fDisplay)
  {
-  AliDevice dev;
-  TObjArray ordered=dev.SortHits(idx,mode,hits);
-  return ordered;
+  delete fDisplay;
+  fDisplay=0;
  }
+ fDisplay=dev;
 }
 ///////////////////////////////////////////////////////////////////////////
-TObjArray AliEvent::SortHits(TObjArray* hits,TString name,Int_t mode) const
+TObjArray* AliEvent::SortDevices(const char* classname,TString name,Int_t mode,Int_t mcal)
 {
-// Order the references to an array of hits by looping over the input array "hits"
-// and checking the signal value. The ordered array is returned as a TObjArray.
-// Note that the input array is not modified.
+// Order the references to the various devices based on hit signals registered
+// to the specified device class. The ordered array is returned as a TObjArray.
 // A "hit" represents an abstract object which is derived from AliSignal.
 // The user can specify the name of the signal slot to perform the sorting on.
 // In case no matching slotname is found, the signal will be skipped.
@@ -834,19 +1136,165 @@ TObjArray AliEvent::SortHits(TObjArray* hits,TString name,Int_t mode) const
 // order (mode=-1) or ordering in increasing order (mode=1).
 // The default is mode=-1.
 // Signals which were declared as "Dead" will be rejected.
-// The gain etc... corrected signals will be used in the ordering process.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+
+ TObjArray* ordered=SortHits(classname,name,mode,mcal);
  
- if (abs(mode)!=1 || !hits)
+ if (!ordered) return 0;
+
+ TObjArray* devs=SortDevices(ordered,"*",0,mcal);
+ return devs;
+}
+///////////////////////////////////////////////////////////////////////////
+TObjArray* AliEvent::SortDevices(const char* classname,Int_t idx,Int_t mode,Int_t mcal)
+{
+// Order the references to the various devices based on hit signals registered
+// to the specified device class. The ordered array is returned as a TObjArray.
+// A "hit" represents an abstract object which is derived from AliSignal.
+// The user can specify the index of the signal slot to perform the sorting on.
+// By default the slotindex will be 1.
+// Via the "mode" argument the user can specify ordering in decreasing
+// order (mode=-1) or ordering in increasing order (mode=1).
+// The default is mode=-1.
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+
+ TObjArray* ordered=SortHits(classname,idx,mode,mcal);
+ if (!ordered) return 0;
+
+ TObjArray* devs=SortDevices(ordered,0,0,mcal);
+ return devs;
+}
+///////////////////////////////////////////////////////////////////////////
+TObjArray* AliEvent::SortDevices(TObjArray* hits,TString name,Int_t mode,Int_t mcal)
+{
+// Order the references to the various devices based on hit signals contained
+// in the input array. The ordered array is returned as a TObjArray.
+// A "hit" represents an abstract object which is derived from AliSignal.
+// The user can specify the name of the signal slot to perform the sorting on.
+// In case no matching slotname is found, the signal will be skipped.
+// Via the "mode" argument the user can specify ordering in decreasing
+// order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
+// The latter option provides a means to quickly obtain an ordered devices list
+// when the hits in the array were already ordered by the user. In this case
+// the input argument "name" is irrelevant.
+// The default is mode=-1.
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+
+ if (!hits) return 0;
+
+ TObjArray* ordered=hits;
+ AliDevice dev;
+ if (mode) ordered=dev.SortHits(name,mode,hits,mcal);
+ if (!ordered) return 0;
+
+ if (fOrdered)
  {
-  TObjArray ordered;
-  return ordered;
+  fOrdered->Clear();
  }
  else
  {
-  AliDevice dev;
-  TObjArray ordered=dev.SortHits(name,mode,hits);
-  return ordered;
+  fOrdered=new TObjArray();
+ }
+
+ Int_t nhits=ordered->GetEntries();
+ Int_t exist=0;
+ for (Int_t ih=0; ih<nhits; ih++)
+ {
+  AliSignal* sx=(AliSignal*)ordered->At(ih);
+  if (!sx) continue;
+  AliDevice* dx=sx->GetDevice();
+  exist=0;
+  for (Int_t id=0; id<fOrdered->GetEntries(); id++)
+  {
+   AliDevice* odx=(AliDevice*)fOrdered->At(id);
+   if (dx==odx)
+   {
+    exist=1;
+    break;
+   }
+  }
+  if (!exist) fOrdered->Add(dx);
+ }
+ return fOrdered;
+}
+///////////////////////////////////////////////////////////////////////////
+TObjArray* AliEvent::SortDevices(TObjArray* hits,Int_t idx,Int_t mode,Int_t mcal)
+{
+// Order the references to the various devices based on hit signals contained
+// in the input array. The ordered array is returned as a TObjArray.
+// A "hit" represents an abstract object which is derived from AliSignal.
+// The user can specify the index of the signal slot to perform the sorting on.
+// By default the slotindex will be 1.
+// Via the "mode" argument the user can specify ordering in decreasing
+// order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
+// The latter option provides a means to quickly obtain an ordered devices list
+// when the hits in the array were already ordered by the user. In this case
+// the input argument "idx" is irrelevant.
+// The default is mode=-1.
+// Signals which were declared as "Dead" will be rejected.
+// The gain etc... corrected signals will be used in the ordering process as
+// specified by the "mcal" argument. The definition of this "mcal" parameter
+// corresponds to the signal correction mode described in the GetSignal
+// memberfunction of class AliSignal.
+// The default is mcal=1 (for backward compatibility reasons).
+//
+
+ if (!hits) return 0;
+
+ TObjArray* ordered=hits;
+ AliDevice dev;
+ if (mode) ordered=dev.SortHits(idx,mode,hits,mcal);
+ if (!ordered) return 0;
+
+ if (fOrdered)
+ {
+  fOrdered->Clear();
+ }
+ else
+ {
+  fOrdered=new TObjArray();
+ }
+
+ Int_t nhits=ordered->GetEntries();
+ Int_t exist=0;
+ for (Int_t ih=0; ih<nhits; ih++)
+ {
+  AliSignal* sx=(AliSignal*)ordered->At(ih);
+  if (!sx) continue;
+  AliDevice* dx=sx->GetDevice();
+  exist=0;
+  for (Int_t id=0; id<fOrdered->GetEntries(); id++)
+  {
+   AliDevice* odx=(AliDevice*)fOrdered->At(id);
+   if (dx==odx)
+   {
+    exist=1;
+    break;
+   }
+  }
+  if (!exist) fOrdered->Add(dx);
  }
+ return fOrdered;
 }
 ///////////////////////////////////////////////////////////////////////////
 TObject* AliEvent::Clone(const char* name) const