1 Int_t AliTOFSDigits2Digits(TString infileNameSDigits, Int_t firstEvent=0,Int_t nEvents=1, Int_t ndump=15)
3 // Create TOF digits out of TOF sdigits (no merging implemented here).
4 // Input: infileNameSDigits --> TOF sdigits filename
5 // firstEvent --> first event to digitize
6 // nEvents --> number of events to digitize
7 // including the first and the last ones
8 // if nEvents==0 we sdigitize all events in infileNameSDigits
9 // ndump --> number of dumped digits
11 // Author: F. Pierella (Bologna University)
12 // report problem to pierella@bo.infn.it
14 // Use case: (start root)
15 //root [0] .L AliTOFSDigits2Digits.C
16 //root [1] AliTOFSDigits2Digits("fileWithTOFSdigits.root")
19 // number 3 is a legacy from AliDigit object
20 const Int_t kMAXDIGITS = 3;
23 // Dynamically link some shared libs
24 if (gClassTable->GetID("AliRun") < 0) {
25 gROOT->LoadMacro("loadlibs.C");
35 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(infileNameSDigits.Data());
37 cout<<"headerFile already open \n";
40 // file is open in "update" mode
41 // in order to have a writable digits tree
42 if(!file)file=TFile::Open(infileNameSDigits.Data(),"update");
45 // Get AliRun object from file
47 gAlice = (AliRun*)file->Get("gAlice");
48 if (gAlice) printf("AliRun object found on file\n");
51 if (nEvents == 0) nEvents = (Int_t) gAlice->TreeE()->GetEntries();
53 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
56 cout << "<AliTOFSDigits2Digits> No TOF detector found" << endl;
61 Int_t totndig=0; // total number of digits
62 Int_t tottracks=0; // total number of tracks contributing to totndig
63 Int_t upperBoundEvNum=firstEvent+nEvents;
64 for (Int_t ievent = firstEvent; ievent < upperBoundEvNum; ievent++) {
66 gAlice->GetEvent(ievent);
67 if (gAlice->TreeD () == 0)
68 gAlice->MakeTree ("D");
72 sprintf (branchname, "%s", tof->GetName ());
73 //Make branch for digits
74 tof->MakeBranch ("D");
77 // get the TOF branch in TreeS for current event
78 char tname[100]; sprintf(tname,"TreeS%d",ievent);
80 TTree *sdigitstree=(TTree*)file->Get(tname);
82 TClonesArray * fSDigits= new TClonesArray("AliTOFSDigit", 1000);
83 sdigitstree->GetBranch("TOF")->SetAddress(&fSDigits);
85 Int_t nEntries = sdigitstree->GetEntries();
86 //cout << nEntries << endl;
88 // Loop through all entries in the tree
91 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
94 nbytes += sdigitstree->GetEvent(iEntry);
96 // Get the number of sdigits
97 Int_t ndig = fSDigits->GetEntriesFast();
98 cout << "------------------<AliTOFSDigits2Digits>------------------" << endl;
99 cout << "Found " << ndig << " TOF SDigits for event " << ievent << endl;
100 cout << "------------------------------------------------------------" << endl;
102 // start loop on sdigits
103 for (Int_t k = 0; k < ndig; k++) {
105 Int_t vol[5]; // location for a digit
107 // Get the information for this digit
108 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigits->UncheckedAt(k);
110 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
111 // for current sdigit
113 // TOF sdigit volumes (always the same for all slots)
114 Int_t sector = tofsdigit->GetSector(); // range [1-18]
115 Int_t plate = tofsdigit->GetPlate(); // range [1- 5]
116 Int_t strip = tofsdigit->GetStrip(); // range [1-20]
117 Int_t padz = tofsdigit->GetPadz(); // range [1- 2]
118 Int_t padx = tofsdigit->GetPadx(); // range [1-48]
126 //--------------------- QA section ----------------------
127 // in the while, I perform QA
128 Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
131 cout << "<AliTOFSDigits2Digits> strange sdigit found" << endl;
135 //-------------------------------------------------------
137 //------------------- Dump section ----------------------
139 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
140 cout << k << "-th sdigit" << endl;
141 cout << "----------------------------------------------------"<< endl;
143 // ------------------------------------------------------
145 // start loop on number of slots for current sdigit
146 for (Int_t islot = 0; islot < nslot; islot++) {
147 Float_t digit[2]; // TOF digit variables
148 Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot
150 Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
151 Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
153 tracknum[0]=tofsdigit->GetTrack(islot,0);
154 tracknum[1]=tofsdigit->GetTrack(islot,1);
155 tracknum[2]=tofsdigit->GetTrack(islot,2);
157 for (Int_t i = 0; i < kMAXDIGITS; i++) {
159 // search for the first empty location
166 // adding a TOF digit for each slot
167 tof->AddDigit(tracknum, vol, digit);
172 } // end loop on sdigits
174 } // end loop on entries
180 gAlice->TreeD()->Reset();
181 gAlice->TreeD()->Fill();
182 //gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
183 gAlice->TreeD()->AutoSave();
185 } // end loop on events
187 cout << "----------------------------------------------------------" << endl;
188 cout << "<AliTOFSDigits2Digits> Summary" << endl;
189 cout << "contributing tracks to " << totndig << " digits: " << tottracks << endl;
190 cout << "----------------------------------------------------------" << endl;