]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RALICE/AliEvent.cxx
Prepare for new code
[u/mrichter/AliRoot.git] / RALICE / AliEvent.cxx
index 541d0ddf3a9aef3848844c8fc87fe34b18d33b95..e1b33d98bd40fa0afa3c9e5d4f751b8a590e99de 100644 (file)
 //        ... // code to create tracks etc... 
 //        ...
 //
-// Note : All quantities are in GeV, GeV/c or GeV/c**2
+// Note : By default all quantities are in meter, GeV, GeV/c or GeV/c**2
+//        but the user can indicate the usage of a different scale for
+//        the metric and/or energy-momentum units via the SetUnitScale()
+//        and SetEscale() memberfunctions, respectively.
+//        The actual metric and energy-momentum unit scales in use can be
+//        obtained via the GetUnitScale() and GetEscale() memberfunctions.
 //
 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
 //- Modified: NvE $Date: 2004/10/20 10:49:44 $ UU-SAP Utrecht
 ///////////////////////////////////////////////////////////////////////////
 
+#include <cstdlib>
 #include "AliEvent.h"
 #include "Riostream.h"
  
@@ -258,14 +264,6 @@ AliEvent::AliEvent() : AliVertex(),AliTimestamp()
 // All variables initialised to default values.
  fRun=0;
  fEvent=0;
- fAproj=0;
- fZproj=0;
- fPnucProj=0;
- fIdProj=0;
- fAtarg=0;
- fZtarg=0;
- fPnucTarg=0;
- fIdTarg=0;
  fDevices=0;
  fDevCopy=0;
  fHits=0;
@@ -284,14 +282,6 @@ AliEvent::AliEvent(Int_t n) : AliVertex(n),AliTimestamp()
  }
  fRun=0;
  fEvent=0;
- fAproj=0;
- fZproj=0;
- fPnucProj=0;
- fIdProj=0;
- fAtarg=0;
- fZtarg=0;
- fPnucTarg=0;
- fIdTarg=0;
  fDevices=0;
  fDevCopy=0;
  fHits=0;
@@ -335,14 +325,6 @@ AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt),AliTimestamp(evt)
 // Copy constructor.
  fRun=evt.fRun;
  fEvent=evt.fEvent;
- fAproj=evt.fAproj;
- fZproj=evt.fZproj;
- fPnucProj=evt.fPnucProj;
- fIdProj=evt.fIdProj;
- fAtarg=evt.fAtarg;
- fZtarg=evt.fZtarg;
- fPnucTarg=evt.fPnucTarg;
- fIdTarg=evt.fIdTarg;
  fDevCopy=evt.fDevCopy;
 
  fHits=0;
@@ -386,14 +368,6 @@ void AliEvent::Reset()
  Set();
  fRun=0;
  fEvent=0;
