]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - START/AliSTART.cxx
Adding comments
[u/mrichter/AliRoot.git] / START / AliSTART.cxx
index 2dfa8919a2749d0adc138c92b5e9ea8949394348..efbcba4d9f49537d7467096b827a9e5d3bfb43f0 100755 (executable)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.3  1999/09/29 09:24:29  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -41,26 +36,47 @@ Introduction of the Copyright and cvs Log
 //                                                                           //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
-#include <stdlib.h>
 
-#include <TTUBE.h>
-#include <TNode.h>
+#include <Riostream.h>
+
+#include <TFile.h>
 #include <TGeometry.h>
+#include <TMath.h>
+#include <TNode.h>
+#include <TParticle.h>
+#include <TRandom.h>
+#include <TTUBE.h>
+#include <TVirtualMC.h>
+#include <AliESD.h>
+
+#include "AliLog.h"
+#include "AliMC.h"
+#include "AliLoader.h"
 #include "AliRun.h"
+#include "TClonesArray.h"
 #include "AliSTART.h"
-#include <iostream.h>
-#include <fstream.h>
-#include "AliMC.h"
+#include "AliSTARTLoader.h"
+#include "AliSTARTdigit.h"
+#include "AliSTARThit.h"
+#include "AliSTARTDigitizer.h"
+#include "AliSTARTRawData.h"
+#include "AliSTARTRecPoint.h"
+#include "AliLog.h"
+
 ClassImp(AliSTART)
+
+  //static  AliSTARTdigit *digits; 
+
 //_____________________________________________________________________________
 AliSTART::AliSTART()
 {
   //
   // Default constructor for class AliSTART
   //
-  fIshunt   = 0;
+  fIshunt   = 1;
+  fHits     = 0;
+  fDigits   = 0;
+  fRecPoints = 0;
 }
  
 //_____________________________________________________________________________
@@ -70,24 +86,39 @@ AliSTART::AliSTART(const char *name, const char *title)
   //
   // Standard constructor for START Detector
   //
-  AliModule *fmd = gAlice->GetModule("FMD");
-  if(fmd) {
-    Int_t fmdversion = fmd->IsVersion();
-    if(fmdversion==0 || fmdversion==1) {
-      Error("ctor","Versions 0 and 1 of FMD incompatible with START\n");
-      exit(1);
-    }
-  }
+
+  
   //
   // Initialise Hit array
-  fHits   = new TClonesArray("AliSTARThit",  405);
-  
-  fIshunt     =  0;
-  fIdSens1    =  0;
-
+  fHits       = new TClonesArray("AliSTARThit",  405);
+  gAlice->GetMCApp()->AddHitList(fHits);
+  fDigits    = new AliSTARTdigit();
+  fRecPoints = new AliSTARTRecPoint();
+  fIshunt     =  1;
+  fIdSens   =  0;
   SetMarkerColor(kRed);
 }
+
+//_____________________________________________________________________________
+AliSTART::~AliSTART() {
+  
+  if (fHits) {
+    fHits->Delete();
+    delete fHits;
+  }
+  /*
+  if (fDigits) {
+    fDigits->Delete();
+    delete fDigits;
+    cout<<" delete fDigits; "<<endl;
+  }
+  if (fRecPoints) {
+   fRecPoints ->Delete();
+    delete fRecPoints;
+    cout<<" delete fRecPoints; "<<endl;
+  }
+  */ 
+}
  
 //_____________________________________________________________________________
 void AliSTART::AddHit(Int_t track, Int_t *vol, Float_t *hits)
@@ -98,36 +129,62 @@ void AliSTART::AddHit(Int_t track, Int_t *vol, Float_t *hits)
   TClonesArray &lhits = *fHits;
   new(lhits[fNhits++]) AliSTARThit(fIshunt,track,vol,hits);
 }
