Tools to check if reconstruction OK
[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"
b3690abb 64#include "TGeometry.h"
8cb3533f 65#include "TBenchmark.h"
ba54256b 66
990119d6 67// --- Standard library ---
8cb3533f 68#include <iomanip.h>
990119d6 69
70// --- AliRoot header files ---
71
8cb3533f 72#include "AliRun.h"
b3690abb 73#include "AliHeader.h"
ea5f3389 74#include "AliStream.h"
3f81a70b 75#include "AliRunDigitizer.h"
990119d6 76#include "AliPHOSDigit.h"
dd5c4038 77#include "AliPHOS.h"
7b7c1533 78#include "AliPHOSGetter.h"
990119d6 79#include "AliPHOSDigitizer.h"
80#include "AliPHOSSDigitizer.h"
8cb3533f 81#include "AliPHOSGeometry.h"
7437a0f7 82#include "AliPHOSTick.h"
990119d6 83
84ClassImp(AliPHOSDigitizer)
85
86
87//____________________________________________________________________________
3f81a70b 88 AliPHOSDigitizer::AliPHOSDigitizer()
990119d6 89{
90 // ctor
8d0f3f77 91 InitParameters() ;
9bd3caba 92 fDefaultInit = kTRUE ;
fbf811ec 93 fManager = 0 ; // We work in the standalong mode
9bd3caba 94
fbf811ec 95 // fHitsFileName = "" ;
96 // fSDigitsFileName = "" ;
9bd3caba 97 }
3f81a70b 98
99//____________________________________________________________________________
fbf811ec 100AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile, const char * name, const Bool_t toSplit)
3f81a70b 101{
102 // ctor
ea5f3389 103
3f81a70b 104 SetTitle(headerFile) ;
38bb0fd5 105 SetName(name) ;
9891b76e 106 fManager = 0 ; // We work in the standalong mode
64c73770 107 fSplitFile= 0 ;
8d0f3f77 108 InitParameters() ;
fbf811ec 109 fToSplit = toSplit ;
3f81a70b 110 Init() ;
92f521a9 111 fDefaultInit = kFALSE ;
fbf811ec 112 // fSDigitsFileName = headerFile ;
113 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
114 // gime->Event(0, "S") ;
115 // fHitsFileName = gime->SDigitizer()->GetTitle() ;
990119d6 116}
117
990119d6 118//____________________________________________________________________________
9891b76e 119AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
990119d6 120{
121 // ctor
fbf811ec 122 SetTitle(ard->GetInputFileName(0,0)) ;
b22e4735 123 InitParameters() ;
fbf811ec 124 fDefaultInit = kFALSE ;
125 fSplitFile = 0 ;
126
127 if (ard->GetOutputFile()) {
128 SetName(ard->GetOutputFile().Data());
129 fToSplit = kTRUE ;
130 } else {
131 SetName("Default") ;
132 fToSplit = kFALSE ;
133 }
134
135// fSDigitsFileName = fManager->GetInputFileName(0, 0) ;
136// AliPHOSGetter * gime = AliPHOSGetter::GetInstance(fSDigitsFileName, GetName()) ;
137// gime->Event(0,"S") ;
138// fHitsFileName = gime->SDigitizer()->GetTitle() ;
9bd3caba 139
990119d6 140}
141
142//____________________________________________________________________________
143 AliPHOSDigitizer::~AliPHOSDigitizer()
144{
145 // dtor
92f521a9 146 // fDefaultInit = kTRUE if Digitizer created by default ctor (to get just the parameters)
79bb1b62 147
fbf811ec 148// if (!fDefaultInit) {
149// AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
ea5f3389 150
fbf811ec 151// // remove the task from the folder list
152// gime->RemoveTask("S",GetName()) ;
153// gime->RemoveTask("D",GetName()) ;
79bb1b62 154
fbf811ec 155// // remove the Digits from the folder list
156// gime->RemoveObjects("D", GetName()) ;
79bb1b62 157
fbf811ec 158// // remove the SDigits from the folder list
159// gime->RemoveSDigits() ;
79bb1b62 160
fbf811ec 161// // Delete gAlice
162// gime->CloseFile() ;
79bb1b62 163
164 fSplitFile = 0 ;
fbf811ec 165 // }
990119d6 166}
167
168//____________________________________________________________________________
7b7c1533 169void AliPHOSDigitizer::Digitize(const Int_t event)
a4e98857 170{
171
172 // Makes the digitization of the collected summable digits.
173 // It first creates the array of all PHOS modules
174 // filled with noise (different for EMC, CPV and PPSD) and
175 // then adds contributions from SDigits.
176 // This design avoids scanning over the list of digits to add
177 // contribution to new SDigits only.
990119d6 178
7b7c1533 179 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
38bb0fd5 180 TClonesArray * digits = gime->Digits(GetName()) ;
7b7c1533 181
182 digits->Clear() ;
990119d6 183
7b7c1533 184 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 185 //Making digits with noise, first EMC
186 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
187
188 Int_t nCPV ;
990119d6 189 Int_t absID ;
190 TString name = geom->GetName() ;
191
9688c1dd 192 nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
193 geom->GetNModules() ;
8cb3533f 194
9688c1dd 195 digits->Expand(nCPV) ;
8cb3533f 196
7b7c1533 197 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
92f521a9 198 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
7b7c1533 199 if ( !sDigitizer) {
200 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
201 abort() ;
202 }
9688c1dd 203
7b7c1533 204 // loop through the sdigits posted to the White Board and add them to the noise
7a9d98f9 205 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
7b7c1533 206 TIter next(folderslist) ;
207 TFolder * folder = 0 ;
3f81a70b 208 TClonesArray * sdigits = 0 ;
209 Int_t input = 0 ;
9688c1dd 210 TObjArray * sdigArray = new TObjArray(2) ;
38bb0fd5 211 while ( (folder = (TFolder*)next()) ) {
3f81a70b 212 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
54b82aa4 213 TString fileName(folder->GetName()) ;
214 fileName.ReplaceAll("_","/") ;
fbf811ec 215// cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
216// << GetName() << " from " << fileName << endl ;
9688c1dd 217 sdigArray->AddAt(sdigits, input) ;
218 input++ ;
219 }
38bb0fd5 220 }
9688c1dd 221
7a9d98f9 222 //Find the first crystall with signal
9688c1dd 223 Int_t nextSig = 200000 ;
224 Int_t i;
225 for(i=0; i<input; i++){
226 sdigits = (TClonesArray *)sdigArray->At(i) ;
a6eedfad 227 if ( !sdigits->GetEntriesFast() )
7a9d98f9 228 continue ;
9688c1dd 229 Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ;
7a9d98f9 230 if(curNext < nextSig)
231 nextSig = curNext ;
9688c1dd 232 }
7437a0f7 233
9688c1dd 234 TArrayI index(input) ;
235 index.Reset() ; //Set all indexes to zero
236
237 AliPHOSDigit * digit ;
238 AliPHOSDigit * curSDigit ;
239
7437a0f7 240 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
241
9688c1dd 242 //Put Noise contribution
243 for(absID = 1; absID <= nEMC; absID++){
244 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
245 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
246 //look if we have to add signal?
b3690abb 247 digit = (AliPHOSDigit *) digits->At(absID-1) ;
248
9688c1dd 249 if(absID==nextSig){
250 //Add SDigits from all inputs
7437a0f7 251 ticks->Clear() ;
9688c1dd 252 Int_t contrib = 0 ;
7437a0f7 253 Float_t a = digit->GetAmp() ;
254 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
255 //Mark the beginnign of the signal
256 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
257 //Mark the end of the ignal
258 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
259
9688c1dd 260 //loop over inputs
261 for(i=0; i<input; i++){
5c9dfca0 262 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
263 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
264 else
265 curSDigit = 0 ;
9688c1dd 266 //May be several digits will contribute from the same input
267 while(curSDigit && curSDigit->GetId() == absID){
268 //Shift primary to separate primaries belonging different inputs
269 Int_t primaryoffset ;
9891b76e 270 if(fManager)
271 primaryoffset = fManager->GetMask(i) ;
9688c1dd 272 else
21c293b7 273 primaryoffset = 10000000*i ;
274 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 275
276 a = curSDigit->GetAmp() ;
277 b = a /fTimeSignalLength ;
278 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
279 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
9688c1dd 280
281 *digit = *digit + *curSDigit ; //add energies
7437a0f7 282
9688c1dd 283 index[i]++ ;
5c9dfca0 284 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
285 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
286 else
287 curSDigit = 0 ;
9688c1dd 288 }
289 }
290
291 //calculate and set time
7437a0f7 292 Float_t time = FrontEdgeTime(ticks) ;
9688c1dd 293 digit->SetTime(time) ;
7437a0f7 294
9688c1dd 295 //Find next signal module
7437a0f7 296 nextSig = 200000 ;
9688c1dd 297 for(i=0; i<input; i++){
298 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
5c9dfca0 299 Int_t curNext = nextSig ;
300 if(sdigits->GetEntriesFast() > index[i] ){
301 curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
302
303 }
9688c1dd 304 if(curNext < nextSig) nextSig = curNext ;
7b7c1533 305 }
306 }
990119d6 307 }
3f81a70b 308
7437a0f7 309 ticks->Delete() ;
310 delete ticks ;
9688c1dd 311
312
313 //Now CPV digits (different noise and no timing)
314 for(absID = nEMC+1; absID <= nCPV; absID++){
315 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
316 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
317 //look if we have to add signal?
318 if(absID==nextSig){
319 digit = (AliPHOSDigit *) digits->At(absID-1) ;
320 //Add SDigits from all inputs
321 for(i=0; i<input; i++){
5c9dfca0 322 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
323 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
324 else
325 curSDigit = 0 ;
a6eedfad 326
9688c1dd 327 //May be several digits will contribute from the same input
328 while(curSDigit && curSDigit->GetId() == absID){
329 //Shift primary to separate primaries belonging different inputs
330 Int_t primaryoffset ;
9891b76e 331 if(fManager)
332 primaryoffset = fManager->GetMask(i) ;
9688c1dd 333 else
334 primaryoffset = 10000000*i ;
335 curSDigit->ShiftPrimary(primaryoffset) ;
336
337 //add energies
338 *digit = *digit + *curSDigit ;
339 index[i]++ ;
5c9dfca0 340 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
341 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
342 else
343 curSDigit = 0 ;
9688c1dd 344 }
345 }
a6eedfad 346
9688c1dd 347 //Find next signal module
a6eedfad 348 nextSig = 200000 ;
9688c1dd 349 for(i=0; i<input; i++){
350 sdigits = (TClonesArray *)sdigArray->At(i) ;
5c9dfca0 351 Int_t curNext = nextSig ;
352 if(sdigits->GetEntriesFast() > index[i] )
353 curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
9688c1dd 354 if(curNext < nextSig) nextSig = curNext ;
355 }
356
357 }
358 }
9688c1dd 359 delete sdigArray ; //We should not delete its contents
360
361
362
990119d6 363 //remove digits below thresholds
a6eedfad 364 for(i = 0; i < nEMC ; i++){
365 digit = (AliPHOSDigit*) digits->At(i) ;
aaf8a71c 366 if(sDigitizer->Calibrate( digit->GetAmp() ) < fEMCDigitThreshold)
a6eedfad 367 digits->RemoveAt(i) ;
aaf8a71c 368 else
369 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
370 }
371
a6eedfad 372
373 for(i = nEMC; i < nCPV ; i++)
374 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(i))->GetAmp()) < fCPVDigitThreshold)
375 digits->RemoveAt(i) ;
9688c1dd 376
7b7c1533 377 digits->Compress() ;
990119d6 378
7b7c1533 379 Int_t ndigits = digits->GetEntriesFast() ;
7b7c1533 380 digits->Expand(ndigits) ;
990119d6 381
3758d9fc 382 //Set indexes in list of digits and make true digitization of the energy
990119d6 383 for (i = 0 ; i < ndigits ; i++) {
7b7c1533 384 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
990119d6 385 digit->SetIndexInList(i) ;
f672adc8 386 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
3758d9fc 387 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
990119d6 388 }
990119d6 389
7b7c1533 390}
3758d9fc 391//____________________________________________________________________________
392Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
393{
394 Int_t chanel ;
395 if(absId <= fEmcCrystals){ //digitize as EMC
396 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalEmc)/fADCchanelEmc) ;
397 if(chanel > fNADCemc ) chanel = fNADCemc ;
398 }
399 else{ //Digitize as CPV
400 chanel = (Int_t) TMath::Ceil((energy - fADCpedestalCpv)/fADCchanelCpv) ;
401 if(chanel > fNADCcpv ) chanel = fNADCcpv ;
402 }
403 return chanel ;
404}
7b7c1533 405//____________________________________________________________________________
406void AliPHOSDigitizer::Exec(Option_t *option)
407{
408 // Managing method
990119d6 409
f672adc8 410 if(strcmp(GetName(), "") == 0 )
7b7c1533 411 Init() ;
7b7c1533 412 if (strstr(option,"print")) {
413 Print("");
414 return ;
8cb3533f 415 }
990119d6 416
7b7c1533 417 if(strstr(option,"tim"))
418 gBenchmark->Start("PHOSDigitizer");
8cb3533f 419
3f81a70b 420 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
421
422 Int_t nevents ;
423
424 TTree * treeD ;
425
9891b76e 426 if(fManager){
427 treeD = fManager->GetTreeD() ;
3f81a70b 428 nevents = 1 ; // Will process only one event
8cb3533f 429
fbf811ec 430 //Check, if this branch already exits
431 if (treeD) {
432 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
433 TIter next(lob) ;
434 TBranch * branch = 0 ;
435 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
b3690abb 436
fbf811ec 437 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
438 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
439 (strcmp(branch->GetTitle(), GetName())==0) )
440 phosfound = kTRUE ;
441
442 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
443 (strcmp(branch->GetTitle(), GetName())==0) )
444 digitizerfound = kTRUE ;
445 }
446
447 if ( phosfound ) {
448 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
449 << " already exits" << endl ;
450 return ;
451 }
452 if ( digitizerfound ) {
453 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
454 << " already exits" << endl ;
455 return ;
456 }
b3690abb 457 }
8cb3533f 458 }
fbf811ec 459 else { //PHOS standalone
460 if(gime->BranchExists("Digits") )
461 return ;
462 nevents=gime->MaxEvent() ;
463 }
464
7b7c1533 465 Int_t ievent ;
b3690abb 466
7b7c1533 467 for(ievent = 0; ievent < nevents; ievent++){
b3690abb 468
9891b76e 469 if(fManager){
b22e4735 470
3f81a70b 471 Int_t input ;
9891b76e 472 for(input = 0 ; input < fManager->GetNinputs(); input ++){
473 TTree * treeS = fManager->GetInputTreeS(input) ;
3f81a70b 474 if(!treeS){
b22e4735 475 cerr << "AliPHOSDigitizer::Exec -> No Input " << endl ;
3f81a70b 476 return ;
477 }
478 gime->ReadTreeS(treeS,input) ;
479 }
b22e4735 480
3f81a70b 481 }
482 else
483 gime->Event(ievent,"S") ;
990119d6 484
7b7c1533 485 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
3f81a70b 486
7b7c1533 487 WriteDigits(ievent) ;
3f81a70b 488
01a599c9 489 if(strstr(option,"deb"))
490 PrintDigits(option);
94de8339 491
492 //increment the total number of Digits per run
493 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
01a599c9 494 }
8d0f3f77 495
8cb3533f 496 if(strstr(option,"tim")){
497 gBenchmark->Stop("PHOSDigitizer");
498 cout << "AliPHOSDigitizer:" << endl ;
ba54256b 499 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
500 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
8cb3533f 501 cout << endl ;
502 }
990119d6 503
504}
505
7b7c1533 506//____________________________________________________________________________
7437a0f7 507Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks)
9688c1dd 508{ //
7437a0f7 509 ticks->Sort() ; //Sort in accordance with times of ticks
510 TIter it(ticks) ;
511 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
512 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
513
514 AliPHOSTick * t ;
515 while((t=(AliPHOSTick*) it.Next())){
516 if(t->GetTime() < time) //This tick starts before crossing
517 *ctick+=*t ;
518 else
519 return time ;
520
521 time = ctick->CrossingTime(fTimeThreshold) ;
9688c1dd 522 }
523 return time ;
9688c1dd 524}
8d0f3f77 525
9688c1dd 526//____________________________________________________________________________
3f81a70b 527Bool_t AliPHOSDigitizer::Init()
a4e98857 528{
fbf811ec 529 // Makes all memory allocations
530
531 if( strcmp(GetTitle(), "") == 0 )
532 SetTitle("galice.root") ;
8d0f3f77 533
fbf811ec 534 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(), fToSplit) ;
8d0f3f77 535 if ( gime == 0 ) {
536 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
537 return kFALSE;
538 }
539
540 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
b22e4735 541
8d0f3f77 542 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
543
544 // Post Digits to the white board
545 gime->PostDigits(GetName() ) ;
546
547 // Post Digitizer to the white board
548 gime->PostDigitizer(this) ;
fbf811ec 549
550 fSplitFile = 0 ;
551 if(fToSplit){
552 // construct the name of the file as /path/PHOS.SDigits.root
553 //First - extract full path if necessary
554 TString digitsFileName(GetTitle()) ;
555 Ssiz_t islash = digitsFileName.Last('/') ;
556 if(islash<digitsFileName.Length())
557 digitsFileName.Remove(islash+1,digitsFileName.Length()) ;
558 else
559 digitsFileName="" ;
560 // Next - append the file name
561 digitsFileName+="PHOS.Digits." ;
562 if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){
563 digitsFileName+=GetName() ;
564 digitsFileName+="." ;
565 }
566 digitsFileName+="root" ;
567 // Finally - check if the file already opened or open the file
568 fSplitFile = static_cast<TFile*>(gROOT->GetFile(digitsFileName.Data()));
569 if(!fSplitFile)
570 fSplitFile = TFile::Open(digitsFileName.Data(),"update") ;
571 }
8d0f3f77 572
573 //Mark that we will use current header file
574 if(!fManager){
575 gime->PostSDigits(GetName(),GetTitle()) ;
576 gime->PostSDigitizer(GetName(),GetTitle()) ;
577 }
578 return kTRUE ;
579}
580
581//____________________________________________________________________________
582void AliPHOSDigitizer::InitParameters()
583{
c74936f1 584 fPinNoise = 0.004 ;
585 fEMCDigitThreshold = 0.012 ;
3758d9fc 586 fCPVNoise = 0.01;
587 fCPVDigitThreshold = 0.09 ;
aaf8a71c 588 fTimeResolution = 0.5e-9 ;
3758d9fc 589 fTimeSignalLength = 1.0e-9 ;
590 fDigitsInRun = 0 ;
591 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
592 fADCpedestalEmc = 0.005 ; //
593 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
594
595 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
596 fADCpedestalCpv = 0.012 ; //
597 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
598
599 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
8cb3533f 600
990119d6 601}
7b7c1533 602
990119d6 603//__________________________________________________________________
7b7c1533 604void AliPHOSDigitizer::MixWith(const char* headerFile)
a4e98857 605{
ba54256b 606 // Allows to produce digits by superimposing background and signal event.
bca3b32a 607 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 608 // the constructor.
609 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
610 // Thus we avoid writing (changing) huge and expensive
bca3b32a 611 // backgound files: all output will be writen into SIGNAL, i.e.
612 // opened in constructor file.
613 //
a4e98857 614 // One can open as many files to mix with as one needs.
7b7c1533 615 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
616 // can be mixed.
bca3b32a 617
7b7c1533 618 if( strcmp(GetName(), "") == 0 )
8cb3533f 619 Init() ;
620
9891b76e 621 if(fManager){
3f81a70b 622 cout << "Can not use this method under AliRunDigitizer " << endl ;
623 return ;
624 }
7b7c1533 625
626 // check if the specified SDigits do not already exist on the White Board:
aad24ee7 627 // //Folders/RunMC/Event/Data/PHOS/SDigits/headerFile/sdigitsname
990119d6 628
aad24ee7 629 TString path = "Folders/RunMC/Event/Data/PHOS/SDigits" ;
7b7c1533 630 path += headerFile ;
631 path += "/" ;
3f81a70b 632 path += GetName() ;
7b7c1533 633 if ( gROOT->FindObjectAny(path.Data()) ) {
634 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
635 return;
990119d6 636 }
3f81a70b 637
638 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
639 gime->PostSDigits(GetName(),headerFile) ;
640
7b7c1533 641 // check if the requested file is already open or exist and if SDigits Branch exist
642 TFile * file = (TFile*)gROOT->FindObject(headerFile);
643 if ( !file ) {
644 file = new TFile(headerFile, "READ") ;
645 if (!file) {
646 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
647 return ;
648 }
649 }
3f81a70b 650
990119d6 651}
7b7c1533 652
fbf811ec 653// //__________________________________________________________________
654// void AliPHOSDigitizer::SetSplitFile(const TString splitFileName)
655// {
656// // Diverts the Digits in a file separate from the hits file
b3690abb 657
fbf811ec 658// // I guess it is not going to work if we do merging
659// // if (fManager) {
660// // cerr << "ERROR: AliPHOSDigitizer::SetSplitFile -> Not yet available in case of merging activated " << endl ;
661// // return ;
662// // }
6e89b8da 663
fbf811ec 664// cout << "AliPHOSDigitizer::SetSplitFile " << gDirectory->GetName() << endl ;
665// cout << "AliPHOSDigitizer::SetSplitFile " << gAlice->GetTreeDFileName() << endl ;
666// cout << "AliPHOSDigitizer::SetSplitFile " << splitFileName.Data() << endl ;
6e89b8da 667
fbf811ec 668// SetTitle(splitFileName) ;
b3690abb 669
fbf811ec 670// TDirectory * cwd = gDirectory ;
671// if ( !(gAlice->GetTreeDFileName() == splitFileName) ) {
672// if (gAlice->GetTreeDFile() )
673// gAlice->GetTreeDFile()->Close() ;
674// }
64c73770 675
fbf811ec 676// fSplitFile = gAlice->InitTreeFile("D",splitFileName.Data());
677// fSplitFile->cd() ;
678// gAlice->Write(0, TObject::kOverwrite);
679
680// TTree *treeE = gAlice->TreeE();
681// if (!treeE) {
682// cerr << "ERROR: AliPHOSDigitizer::SetSplitFile -> No TreeE found "<<endl;
683// abort() ;
684// }
685
686// // copy TreeE
687// AliHeader *header = new AliHeader();
688// treeE->SetBranchAddress("Header", &header);
689// treeE->SetBranchStatus("*",1);
690// TTree *treeENew = treeE->CloneTree();
691// treeENew->Write(0, TObject::kOverwrite);
692
693// // copy AliceGeom
694// TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
695// if (!AliceGeom) {
696// cerr << "ERROR: AliPHOSDigitizer::SetSplitFile -> AliceGeom was not found in the input file "<<endl;
697// abort() ;
698// }
699// AliceGeom->Write(0, TObject::kOverwrite);
700
701// gAlice->MakeTree("D",fSplitFile);
702// cwd->cd() ;
703// cout << "INFO: AliPHOSDigitizer::SetSPlitMode -> Digits will be stored in " << splitFileName.Data() << endl ;
704// }
b3690abb 705
706//__________________________________________________________________
dd5c4038 707void AliPHOSDigitizer::Print(Option_t* option)const {
708 // Print Digitizer's parameters
7b7c1533 709 if( strcmp(GetName(), "") != 0 ){
fbf811ec 710
711
8cb3533f 712 cout << "------------------- "<< GetName() << " -------------" << endl ;
6e89b8da 713
714 const Int_t nStreams = GetNInputStreams() ;
715 if (nStreams) {
716 Int_t index = 0 ;
717 for (index = 0 ; index < nStreams ; index++)
3685cf52 718 cout << "Adding SDigits " << GetName() << " from " << fManager->GetInputFileName(index, 0) << endl ;
6e89b8da 719
ea5f3389 720 cout << endl ;
3685cf52 721 cout << "Writing digits to " << fManager->GetInputFileName(0, 0) << endl ;
6e89b8da 722 } else {
723// AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
724// gime->Folder("sdigits") ;
725// cout << "Digitizing sDigits from file(s): " <<endl ;
726// TCollection * folderslist = gime->Folder("sdigits")->GetListOfFolders() ;
727// TIter next(folderslist) ;
728// TFolder * folder = 0 ;
ea5f3389 729
6e89b8da 730// while ( (folder = (TFolder*)next()) ) {
731// if ( folder->FindObject(GetName()) )
fbf811ec 732 // cout << "Adding SDigits " << GetName() << " from " << GetSDigitsFileName() << endl ;
6e89b8da 733// }
ea5f3389 734 cout << endl ;
735 cout << "Writing digits to " << GetTitle() << endl ;
736 }
8cb3533f 737 cout << endl ;
738 cout << "With following parameters: " << endl ;
739 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
740 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
741 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
742 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
8cb3533f 743 cout << "---------------------------------------------------" << endl ;
990119d6 744 }
8cb3533f 745 else
746 cout << "AliPHOSDigitizer not initialized " << endl ;
747
748}
9688c1dd 749
8cb3533f 750//__________________________________________________________________
dd5c4038 751void AliPHOSDigitizer::PrintDigits(Option_t * option){
752 // Print a table of digits
a4e98857 753
7b7c1533 754 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
755 TClonesArray * digits = gime->Digits() ;
756
01a599c9 757 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
7b7c1533 758 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
990119d6 759 cout << endl ;
9688c1dd 760 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 761
762 //loop over digits
763 AliPHOSDigit * digit;
a6eedfad 764 cout << "EMC digits (with primaries): " << endl ;
765 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
9688c1dd 766 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
8cb3533f 767 Int_t index ;
a6eedfad 768 for (index = 0 ; (index < digits->GetEntriesFast()) &&
9688c1dd 769 (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 770 digit = (AliPHOSDigit * ) digits->At(index) ;
9688c1dd 771 if(digit->GetNprimary() == 0) continue;
772 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
773 << setw(6) << digit->GetIndexInList() << " "
774 << setw(5) << digit->GetNprimary() <<" ";
8cb3533f 775
776 Int_t iprimary;
777 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
9688c1dd 778 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
8cb3533f 779 cout << endl;
9688c1dd 780 }
781 cout << endl;
782 }
783
784 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 785
9688c1dd 786 //loop over CPV digits
787 AliPHOSDigit * digit;
a6eedfad 788 cout << "CPV digits: " << endl ;
789 cout << "Digit Id Amplitude Index Nprim Primaries list " << endl;
9688c1dd 790 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
791 Int_t index ;
a6eedfad 792 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 793 digit = (AliPHOSDigit * ) digits->At(index) ;
794 if(digit->GetId() > maxEmc){
795 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
796 << setw(6) << digit->GetIndexInList() << " "
797 << setw(5) << digit->GetNprimary() <<" ";
798
799 Int_t iprimary;
800 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
801 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
802 cout << endl;
803 }
804 }
8cb3533f 805 }
9688c1dd 806
8cb3533f 807}
7b7c1533 808
fbf811ec 809// //__________________________________________________________________
810// void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
811// {
812// // we set title (comment) of the SDigits branch in the first! header file
813// if( strcmp(GetName(), "") == 0 )
814// Init() ;
990119d6 815
fbf811ec 816// AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
7b7c1533 817
fbf811ec 818// }
9688c1dd 819//__________________________________________________________________
820Float_t AliPHOSDigitizer::TimeOfNoise(void)
821{ // Calculates the time signal generated by noise
822 //to be rewritten, now returns just big number
823 return 1. ;
824
825}
fbf811ec 826// //____________________________________________________________________________
827// void AliPHOSDigitizer::Reset()
828// {
829// // sets current event number to the first simulated event
7b7c1533 830
fbf811ec 831// if( strcmp(GetName(), "") == 0 )
832// Init() ;
7b7c1533 833
fbf811ec 834// // Int_t inputs ;
835// // for(inputs = 0; inputs < fNinputs ;inputs++)
836// // fIevent->AddAt(-1, inputs ) ;
7b7c1533 837
fbf811ec 838// }
7b7c1533 839
840//____________________________________________________________________________
841void AliPHOSDigitizer::WriteDigits(Int_t event)
842{
843
844 // Makes TreeD in the output file.
845 // Check if branch already exists:
846 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
847 // already existing branches.
848 // else creates branch with Digits, named "PHOS", title "...",
849 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
850 // and names of files, from which digits are made.
851
852 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
aad24ee7 853 const TClonesArray * digits = gime->Digits(GetName()) ;
8d0f3f77 854 TTree * treeD ;
fbf811ec 855
856 if(fManager)
857 treeD = fManager->GetTreeD() ;
858 else {
859 if((gAlice->TreeD() == 0) || (fSplitFile)) // we should not create TreeD if it is already here
860 gAlice->MakeTree("D", fSplitFile); // We overwrite TreeD in split file in the case of second reconstruction
861 if(fSplitFile)
862 fSplitFile->cd() ;
863 treeD = gAlice->TreeD();
864 }
865
7b7c1533 866 // -- create Digits branch
867 Int_t bufferSize = 32000 ;
ba54256b 868 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
7b7c1533 869 digitsBranch->SetTitle(GetName());
fbf811ec 870
7b7c1533 871 // -- Create Digitizer branch
872 Int_t splitlevel = 0 ;
fbf811ec 873 const AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
ba54256b 874 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
7b7c1533 875 digitizerBranch->SetTitle(GetName());
b3690abb 876
ec85099a 877 digitsBranch->Fill() ;
64c73770 878 digitizerBranch->Fill() ;
b3690abb 879 treeD->AutoSave() ;
7b7c1533 880}