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