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 // This is a TTask that constructs SDigits out of Hits
20 // A Summable Digits is the sum of all hits in a cell
21 // A threshold is applied
23 //*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
24 //////////////////////////////////////////////////////////////////////////////
25 // Class performs digitization of Summable digits (in the PHOS case this is just
26 // sum of contributions of all primary particles into give cell).
27 // In addition it performs mixing of summable digits from different events.
29 // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
30 // root[1] d->ExecuteTask()
31 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
32 // //Digitizes SDigitis in all events found in file galice.root
33 // //Depending on variable "CONFIG_SPLIT_FILE" reads branches stored in galice.root
34 // //or in PHOS.SDigits.root
35 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ; // Will read sdigits from galice1.root
36 // root[3] d1->MixWith("galice2.root",1) // Reads another portion of sdigits from galice2.root
37 // // says, that this will be output file
38 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
39 // root[3] d1->MixWith("galice3.root",1) // Reads another portion of sdigits from galice3.root
40 // // overwrides previous definition of output file
41 // root[4] d->ExecuteTask() // Reads SDigits from files galice1.root, galice2.root ....
42 // // mixes them and stores produced Digits in file galice3.root
47 // --- ROOT system ---
51 // --- Standard library ---
53 // --- AliRoot header files ---
55 #include "AliPHOSDigit.h"
56 #include "AliPHOSHit.h"
57 #include "AliPHOSv1.h"
58 #include "AliPHOSDigitizer.h"
59 #include "AliPHOSSDigitizer.h"
63 ClassImp(AliPHOSDigitizer)
66 //____________________________________________________________________________
67 AliPHOSDigitizer::AliPHOSDigitizer():TTask("AliPHOSDigitizer","")
74 fEMCDigitThreshold = 0.01 ;
76 fCPVDigitThreshold = 0.09 ;
77 fPPSDNoise = 0.0000001;
78 fPPSDDigitThreshold = 0.0000002 ;
79 fInitialized = kFALSE ;
80 // add Task to //root/Tasks folder
81 TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
82 roottasks->Add(this) ;
85 //____________________________________________________________________________
86 void AliPHOSDigitizer::Init(Int_t isOutFile){
87 // Mades all memory allocations and defiles,
88 // whether first (default) file will be output file (isOutFile !=0)
92 fHeaderFiles = new TClonesArray("TObjString",1) ;
93 new((*fHeaderFiles)[0]) TObjString("galice.root") ;
97 file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ;
99 file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString()) ;
103 fSDigitsFiles = new TClonesArray("TObjString",1);
104 if(gSystem->Getenv("CONFIG_SPLIT_FILE"))
105 new((*fSDigitsFiles)[0]) TObjString("./PHOS.SDigits.root") ;
107 new((*fSDigitsFiles)[0]) TObjString("") ;
109 fSDigits = new TClonesArray("TClonesArray",1) ;
110 new((*fSDigits)[0]) TClonesArray("AliPHOSDigit",1000) ;
112 fDigits = new TClonesArray("AliPHOSDigit",200000) ;
114 fIevent = new TArrayI(1) ;
115 fIevent->AddAt(-1,0 ) ;
116 fIeventMax = new TArrayI(1) ;
118 //Store digits in this file
120 gAlice = (AliRun *) file->Get("gAlice") ;
121 fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
125 TTree * te = (TTree *) file->Get("TE") ;
126 fIeventMax->AddAt((Int_t) te->GetEntries(), 0 );
127 fOutFileNumber = -1 ;
130 fInitialized = kTRUE ;
136 //____________________________________________________________________________
137 AliPHOSDigitizer::AliPHOSDigitizer(char *HeaderFile,char *DigitsFile):TTask("AliPHOSDigitizer","")
140 fHeaderFiles = new TClonesArray("TFile",1) ;
141 new((*fHeaderFiles)[0]) TObjString(HeaderFile) ;
142 TFile * file = new TFile(((TObjString *) fHeaderFiles->At(0))->GetString(),"update") ; // Header file, where result will be stored
146 fSDigitsFiles = new TClonesArray("TObjString",1); // File name of the SDigits branch
148 new((*fSDigitsFiles)[0]) TObjString(DigitsFile) ;
150 if(gSystem->Getenv("CONFIG_SPLIT_FILE"))
151 new((*fSDigitsFiles)[0]) TObjString("./PHOS.SDigits.root") ;
153 new((*fSDigitsFiles)[0]) TObjString("") ;
155 fSDigits = new TClonesArray("TClonesArray",1) ; // here list of SDigits wil be stored
156 new((*fSDigits)[0]) TClonesArray("AliPHOSDigit",1000) ;
158 fDigits = new TClonesArray("AliPHOSDigit",200000) ;
159 fDigitsFile="PHOS.Digits" ;
161 fIevent = new TArrayI(1) ;
162 fIevent->AddAt(-1,0 ) ;
163 fIeventMax = new TArrayI(1) ;
164 //Should be check whether gAlice in memory is the same as in file
165 //However, there is no such method (?) ==> we are forced to read it
166 // if(gAlice->TreeE()==0)
168 gAlice = (AliRun *) file->Get("gAlice") ; //If not read yet
170 // Get number of events to process
171 fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
177 fEMCDigitThreshold = 0.01 ;
179 fCPVDigitThreshold = 0.09 ;
180 fPPSDNoise = 0.0000001;
181 fPPSDDigitThreshold = 0.0000002 ;
183 // add Task to //root/Tasks folder
184 TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
185 roottasks->Add(this) ;
186 fInitialized = kTRUE ;
190 //____________________________________________________________________________
191 AliPHOSDigitizer::~AliPHOSDigitizer()
194 delete fHeaderFiles ;
195 delete fSDigitsFiles ;
199 //____________________________________________________________________________
200 Bool_t AliPHOSDigitizer::Combinator() {
202 //Makes all desirable combinations Signal+Background,
203 // returns kFALSE when all combinations are made
204 // May be useful to introduce some options like "One-to-One", "All-to-One" and "All-to-All" ?
206 //realizing "One-to-One" option...
212 Bool_t endNotReached = kTRUE ;
214 for(inputs = 0; (inputs < fNinputs) && endNotReached ;inputs++){
215 if(fIevent->At(inputs)+1 < fIeventMax->At(inputs))
216 fIevent->AddAt(fIevent->At(inputs)+1, inputs ) ;
218 endNotReached = kFALSE ;
220 return endNotReached ;
224 //____________________________________________________________________________
225 void AliPHOSDigitizer::Digitize(Option_t *option) {
227 //Makes the digitization of the collected summable digits
232 //Collects all hits in the same active volume into digit
233 //if(option == "raw") // add simulated data to row data -- to be implemented
238 AliPHOS * PHOS = (AliPHOS *) gAlice->GetDetector("PHOS") ;
239 AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance( PHOS->GetGeometry()->GetName(), PHOS->GetGeometry()->GetTitle() );
241 //Making digits with noise, first EMC
242 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
247 TString name = geom->GetName() ;
249 if ( name == "IHEP" || name == "MIXT" )
250 nCPV =nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
251 geom->GetNCPVModules()*geom->GetNumberOfCPVLayers() ;
255 if ( name == "GPS2" || name == "MIXT" )
256 nPPSD =nCPV+2*geom->GetNPPSDModules()*geom->GetNumberOfModulesPhi()*geom->GetNumberOfModulesZ()*
257 geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsZ() ;
261 for(absID = 1; absID <= nEMC; absID++){
262 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
263 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
266 for(absID = nEMC+1; absID <= nCPV; absID++){
267 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
268 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
271 for(absID = nCPV+1; absID <= nPPSD; absID++){
272 Float_t noise = gRandom->Gaus(0., fPPSDNoise) ;
273 new((*fDigits)[absID-1]) AliPHOSDigit( -1,absID,fSDigitizer->Digitize(noise) ) ;
277 // Now look throught (unsorted) list of SDigits and add corresponding digits
278 AliPHOSDigit *curSDigit ;
279 AliPHOSDigit *digit ;
282 for(inputs = 0; inputs< fNinputs ; inputs++){ //loop over (possible) merge sources
284 TClonesArray * sdigits= (TClonesArray *)fSDigits->At(inputs) ;
286 Int_t nSDigits = sdigits->GetEntries() ;
287 for(isdigit=0;isdigit< nSDigits; isdigit++){
288 curSDigit = (AliPHOSDigit *)sdigits->At(isdigit) ;
289 if(inputs) //Shift primaries for non-background sdigits
290 curSDigit->ShiftPrimary(inputs) ;
291 digit = (AliPHOSDigit *)fDigits->At(curSDigit->GetId() - 1);
292 *digit = *digit + *curSDigit ;
298 //remove digits below thresholds
299 for(absID = 0; absID < nEMC ; absID++)
300 if(fSDigitizer->Calibrate(((AliPHOSDigit*)fDigits->At(absID))->GetAmp()) < fEMCDigitThreshold)
301 fDigits->RemoveAt(absID) ;
302 for(absID = nEMC; absID < nCPV ; absID++)
303 if(fSDigitizer->Calibrate(((AliPHOSDigit*)fDigits->At(absID))->GetAmp()) < fCPVDigitThreshold)
304 fDigits->RemoveAt(absID) ;
305 for(absID = nCPV; absID < nPPSD ; absID++)
306 if(fSDigitizer->Calibrate(((AliPHOSDigit *)fDigits->At(absID))->GetAmp()) < fPPSDDigitThreshold)
307 fDigits->RemoveAt(absID) ;
309 fDigits->Compress() ;
311 Int_t ndigits = fDigits->GetEntries() ;
312 fDigits->Expand(ndigits) ;
315 //Set indexes in list of digits
317 for (i = 0 ; i < ndigits ; i++) {
318 AliPHOSDigit * digit = (AliPHOSDigit *) fDigits->At(i) ;
319 digit->SetIndexInList(i) ;
322 //____________________________________________________________________________
323 void AliPHOSDigitizer::WriteDigits(){
325 //Made TreeD in the output file if necessary and writes digiths there.
327 gAlice->GetEvent(fIevent->At(fOutFileNumber)) ; // Suitable only for One-To-One mixing
328 gAlice->SetEvent(fIevent->At(fOutFileNumber)) ; // for all-to-all will produce a lot of branches in TreeD
330 if(gAlice->TreeD()==0)
331 gAlice->MakeTree("D") ;
333 //Make branches in TreeD for digits and Digitizer
335 sprintf(branchname,"PHOS");
337 Int_t bufferSize = 16000 ;
339 if(!fDigitsFile.IsNull())
340 filename = (char*) fDigitsFile.Data() ; //ievent ;
342 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
343 filename = new char[30] ;
344 // sprintf(filename,"PHOS.Digits%d.root",ievent) ;
345 sprintf(filename,"PHOS.Digits.root") ;
351 gAlice->MakeBranchInTree(gAlice->TreeD(),branchname,&fDigits,bufferSize,filename);
353 AliPHOSDigitizer * d = this ;
354 Int_t splitlevel = 0 ;
355 sprintf(branchname,"AliPHOSDigitizer");
356 gAlice->MakeBranchInTree(gAlice->TreeD(),branchname,"AliPHOSDigitizer",&d, bufferSize, splitlevel,filename);
358 gAlice->TreeD()->Fill() ;
360 gAlice->TreeD()->Write(0,kOverwrite) ;
363 //____________________________________________________________________________
364 void AliPHOSDigitizer::Exec(Option_t *option) {
367 if(!fInitialized) Init(1) ;
371 if(!ReadSDigits()) //read sdigits event(s) evaluated by Combinator() from file(s)
374 Digitize(option) ; //Add prepared SDigits to digits and add the noise
378 // //Close all opened files
380 // for(input = 0; input < fNinputs ; input ++){
381 // TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(input))->GetString() ) ;
388 //__________________________________________________________________
389 Bool_t AliPHOSDigitizer::ReadSDigits(){
390 // Reads summable digits from the opened files for the particular set of events given by fIevent
392 if(!fInitialized) Init(1) ;
395 for(inputs = fNinputs-1; inputs >= 0; inputs --){
397 Int_t event = fIevent->At(inputs) ;
399 TFile * file = (TFile*) gROOT->GetFile(((TObjString *) fHeaderFiles->At(inputs))->GetString() ) ;
402 // Get SDigits Tree header from file
404 sprintf(treeName,"TreeS%d",event);
405 TTree * treeS = (TTree*)file->Get(treeName);
408 cout << "Error at AliPHOSDigitizer: no "<<treeName << " in file " << file->GetName() << endl ;
409 cout << "Do nothing " << endl ;
413 TBranch * sdigitsBranch = 0;
414 TBranch * sdigitizerBranch = 0;
416 TObjArray * branches = treeS->GetListOfBranches() ;
418 Bool_t phosNotFound = kTRUE ;
419 Bool_t sdigitizerNotFound = kTRUE ;
421 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
424 sdigitsBranch=(TBranch *) branches->At(ibranch) ;
425 if( ((TObjString*)fSDigitsFiles->At(inputs))->GetString().CompareTo(sdigitsBranch->GetFileName())==0 ){
426 if( strcmp(sdigitsBranch->GetName(),"PHOS") == 0) {
427 phosNotFound = kFALSE ;
432 if(sdigitizerNotFound){
433 sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
434 if( ((TObjString*)fSDigitsFiles->At(inputs))->GetString().CompareTo(sdigitizerBranch->GetFileName()) == 0){
435 if( strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) {
436 sdigitizerNotFound = kFALSE ;
443 if(sdigitizerNotFound || phosNotFound){
444 cout << "Can't find Branch with sdigits or SDigitizer in the file " ;
445 if( ((TObjString*)fSDigitsFiles->At(inputs))->GetString().IsNull() )
446 cout << file->GetName() << endl ;
448 cout << ((TObjString*)fSDigitsFiles->At(inputs))->GetString().Data() << endl ;
449 cout << "Do nothing" <<endl ;
454 TClonesArray * sdigits = (TClonesArray*) fSDigits->At(inputs) ;
455 sdigitsBranch->SetAddress(&sdigits) ;
457 AliPHOSSDigitizer *sDigitizer = new AliPHOSSDigitizer();
458 sdigitizerBranch->SetAddress(&sDigitizer) ;
462 fSDigitizer = sDigitizer ;
464 if(!((*fSDigitizer)==(*sDigitizer)) ){
465 cout << "ERROR: you are using sdigits made with different SDigitizers" << endl ;
466 fSDigitizer->Print("") ;
467 sDigitizer->Print("") ;
468 cout << "Do Nothing " << endl ;
478 //__________________________________________________________________
479 void AliPHOSDigitizer::MixWith(char* HeaderFile,Int_t isOutFile, char* SDigitsFile){
484 Init(0) ; //Do not read gAlice from Background file
486 Init(1) ; //read gAlice from background file
489 cout << "Specify at least header file to merge"<< endl ;
494 for(inputs = 0; inputs < fNinputs ; inputs++){
495 if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){
496 if(SDigitsFile == 0){
497 if(((TObjString*)fSDigitsFiles->At(inputs))->GetString().CompareTo("") == 0){
498 cout << "Entry already exists, do not add" << endl ;
503 if(((TObjString*)fSDigitsFiles->At(inputs))->GetString().CompareTo(SDigitsFile) == 0){
504 cout << "Entry already exists, do not add" << endl ;
510 fHeaderFiles->Expand(fNinputs+1) ;
511 new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ;
516 file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString(),"update") ;
518 file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ;
522 fSDigitsFiles->Expand(fNinputs+1) ;
523 new((*fSDigitsFiles)[fNinputs]) TObjString(SDigitsFile) ;
525 fSDigits->Expand(fNinputs+1) ;
526 new((*fSDigits)[fNinputs]) TClonesArray("AliPHOSDigit",1000) ;
528 fIevent->Set(fNinputs+1) ;
529 fIevent->AddAt(-1, fNinputs) ;
531 fIeventMax->Set(fNinputs+1) ;
534 gAlice = (AliRun*) file->Get("gAlice") ;
535 fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), fNinputs );
536 fOutFileNumber = fNinputs ;
539 TTree * te = (TTree *) file->Get("TE") ;
540 fIeventMax->AddAt((Int_t) te->GetEntries(), fNinputs );
546 //__________________________________________________________________
547 void AliPHOSDigitizer::Print(Option_t* option){
549 if(!fInitialized) Init(1) ;
551 cout << "------------------- "<< GetName() << " -------------" << endl ;
552 cout << "Digitizing sDigits from file(s): " <<endl ;
554 for(input = 0; input < fNinputs ; input++) {
555 cout << " " << ((TObjString *) fHeaderFiles->At(input))->GetString() <<
556 " Branch: " << ((TObjString *) fSDigitsFiles->At(input))->GetString() << endl ;
559 cout << "Writing digits to " << ((TObjString *) fHeaderFiles->At(fOutFileNumber))->GetString() << endl ;
562 cout << "With following parameters: " << endl ;
563 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
564 cout << " Threshold in EMC (fEMCDigitThreshold) = " << fEMCDigitThreshold << endl ; ;
565 cout << " Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ;
566 cout << " Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ;
567 cout << " Noise in PPSD (fPPSDNoise) = " << fPPSDNoise << endl ;
568 cout << " Threshold in PPSD (fPPSDDigitThreshold) = " << fPPSDDigitThreshold << endl ;
569 cout << "---------------------------------------------------" << endl ;