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