+
+
+//_____________________________________________________________________________
+
+void AliSTART::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime, 
+                       Int_t timediff, TArrayI *sumMult,
+                       TArrayI *time, TArrayI *adc, TArrayI *timeAmp, TArrayI *adcAmp)
+{
+  
+  //  Add a START digit to the list.
+ //
+  
+  if (!fDigits) {
+    fDigits = new AliSTARTdigit();
+  }
+  fDigits-> SetTimeBestRight(besttimeright);
+  fDigits->SetTimeBestLeft(besttimeleft);
+  fDigits-> SetMeanTime(meantime);
+  fDigits-> SetDiffTime(timediff);
+  fDigits-> SetSumMult(*sumMult);
+  fDigits->SetTime(*time);
+  fDigits->SetTimeAmp(*timeAmp);
+  fDigits->SetADC(*adc);
+  fDigits->SetADCAmp(*adcAmp);
+}
+
+
 //_____________________________________________________________________________
 void AliSTART::BuildGeometry()
 {
   //
   // Build simple ROOT TNode geometry for event display
   //
-  TNode *Node, *Top;
+  TNode *node, *top;
   const int kColorSTART  = 19;
-  //
-  Top=gAlice->GetGeometry()->GetNode("alice");
+
+  top=gAlice->GetGeometry()->GetNode("alice");
 
   // START define the different volumes
-  new TRotMatrix("rot999","rot999",  90,0,90,90,180,0);
-
-  new TTUBE("S_STR1","START  volume 1","void",5.,10.7,5.3);
-  Top->cd();
-  Node = new TNode("STR1","STR1","S_STR1",0,0,75.,"");
-  Node->SetLineColor(kColorSTART);
-  fNodes->Add(Node);
-
-  new TTUBE("S_STR2","START volume 2","void",5.,10.7,5.3);
-  Top->cd();
-  Node = new TNode("STR2","STR2","S_STR2",0,0,-75,"rot999");
-  Node->SetLineColor(kColorSTART);
-  fNodes->Add(Node);
+  new TRotMatrix("rotx999","rot999",  90,0,90,90,180,0);
+
+  new TTUBE("S_0ST1","START  volume 1","void",5.,10.7,5.3);
+  top->cd();
+  node = new TNode("0ST1","0ST01","S_0ST1",0,0,-69.7,"");
+  node->SetLineColor(kColorSTART);
+  fNodes->Add(node);
+
+  new TTUBE("S_0ST2","START volume 2","void",5.,10.7,5.3);
+  top->cd();
+  node = new TNode("0ST2","0ST2","S_0ST2",0,0,350,"rotx999");
+  node->SetLineColor(kColorSTART);
+  fNodes->Add(node);
 }
  
 //_____________________________________________________________________________
-Int_t AliSTART::DistanceToPrimitive(Int_t px, Int_t py)
+Int_t AliSTART::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
 {
   //
   // Calculate the distance from the mouse to the START on the screen
@@ -136,8 +193,6 @@ Int_t AliSTART::DistanceToPrimitive(Int_t px, Int_t py)
   return 9999;
 }
  
-//_____________________________________________________________________________
-
 //-------------------------------------------------------------------------
 void AliSTART::Init()
 {
@@ -145,66 +200,158 @@ void AliSTART::Init()
   // Initialis the START after it has been built
   Int_t i;
   //
-  printf("\n");
-  for(i=0;i<35;i++) printf("*");
-  printf(" START_INIT ");
-  for(i=0;i<35;i++) printf("*");
-  printf("\n");
-  //
-  // Here the START initialisation code (if any!)
-  for(i=0;i<80;i++) printf("*");
-  printf("\n");
- //
- //
- fIdSens1=gMC->VolId("PTOP");
-
+  if(AliLog::GetGlobalDebugLevel()>0) {
+    printf("\n%s: ",ClassName());
+    for(i=0;i<35;i++) printf("*");
+    printf(" START_INIT ");
+    for(i=0;i<35;i++) printf("*");
+    printf("\n%s: ",ClassName());
+    //
+    // Here the START initialisation code (if any!)
+    for(i=0;i<80;i++) printf("*");
+    printf("\n");
+  }
 }
 
 //---------------------------------------------------------------------------
 void AliSTART::MakeBranch(Option_t* option)
 {
-  
-  // Create Tree branches for the START.
-  Int_t buffersize = 4000;
-  char branchname[10];
-  sprintf(branchname,"%s",GetName());
+  //
+// Create Tree branches for the START.
 
-  AliDetector::MakeBranch(option);
+ // Options:
+  //
+  //    H          Make a branch of TClonesArray of AliSTARTHit's
+  //    D          Make a branch of TClonesArray of AliSTARTDigit's
+  //
+  //    R         Make a branch of  AliSTARTRecPoints
+  //
+  char branchname[20];
+  sprintf(branchname,"%s",GetName());
 
-  char *D = strstr(option,"D");
+  const char *cH = strstr(option,"H");
+  const char *cD = strstr(option,"D");
+  const char *cR = strstr(option,"R");
 
-  if (fDigits   && gAlice->TreeD() && D) {
-    gAlice->TreeD()->Branch(branchname,&fDigits, buffersize);
-    printf("Making Branch %s for digits\n",branchname);
-  }
+    if (cH && fLoader->TreeH())
+  {
+     if (fHits == 0x0) fHits  = new TClonesArray("AliSTARThit",  405);
+     AliDetector::MakeBranch(option);
+  } 
+    
+    
+  if (cD && fLoader->TreeD())
+    {
+      if (fDigits == 0x0) fDigits  = new AliSTARTdigit();
+      //     MakeBranchInTree(fLoader->TreeD(), branchname,
+      //                      &fDigits, 405, 0);
+      fLoader->TreeD()->Branch(branchname,"AliSTARTdigit",&fDigits,405,1);
+    } 
+  if (cR && fLoader->TreeR())
+    {
+      if (fRecPoints == 0x0) fRecPoints  = new AliSTARTRecPoint();
+      MakeBranchInTree(fLoader->TreeR(), branchname,
+                      &fRecPoints, 405, 0);
+    } 
   
 }    
