]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - START/AliSTART.cxx
Adding comments
[u/mrichter/AliRoot.git] / START / AliSTART.cxx
index bf36571d0bf311522a65f58625e9ee54a3fb02f5..efbcba4d9f49537d7467096b827a9e5d3bfb43f0 100755 (executable)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.16  2001/01/17 10:56:08  hristov
-Corrections to destructors
-
-Revision 1.15  2001/01/01 13:10:42  hristov
-Local definition of digits removed
-
-Revision 1.14  2000/12/22 16:17:15  hristov
-Updated  START code from Alla
-
-Revision 1.13  2000/12/18 11:39:41  alibrary
-Quick fix to avoid crash in display waiting for new version
-
-Revision 1.12  2000/12/04 08:48:19  alibrary
-Fixing problems in the HEAD
-
-Revision 1.11  2000/10/13 13:14:08  hristov
-Bug fixes and code cleaning
-
-Revision 1.10  2000/10/02 21:28:13  fca
-Removal of useless dependecies via forward declarations
-
-Revision 1.9  2000/07/13 16:41:29  fca
-New START corrected for coding conventions
-
-Revision 1.8  2000/03/27 17:24:25  alla
-Modifing geometry
-
-Revision 1.6  2000/01/21 15:45:23  fca
-New Version from Alla
-
-Revision 1.5  2000/01/19 17:17:15  fca
-Introducing a list of lists of hits -- more hits allowed for detector now
-
-Revision 1.4  1999/11/12 15:04:00  fca
-Modifications from A.Maevskaya
-
-Revision 1.3  1999/09/29 09:24:29  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -78,27 +37,35 @@ Introduction of the Copyright and cvs Log
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <iostream.h>
-#include <fstream.h>
+#include <Riostream.h>
 
-#include "TMath.h"
-#include "TTUBE.h"
-#include "TNode.h"
-#include "TRandom.h"
-#include "TGeometry.h"
-#include "TFile.h"
-#include "TParticle.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 "AliSTARTLoader.h"
 #include "AliSTARTdigit.h"
-#include "AliMC.h"
 #include "AliSTARThit.h"
-#include "AliSTARTvertex.h"
+#include "AliSTARTDigitizer.h"
+#include "AliSTARTRawData.h"
+#include "AliSTARTRecPoint.h"
+#include "AliLog.h"
 
 ClassImp(AliSTART)
 
-static  AliSTARTdigit *digits; 
+  //static  AliSTARTdigit *digits; 
 
 //_____________________________________________________________________________
 AliSTART::AliSTART()
@@ -109,6 +76,7 @@ AliSTART::AliSTART()
   fIshunt   = 1;
   fHits     = 0;
   fDigits   = 0;
+  fRecPoints = 0;
 }
  
 //_____________________________________________________________________________
@@ -123,8 +91,9 @@ AliSTART::AliSTART(const char *name, const char *title)
   //
   // Initialise Hit array
   fHits       = new TClonesArray("AliSTARThit",  405);
-  gAlice->AddHitList(fHits);
-  
+  gAlice->GetMCApp()->AddHitList(fHits);
+  fDigits    = new AliSTARTdigit();
+  fRecPoints = new AliSTARTRecPoint();
   fIshunt     =  1;
   fIdSens   =  0;
   SetMarkerColor(kRed);
@@ -132,10 +101,23 @@ AliSTART::AliSTART(const char *name, const char *title)
 
 //_____________________________________________________________________________
 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;
+  }
+  */ 
 }
  
 //_____________________________________________________________________________
@@ -148,15 +130,32 @@ void AliSTART::AddHit(Int_t track, Int_t *vol, Float_t *hits)
   new(lhits[fNhits++]) AliSTARThit(fIshunt,track,vol,hits);
 }
 
+
 //_____________________________________________________________________________
 
