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"
79 #include "AliPHOSTick.h"
81 ClassImp(AliPHOSDigitizer)
84 //____________________________________________________________________________
85 AliPHOSDigitizer::AliPHOSDigitizer()
90 fEMCDigitThreshold = 0.01 ;
92 fCPVDigitThreshold = 0.09 ;
93 fTimeResolution = 1.0e-9 ;
94 fTimeSignalLength = 1.0e-9 ;
96 fPedestal = 0.; // Calibration parameters
98 fTimeThreshold = 0.001*fSlope ; //Means 1 MeV in terms of SDigits amplitude
99 fARD = 0 ; // We work in the standalong mode
102 //____________________________________________________________________________
103 AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name)
107 SetTitle(headerFile) ;
109 fEMCDigitThreshold = 0.01 ;
111 fCPVDigitThreshold = 0.09 ;
113 fPedestal = 0.; // Calibration parameters
115 fTimeSignalLength = 1.0e-9 ;
116 fTimeThreshold = 0.001*fSlope ; //Means 1 MeV in terms of SDigits amplitude
117 fARD = 0 ; // We work in the standalong mode
123 //____________________________________________________________________________
124 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * ard)
129 SetTitle("aliroot") ;
132 fEMCDigitThreshold = 0.01 ;
134 fCPVDigitThreshold = 0.09 ;
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();
177 TString name = geom->GetName() ;
179 nCPV = nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
180 geom->GetNModules() ;
182 digits->Expand(nCPV) ;
185 // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD)
186 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
187 const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName());
189 cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
193 // loop through the sdigits posted to the White Board and add them to the noise
194 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
195 TIter next(folderslist) ;
196 TFolder * folder = 0 ;
197 TClonesArray * sdigits = 0 ;
199 TObjArray * sdigArray = new TObjArray(2) ;
200 while ( (folder = (TFolder*)next()) )
201 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
202 cout << "INFO: AliPHOSDigitizer::Digitize -> Adding SDigits "
203 << GetName() << " from " << folder->GetName() << endl ;
204 sdigArray->AddAt(sdigits, input) ;
208 //Find the first crystall with sygnal
209 Int_t nextSig = 200000 ;
211 for(i=0; i<input; i++){
212 sdigits = (TClonesArray *)sdigArray->At(i) ;
213 Int_t curNext = ((AliPHOSDigit *)sdigits->At(0))->GetId() ;
214 if(curNext < nextSig) nextSig = curNext ;
217 TArrayI index(input) ;
218 index.Reset() ; //Set all indexes to zero
220 AliPHOSDigit * digit ;
221 AliPHOSDigit * curSDigit ;
223 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
225 //Put Noise contribution
226 for(absID = 1; absID <= nEMC; absID++){
227 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
228 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
229 //look if we have to add signal?
231 //Add SDigits from all inputs
232 digit = (AliPHOSDigit *) digits->At(absID-1) ;
236 Float_t a = digit->GetAmp() ;
237 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
238 //Mark the beginnign of the signal
239 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
240 //Mark the end of the ignal
241 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
244 for(i=0; i<input; i++){
245 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
246 //May be several digits will contribute from the same input
247 while(curSDigit && curSDigit->GetId() == absID){
248 //Shift primary to separate primaries belonging different inputs
249 Int_t primaryoffset ;
251 primaryoffset = fARD->GetMask(i) ;
253 primaryoffset = 10000000*i ;
254 curSDigit->ShiftPrimary(primaryoffset) ;
256 a = curSDigit->GetAmp() ;
257 b = a /fTimeSignalLength ;
258 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
259 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
261 *digit = *digit + *curSDigit ; //add energies
264 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
268 //calculate and set time
269 Float_t time = FrontEdgeTime(ticks) ;
270 digit->SetTime(time) ;
272 //Find next signal module
274 for(i=0; i<input; i++){
275 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
276 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
277 if(curNext < nextSig) nextSig = curNext ;
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?
292 digit = (AliPHOSDigit *) digits->At(absID-1) ;
293 //Add SDigits from all inputs
294 for(i=0; i<input; i++){
295 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
296 //May be several digits will contribute from the same input
297 while(curSDigit && curSDigit->GetId() == absID){
298 //Shift primary to separate primaries belonging different inputs
299 Int_t primaryoffset ;
301 primaryoffset = fARD->GetMask(i) ;
303 primaryoffset = 10000000*i ;
304 curSDigit->ShiftPrimary(primaryoffset) ;
307 *digit = *digit + *curSDigit ;
309 curSDigit = (AliPHOSDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
313 //Find next signal module
314 for(i=0; i<input; i++){
315 sdigits = (TClonesArray *)sdigArray->At(i) ;
316 Int_t curNext = ((AliPHOSDigit *) sdigits->At(index[i]))->GetId() ;
317 if(curNext < nextSig) nextSig = curNext ;
322 delete sdigArray ; //We should not delete its contents
326 //remove digits below thresholds
327 for(absID = 0; absID < nEMC ; absID++)
328 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
329 digits->RemoveAt(absID) ;
331 for(absID = nEMC; absID < nCPV ; absID++)
332 if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
333 digits->RemoveAt(absID) ;
337 Int_t ndigits = digits->GetEntriesFast() ;
338 digits->Expand(ndigits) ;
340 //Set indexes in list of digits
341 for (i = 0 ; i < ndigits ; i++) {
342 AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ;
343 digit->SetIndexInList(i) ;
348 //____________________________________________________________________________
349 void AliPHOSDigitizer::Exec(Option_t *option)
353 if( strcmp(GetName(), "") == 0 )
356 if (strstr(option,"print")) {
361 if(strstr(option,"tim"))
362 gBenchmark->Start("PHOSDigitizer");
364 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
371 treeD = fARD->GetTreeD() ;
372 nevents = 1 ; // Will process only one event
375 gAlice->GetEvent(0) ;
376 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
377 treeD=gAlice->TreeD() ;
380 cerr << " AliPHOSDigitizer :: Can not find TreeD " << endl ;
384 //Check, if this branch already exits
385 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
387 TBranch * branch = 0 ;
388 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
390 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
391 if ( (strcmp(branch->GetName(), "PHOS")==0) &&
392 (strcmp(branch->GetTitle(), GetName())==0) )
395 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) &&
396 (strcmp(branch->GetTitle(), GetName())==0) )
397 digitizerfound = kTRUE ;
401 cerr << "WARNING: AliPHOSDigitizer -> Digits branch with name " << GetName()
402 << " already exits" << endl ;
405 if ( digitizerfound ) {
406 cerr << "WARNING: AliPHOSDigitizer -> Digitizer branch with name " << GetName()
407 << " already exits" << endl ;
413 for(ievent = 0; ievent < nevents; ievent++){
417 for(input = 0 ; input < fARD->GetNinputs(); input ++){
418 TTree * treeS = fARD->GetInputTreeS(input) ;
420 cerr << "AliPHOSDigitizer -> No Input " << endl ;
423 gime->ReadTreeS(treeS,input) ;
427 gime->Event(ievent,"S") ;
429 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
431 WriteDigits(ievent) ;
433 if(strstr(option,"deb"))
437 if(strstr(option,"tim")){
438 gBenchmark->Stop("PHOSDigitizer");
439 cout << "AliPHOSDigitizer:" << endl ;
440 cout << " took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for Digitizing "
441 << gBenchmark->GetCpuTime("PHOSDigitizer")/nevents << " seconds per event " << endl ;
447 //____________________________________________________________________________
448 Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks)
450 ticks->Sort() ; //Sort in accordance with times of ticks
452 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
453 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
456 while((t=(AliPHOSTick*) it.Next())){
457 if(t->GetTime() < time) //This tick starts before crossing
462 time = ctick->CrossingTime(fTimeThreshold) ;
466 //____________________________________________________________________________
467 Bool_t AliPHOSDigitizer::Init()
469 // Makes all memory allocations
470 // Adds Digitizer task to the folder of PHOS tasks
471 //============================================================= YS
472 // The initialisation is now done by AliPHOSGetter
474 if( strcmp(GetTitle(), "") == 0 )
475 SetTitle("galice.root") ;
477 // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array
478 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.
480 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
482 cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
486 // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
487 gime->PostDigits(GetName() ) ;
489 //add Task to //YSAlice/tasks/Digitizer/PHOS
490 gime->PostDigitizer(this) ;
492 //Mark that we will use current header file
494 gime->PostSDigits(GetName(),GetTitle()) ;
495 gime->PostSDigitizer(GetName(),GetTitle()) ;
500 //__________________________________________________________________
501 void AliPHOSDigitizer::MixWith(const char* headerFile)
503 // Allows to produce digits by superimposing background and signal event.
504 // It is assumed, that headers file with SIGNAL events is opened in
506 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
507 // Thus we avoid writing (changing) huge and expensive
508 // backgound files: all output will be writen into SIGNAL, i.e.
509 // opened in constructor file.
511 // One can open as many files to mix with as one needs.
512 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
515 if( strcmp(GetName(), "") == 0 )
519 cout << "Can not use this method under AliRunDigitizer " << endl ;
523 // check if the specified SDigits do not already exist on the White Board:
524 // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
526 TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ;
530 if ( gROOT->FindObjectAny(path.Data()) ) {
531 cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
535 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
536 gime->PostSDigits(GetName(),headerFile) ;
538 // check if the requested file is already open or exist and if SDigits Branch exist
539 TFile * file = (TFile*)gROOT->FindObject(headerFile);
541 file = new TFile(headerFile, "READ") ;
543 cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
550 //__________________________________________________________________
551 void AliPHOSDigitizer::Print(Option_t* option)const {
552 // Print Digitizer's parameters
553 if( strcmp(GetName(), "") != 0 ){
555 cout << "------------------- "<< GetName() << " -------------" << endl ;
556 cout << "Digitizing sDigits from file(s): " <<endl ;
558 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ;
559 TIter next(folderslist) ;
560 TFolder * folder = 0 ;
562 while ( (folder = (TFolder*)next()) ) {
563 if ( folder->FindObject(GetName()) )
564 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
567 cout << "Writing digits to " << GetTitle() << endl ;
570 cout << "With following parameters: " << endl ;
571 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
572 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
573 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
574 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
575 cout << "---------------------------------------------------" << endl ;
578 cout << "AliPHOSDigitizer not initialized " << endl ;
582 //__________________________________________________________________
583 void AliPHOSDigitizer::PrintDigits(Option_t * option){
584 // Print a table of digits
586 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
587 TClonesArray * digits = gime->Digits() ;
589 cout << "AliPHOSDigitiser: event " << gAlice->GetEvNumber() << endl ;
590 cout << " Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
592 if(strstr(option,"all")||strstr(option,"EMC")){
595 AliPHOSDigit * digit;
596 cout << "Digit Id Amplitude Index " << " Nprim " << " Primaries list " << endl;
597 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
599 for (index = 0 ; (index < digits->GetEntries()) &&
600 (((AliPHOSDigit * ) digits->At(index))->GetId() <= maxEmc) ; index++) {
601 digit = (AliPHOSDigit * ) digits->At(index) ;
602 if(digit->GetNprimary() == 0) continue;
603 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
604 << setw(6) << digit->GetIndexInList() << " "
605 << setw(5) << digit->GetNprimary() <<" ";
608 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
609 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
615 if(strstr(option,"all")||strstr(option,"CPV")){
617 //loop over CPV digits
618 AliPHOSDigit * digit;
619 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
620 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
622 for (index = 0 ; index < digits->GetEntries(); index++) {
623 digit = (AliPHOSDigit * ) digits->At(index) ;
624 if(digit->GetId() > maxEmc){
625 cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " "
626 << setw(6) << digit->GetIndexInList() << " "
627 << setw(5) << digit->GetNprimary() <<" ";
630 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
631 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
639 //__________________________________________________________________
640 void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
642 // we set title (comment) of the SDigits branch in the first! header file
643 if( strcmp(GetName(), "") == 0 )
646 AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ;
649 //__________________________________________________________________
650 Float_t AliPHOSDigitizer::TimeOfNoise(void)
651 { // Calculates the time signal generated by noise
652 //to be rewritten, now returns just big number
656 //____________________________________________________________________________
657 void AliPHOSDigitizer::Reset()
659 // sets current event number to the first simulated event
661 if( strcmp(GetName(), "") == 0 )
665 // for(inputs = 0; inputs < fNinputs ;inputs++)
666 // fIevent->AddAt(-1, inputs ) ;
670 //____________________________________________________________________________
671 void AliPHOSDigitizer::WriteDigits(Int_t event)
674 // Makes TreeD in the output file.
675 // Check if branch already exists:
676 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
677 // already existing branches.
678 // else creates branch with Digits, named "PHOS", title "...",
679 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
680 // and names of files, from which digits are made.
682 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
683 TClonesArray * digits = gime->Digits(GetName()) ;
688 treeD = fARD->GetTreeD() ;
690 treeD = gAlice->TreeD();
692 // create new branches
693 // -- generate file name if necessary
695 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
696 file = new char[strlen(gAlice->GetBaseFile())+20] ;
697 sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
700 TDirectory *cwd = gDirectory;
701 // -- create Digits branch
702 Int_t bufferSize = 32000 ;
703 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
704 digitsBranch->SetTitle(GetName());
706 digitsBranch->SetFile(file);
707 TIter next( digitsBranch->GetListOfBranches());
709 while ((sbr=(TBranch*)next())) {
715 // -- Create Digitizer branch
716 Int_t splitlevel = 0 ;
717 AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
718 TBranch * digitizerBranch = treeD->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
719 digitizerBranch->SetTitle(GetName());
721 digitizerBranch->SetFile(file);
722 TIter next( digitizerBranch->GetListOfBranches());
724 while ((sbr=(TBranch*)next())) {
730 digitsBranch->Fill() ;
731 digitizerBranch->Fill() ;
733 treeD->Write(0,kOverwrite) ;