-ClassImp(AliSTARThit)
+
 //_____________________________________________________________________________
-AliSTARThit::AliSTARThit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
-  AliHit(shunt, track)
+void AliSTART::ResetHits()
+{
+  AliDetector::ResetHits();
+  
+}
+//____________________________________________________________________
+void AliSTART::ResetDigits()
 {
   //
-  // Add a START hit
+  // Reset number of digits and the digits array for this detector
   //
+  if (fDigits) fDigits->Clear();
+}
+
+//_____________________________________________________________________________
+void AliSTART::SetTreeAddress()
+{
+
+  TTree    *treeH;
+  treeH = TreeH();
   
-//  Int_t i;
-  fVolume = vol[0];
-  fPmt=vol[1];
-//printf("fvolume %d\n",fVolume);
-//printf("fpmt %d\n",fPmt);
-
-  fX=hits[0];
-  fY=hits[1];
-  fZ=hits[2];
-  fEdep=hits[3];
-  fEtot=hits[4];
-  fParticle=Int_t (hits[5]);
-  fTime=hits[6];
-
-//for (i=0; i<=6; i++) {printf("Hits up %f\n",hits[i]);} 
+  if (treeH)
+    {
+      if (fHits == 0x0) fHits  = new TClonesArray("AliSTARThit",  405);
+    }
+    
+  AliDetector::SetTreeAddress();
+  TTree *treeD = fLoader->TreeD();
+  if (treeD) {
+    if (fDigits == 0x0)  fDigits  = new AliSTARTdigit();
+    TBranch* branch = treeD->GetBranch ("START");
+    if (branch) branch->SetAddress(&fDigits);
+  }
+
+  TTree *treeR = fLoader->TreeR();
+  if (treeR) {
+    if (fRecPoints == 0x0) fRecPoints  = new  AliSTARTRecPoint()  ;
+    TBranch* branch = treeR->GetBranch ("START");
+    if (branch) branch->SetAddress(&fRecPoints);
+  }
+}
+
+
+//_____________________________________________________________________________
+void AliSTART::MakeBranchInTreeD(TTree *treeD, const char *file)
+{
+    //
+    // Create TreeD branches for the FMD
+    //
+    const Int_t kBufferSize = 4000;
+    char branchname[20];
+    sprintf(branchname,"%s",GetName());
+    if(treeD)
+     {
+       MakeBranchInTree(treeD,  branchname,&fDigits, kBufferSize, file);
+     }
 }
 
-// ClassImp(AliSTARTdigit)
+//_____________________________________________________________________________
+AliDigitizer* AliSTART::CreateDigitizer(AliRunDigitizer* manager) const
+{
+  return new AliSTARTDigitizer(manager);
+}
+//____________________________________________________________________________
+void AliSTART::Digits2Raw()
+{
+//
+// Starting from the START digits, writes the Raw Data objects
+//
+//  AliSTARTLoader* pStartLoader = (AliSTARTLoader*)fLoader;
+  fLoader ->LoadDigits("read");
+  TTree* treeD = fLoader->TreeD();
+  if (!treeD) {
+    AliError("no digits tree");
+    return;
+  }
+  if (fDigits == 0x0)  fDigits  = new AliSTARTdigit();
+  
+  TBranch *branch = treeD->GetBranch("START");
+  if (branch) {
+    branch->SetAddress(&fDigits);
+  }else{
+    AliError("Branch START DIGIT not found");
+    exit(111);
+  } 
+  AliSTARTRawData rawWriter;
+  rawWriter.SetVerbose(0);
+  
+  AliDebug(2,Form(" Formatting raw data for START "));
+  branch->GetEntry(0);
+  //  rawWriter.RawDataSTART(treeD->GetBranch("START"));
+  rawWriter.RawDataSTART(fDigits);
+  
+  
+  fLoader->UnloadDigits();
+  
+}