1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
20 //////////////////////////////////////////////////////////////////////////////
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).
23 // In addition it performs mixing of summable digits from different events.
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
29 // For each event two branches are created in TreeD:
30 // "PHOS" - list of digits
31 // "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
33 // Note, that one can set a title for new digits branch, and repeat digitization with
34 // another set of parameters.
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
42 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
43 // // Will read sdigits from galice1.root
44 // root[3] d1->MixWith("galice2.root")
45 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
46 // // Reads another set of sdigits from galice2.root
47 // root[3] d1->MixWith("galice3.root")
48 // // Reads another set of sdigits from galice3.root
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
57 // --- ROOT system ---
63 #include "TObjString.h"
64 #include "TBenchmark.h"
66 // --- Standard library ---
69 // --- AliRoot header files ---
72 #include "AliRunDigitizer.h"
73 #include "AliPHOSDigit.h"
75 #include "AliPHOSGetter.h"
76 #include "AliPHOSDigitizer.h"
77 #include "AliPHOSSDigitizer.h"
78 #include "AliPHOSGeometry.h"
80 ClassImp(AliPHOSDigitizer)
83 //____________________________________________________________________________
84 AliPHOSDigitizer::AliPHOSDigitizer()
89 fEMCDigitThreshold = 0.01 ;
91 fCPVDigitThreshold = 0.09 ;
92 fTimeResolution = 1.0e-9 ;
94 fPedestal = 0.; // Calibration parameters
96 fARD = 0 ; // We work in the standalong mode
99 //____________________________________________________________________________
100 AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name)
104 SetTitle(headerFile) ;
106 fEMCDigitThreshold = 0.01 ;
108 fCPVDigitThreshold = 0.09 ;
110 fPedestal = 0.; // Calibration parameters
112 fARD = 0 ; // We work in the standalong mode
118 //____________________________________________________________________________
119 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard)
124 SetTitle("aliroot") ;
127 fEMCDigitThreshold = 0.01 ;
129 fCPVDigitThreshold = 0.09 ;
131 fPedestal = 0.; // Calibration parameters
138 //____________________________________________________________________________
139 AliPHOSDigitizer::~AliPHOSDigitizer()
146 //____________________________________________________________________________
147 void AliPHOSDigitizer::Digitize(const Int_t event)
150 // Makes the digitization of the collected summable digits.
151 // It first creates the array of all PHOS modules
152 // filled with noise (different for EMC, CPV and PPSD) and
153 // then adds contributions from SDigits.
154 // This design avoids scanning over the list of digits to add
155 // contribution to new SDigits only.
157 if( strcmp(GetName(), "") == 0 )
160 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
161 TClonesArray * digits = gime->Digits(GetName()) ;
165 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
167 //Making digits with noise, first EMC
168 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
172 TString name = geom->GetName() ;
174 nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
175 geom->GetNModules() ;
177 digits->Expand(nCPV) ;
180 // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD)
181 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
182 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
184 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
188 // loop through the sdigits posted to the White Board and add them to the noise
189 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
190 TIter next(folderslist) ;
191 TFolder * folder = 0 ;
192 TClonesArray * sdigits = 0 ;
194 TObjArray * sdigArray = new TObjArray(2) ;
195 while ( (folder = (TFolder*)next()) )
196 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
197 cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
198 << GetName() << " from " << folder->GetName() << endl ;
199 sdigArray->AddAt(sdigits, input) ;
203 //Find the first crystall with sygnal
204 Int_t nextSig = 200000 ;
206 for(i=0; i<input; i++){
207 sdigits = (TClonesArray *)sdigArray->At(i) ;
208 Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ;
209 if(curNext < nextSig) nextSig = curNext ;
212 TArrayF * energies = new TArrayF(input);
213 TArrayF * times = new TArrayF(input) ;
214 TArrayI index(input) ;
215 index.Reset() ; //Set all indexes to zero
217 AliPHOSDigit * digit ;
218 AliPHOSDigit * curSDigit ;
220 //Put Noise contribution
221 for(absID = 1; absID <= nEMC; absID++){
222 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
223 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
224 //look if we have to add signal?
226 //Add SDigits from all inputs
227 digit = (AliPHOSDigit *) digits->At(absID-1) ;
229 energies[contrib] = digit->GetAmp() ;
230 times[contrib] = digit->GetTime() ;
232 for(i=0; i<input; i++){
233 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
234 //May be several digits will contribute from the same input
235 while(curSDigit && curSDigit->GetId() == absID){
236 //Shift primary to separate primaries belonging different inputs
237 Int_t primaryoffset ;
239 primaryoffset = fARD->GetMask(i) ;
241 primaryoffset = 10000000*i ;
242 curSDigit->ShiftPrimary(primaryoffset) ;
244 *digit = *digit + *curSDigit ; //add energies
245 energies[contrib] = curSDigit->GetAmp() ;
246 times[contrib] = curSDigit->GetTime() ;
249 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
253 //calculate and set time
254 Float_t time = FrontEdgeTime(energies, times) ;
255 digit->SetTime(time) ;
258 //Find next signal module
259 for(i=0; i<input; i++){
260 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
261 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
262 if(curNext < nextSig) nextSig = curNext ;
269 //Now CPV digits (different noise and no timing)
270 for(absID = nEMC+1; absID <= nCPV; absID++){
271 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
272 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
273 //look if we have to add signal?
275 digit = (AliPHOSDigit *) digits->At(absID-1) ;
276 //Add SDigits from all inputs
277 for(i=0; i<input; i++){
278 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
279 //May be several digits will contribute from the same input
280 while(curSDigit && curSDigit->GetId() == absID){
281 //Shift primary to separate primaries belonging different inputs
282 Int_t primaryoffset ;
284 primaryoffset = fARD->GetMask(i) ;
286 primaryoffset = 10000000*i ;
287 curSDigit->ShiftPrimary(primaryoffset) ;
290 *digit = *digit + *curSDigit ;
292 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
296 //Find next signal module
297 for(i=0; i<input; i++){
298 sdigits = (TClonesArray *)sdigArray->At(i) ;
299 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
300 if(curNext < nextSig) nextSig = curNext ;
307 delete sdigArray ; //We should not delete its contents
311 //remove digits below thresholds
312 for(absID = 0; absID < nEMC ; absID++)
313 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
314 digits->RemoveAt(absID) ;
316 for(absID = nEMC; absID < nCPV ; absID++)
317 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
318 digits->RemoveAt(absID) ;
322 Int_t ndigits = digits->GetEntriesFast() ;
323 digits->Expand(ndigits) ;
325 //Set indexes in list of digits
326 for (i = 0 ; i < ndigits ; i++) {
327 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
328 digit->SetIndexInList(i) ;
333 //____________________________________________________________________________
334 void AliPHOSDigitizer::Exec(Option_t *option)
338 if( strcmp(GetName(), "") == 0 )
341 if (strstr(option,"print")) {
346 if(strstr(option,"tim"))
347 gBenchmark->Start("PHOSDigitizer");
349 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
356 treeD = fARD->GetTreeD() ;
357 nevents = 1 ; // Will process only one event
360 gAlice->GetEvent(0) ;
361 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
362 treeD=gAlice->TreeD() ;
365 cerr << " AliPHOSDigitizer :: Can not find TreeD " << endl ;
369 //Check, if this branch already exits
370 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
372 TBranch * branch = 0 ;
373 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
375 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
376 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
377 (strcmp(branch->GetTitle(), GetName())==0) )
380 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
381 (strcmp(branch->GetTitle(), GetName())==0) )
382 digitizerfound = kTRUE ;
386 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
387 << " already exits" << endl ;
390 if ( digitizerfound ) {
391 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
392 << " already exits" << endl ;
398 for(ievent = 0; ievent < nevents; ievent++){
402 for(input = 0 ; input < fARD->GetNinputs(); input ++){
403 TTree * treeS = fARD->GetInputTreeS(input) ;
405 cerr << "AliPHOSDigitizer -> No Input " << endl ;
408 gime->ReadTreeS(treeS,input) ;
412 gime->Event(ievent,"S") ;
414 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
416 WriteDigits(ievent) ;
418 if(strstr(option,"deb"))
422 if(strstr(option,"tim")){
423 gBenchmark->Stop("PHOSDigitizer");
424 cout << "AliPHOSDigitizer:" << endl ;
425 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
426 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
432 //____________________________________________________________________________
433 Float_t AliPHOSDigitizer::FrontEdgeTime(TArrayF * energies, TArrayF * times)
435 Float_t curtime = times->At(0) ;
436 Float_t time = curtime ;
439 if(time > curtime) time = curtime ;
440 curtime = times->At(i++) ;
445 //____________________________________________________________________________
446 Bool_t AliPHOSDigitizer::Init()
448 // Makes all memory allocations
449 // Adds Digitizer task to the folder of PHOS tasks
450 //============================================================= YS
451 // The initialisation is now done by AliPHOSGetter
453 if( strcmp(GetTitle(), "") == 0 )
454 SetTitle("galice.root") ;
456 // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array
457 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.
459 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
461 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
465 // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
466 gime->PostDigits(GetName() ) ;
468 //add Task to //YSAlice/tasks/Digitizer/PHOS
469 gime->PostDigitizer(this) ;
471 //Mark that we will use current header file
473 gime->PostSDigits(GetName(),GetTitle()) ;
474 gime->PostSDigitizer(GetName(),GetTitle()) ;
479 //__________________________________________________________________
480 void AliPHOSDigitizer::MixWith(const char* headerFile)
482 // Allows to produce digits by superimposing background and signal event.
483 // It is assumed, that headers file with SIGNAL events is opened in
485 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
486 // Thus we avoid writing (changing) huge and expensive
487 // backgound files: all output will be writen into SIGNAL, i.e.
488 // opened in constructor file.
490 // One can open as many files to mix with as one needs.
491 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
494 if( strcmp(GetName(), "") == 0 )
498 cout << "Can not use this method under AliRunDigitizer " << endl ;
502 // check if the specified SDigits do not already exist on the White Board:
503 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
505 TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ;
509 if ( gROOT->FindObjectAny(path.Data()) ) {
510 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
514 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
515 gime->PostSDigits(GetName(),headerFile) ;
517 // check if the requested file is already open or exist and if SDigits Branch exist
518 TFile * file = (TFile*)gROOT->FindObject(headerFile);
520 file = new TFile(headerFile, "READ") ;
522 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
529 //__________________________________________________________________
530 void AliPHOSDigitizer::Print(Option_t* option)const {
531 // Print Digitizer's parameters
532 if( strcmp(GetName(), "") != 0 ){
534 cout << "------------------- "<< GetName() << " -------------" << endl ;
535 cout << "Digitizing sDigits from file(s): " <<endl ;
537 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
538 TIter next(folderslist) ;
539 TFolder * folder = 0 ;
541 while ( (folder = (TFolder*)next()) ) {
542 if ( folder->FindObject(GetName()) )
543 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
546 cout << "Writing digits to " << GetTitle() << endl ;
549 cout << "With following parameters: " << endl ;
550 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
551 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
552 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
553 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
554 cout << "---------------------------------------------------" << endl ;
557 cout << "AliPHOSDigitizer not initialized " << endl ;
561 //__________________________________________________________________
562 void AliPHOSDigitizer::PrintDigits(Option_t * option){
563 // Print a table of digits
565 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
566 TClonesArray * digits = gime->Digits() ;
568 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
569 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
571 if(strstr(option,"all")||strstr(option,"EMC")){
574 AliPHOSDigit * digit;
575 cout << "Digit Id Amplitude Index " << " Nprim " << " Primaries list " << endl;
576 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
578 for (index = 0 ; (index < digits->GetEntries()) &&
579 (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) {
580 digit = (AliPHOSDigit * ) digits->At(index) ;
581 if(digit->GetNprimary() == 0) continue;
582 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
583 << setw(6) << digit->GetIndexInList() << " "
584 << setw(5) << digit->GetNprimary() <<" ";
587 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
588 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
594 if(strstr(option,"all")||strstr(option,"CPV")){
596 //loop over CPV digits
597 AliPHOSDigit * digit;
598 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
599 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
601 for (index = 0 ; index < digits->GetEntries(); index++) {
602 digit = (AliPHOSDigit * ) digits->At(index) ;
603 if(digit->GetId() > maxEmc){
604 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
605 << setw(6) << digit->GetIndexInList() << " "
606 << setw(5) << digit->GetNprimary() <<" ";
609 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
610 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
618 //__________________________________________________________________
619 void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
621 // we set title (comment) of the SDigits branch in the first! header file
622 if( strcmp(GetName(), "") == 0 )
625 AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
628 //__________________________________________________________________
629 Float_t AliPHOSDigitizer::TimeOfNoise(void)
630 { // Calculates the time signal generated by noise
631 //to be rewritten, now returns just big number
635 //____________________________________________________________________________
636 void AliPHOSDigitizer::Reset()
638 // sets current event number to the first simulated event
640 if( strcmp(GetName(), "") == 0 )
644 // for(inputs = 0; inputs < fNinputs ;inputs++)
645 // fIevent->AddAt(-1, inputs ) ;
649 //____________________________________________________________________________
650 void AliPHOSDigitizer::WriteDigits(Int_t event)
653 // Makes TreeD in the output file.
654 // Check if branch already exists:
655 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
656 // already existing branches.
657 // else creates branch with Digits, named "PHOS", title "...",
658 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
659 // and names of files, from which digits are made.
661 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
662 TClonesArray * digits = gime->Digits(GetName()) ;
667 treeD = fARD->GetTreeD() ;
669 treeD = gAlice->TreeD();
671 // create new branches
672 // -- generate file name if necessary
674 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
675 file = new char[strlen(gAlice->GetBaseFile())+20] ;
676 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
679 TDirectory *cwd = gDirectory;
680 // -- create Digits branch
681 Int_t bufferSize = 32000 ;
682 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
683 digitsBranch->SetTitle(GetName());
685 digitsBranch->SetFile(file);
686 TIter next( digitsBranch->GetListOfBranches());
688 while ((sbr=(TBranch*)next())) {
694 // -- Create Digitizer branch
695 Int_t splitlevel = 0 ;
696 AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
697 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
698 digitizerBranch->SetTitle(GetName());
700 digitizerBranch->SetFile(file);
701 TIter next( digitizerBranch->GetListOfBranches());
703 while ((sbr=(TBranch*)next())) {
709 digitsBranch->Fill() ;
710 digitizerBranch->Fill() ;
712 treeD->Write(0,kOverwrite) ;