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 fPPSDNoise = 0.0000001;
93 fPPSDDigitThreshold = 0.0000002 ;
95 fPedestal = 0.; // Calibration parameters
97 fARD = 0 ; // We work in the standalong mode
100 //____________________________________________________________________________
101 AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name)
105 SetTitle(headerFile) ;
107 fEMCDigitThreshold = 0.01 ;
109 fCPVDigitThreshold = 0.09 ;
110 fPPSDNoise = 0.0000001;
111 fPPSDDigitThreshold = 0.0000002 ;
113 fPedestal = 0.; // Calibration parameters
115 fARD = 0 ; // We work in the standalong mode
121 //____________________________________________________________________________
122 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard)
127 SetTitle("aliroot") ;
130 fEMCDigitThreshold = 0.01 ;
132 fCPVDigitThreshold = 0.09 ;
133 fPPSDNoise = 0.0000001;
134 fPPSDDigitThreshold = 0.0000002 ;
136 fPedestal = 0.; // Calibration parameters
143 //____________________________________________________________________________
144 AliPHOSDigitizer::~AliPHOSDigitizer()
151 //____________________________________________________________________________
152 void AliPHOSDigitizer::Digitize(const Int_t event)
155 // Makes the digitization of the collected summable digits.
156 // It first creates the array of all PHOS modules
157 // filled with noise (different for EMC, CPV and PPSD) and
158 // then adds contributions from SDigits.
159 // This design avoids scanning over the list of digits to add
160 // contribution to new SDigits only.
162 if( strcmp(GetName(), "") == 0 )
165 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
166 TClonesArray * digits = gime->Digits(GetName()) ;
170 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
172 //Making digits with noise, first EMC
173 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
178 TString name = geom->GetName() ;
180 if ( name == "IHEP" || name == "MIXT" )
181 nCPV =nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
182 geom->GetNCPVModules()*geom->GetNumberOfCPVLayers() ;
186 if ( name == "GPS2" || name == "MIXT" )
187 nPPSD =nCPV+2*geom->GetNPPSDModules()*geom->GetNumberOfModulesPhi()*geom->GetNumberOfModulesZ()*
188 geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsZ() ;
193 digits->Expand(nPPSD) ;
196 // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD)
197 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
198 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
200 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
203 for(absID = 1; absID <= nEMC; absID++){
204 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
205 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
208 for(absID = nEMC+1; absID <= nCPV; absID++){
209 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
210 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
213 for(absID = nCPV+1; absID <= nPPSD; absID++){
214 Float_t noise = gRandom->Gaus(0., fPPSDNoise) ;
215 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
218 // loop through the sdigits posted to the White Board and add them to the noise
219 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
220 TIter next(folderslist) ;
221 TFolder * folder = 0 ;
222 TClonesArray * sdigits = 0 ;
224 while ( (folder = (TFolder*)next()) ) {
225 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
226 cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
227 << GetName() << " from " << folder->GetName() << endl ;
228 Int_t primaryoffset ;
230 primaryoffset = fARD->GetMask(input) ;
232 primaryoffset = 10000000*input ;
235 AliPHOSDigit * curSDigit ;
236 AliPHOSDigit * digit ;
237 for ( index = 0 ; index < sdigits->GetEntriesFast(); index++) {
238 curSDigit = (AliPHOSDigit*)sdigits->At(index) ;
239 curSDigit->ShiftPrimary(primaryoffset) ;
240 digit = (AliPHOSDigit*)digits->At(curSDigit->GetId() - 1 ) ;
241 *digit = *digit + *curSDigit ;
246 //remove digits below thresholds
247 for(absID = 0; absID < nEMC ; absID++)
248 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
249 digits->RemoveAt(absID) ;
251 for(absID = nEMC; absID < nCPV ; absID++)
252 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
253 digits->RemoveAt(absID) ;
255 for(absID = nCPV; absID < nPPSD ; absID++)
256 if(sDigitizer->Calibrate(((AliPHOSDigit *)digits->At(absID))->GetAmp()) < fPPSDDigitThreshold)
257 digits->RemoveAt(absID) ;
261 Int_t ndigits = digits->GetEntriesFast() ;
262 digits->Expand(ndigits) ;
264 //Set indexes in list of digits
266 for (i = 0 ; i < ndigits ; i++) {
267 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
268 digit->SetIndexInList(i) ;
273 //____________________________________________________________________________
274 void AliPHOSDigitizer::Exec(Option_t *option)
278 if( strcmp(GetName(), "") == 0 )
281 if (strstr(option,"print")) {
286 if(strstr(option,"tim"))
287 gBenchmark->Start("PHOSDigitizer");
289 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
296 treeD = fARD->GetTreeD() ;
297 nevents = 1 ; // Will process only one event
300 gAlice->GetEvent(0) ;
301 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
302 treeD=gAlice->TreeD() ;
305 cerr << " AliPHOSDigitizer :: Can not find TreeD " << endl ;
309 //Check, if this branch already exits
310 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
312 TBranch * branch = 0 ;
313 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
315 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
316 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
317 (strcmp(branch->GetTitle(), GetName())==0) )
320 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
321 (strcmp(branch->GetTitle(), GetName())==0) )
322 digitizerfound = kTRUE ;
326 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
327 << " already exits" << endl ;
330 if ( digitizerfound ) {
331 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
332 << " already exits" << endl ;
338 for(ievent = 0; ievent < nevents; ievent++){
342 for(input = 0 ; input < fARD->GetNinputs(); input ++){
343 TTree * treeS = fARD->GetInputTreeS(input) ;
345 cerr << "AliPHOSDigitizer -> No Input " << endl ;
348 gime->ReadTreeS(treeS,input) ;
352 gime->Event(ievent,"S") ;
354 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
356 WriteDigits(ievent) ;
358 if(strstr(option,"deb"))
362 if(strstr(option,"tim")){
363 gBenchmark->Stop("PHOSDigitizer");
364 cout << "AliPHOSDigitizer:" << endl ;
365 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
366 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
372 //____________________________________________________________________________
373 Bool_t AliPHOSDigitizer::Init()
375 // Makes all memory allocations
376 // Adds Digitizer task to the folder of PHOS tasks
377 //============================================================= YS
378 // The initialisation is now done by AliPHOSGetter
380 if( strcmp(GetTitle(), "") == 0 )
381 SetTitle("galice.root") ;
383 // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array
384 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.
386 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
388 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
392 // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
393 gime->PostDigits(GetName() ) ;
395 //add Task to //YSAlice/tasks/Digitizer/PHOS
396 gime->PostDigitizer(this) ;
398 //Mark that we will use current header file
400 gime->PostSDigits(GetName(),GetTitle()) ;
401 gime->PostSDigitizer(GetName(),GetTitle()) ;
406 //__________________________________________________________________
407 void AliPHOSDigitizer::MixWith(const char* headerFile)
409 // Allows to produce digits by superimposing background and signal event.
410 // It is assumed, that headers file with SIGNAL events is opened in
412 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
413 // Thus we avoid writing (changing) huge and expensive
414 // backgound files: all output will be writen into SIGNAL, i.e.
415 // opened in constructor file.
417 // One can open as many files to mix with as one needs.
418 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
421 if( strcmp(GetName(), "") == 0 )
425 cout << "Can not use this method under AliRunDigitizer " << endl ;
429 // check if the specified SDigits do not already exist on the White Board:
430 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
432 TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ;
436 if ( gROOT->FindObjectAny(path.Data()) ) {
437 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
441 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
442 gime->PostSDigits(GetName(),headerFile) ;
444 // check if the requested file is already open or exist and if SDigits Branch exist
445 TFile * file = (TFile*)gROOT->FindObject(headerFile);
447 file = new TFile(headerFile, "READ") ;
449 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
456 //__________________________________________________________________
457 void AliPHOSDigitizer::Print(Option_t* option)const {
458 // Print Digitizer's parameters
459 if( strcmp(GetName(), "") != 0 ){
461 cout << "------------------- "<< GetName() << " -------------" << endl ;
462 cout << "Digitizing sDigits from file(s): " <<endl ;
464 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
465 TIter next(folderslist) ;
466 TFolder * folder = 0 ;
468 while ( (folder = (TFolder*)next()) ) {
469 if ( folder->FindObject(GetName()) )
470 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
473 cout << "Writing digits to " << GetTitle() << endl ;
476 cout << "With following parameters: " << endl ;
477 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
478 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
479 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
480 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
481 cout << " Noise in PPSD (fPPSDNoise) = " << fPPSDNoise << endl ;
482 cout << " Threshold in PPSD (fPPSDDigitThreshold) = " << fPPSDDigitThreshold << endl ;
483 cout << "---------------------------------------------------" << endl ;
486 cout << "AliPHOSDigitizer not initialized " << endl ;
489 //__________________________________________________________________
490 void AliPHOSDigitizer::PrintDigits(Option_t * option){
491 // Print a table of digits
493 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
494 TClonesArray * digits = gime->Digits() ;
496 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
497 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
500 fDigitsInRun += digits->GetEntriesFast() ;
502 if(strstr(option,"all")){
505 AliPHOSDigit * digit;
506 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
508 for (index = 0 ; index < digits->GetEntries() ; index++) {
509 digit = (AliPHOSDigit * ) digits->At(index) ;
510 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
511 << setw(6) << digit->GetIndexInList() << " "
512 << setw(5) << digit->GetNprimary() <<" ";
515 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
516 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
523 //__________________________________________________________________
524 void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
526 // we set title (comment) of the SDigits branch in the first! header file
527 if( strcmp(GetName(), "") == 0 )
530 AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
533 //____________________________________________________________________________
534 void AliPHOSDigitizer::Reset()
536 // sets current event number to the first simulated event
538 if( strcmp(GetName(), "") == 0 )
542 // for(inputs = 0; inputs < fNinputs ;inputs++)
543 // fIevent->AddAt(-1, inputs ) ;
547 //____________________________________________________________________________
548 void AliPHOSDigitizer::WriteDigits(Int_t event)
551 // Makes TreeD in the output file.
552 // Check if branch already exists:
553 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
554 // already existing branches.
555 // else creates branch with Digits, named "PHOS", title "...",
556 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
557 // and names of files, from which digits are made.
559 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
560 TClonesArray * digits = gime->Digits(GetName()) ;
565 treeD = fARD->GetTreeD() ;
567 treeD = gAlice->TreeD();
569 // create new branches
570 // -- generate file name if necessary
572 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
573 file = new char[strlen(gAlice->GetBaseFile())+20] ;
574 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
577 TDirectory *cwd = gDirectory;
578 // -- create Digits branch
579 Int_t bufferSize = 32000 ;
580 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
581 digitsBranch->SetTitle(GetName());
583 digitsBranch->SetFile(file);
584 TIter next( digitsBranch->GetListOfBranches());
586 while ((sbr=(TBranch*)next())) {
592 // -- Create Digitizer branch
593 Int_t splitlevel = 0 ;
594 AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
595 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
596 digitizerBranch->SetTitle(GetName());
598 digitizerBranch->SetFile(file);
599 TIter next( digitizerBranch->GetListOfBranches());
601 while ((sbr=(TBranch*)next())) {
607 digitsBranch->Fill() ;
608 digitizerBranch->Fill() ;
610 treeD->Write(0,kOverwrite) ;