-void AliSTART::AddDigit(Int_t *tracks,Int_t *digits)
+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. Dummy function.
+  //  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()
 {
@@ -169,23 +168,23 @@ void AliSTART::BuildGeometry()
   top=gAlice->GetGeometry()->GetNode("alice");
 
   // START define the different volumes
-  new TRotMatrix("rot999","rot999",  90,0,90,90,180,0);
+  new TRotMatrix("rotx999","rot999",  90,0,90,90,180,0);
 
-  new TTUBE("S_STR1","START  volume 1","void",5.,10.7,5.3);
+  new TTUBE("S_0ST1","START  volume 1","void",5.,10.7,5.3);
   top->cd();
-  node = new TNode("STR1","STR1","S_STR1",0,0,75.,"");
+  node = new TNode("0ST1","0ST01","S_0ST1",0,0,-69.7,"");
   node->SetLineColor(kColorSTART);
   fNodes->Add(node);
 
-  new TTUBE("S_STR2","START volume 2","void",5.,10.7,5.3);
+  new TTUBE("S_0ST2","START volume 2","void",5.,10.7,5.3);
   top->cd();
-  node = new TNode("STR2","STR2","S_STR2",0,0,-75,"rot999");
+  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
@@ -201,177 +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");
-  //
-  //
-  //  fIdSensRad=gMC->VolId("PTOP");
-  //  fIdSensPC =gMC->VolId("T0PC");
-
+  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, char *file)
+void AliSTART::MakeBranch(Option_t* option)
 {
   //
-  // Specific START branches
+// Create Tree branches for the START.
+
+ // 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
   //
-  // Create Tree branches for the START.
-  Int_t buffersize = 400;
-  char branchname[10];
+  char branchname[20];
   sprintf(branchname,"%s",GetName());
 
-  AliDetector::MakeBranch(option,file);
+  const char *cH = strstr(option,"H");
+  const char *cD = strstr(option,"D");
+  const char *cR = strstr(option,"R");
 
-  char *cD = strstr(option,"D");
-  
-  if (cD) {
-    digits = new AliSTARTdigit();
-    gAlice->MakeBranchInTree(gAlice->TreeD(), 
-                             branchname, "AliSTARTdigit", digits, buffersize, 1, file) ;
+    if (cH && fLoader->TreeH())
+  {
+     if (fHits == 0x0) fHits  = new TClonesArray("AliSTARThit",  405);
+     AliDetector::MakeBranch(option);
   } 
-/*
-  char *cR = strstr(option,"R");
+    
+    
+  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);
+    } 
   
-  if (cR)   {  
-    gAlice->MakeBranchInTree(gAlice->TreeR(), 
-                             branchname, "Int_t", &fZposit, buffersize, 1, file) ;
-  }
-  */
 }    
 
 //_____________________________________________________________________________
-
-void AliSTART::Hit2digit(Int_t evnum) 
+void AliSTART::ResetHits()
+{
+  AliDetector::ResetHits();
+  
+}
+//____________________________________________________________________
+void AliSTART::ResetDigits()
 {
   //
-  // From hits to digits
+  // Reset number of digits and the digits array for this detector
   //
-  Float_t x,y,e;
-  Int_t nbytes = 0;
-  Int_t hit;
-  Int_t nhits;
-  Int_t volume,pmt;
-  char nameTH[8],nameTD[8];
-  Float_t timediff,timeright,timeleft,timeav;
-  Float_t besttimeright,besttimeleft,meanTime;
-  Int_t channelWidth=10;
-
-  TParticle *particle;
-  AliSTARThit  *startHit;
-
-  Int_t buffersize=256;
-  Int_t split=1;
+  if (fDigits) fDigits->Clear();
+}
 
-  digits= new AliSTARTdigit();
-  TBranch *bDig=0;
+//_____________________________________________________________________________
+void AliSTART::SetTreeAddress()
+{
 
+  TTree    *treeH;
+  treeH = TreeH();
   
- // Event ------------------------- LOOP  
-    sprintf(nameTD,"TreeD%d",evnum);
-    TTree *td = new TTree(nameTD,"START");
-    bDig = td->Branch("START","AliSTARTdigit",&digits,buffersize,split);
+  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);
+  }
 
