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 **************************************************************************/
15 //Piotr.Skowronski@cern.ch :
16 //Corrections applied in order to compile (only) with new I/O and folder structure
17 //To be implemented correctly by responsible
19 #include "AliRunLoader.h"
20 #include "AliLoader.h"
24 #include <TObjArray.h>
26 #include <TDirectory.h>
29 #include "AliTOFMerger.h"
31 #include "AliTOFSDigitizer.h"
32 #include "AliTOFhit.h"
33 #include "AliTOFdigit.h"
39 #include <Riostream.h>
40 #include <Riostream.h>
42 ClassImp(AliTOFMerger)
44 //___________________________________________
45 AliTOFMerger::AliTOFMerger()
60 //------------------------------------------------------------------------
61 AliTOFMerger::~AliTOFMerger()
83 //------------------------------------------------------------------------
84 void AliTOFMerger::Init()
87 if (fMerge) fBgrFile = InitBgr();
93 //------------------------------------------------------------------------
94 TFile* AliTOFMerger::InitBgr()
96 // Initialise background event
97 fRunLoader = AliRunLoader::Open(fFnBgr);//open session and mount on default event folder
99 TFile *file = new TFile(fFnBgr);
100 // add error checking later
101 printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
105 //------------------------------------------------------------------------
106 void AliTOFMerger::Digitise()
109 // keep galice.root for signal and name differently the file for
110 // background when add! otherwise the track info for signal will be lost !
113 cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
117 if (fRunLoader == 0x0)
119 Error("Exec","Event is not loaded. Exiting");
122 retval = fRunLoader->LoadgAlice();
125 Error("Exec","Error occured while loading gAlice. Exiting");
128 retval = fRunLoader->LoadHeader();
131 Error("Exec","Error occured while loading header. Exiting");
135 retval = fRunLoader->LoadKinematics("READ");
138 Error("Exec","Error occured while loading kinematics. Exiting");
142 AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
145 Error("Exec","Can not find TOF loader in event. Exiting.");
148 gAlice = fRunLoader->GetAliRun();
150 AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
154 TTree *TK = fRunLoader->TreeK();
155 if (TK) f1 = TK->GetCurrentFile();
157 fRunLoader->GetEvent(fEvNrSig);
159 if(gime->TreeD() == 0)
160 gime->MakeTree("D") ;
162 gime->TreeD()->Reset();
164 // read and write digits for signal
165 ReadWriteDigit(fEvNrSig);
171 // gAlice->TreeS()->Reset();
172 gAlice = (AliRun*)fBgrFile->Get("gAlice");
173 ReadWriteDigit(fEvNrBgr);
179 //Make branch for digits
180 TOF->MakeBranch("D");
182 gime->TreeD()->Reset();
183 gime->TreeD()->Fill();
185 fDigits = TOF->Digits();
187 gime->WriteDigits("OVERWRITE");
189 gAlice->ResetDigits();
193 //---------------------------------------------------------------------
195 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
198 // Read Sdigits from the current file and write them in the TreeD
200 AliTOFdigit* tofsdigit;
202 AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
204 Int_t retval = fRunLoader->GetEvent(iEvNum);
207 Error("ReadWriteDigit","Error while getting event %d",iEvNum);
211 AliLoader* gime = fRunLoader->GetLoader("TOFLoader");
214 Error("Exec","Can not find TOF loader in event. Exiting.");
222 cout<<" TreeS==0 -> return"<<gime->TreeS()<<endl;
227 Int_t tracks[3]; // track info
228 Int_t vol[5]; // location for a digit
229 Float_t digit[2]; // TOF digit variables
231 gAlice->ResetDigits();
232 gime->TreeS()->GetEvent(iEvNum);
233 TClonesArray * TOFdigits = tofinfile->SDigits();
235 ndig=TOFdigits->GetEntries();
237 for (k=0; k<ndig; k++) {
238 tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
240 tracks[0] = tofsdigit->GetTrack(0);
241 tracks[1] = tofsdigit->GetTrack(1);
242 tracks[2] = tofsdigit->GetTrack(2);
244 vol[0] = tofsdigit->GetSector();
245 vol[1] = tofsdigit->GetPlate();
246 vol[2] = tofsdigit->GetStrip();
247 vol[3] = tofsdigit->GetPadx();
248 vol[4] = tofsdigit->GetPadz();
250 digit[0] = tofsdigit->GetTdc();
251 digit[1] = tofsdigit->GetAdc();
253 new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
254 } // end loop on sdigits in the current file