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()
49 //------------------------------------------------------------------------
50 AliTOFMerger::~AliTOFMerger()
61 //------------------------------------------------------------------------
62 void AliTOFMerger::Init()
65 if (fMerge) fBgrFile = InitBgr();
71 //------------------------------------------------------------------------
72 TFile* AliTOFMerger::InitBgr()
74 // Initialise background event
75 TFile *file = new TFile(fFnBgr);
76 // add error checking later
77 printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
81 //------------------------------------------------------------------------
82 void AliTOFMerger::Digitise()
85 // keep galice.root for signal and name differently the file for
86 // background when add! otherwise the track info for signal will be lost !
91 cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
94 AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
98 TTree *TK = gAlice->TreeK();
99 if (TK) f1 = TK->GetCurrentFile();
101 gAlice->GetEvent(fEvNrSig) ;
103 if(gAlice->TreeD() == 0)
104 gAlice->MakeTree("D") ;
105 gAlice->TreeD()->Reset();
107 // read and write digits for signal
108 ReadWriteDigit(fEvNrSig);
113 // gAlice->TreeS()->Reset();
114 gAlice = (AliRun*)fBgrFile->Get("gAlice");
115 ReadWriteDigit(fEvNrBgr);
121 //Make branch for digits
122 TOF->MakeBranch("D");
124 gAlice->TreeD()->Reset();
125 gAlice->TreeD()->Fill();
127 fDigits = TOF->Digits();
129 gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
131 gAlice->ResetDigits();
135 //---------------------------------------------------------------------
137 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
140 // Read Sdigits from the current file and write them in the TreeD
142 AliTOFdigit* tofsdigit;
144 AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
146 gAlice->GetEvent(iEvNum) ;
147 if(gAlice->TreeS()==0) {
148 cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl;
152 Int_t tracks[3]; // track info
153 Int_t vol[5]; // location for a digit
154 Float_t digit[2]; // TOF digit variables
156 gAlice->ResetDigits();
157 gAlice->TreeS()->GetEvent(iEvNum);
158 TClonesArray * TOFdigits = tofinfile->SDigits();
160 ndig=TOFdigits->GetEntries();
162 for (k=0; k<ndig; k++) {
163 tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
165 tracks[0] = tofsdigit->GetTrack(0);
166 tracks[1] = tofsdigit->GetTrack(1);
167 tracks[2] = tofsdigit->GetTrack(2);
169 vol[0] = tofsdigit->GetSector();
170 vol[1] = tofsdigit->GetPlate();
171 vol[2] = tofsdigit->GetPadx();
172 vol[3] = tofsdigit->GetPadz();
173 vol[4] = tofsdigit->GetStrip();
175 digit[0] = tofsdigit->GetTdc();
176 digit[1] = tofsdigit->GetAdc();
178 new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
179 } // end loop on sdigits in the current file