- fAproj=0;
- fZproj=0;
- fPnucProj=0;
- fIdProj=0;
- fAtarg=0;
- fZtarg=0;
- fPnucTarg=0;
- fIdTarg=0;
 
  if (fDevices)
  {
@@ -522,69 +496,161 @@ Int_t AliEvent::GetEventNumber() const
 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
 {
 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
-// By default the particle ID is set to zero.
- fAproj=a;
- fZproj=z;
- fPnucProj=pnuc;
- fIdProj=id;
+// If not explicitly specified by the user, the projectile particle ID is set
+// to zero by default and will not be stored in the event structure.
+// The projectile specifications will be stored in a device named "Beam"
+// which is an instance of AliSignal.
+// As such these data are easily retrievable from the event structure.
+// However, for backward compatibility reasons the beam data can also be
+// retrieved via memberfunctions like GetProjectileA() etc...
+
+ Int_t newdev=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (!beam)
+ {
+  beam=new AliSignal();
+  beam->SetNameTitle("Beam","Beam and target specifications");
+  newdev=1;
+ }
+
+ if (a || z)
+ {
+  beam->AddNamedSlot("Aproj");
+  beam->SetSignal(a,"Aproj");
+  beam->AddNamedSlot("Zproj");
+  beam->SetSignal(z,"Zproj");
+ }
+ beam->AddNamedSlot("Pnucproj");
+ beam->SetSignal(pnuc,"Pnucproj");
+ if (id)
+ {
+  beam->AddNamedSlot("Idproj");
+  beam->SetSignal(id,"Idproj");
+ }
+
+ if (newdev)
+ {
+  AddDevice(beam);
+  if (fDevCopy) delete beam;
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetProjectileA() const
 {
 // Provide the projectile A value.
- return fAproj;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Aproj"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetProjectileZ() const
 {
 // Provide the projectile Z value.
- return fZproj;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Zproj"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Double_t AliEvent::GetProjectilePnuc() const
 {
 // Provide the projectile momentum value per nucleon.
- return fPnucProj;
+ Double_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=beam->GetSignal("Pnucproj");
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetProjectileId() const
 {
 // Provide the user defined particle ID of the projectile.
- return fIdProj;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Idproj"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
 {
 // Set the target A, Z, momentum per nucleon and user defined particle ID.
-// By default the particle ID is set to zero.
- fAtarg=a;
- fZtarg=z;
- fPnucTarg=pnuc;
- fIdTarg=id;
+// If not explicitly specified by the user, the target particle ID is set
+// to zero by default and will not be stored in the event structure.
+// The target specifications will be stored in a device named "Beam"
+// which is an instance of AliSignal.
+// As such these data are easily retrievable from the event structure.
+// However, for backward compatibility reasons the beam data can also be
+// retrieved via memberfunctions like GetTargetA() etc...
+
+ Int_t newdev=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (!beam)
+ {
+  beam=new AliSignal();
+  beam->SetNameTitle("Beam","Beam and target specifications");
+  newdev=1;
+ }
+
+ if (a || z)
+ {
+  beam->AddNamedSlot("Atarg");
+  beam->SetSignal(a,"Atarg");
+  beam->AddNamedSlot("Ztarg");
+  beam->SetSignal(z,"Ztarg");
+ }
+ beam->AddNamedSlot("Pnuctarg");
+ beam->SetSignal(pnuc,"Pnuctarg");
+ if (id)
+ {
+  beam->AddNamedSlot("Idtarg");
+  beam->SetSignal(id,"Idtarg");
+ }
+
+ if (newdev)
+ {
+  AddDevice(beam);
+  if (fDevCopy) delete beam;
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetTargetA() const
 {
 // Provide the target A value.
- return fAtarg;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Atarg"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetTargetZ() const
 {
 // Provide the target Z value.
- return fZtarg;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Ztarg"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Double_t AliEvent::GetTargetPnuc() const
 {
 // Provide the target momentum value per nucleon.
- return fPnucTarg;
+ Double_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=beam->GetSignal("Pnuctarg");
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 Int_t AliEvent::GetTargetId() const
 {
 // Provide the user defined particle ID of the target.
- return fIdTarg;
+ Int_t val=0;
+ AliSignal* beam=(AliSignal*)GetDevice("Beam");
+ if (beam) val=int(beam->GetSignal("Idtarg"));
+ return val;
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::HeaderData()
@@ -625,6 +691,21 @@ Int_t AliEvent::GetNdevices() const
  return ndevs;
 } 
 ///////////////////////////////////////////////////////////////////////////
+Int_t AliEvent::GetNdevices(const char* classname) const
+{
+// Provide the number of stored devices of the specified class.
+
+ Int_t ndevs=0;
+ for (Int_t idev=1; idev<=GetNdevices(); idev++)
+ {
+  TObject* obj=GetDevice(idev);
+  if (!obj) continue;
+
+  if (obj->InheritsFrom(classname)) ndevs++;
+ }
+ return ndevs;
+} 
+///////////////////////////////////////////////////////////////////////////
 void AliEvent::AddDevice(TObject& d)
 {
 // Add a device to the event.
@@ -656,6 +737,20 @@ void AliEvent::AddDevice(TObject& d)
  }
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliEvent::RemoveDevice(TObject* d)
+{
+// Remove the specified device from the event.
+
+ if (!fDevices || !d) return;
+
+ TObject* obj=fDevices->Remove(d);
+ if (obj)
+ {
+  if (fDevCopy) delete obj;
+  fDevices->Compress();
+ }
+}
+///////////////////////////////////////////////////////////////////////////
 void AliEvent::SetDevCopy(Int_t j)
 {
 // (De)activate the creation of private copies of the added devices.
@@ -765,9 +860,38 @@ TObject* AliEvent::GetDevice(TString name) const
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-TObject* AliEvent::GetIdDevice(Int_t id) const
+TObject* AliEvent::GetIdDevice(Int_t id,TObjArray* devs) const
 {
-// Return the device with unique identifier "id".
+// Return the device with identifier "id" from the specified array "devs".
+// In case devs=0 (which is the default) all devices stored in the event
+// structure will be evaluated.
+// Note : In case of multiple occurrences of identifier "id", the first
+//        encountered matching device will be returned.
+
+ TObjArray* arr=devs;
+ if (!arr) arr=fDevices;
+
+ if (!arr || id<0) return 0;
+
+ Int_t idx=0;
+ for (Int_t i=0; i<arr->GetSize(); i++)
+ {
+  TObject* dev=arr->At(i);
+  if (dev)
+  {
+   idx=dev->GetUniqueID();
+   if (idx==id) return dev;
+  }
+ }
+ return 0; // No matching id found
+}
+///////////////////////////////////////////////////////////////////////////
+TObject* AliEvent::GetIdDevice(Int_t id,const char* classname) const
+{
+// Return the device with identifier "id" of the specified class.
+// Note : In case of multiple occurrences of identifier "id", the first
+//        encountered matching device will be returned.
+
  if (!fDevices || id<0) return 0;
 
  Int_t idx=0;
@@ -777,10 +901,10 @@ TObject* AliEvent::GetIdDevice(Int_t id) const
   if (dev)
   {
    idx=dev->GetUniqueID();
-   if (idx==id) return dev;
+   if (idx==id && dev->InheritsFrom(classname)) return dev;
   }
  }
- return 0; // No matching id found
+ return 0; // No matching id found for the specified class
 }
 ///////////////////////////////////////////////////////////////////////////
 void AliEvent::ShowDevices(Int_t mode) const
@@ -802,6 +926,7 @@ void AliEvent::ShowDevices(Int_t mode) const
   else
   {
    cout << " The following " << ndevs << " devices are available :" << endl; 
+   Int_t nh=0,nw=0;
    for (Int_t i=1; i<=ndevs; i++)
    {
     TObject* dev=GetDevice(i);
@@ -811,8 +936,16 @@ void AliEvent::ShowDevices(Int_t mode) const
      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();
+     if (dev->InheritsFrom("AliDevice"))
+     {
+      nh=((AliDevice*)dev)->GetNhits();
+      if (nh) cout << " Nhits : " << nh;
+     }
+     if (dev->InheritsFrom("AliSignal"))
+     {
+      nw=((AliSignal*)dev)->GetNwaveforms();
+      if (nw) cout << " Nwaveforms : " << nw;
+     }
      cout << endl;
     }
    }
@@ -824,6 +957,60 @@ void AliEvent::ShowDevices(Int_t mode) const
  }
 }
 ///////////////////////////////////////////////////////////////////////////
+void AliEvent::ShowDevices(const char* classname,Int_t mode) const
+{
+// Provide an overview of the available devices of the specified class.
+// 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)
+ {
+  Int_t ndevs2=GetNdevices(classname);
+  if (!mode || !ndevs2)
+  {
+   cout << " There are " << ndevs2 << " selected devices available." << endl; 
+  }
+  else
+  {
+   cout << " The following " << ndevs2 << " selected devices are available :" << endl; 
+   Int_t nh=0,nw=0;
+   for (Int_t i=1; i<=ndevs; i++)
+   {
+    TObject* dev=GetDevice(i);
+    if (dev)
+    {
+     if (dev->InheritsFrom(classname))
+     {
+      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"))
+      {
+       nh=((AliDevice*)dev)->GetNhits();
+       if (nh) cout << " Nhits : " << nh;
+      }
+      if (dev->InheritsFrom("AliSignal"))
+      {
+       nw=((AliSignal*)dev)->GetNwaveforms();
+       if (nw) cout << " Nwaveforms : " << nw;
+      }
+      cout << endl;
+     }
+    }
+   }
+  }
+ }
+ else
+ {
+  cout << " No devices present for this event." << endl;
+ }
+}
+///////////////////////////////////////////////////////////////////////////
 TObjArray* AliEvent::GetDevices(const char* classname)
 {
 // Provide the references to the various devices derived from the