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