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