HBTP code imported (P.Skowronski)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.cxx
CommitLineData
990119d6 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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
16/* $Id$ */
17
18//_________________________________________________________________________
990119d6 19//*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
20//////////////////////////////////////////////////////////////////////////////
a4e98857 21// This TTask performs digitization of Summable digits (in the PHOS case it is just
22// the sum of contributions from all primary particles into a given cell).
990119d6 23// In addition it performs mixing of summable digits from different events.
7b7c1533 24// The name of the TTask is also the title of the branch that will contain
25// the created SDigits
26// The title of the TTAsk is the name of the file that contains the hits from
27// which the SDigits are created
bca3b32a 28//
29// For each event two branches are created in TreeD:
30// "PHOS" - list of digits
31// "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
32//
a4e98857 33// Note, that one can set a title for new digits branch, and repeat digitization with
bca3b32a 34// another set of parameters.
35//
a4e98857 36// Use case:
990119d6 37// root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
38// root[1] d->ExecuteTask()
39// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
40// //Digitizes SDigitis in all events found in file galice.root
bca3b32a 41//
8cb3533f 42// root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
43// // Will read sdigits from galice1.root
44// root[3] d1->MixWith("galice2.root")
990119d6 45// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
a4e98857 46// // Reads another set of sdigits from galice2.root
8cb3533f 47// root[3] d1->MixWith("galice3.root")
a4e98857 48// // Reads another set of sdigits from galice3.root
8cb3533f 49// root[4] d->ExecuteTask("deb timing")
50// // Reads SDigits from files galice1.root, galice2.root ....
51// // mixes them and stores produced Digits in file galice1.root
52// // deb - prints number of produced digits
53// // deb all - prints list of produced digits
54// // timing - prints time used for digitization
990119d6 55//
990119d6 56
57// --- ROOT system ---
8cb3533f 58#include "TFile.h"
990119d6 59#include "TTree.h"
60#include "TSystem.h"
8cb3533f 61#include "TROOT.h"
62#include "TFolder.h"
63#include "TObjString.h"
64#include "TBenchmark.h"
ba54256b 65
990119d6 66// --- Standard library ---
8cb3533f 67#include <iomanip.h>
990119d6 68
69// --- AliRoot header files ---
70
8cb3533f 71#include "AliRun.h"
3f81a70b 72#include "AliRunDigitizer.h"
990119d6 73#include "AliPHOSDigit.h"
dd5c4038 74#include "AliPHOS.h"
7b7c1533 75#include "AliPHOSGetter.h"
990119d6 76#include "AliPHOSDigitizer.h"
77#include "AliPHOSSDigitizer.h"
8cb3533f 78#include "AliPHOSGeometry.h"
7437a0f7 79#include "AliPHOSTick.h"
990119d6 80
81ClassImp(AliPHOSDigitizer)
82
83
84//____________________________________________________________________________
3f81a70b 85 AliPHOSDigitizer::AliPHOSDigitizer()
990119d6 86{
87 // ctor
88
2bd5457f 89 fPinNoise = 0.01 ;
90 fEMCDigitThreshold = 0.01 ;
91 fCPVNoise = 0.01;
92 fCPVDigitThreshold = 0.09 ;
9688c1dd 93 fTimeResolution = 1.0e-9 ;
7437a0f7 94 fTimeSignalLength = 1.0e-9 ;
2b60655b 95 fDigitsInRun = 0 ;
3758d9fc 96 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
97 fADCpedestalEmc = 0.005 ; //
98 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
99
100 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
101 fADCpedestalCpv = 0.012 ; //
102 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
103
104 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
105 fARD = 0 ; // We work in the standalong mode
3f81a70b 106}
107
108//____________________________________________________________________________
109AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name)
110{
111 // ctor
112 SetName(name) ;
113 SetTitle(headerFile) ;
3f81a70b 114 fARD = 0 ; // We work in the standalong mode
3f81a70b 115 Init() ;
116
990119d6 117}
118
990119d6 119//____________________________________________________________________________
3f81a70b 120AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard)
990119d6 121{
122 // ctor
3f81a70b 123 fARD = ard ;
124 SetName("Default");
125 SetTitle("aliroot") ;
2bd5457f 126 Init() ;
8cb3533f 127
990119d6 128}
129
130//____________________________________________________________________________
131 AliPHOSDigitizer::~AliPHOSDigitizer()
132{
133 // dtor
8cb3533f 134
8cb3533f 135
990119d6 136}
137
138//____________________________________________________________________________
7b7c1533 139void AliPHOSDigitizer::Digitize(const Int_t event)
a4e98857 140{
141
142 // Makes the digitization of the collected summable digits.
143 // It first creates the array of all PHOS modules
144 // filled with noise (different for EMC, CPV and PPSD) and
145 // then adds contributions from SDigits.
146 // This design avoids scanning over the list of digits to add
147 // contribution to new SDigits only.
990119d6 148
7b7c1533 149 if( strcmp(GetName(), "") == 0 )
8cb3533f 150 Init() ;
990119d6 151
7b7c1533 152 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
3f81a70b 153 TClonesArray * digits = gime->Digits(GetName()) ;
3758d9fc 154 AliPHOSSDigitizer * sdiz = gime->SDigitizer(GetName()) ;
7b7c1533 155
156 digits->Clear() ;
990119d6 157
7b7c1533 158 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 159
160 //Making digits with noise, first EMC
161 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
162
163 Int_t nCPV ;
990119d6 164 Int_t absID ;
165 TString name = geom->GetName() ;
166
9688c1dd 167 nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
168 geom->GetNModules() ;
8cb3533f 169
9688c1dd 170 digits->Expand(nCPV) ;
8cb3533f 171
7b7c1533 172
173 // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD)
174 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
175 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
176 if ( !sDigitizer) {
177 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
178 abort() ;
179 }
9688c1dd 180
7b7c1533 181 // loop through the sdigits posted to the White Board and add them to the noise
182 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
183 TIter next(folderslist) ;
184 TFolder * folder = 0 ;
3f81a70b 185 TClonesArray * sdigits = 0 ;
186 Int_t input = 0 ;
9688c1dd 187 TObjArray * sdigArray = new TObjArray(2) ;
188 while ( (folder = (TFolder*)next()) )
3f81a70b 189 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
190 cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
191 << GetName() << " from " << folder->GetName() << endl ;
9688c1dd 192 sdigArray->AddAt(sdigits, input) ;
193 input++ ;
194 }
195
196 //Find the first crystall with sygnal
197 Int_t nextSig = 200000 ;
198 Int_t i;
199 for(i=0; i<input; i++){
200 sdigits = (TClonesArray *)sdigArray->At(i) ;
201 Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ;
202 if(curNext < nextSig) nextSig = curNext ;
203 }
7437a0f7 204
9688c1dd 205 TArrayI index(input) ;
206 index.Reset() ; //Set all indexes to zero
207
208 AliPHOSDigit * digit ;
209 AliPHOSDigit * curSDigit ;
210
7437a0f7 211 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
212
9688c1dd 213 //Put Noise contribution
214 for(absID = 1; absID <= nEMC; absID++){
215 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
216 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
217 //look if we have to add signal?
218 if(absID==nextSig){
219 //Add SDigits from all inputs
220 digit = (AliPHOSDigit *) digits->At(absID-1) ;
7437a0f7 221
222 ticks->Clear() ;
9688c1dd 223 Int_t contrib = 0 ;
7437a0f7 224 Float_t a = digit->GetAmp() ;
225 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
226 //Mark the beginnign of the signal
227 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
228 //Mark the end of the ignal
229 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
230
9688c1dd 231 //loop over inputs
232 for(i=0; i<input; i++){
233 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
234 //May be several digits will contribute from the same input
235 while(curSDigit && curSDigit->GetId() == absID){
236 //Shift primary to separate primaries belonging different inputs
237 Int_t primaryoffset ;
238 if(fARD)
239 primaryoffset = fARD->GetMask(i) ;
240 else
241 primaryoffset = 10000000*i ;
242 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 243
244 a = curSDigit->GetAmp() ;
245 b = a /fTimeSignalLength ;
246 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
247 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
9688c1dd 248
249 *digit = *digit + *curSDigit ; //add energies
7437a0f7 250
9688c1dd 251 index[i]++ ;
252 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
253 }
254 }
255
256 //calculate and set time
7437a0f7 257 Float_t time = FrontEdgeTime(ticks) ;
9688c1dd 258 digit->SetTime(time) ;
7437a0f7 259
9688c1dd 260 //Find next signal module
7437a0f7 261 nextSig = 200000 ;
9688c1dd 262 for(i=0; i<input; i++){
263 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
264 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
265 if(curNext < nextSig) nextSig = curNext ;
7b7c1533 266 }
267 }
990119d6 268 }
3f81a70b 269
7437a0f7 270 ticks->Delete() ;
271 delete ticks ;
9688c1dd 272
273
274 //Now CPV digits (different noise and no timing)
275 for(absID = nEMC+1; absID <= nCPV; absID++){
276 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
277 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
278 //look if we have to add signal?
279 if(absID==nextSig){
280 digit = (AliPHOSDigit *) digits->At(absID-1) ;
281 //Add SDigits from all inputs
282 for(i=0; i<input; i++){
283 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
284 //May be several digits will contribute from the same input
285 while(curSDigit && curSDigit->GetId() == absID){
286 //Shift primary to separate primaries belonging different inputs
287 Int_t primaryoffset ;
288 if(fARD)
289 primaryoffset = fARD->GetMask(i) ;
290 else
291 primaryoffset = 10000000*i ;
292 curSDigit->ShiftPrimary(primaryoffset) ;
293
294 //add energies
295 *digit = *digit + *curSDigit ;
296 index[i]++ ;
297 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
298 }
299 }
300
301 //Find next signal module
302 for(i=0; i<input; i++){
303 sdigits = (TClonesArray *)sdigArray->At(i) ;
304 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
305 if(curNext < nextSig) nextSig = curNext ;
306 }
307
308 }
309 }
9688c1dd 310 delete sdigArray ; //We should not delete its contents
311
312
313
990119d6 314 //remove digits below thresholds
315 for(absID = 0; absID < nEMC ; absID++)
7b7c1533 316 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
317 digits->RemoveAt(absID) ;
318
990119d6 319 for(absID = nEMC; absID < nCPV ; absID++)
7b7c1533 320 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
321 digits->RemoveAt(absID) ;
9688c1dd 322
7b7c1533 323 digits->Compress() ;
990119d6 324
7b7c1533 325 Int_t ndigits = digits->GetEntriesFast() ;
7b7c1533 326 digits->Expand(ndigits) ;
990119d6 327
3758d9fc 328 //Set indexes in list of digits and make true digitization of the energy
990119d6 329 for (i = 0 ; i < ndigits ; i++) {
7b7c1533 330 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
990119d6 331 digit->SetIndexInList(i) ;
3758d9fc 332 Float_t energy = sdiz->Calibrate(digit->GetAmp()) ;
333 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
990119d6 334 }
990119d6 335
7b7c1533 336}
3758d9fc 337//____________________________________________________________________________
338Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
339{
340 Int_t chanel ;
341 if(absId <= fEmcCrystals){ //digitize as EMC
342 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalEmc)/fADCchanelEmc) ;
343 if(chanel > fNADCemc ) chanel = fNADCemc ;
344 }
345 else{ //Digitize as CPV
346 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalCpv)/fADCchanelCpv) ;
347 if(chanel > fNADCcpv ) chanel = fNADCcpv ;
348 }
349 return chanel ;
350}
7b7c1533 351//____________________________________________________________________________
352void AliPHOSDigitizer::Exec(Option_t *option)
353{
354 // Managing method
990119d6 355
7b7c1533 356 if( strcmp(GetName(), "") == 0 )
357 Init() ;
8cb3533f 358
7b7c1533 359 if (strstr(option,"print")) {
360 Print("");
361 return ;
8cb3533f 362 }
990119d6 363
7b7c1533 364 if(strstr(option,"tim"))
365 gBenchmark->Start("PHOSDigitizer");
8cb3533f 366
3f81a70b 367 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
368
369 Int_t nevents ;
370
371 TTree * treeD ;
372
373 if(fARD){
374 treeD = fARD->GetTreeD() ;
375 nevents = 1 ; // Will process only one event
376 }
377 else {
378 gAlice->GetEvent(0) ;
379 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
380 treeD=gAlice->TreeD() ;
381 }
382 if(treeD == 0 ){
383 cerr << " AliPHOSDigitizer :: Can not find TreeD " << endl ;
384 return ;
385 }
386
7b7c1533 387 //Check, if this branch already exits
3f81a70b 388 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
7b7c1533 389 TIter next(lob) ;
390 TBranch * branch = 0 ;
391 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
8cb3533f 392
7b7c1533 393 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
3f81a70b 394 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
395 (strcmp(branch->GetTitle(), GetName())==0) )
7b7c1533 396 phosfound = kTRUE ;
8cb3533f 397
3f81a70b 398 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
399 (strcmp(branch->GetTitle(), GetName())==0) )
7b7c1533 400 digitizerfound = kTRUE ;
8cb3533f 401 }
990119d6 402
3f81a70b 403 if ( phosfound ) {
404 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
405 << " already exits" << endl ;
406 return ;
407 }
408 if ( digitizerfound ) {
409 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
7b7c1533 410 << " already exits" << endl ;
411 return ;
412 }
eec3ac52 413
7b7c1533 414 Int_t ievent ;
bca3b32a 415
7b7c1533 416 for(ievent = 0; ievent < nevents; ievent++){
3f81a70b 417
418 if(fARD){
419 Int_t input ;
420 for(input = 0 ; input < fARD->GetNinputs(); input ++){
421 TTree * treeS = fARD->GetInputTreeS(input) ;
422 if(!treeS){
423 cerr << "AliPHOSDigitizer -> No Input " << endl ;
424 return ;
425 }
426 gime->ReadTreeS(treeS,input) ;
427 }
428 }
429 else
430 gime->Event(ievent,"S") ;
990119d6 431
7b7c1533 432 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
3f81a70b 433
7b7c1533 434 WriteDigits(ievent) ;
3f81a70b 435
01a599c9 436 if(strstr(option,"deb"))
437 PrintDigits(option);
438 }
3f81a70b 439
8cb3533f 440 if(strstr(option,"tim")){
441 gBenchmark->Stop("PHOSDigitizer");
442 cout << "AliPHOSDigitizer:" << endl ;
ba54256b 443 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
444 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
8cb3533f 445 cout << endl ;
446 }
990119d6 447
448}
449
7b7c1533 450//____________________________________________________________________________
7437a0f7 451Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks)
9688c1dd 452{ //
7437a0f7 453 ticks->Sort() ; //Sort in accordance with times of ticks
454 TIter it(ticks) ;
455 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
456 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
457
458 AliPHOSTick * t ;
459 while((t=(AliPHOSTick*) it.Next())){
460 if(t->GetTime() < time) //This tick starts before crossing
461 *ctick+=*t ;
462 else
463 return time ;
464
465 time = ctick->CrossingTime(fTimeThreshold) ;
9688c1dd 466 }
467 return time ;
9688c1dd 468}
469//____________________________________________________________________________
3f81a70b 470Bool_t AliPHOSDigitizer::Init()
a4e98857 471{
3758d9fc 472 fPinNoise = 0.01 ;
473 fEMCDigitThreshold = 0.01 ;
474 fCPVNoise = 0.01;
475 fCPVDigitThreshold = 0.09 ;
476 fTimeResolution = 1.0e-9 ;
477 fTimeSignalLength = 1.0e-9 ;
478 fDigitsInRun = 0 ;
479 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
480 fADCpedestalEmc = 0.005 ; //
481 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
482
483 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
484 fADCpedestalCpv = 0.012 ; //
485 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
486
487 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
488
7b7c1533 489 // Makes all memory allocations
490 // Adds Digitizer task to the folder of PHOS tasks
3758d9fc 491
7b7c1533 492 //============================================================= YS
493 // The initialisation is now done by AliPHOSGetter
8cb3533f 494
7b7c1533 495 if( strcmp(GetTitle(), "") == 0 )
496 SetTitle("galice.root") ;
497
7b7c1533 498 // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array
499 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.
990119d6 500
7b7c1533 501 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
502 if ( gime == 0 ) {
503 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
3f81a70b 504 return kFALSE;
7b7c1533 505 }
3758d9fc 506
507 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
508 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
3f81a70b 509
510 // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
511 gime->PostDigits(GetName() ) ;
7b7c1533 512
513 //add Task to //YSAlice/tasks/Digitizer/PHOS
3f81a70b 514 gime->PostDigitizer(this) ;
515
516 //Mark that we will use current header file
517 if(!fARD){
518 gime->PostSDigits(GetName(),GetTitle()) ;
519 gime->PostSDigitizer(GetName(),GetTitle()) ;
520 }
521 return kTRUE ;
990119d6 522}
7b7c1533 523
990119d6 524//__________________________________________________________________
7b7c1533 525void AliPHOSDigitizer::MixWith(const char* headerFile)
a4e98857 526{
ba54256b 527 // Allows to produce digits by superimposing background and signal event.
bca3b32a 528 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 529 // the constructor.
530 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
531 // Thus we avoid writing (changing) huge and expensive
bca3b32a 532 // backgound files: all output will be writen into SIGNAL, i.e.
533 // opened in constructor file.
534 //
a4e98857 535 // One can open as many files to mix with as one needs.
7b7c1533 536 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
537 // can be mixed.
bca3b32a 538
7b7c1533 539 if( strcmp(GetName(), "") == 0 )
8cb3533f 540 Init() ;
541
3f81a70b 542 if(fARD){
543 cout << "Can not use this method under AliRunDigitizer " << endl ;
544 return ;
545 }
7b7c1533 546
547 // check if the specified SDigits do not already exist on the White Board:
548 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
990119d6 549
7b7c1533 550 TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ;
551 path += headerFile ;
552 path += "/" ;
3f81a70b 553 path += GetName() ;
7b7c1533 554 if ( gROOT->FindObjectAny(path.Data()) ) {
555 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
556 return;
990119d6 557 }
3f81a70b 558
559 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
560 gime->PostSDigits(GetName(),headerFile) ;
561
7b7c1533 562 // check if the requested file is already open or exist and if SDigits Branch exist
563 TFile * file = (TFile*)gROOT->FindObject(headerFile);
564 if ( !file ) {
565 file = new TFile(headerFile, "READ") ;
566 if (!file) {
567 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
568 return ;
569 }
570 }
3f81a70b 571
990119d6 572}
7b7c1533 573
990119d6 574//__________________________________________________________________
dd5c4038 575void AliPHOSDigitizer::Print(Option_t* option)const {
576 // Print Digitizer's parameters
7b7c1533 577 if( strcmp(GetName(), "") != 0 ){
8cb3533f 578
579 cout << "------------------- "<< GetName() << " -------------" << endl ;
580 cout << "Digitizing sDigits from file(s): " <<endl ;
7b7c1533 581
582 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
583 TIter next(folderslist) ;
584 TFolder * folder = 0 ;
585
586 while ( (folder = (TFolder*)next()) ) {
587 if ( folder->FindObject(GetName()) )
588 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
8cb3533f 589 }
590 cout << endl ;
7b7c1533 591 cout << "Writing digits to " << GetTitle() << endl ;
8cb3533f 592
593 cout << endl ;
594 cout << "With following parameters: " << endl ;
595 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
596 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
597 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
598 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
8cb3533f 599 cout << "---------------------------------------------------" << endl ;
990119d6 600 }
8cb3533f 601 else
602 cout << "AliPHOSDigitizer not initialized " << endl ;
603
604}
9688c1dd 605
8cb3533f 606//__________________________________________________________________
dd5c4038 607void AliPHOSDigitizer::PrintDigits(Option_t * option){
608 // Print a table of digits
a4e98857 609
7b7c1533 610 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
611 TClonesArray * digits = gime->Digits() ;
612
01a599c9 613 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
7b7c1533 614 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
990119d6 615 cout << endl ;
9688c1dd 616 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 617
618 //loop over digits
619 AliPHOSDigit * digit;
9688c1dd 620 cout << "Digit Id Amplitude Index " << " Nprim " << " Primaries list " << endl;
621 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
8cb3533f 622 Int_t index ;
9688c1dd 623 for (index = 0 ; (index < digits->GetEntries()) &&
624 (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 625 digit = (AliPHOSDigit * ) digits->At(index) ;
9688c1dd 626 if(digit->GetNprimary() == 0) continue;
627 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
628 << setw(6) << digit->GetIndexInList() << " "
629 << setw(5) << digit->GetNprimary() <<" ";
8cb3533f 630
631 Int_t iprimary;
632 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
9688c1dd 633 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
8cb3533f 634 cout << endl;
9688c1dd 635 }
636 cout << endl;
637 }
638
639 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 640
9688c1dd 641 //loop over CPV digits
642 AliPHOSDigit * digit;
643 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
644 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
645 Int_t index ;
646 for (index = 0 ; index < digits->GetEntries(); index++) {
647 digit = (AliPHOSDigit * ) digits->At(index) ;
648 if(digit->GetId() > maxEmc){
649 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
650 << setw(6) << digit->GetIndexInList() << " "
651 << setw(5) << digit->GetNprimary() <<" ";
652
653 Int_t iprimary;
654 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
655 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
656 cout << endl;
657 }
658 }
8cb3533f 659 }
9688c1dd 660
8cb3533f 661}
7b7c1533 662
8cb3533f 663//__________________________________________________________________
a4e98857 664void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
665{
bca3b32a 666 // we set title (comment) of the SDigits branch in the first! header file
7b7c1533 667 if( strcmp(GetName(), "") == 0 )
668 Init() ;
990119d6 669
7b7c1533 670 AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
671
8cb3533f 672}
9688c1dd 673//__________________________________________________________________
674Float_t AliPHOSDigitizer::TimeOfNoise(void)
675{ // Calculates the time signal generated by noise
676 //to be rewritten, now returns just big number
677 return 1. ;
678
679}
7b7c1533 680//____________________________________________________________________________
681void AliPHOSDigitizer::Reset()
682{
683 // sets current event number to the first simulated event
684
685 if( strcmp(GetName(), "") == 0 )
686 Init() ;
687
688 // Int_t inputs ;
689// for(inputs = 0; inputs < fNinputs ;inputs++)
690// fIevent->AddAt(-1, inputs ) ;
691
692}
693
694//____________________________________________________________________________
695void AliPHOSDigitizer::WriteDigits(Int_t event)
696{
697
698 // Makes TreeD in the output file.
699 // Check if branch already exists:
700 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
701 // already existing branches.
702 // else creates branch with Digits, named "PHOS", title "...",
703 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
704 // and names of files, from which digits are made.
705
706 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
3f81a70b 707 TClonesArray * digits = gime->Digits(GetName()) ;
ba54256b 708
3f81a70b 709 TTree * treeD ;
7b7c1533 710
3f81a70b 711 if(fARD)
712 treeD = fARD->GetTreeD() ;
713 else
714 treeD = gAlice->TreeD();
715
7b7c1533 716 // create new branches
717 // -- generate file name if necessary
718 char * file =0;
719 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
720 file = new char[strlen(gAlice->GetBaseFile())+20] ;
721 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
722 }
723
724 TDirectory *cwd = gDirectory;
7b7c1533 725 // -- create Digits branch
726 Int_t bufferSize = 32000 ;
ba54256b 727 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
7b7c1533 728 digitsBranch->SetTitle(GetName());
729 if (file) {
730 digitsBranch->SetFile(file);
731 TIter next( digitsBranch->GetListOfBranches());
732 TBranch * sbr ;
733 while ((sbr=(TBranch*)next())) {
734 sbr->SetFile(file);
735 }
736 cwd->cd();
737 }
738
739 // -- Create Digitizer branch
740 Int_t splitlevel = 0 ;
741 AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
ba54256b 742 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
7b7c1533 743 digitizerBranch->SetTitle(GetName());
744 if (file) {
745 digitizerBranch->SetFile(file);
746 TIter next( digitizerBranch->GetListOfBranches());
747 TBranch * sbr;
748 while ((sbr=(TBranch*)next())) {
749 sbr->SetFile(file);
750 }
751 cwd->cd();
752 }
3f81a70b 753
7b7c1533 754 digitsBranch->Fill() ;
755 digitizerBranch->Fill() ;
756
ba54256b 757 treeD->Write(0,kOverwrite) ;
3f81a70b 758
7b7c1533 759}