* provided "as is" without express or implied warranty. *
**************************************************************************/
-/*
-$Log$
-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$ */
///////////////////////////////////////////////////////////////////////////////
// //
// //
///////////////////////////////////////////////////////////////////////////////
-#include <iostream.h>
-#include <fstream.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 "TMath.h"
-#include "TTUBE.h"
-#include "TNode.h"
-#include "TGeometry.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 "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;
}
//_____________________________________________________________________________
// 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);
- gAlice->AddHitList(fHits);
- fDigits = new TClonesArray("AliSTARTdigit",500);
-
- fIshunt = 0;
- fIdSens1 = 0;
-
+ 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)
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
- //
- TClonesArray &ldigits = *fDigits;
- new(ldigits[fNdigits++]) AliSTARTdigit(tracks,digits);
+
+ // 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");
-
- // 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);
+ top=gAlice->GetGeometry()->GetNode("alice");
- 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);
+ // START define the different volumes
+ 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
// 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);
+ }
}
//_____________________________________________________________________________
-void AliSTART::Hit2digit(Int_t evnum)
+void AliSTART::ResetHits()
{
+ AliDetector::ResetHits();
- Float_t x,y,e;
- Int_t nbytes = 0;
- Int_t hit,i;
- Int_t nhits;
- Int_t volume,pmt;
- char nameTH[8];
- Float_t timediff,timeright,timeleft,t1,t2,timeav;
- Float_t besttimeright,besttimeleft;
- Float_t pp_bunch=25;
- Int_t channel_width=10;
- Int_t digits[3];
- Int_t tracks[2];
-
- TParticle *particle;
-
- AliSTARThit *startHit;
-
-
- // Event ------------------------- LOOP
- // for (evnum=0; evnum<=9; evnum++){
+}
+//____________________________________________________________________
+void AliSTART::ResetDigits()
+{
+ //
+ // Reset number of digits and the digits array for this detector
+ //
+ if (fDigits) fDigits->Clear();
+}
- besttimeright=9999.;
- besttimeleft=9999.;
+//_____________________________________________________________________________
+void AliSTART::SetTreeAddress()
+{
- Int_t nparticles = gAlice->GetEvent(evnum);
- if (nparticles <= 0) return;
- printf("\n nparticles %d\n",nparticles);
-
- TClonesArray *Particles = gAlice->Particles();
+ TTree *treeH;
+ treeH = TreeH();
+
+ if (treeH)
+ {
+ if (fHits == 0x0) fHits = new TClonesArray("AliSTARThit", 405);
+ }
- 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=(TParticle*)Particles->UncheckedAt(track);
- nhits = fHits->GetEntriesFast();
-
- for (hit=0;hit<nhits;hit++) {
- startHit = (AliSTARThit*)fHits->UncheckedAt(hit);
- pmt=startHit->fPmt;
- e=startHit->fEtot;
- x=startHit->fX;
- y=startHit->fY;
- volume = startHit->fVolume;
- if(volume==1){
- timeright = startHit->fTime;
- if(timeright<besttimeright) {
- besttimeright=timeright;
- tracks[0]=track;
- } //timeright
- }//time for right shoulder
- if(volume==2){
- timeleft = startHit->fTime;
- // printf("timeleft %f\n",timeleft);
- if(timeleft<besttimeleft) {
- besttimeleft=timeleft;
- tracks[1]=track;
- } //timeleftbest
- }//time for left shoulder
- } //hit loop
- } //track loop
- printf("\n----time1stright %f \n",besttimeright);
- printf("----time1stleft %f \n",besttimeleft);
- timediff=besttimeright-besttimeleft;
- if (timediff!=0 && TMath::Abs(timediff)<100) {
- //we assume centre of bunch is 5ns after TTS signal
- //TOF values are relative of the end of bunch
- pp_bunch=pp_bunch-10/2;
- t1=besttimeleft+pp_bunch;
- t2=besttimeright+pp_bunch;
- t1=1000*t1/channel_width; //time in ps to channel_width
- t2=1000*t2/channel_width; //time in ps to channel_width
- printf(" t1= %f t2= %f\n",t1,t2);
-
- timeav=(t1+t2)/2.;
- printf("timediff= %f timeav= %f\n",timediff,timeav);
+ AliDetector::SetTreeAddress();
+ TTree *treeD = fLoader->TreeD();
+ if (treeD) {
+ if (fDigits == 0x0) fDigits = new AliSTARTdigit();
+ TBranch* branch = treeD->GetBranch ("START");
+ if (branch) branch->SetAddress(&fDigits);
+ }
- // Time to TDC signal
- // 1024 channels for timediff, range 1ns
-
- timediff=512+1000*timediff/channel_width; // time in ps
- printf("timediff= %f timeav= %f\n",timediff,timeav);
+ TTree *treeR = fLoader->TreeR();
+ if (treeR) {
+ if (fRecPoints == 0x0) fRecPoints = new AliSTARTRecPoint() ;
+ TBranch* branch = treeR->GetBranch ("START");
+ if (branch) branch->SetAddress(&fRecPoints);
+ }
+
+}
- digits[0]=evnum;
- digits[1]=(Int_t)(timeav); // time in ps
- digits[2]=(Int_t)(timediff); // time in ps
- // new(ldigits[fNdigits++]) AliSTARTdigit(track,digits);
-
-
- for (i=0; i<3; i++){
- printf(" DIGITS on START %d\n",digits[i]); }
- for (i=0; i<=1; i++) { printf("START track %d\n",tracks[i]);}
- AddDigit(tracks,digits);
- // sprintf(nameTD,"TreeD%d",evnum);
- // gAlice->TreeD()->Fill();
- //gAlice->TreeD()->Write();
- //printf("%s\n",nameTD);
- MakeTree(evnum);
- if (fTreeD!=0) fTreeD->Fill();
- if (fTreeD!=0) fTreeD->Write();
- } // if timediff !=0
-
- // } // event loop
-
-} // end of mcro
-
//_____________________________________________________________________________
-Bool_t AliSTART::SetTree(Int_t nevent, TDirectory *dir )
+void AliSTART::MakeBranchInTreeD(TTree *treeD, const char *file)
{
- char treeName[100];
- // Get Hits Tree header from file
- sprintf(treeName,"TreeD%d",nevent);
- fTreeD = (TTree*)dir->Get(treeName);
- if (fTreeD == 0) return kFALSE;
- //set Digit branch
- TBranch *b = fTreeD->GetBranch("Digits");
- if (b==0) return kFALSE;
- b->SetAddress(&fDigits);
- return kTRUE;
+ //
+ // 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);
+ }
}
-
//_____________________________________________________________________________
-Bool_t AliSTART::MakeTree(Int_t nevent)
+AliDigitizer* AliSTART::CreateDigitizer(AliRunDigitizer* manager) const
{
- char treeName[100];
- // Get Hits Tree header from file
- sprintf(treeName,"TreeD%d",nevent);
- fTreeD = new TTree(treeName,treeName);
- if (fTreeD == 0) return kFALSE;
- //set Digit branch
- TBranch *b = fTreeD->Branch("Digits",&fDigits,40000);
- if (b==0) return kFALSE;
- b->SetAddress(&fDigits);
-
- return kTRUE;
+ 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();
+
}