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