-    besttimeright=9999.;
-    besttimeleft=9999.;
-    Int_t timeDiff=0;
-    Int_t timeAv=0;
+  TTree *treeR = fLoader->TreeR();
+  if (treeR) {
+    if (fRecPoints == 0x0) fRecPoints  = new  AliSTARTRecPoint()  ;
+    TBranch* branch = treeR->GetBranch ("START");
+    if (branch) branch->SetAddress(&fRecPoints);
+  }
+}
 
-    Int_t nparticles = gAlice->GetEvent(evnum);
-    if (nparticles <= 0) return;
-    printf("\n nparticles %d\n",nparticles);
-    
-   
-    sprintf(nameTH,"TreeH%d",evnum);
-    printf("%s\n",nameTH);
-    TTree *th = gAlice->TreeH();
-    Int_t ntracks    = (Int_t) th->GetEntries();
-    if (ntracks<=0) return;
-    // Start loop on tracks in the hits containers
-    for (Int_t track=0; track<ntracks;track++) {
-      gAlice->ResetHits();
-      nbytes += th->GetEvent(track);
-      particle=gAlice->Particle(track);
-      nhits =fHits->GetEntriesFast();
-      
-      for (hit=0;hit<nhits;hit++) {
-       startHit   = (AliSTARThit*)fHits->UncheckedAt(hit);
-       pmt=startHit->fPmt;
-       e=startHit->fEtot;
-       x=startHit->X();
-       y=startHit->Y();
-       volume = startHit->fVolume;
-       if(volume==1){
-         timeright = startHit->fTime;
-         if(timeright<besttimeright) {
-           besttimeright=timeright;
-         } //timeright
-       }//time for right shoulder
-       if(volume==2){            
-         timeleft = startHit->fTime;
-         //                printf("timeleft %f\n",timeleft);
-         if(timeleft<besttimeleft) {
-           besttimeleft=timeleft;
-         } //timeleftbest
-       }//time for left shoulder
-      } //hit loop
-    } //track loop
 
-    //folding with experimental time distribution
-    Float_t besttimerightGaus=gRandom->Gaus(besttimeright,0.05);
-    Float_t besttimeleftGaus=gRandom->Gaus(besttimeleft,0.05);
-    timediff=besttimerightGaus-besttimeleftGaus;
-    meanTime=(besttimerightGaus+besttimeleftGaus)/2.;
-    if ( TMath::Abs(timediff)<2. && meanTime<3.) 
+//_____________________________________________________________________________
+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)
      {
-       //we assume centre of bunch is 5ns after TTS signal
-       //TOF values are relative of the end of bunch
-       Float_t ppBunch=25;
-    
-       ppBunch=ppBunch-10/2;
-       Float_t t1=1000.*besttimeleftGaus;
-       Float_t t2=1000.*besttimerightGaus;
-       t1=t1/channelWidth+ppBunch; //time in ps to channelWidth
-       t2=t2/channelWidth+ppBunch; //time in ps to channelWidth
-     
-       timeav=(t1+t2)/2.;
-     
-       // Time to TDC signal
-       // 256 channels for timediff, range 1ns
-       
-       timediff=128+1000*timediff/channelWidth; // time in ps 
-
-       timeAv = (Int_t)(timeav);   // time (ps) channel numbres
-       timeDiff = (Int_t)(timediff); // time ( ps) channel numbres
-       digits->Set(timeAv,timeDiff);
+       MakeBranchInTree(treeD,  branchname,&fDigits, kBufferSize, file);
      }
-    else
-      {timeAv=999999; timeDiff=99999;}
-      
-    td->Fill();
-    printf("digits-> %d \n",digits->GetTime());
-    td->Write();
-
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
+//_____________________________________________________________________________
+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();
+  
+}