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