1 /**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include <TObjArray.h>
20 #include <TDirectory.h>
23 #include "AliTOFMerger.h"
25 #include "AliTOFSDigitizer.h"
26 #include "AliTOFhit.h"
27 #include "AliTOFdigit.h"
36 ClassImp(AliTOFMerger)
38 //___________________________________________
39 AliTOFMerger::AliTOFMerger()
54 //------------------------------------------------------------------------
55 AliTOFMerger::~AliTOFMerger()
66 //------------------------------------------------------------------------
67 void AliTOFMerger::Init()
70 if (fMerge) fBgrFile = InitBgr();
76 //------------------------------------------------------------------------
77 TFile* AliTOFMerger::InitBgr()
79 // Initialise background event
80 TFile *file = new TFile(fFnBgr);
81 // add error checking later
82 printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
86 //------------------------------------------------------------------------
87 void AliTOFMerger::Digitise()
90 // keep galice.root for signal and name differently the file for
91 // background when add! otherwise the track info for signal will be lost !
96 cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
99 AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
103 TTree *TK = gAlice->TreeK();
104 if (TK) f1 = TK->GetCurrentFile();
106 gAlice->GetEvent(fEvNrSig) ;
108 if(gAlice->TreeD() == 0)
109 gAlice->MakeTree("D") ;
110 gAlice->TreeD()->Reset();
112 // read and write digits for signal
113 ReadWriteDigit(fEvNrSig);
118 // gAlice->TreeS()->Reset();
119 gAlice = (AliRun*)fBgrFile->Get("gAlice");
120 ReadWriteDigit(fEvNrBgr);
126 //Make branch for digits
127 TOF->MakeBranch("D");
129 gAlice->TreeD()->Reset();
130 gAlice->TreeD()->Fill();
132 fDigits = TOF->Digits();
134 gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
136 gAlice->ResetDigits();
140 //---------------------------------------------------------------------
142 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
145 // Read Sdigits from the current file and write them in the TreeD
147 AliTOFdigit* tofsdigit;
149 AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
151 gAlice->GetEvent(iEvNum) ;
152 if(gAlice->TreeS()==0) {
153 cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl;
157 Int_t tracks[3]; // track info
158 Int_t vol[5]; // location for a digit
159 Float_t digit[2]; // TOF digit variables
161 gAlice->ResetDigits();
162 gAlice->TreeS()->GetEvent(iEvNum);
163 TClonesArray * TOFdigits = tofinfile->SDigits();
165 ndig=TOFdigits->GetEntries();
167 for (k=0; k<ndig; k++) {
168 tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
170 tracks[0] = tofsdigit->GetTrack(0);
171 tracks[1] = tofsdigit->GetTrack(1);
172 tracks[2] = tofsdigit->GetTrack(2);
174 vol[0] = tofsdigit->GetSector();
175 vol[1] = tofsdigit->GetPlate();
176 vol[2] = tofsdigit->GetStrip();
177 vol[3] = tofsdigit->GetPadx();
178 vol[4] = tofsdigit->GetPadz();
180 digit[0] = tofsdigit->GetTdc();
181 digit[1] = tofsdigit->GetAdc();
183 new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
184 } // end loop on sdigits in the current file