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 **************************************************************************/
20 /////////////////////////////////////////////////////////////////////
21 // Base simulation functions for ITS //
24 /////////////////////////////////////////////////////////////////////
26 #include "TClonesArray.h"
27 #include "TObjArray.h"
32 #include "AliCDBManager.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBMetaData.h"
38 #include "AliITSdigit.h"
39 #include "AliITSdigitSPD.h"
40 #include "AliITSdigitSDD.h"
41 #include "AliITSdigitSSD.h"
42 #include "AliITSDetTypeSim.h"
43 #include "AliITSgeom.h"
44 #include "AliITSpListItem.h"
45 #include "AliITSresponseSSD.h"
46 #include "AliITSsegmentationSPD.h"
47 #include "AliITSsegmentationSDD.h"
48 #include "AliITSsegmentationSSD.h"
49 #include "AliITSsimulation.h"
50 #include "AliITSsimulationSPD.h"
51 #include "AliITSsimulationSDD.h"
52 #include "AliITSsimulationSSD.h"
55 const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
56 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
57 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
58 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
60 ClassImp(AliITSDetTypeSim)
62 //----------------------------------------------------------------------
63 AliITSDetTypeSim::AliITSDetTypeSim():
66 fSimulation(), // [NDet]
67 fSegmentation(), // [NDet]
68 fResponse(), // [NMod]
69 fPreProcess(), // [] e.g. Fill fHitModule with hits
70 fPostProcess(), // [] e.g. Wright Raw data
71 fNSDigits(0), //! number of SDigits
72 fSDigits(), //! [NMod][NSDigits]
73 fNDigits(0), //! number of Digits
74 fDigits(), //! [NMod][NDigits]
75 fHitClassName(), // String with Hit class name.
76 fSDigClassName(),// String with SDigit class name.
77 fDigClassName(){ // String with digit class name.
78 // Default Constructor
84 // A properly zero-ed AliITSDetTypeSim class.
86 fSimulation = new TObjArray(fgkNdettypes);
87 fSegmentation = new TObjArray(fgkNdettypes);
88 fSegmentation->SetOwner(kTRUE);
93 fSDigits = new TClonesArray("AliITSpListItem",1000);
94 fDigits = new TObjArray(fgkNdettypes);
95 fNDigits = new Int_t[fgkNdettypes];
97 fNMod[0] = fgkDefaultNModulesSPD;
98 fNMod[1] = fgkDefaultNModulesSDD;
99 fNMod[2] = fgkDefaultNModulesSSD;
103 //----------------------------------------------------------------------
104 AliITSDetTypeSim::~AliITSDetTypeSim(){
113 if(fGeom) delete fGeom;
115 fSimulation->Delete();
121 fSegmentation->Delete();
122 delete fSegmentation;
134 fPreProcess->Delete();
140 fPostProcess->Delete();
147 fLoader->GetModulesFolder()->Remove(this);
162 //----------------------------------------------------------------------
163 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source){
164 // Copy Constructor for object AliITSDetTypeSim not allowed
165 if(this==&source) return;
166 Error("Copy constructor",
167 "You are not allowed to make a copy of the AliITSDetTypeSim");
172 //----------------------------------------------------------------------
173 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
174 // The = operator for object AliITSDetTypeSim
176 if(&source==this) return *this;
177 Error("operator=","You are not allowed to make a copy of the AliITSDetTypeSIm");
183 //______________________________________________________________________
184 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
186 //Set simulation model for detector type
188 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
189 fSimulation->AddAt(sim,dettype);
191 //______________________________________________________________________
192 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
194 //Get simulation model for detector type
196 Warning("GetSimulationModel","fSimulation is 0!");
199 return (AliITSsimulation*)(fSimulation->At(dettype));
201 //______________________________________________________________________
202 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
204 //Get simulation model by module number
206 Warning("GetSimulationModelByModule","fGeom is 0!");
210 return GetSimulationModel(fGeom->GetModuleType(module));
212 //_____________________________________________________________________
213 void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
214 // Set default segmentation model objects
215 AliITSsegmentation *seg;
216 if(fSegmentation==0x0){
217 fSegmentation = new TObjArray(fgkNdettypes);
218 fSegmentation->SetOwner(kTRUE);
220 if(GetSegmentationModel(idet))delete (AliITSsegmentation*)fSegmentation->At(idet);
222 seg = new AliITSsegmentationSPD(fGeom);
225 AliITSresponse* res = GetResponseModel(fGeom->GetStartSDD());
226 seg = new AliITSsegmentationSDD(fGeom,res);
229 seg = new AliITSsegmentationSSD(fGeom);
231 SetSegmentationModel(idet,seg);
234 //______________________________________________________________________
235 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
237 //Set segmentation model for detector type
238 if(fSegmentation==0x0) {
239 fSegmentation = new TObjArray(fgkNdettypes);
240 fSegmentation->SetOwner(kTRUE);
242 fSegmentation->AddAt(seg,dettype);
245 //______________________________________________________________________
246 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
248 //Get segmentation model for detector type
250 if(fSegmentation==0) {
251 Warning("GetSegmentationModel","fSegmentation is 0!");
254 return (AliITSsegmentation*)(fSegmentation->At(dettype));
257 //_______________________________________________________________________
258 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
260 //Get segmentation model by module number
262 Warning("GetSegmentationModelByModule","fGeom is 0!");
265 return GetSegmentationModel(fGeom->GetModuleType(module));
268 //_______________________________________________________________________
269 void AliITSDetTypeSim::CreateResponses() {
271 //Create the container of response functions with correct size
278 for (Int_t i=0; i<fgkNdettypes; i++) nModTot += fNMod[i];
279 fResponse = new TObjArray(nModTot);
280 fResponse->SetOwner(kTRUE);
284 //_______________________________________________________________________
285 void AliITSDetTypeSim::SetResponseModel(Int_t iMod, AliITSresponse *resp){
287 //Set response model for modules
289 if (fResponse==0) CreateResponses();
291 if (fResponse->At(iMod)!=0)
292 delete (AliITSresponse*) fResponse->At(iMod);
293 fResponse->AddAt(resp, iMod);
297 //_______________________________________________________________________
298 void AliITSDetTypeSim::SetResponse(Int_t dettype, Int_t iMod, AliITSresponse *resp){
300 //Set response for the module iMod of type dettype
301 if (fResponse==0) CreateResponses();
303 Int_t nModBefore = 0;
304 for (Int_t i=0; i<dettype; i++) nModBefore += fNMod[i];
306 if (fResponse->At(nModBefore+iMod) != 0)
307 delete (AliITSresponse*) fResponse->At(nModBefore+iMod);
308 fResponse->AddAt(resp, nModBefore+iMod);
312 //______________________________________________________________________
313 void AliITSDetTypeSim::ResetResponse(){
315 //resets response array
320 //______________________________________________________________________
321 void AliITSDetTypeSim::ResetSegmentation(){
323 //Resets segmentation array
324 if(fSegmentation)fSegmentation->Clear();
327 //_______________________________________________________________________
328 AliITSresponse* AliITSDetTypeSim::GetResponseModel(Int_t iMod){
329 //Get response model for module number iMod
332 AliError("fResponse is 0!");
336 return (AliITSresponse*)(fResponse->At(iMod));
339 //_______________________________________________________________________
340 void AliITSDetTypeSim::SetDefaults(){
342 //Set defaults for segmentation and response
346 Warning("SetDefaults","fGeom is 0!");
350 if (fResponse==0) CreateResponses();
355 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
357 for(Int_t idet=0;idet<fgkNdettypes;idet++){
360 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
361 const char *kData0=(GetResponseModel(fGeom->GetStartSPD()))->DataType();
362 if (strstr(kData0,"real")) {
363 SetDigitClassName(idet,"AliITSdigit");
366 SetDigitClassName(idet,"AliITSdigitSPD");
371 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
372 const char *kopt = GetResponseModel(fGeom->GetStartSDD())->ZeroSuppOption();
373 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) {
374 SetDigitClassName(idet,"AliITSdigit");
377 SetDigitClassName(idet,"AliITSdigitSDD");
383 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
384 const char *kData2 = (GetResponseModel(fGeom->GetStartSSD())->DataType());
385 if (strstr(kData2,"real")) {
386 SetDigitClassName(idet,"AliITSdigit");
389 SetDigitClassName(idet,"AliITSdigitSSD");
396 //______________________________________________________________________
397 Bool_t AliITSDetTypeSim::GetCalibration() {
398 // Get Default calibration if a storage is not defined.
400 Bool_t deleteManager = kFALSE;
401 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
402 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
403 deleteManager = kTRUE;
405 AliCDBStorage *storage = AliCDBManager::Instance()->GetDefaultStorage();
407 AliCDBEntry *entrySPD = storage->Get("ITS/Calib/RespSPD", fRunNumber);
408 TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
409 entrySPD->SetObject(NULL);
410 entrySPD->SetOwner(kTRUE);
411 AliCDBEntry *entrySDD = storage->Get("ITS/Calib/RespSDD", fRunNumber);
412 TObjArray *respSDD = (TObjArray *)entrySDD->GetObject();
413 entrySDD->SetObject(NULL);
414 entrySDD->SetOwner(kTRUE);
415 AliCDBEntry *entrySSD = storage->Get("ITS/Calib/RespSSD", fRunNumber);
416 TObjArray *respSSD = (TObjArray *)entrySSD->GetObject();
417 entrySSD->SetObject(NULL);
418 entrySSD->SetOwner(kTRUE);
419 // DB entries are dleted. In this waymetadeta objects are deleted as well
424 AliCDBManager::Instance()->Destroy();
425 AliCDBManager::Instance()->RemoveDefaultStorage();
426 storage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
429 if ((! respSPD)||(! respSDD)||(! respSSD)) {
430 AliWarning("Can not get calibration from calibration database !");
433 fNMod[0] = respSPD->GetEntries();
434 fNMod[1] = respSDD->GetEntries();
435 fNMod[2] = respSSD->GetEntries();
436 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
437 fNMod[0], fNMod[1], fNMod[2]));
439 for (Int_t i=0; i<fNMod[0]; i++) {
440 res = (AliITSresponse*) respSPD->At(i);
441 SetResponseModel(i, res);
443 for (Int_t i=0; i<fNMod[1]; i++) {
444 res = (AliITSresponse*) respSDD->At(i);
445 Int_t iMod = i + fNMod[0];
446 SetResponseModel(iMod, res);
448 for (Int_t i=0; i<fNMod[2]; i++) {
449 res = (AliITSresponse*) respSSD->At(i);
450 Int_t iMod = i + fNMod[0] + fNMod[1];
451 SetResponseModel(iMod, res);
459 //_______________________________________________________________________
460 void AliITSDetTypeSim::SetDefaultSimulation(){
462 //Set default simulation for detector type
465 Warning("SetDefaultSimulation","fGeom is 0!\n");
469 Warning("SetDefaultSimulation","fResponse is 0!\n");
472 if(fSegmentation ==0){
473 Warning("SetDefaultSimulation","fSegmentation is 0!\n");
474 for(Int_t i=0;i<fgkNdettypes;i++)SetDefaultSegmentation(i);
477 for(Int_t i=0;i<fgkNdettypes;i++){
478 if(!GetSegmentationModel(i)){
479 Warning("SetDefaultSimulation","Segmentation not defined for det %d - Default taken\n");
480 SetDefaultSegmentation(i);
484 AliITSsimulation* sim;
486 for(Int_t idet=0;idet<fgkNdettypes;idet++){
489 sim = GetSimulationModel(idet);
492 sim = new AliITSsimulationSPD(this);
493 SetSimulationModel(idet,sim);
495 // loop over all SPD modules
496 Int_t nSPD = fGeom->GetStartSDD()-fGeom->GetStartSPD();
497 for(Int_t nsp=fGeom->GetStartSPD();nsp<nSPD;nsp++){
498 sim->SetResponseModel(nsp,GetResponseModel(nsp));
500 sim->SetSegmentationModel(0,(AliITSsegmentationSPD*)GetSegmentationModel(idet));
506 sim = GetSimulationModel(idet);
508 sim = new AliITSsimulationSDD(this);
509 SetSimulationModel(idet,sim);
511 Int_t nSDD = fGeom->GetStartSSD()-fGeom->GetStartSDD();
512 for(Int_t nsd=fGeom->GetStartSDD();nsd<nSDD;nsd++){
513 sim->SetResponseModel(nsd,GetResponseModel(nsd));
516 sim->SetSegmentationModel(1,(AliITSsegmentationSDD*)GetSegmentationModel(idet));
523 sim = GetSimulationModel(idet);
525 sim = new AliITSsimulationSSD(this);
526 SetSimulationModel(idet,sim);
530 Int_t nSSD = fGeom->GetLastSSD()-fGeom->GetStartSSD()+1;
531 for(Int_t nss=fGeom->GetStartSSD();nss<nSSD;nss++){
532 sim->SetResponseModel(nss,GetResponseModel(nss));
535 sim->SetResponseModel(fGeom->GetStartSSD(),(AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD()));
536 sim->SetSegmentationModel(2,(AliITSsegmentationSSD*)GetSegmentationModel(idet));
550 //___________________________________________________________________
551 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
552 // Set branch address for the ITS summable digits Trees.
559 if (fSDigits == 0x0){
560 fSDigits = new TClonesArray("AliITSpListItem",1000);
563 sprintf(branchname,"%s",name);
564 branch = treeS->GetBranch(branchname);
565 if (branch) branch->SetAddress(&fSDigits);
568 //___________________________________________________________________
569 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
570 // Set branch address for the digit Trees.
572 const char *det[3] = {"SPD","SDD","SSD"};
581 fDigits = new TObjArray(fgkNdettypes);
583 for(Int_t i=0;i<fgkNdettypes;i++){
584 Char_t* digclass = GetDigitClassName(i);
586 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
587 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
588 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
589 digclass = GetDigitClassName(i);
591 TString classn = digclass;
592 if(!(fDigits->At(i))){
593 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
598 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
599 else sprintf(branchname,"%sDigits%d",name,i+1);
601 branch = treeD->GetBranch(branchname);
602 if(branch) branch->SetAddress(&((*fDigits)[i]));
607 //___________________________________________________________________
608 void AliITSDetTypeSim::ResetDigits(){
609 // Reset number of digits and the digits array for the ITS detector.
613 Error("ResetDigits","fDigits is null!");
616 for(Int_t i=0;i<fgkNdettypes;i++){
620 //___________________________________________________________________
621 void AliITSDetTypeSim::ResetDigits(Int_t branch){
622 // Reset number of digits and the digits array for this branch.
624 if(fDigits->At(branch)){
625 ((TClonesArray*)fDigits->At(branch))->Clear();
627 if(fNDigits) fNDigits[branch]=0;
633 //_______________________________________________________________________
634 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
635 // Standard Summable digits to Digits function.
637 Warning("SDigitsToDigits","fGeom is null!!");
641 const char *all = strstr(opt,"All");
642 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
644 if( !det[0] && !det[1] && !det[2] ) all = "All";
646 static Bool_t setDef = kTRUE;
647 if(setDef) SetDefaultSimulation();
650 AliITSsimulation *sim =0;
651 TTree* trees = fLoader->TreeS();
652 if( !(trees && GetSDigits()) ){
653 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
656 sprintf(name,"%s",name);
657 TBranch* brchSDigits = trees->GetBranch(name);
660 for(Int_t module=0;module<fGeom->GetIndexMax();module++){
661 id = fGeom->GetModuleType(module);
662 if (!all && !det[id]) continue;
663 sim = (AliITSsimulation*)GetSimulationModel(id);
664 printf("module=%d name=%s\n",module,sim->ClassName());
666 Error("SDigit2Digits","The simulation class was not "
667 "instanciated for module %d type %s!",module,
668 fGeom->GetModuleTypeName(module));
671 sim->InitSimulationModule(module,gAlice->GetEvNumber());
674 brchSDigits->GetEvent(module);
675 sim->AddSDigitsToModule(fSDigits,0);
676 sim->FinishSDigitiseModule();
677 fLoader->TreeD()->Fill();
680 fLoader->TreeD()->GetEntries();
681 fLoader->TreeD()->AutoSave();
682 fLoader->TreeD()->Reset();
687 //_________________________________________________________
688 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
690 //Adds the module full of summable digits to the summable digits tree.
691 TClonesArray &lsdig = *fSDigits;
692 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
694 //__________________________________________________________
695 void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
696 // Add a real digit - as coming from data.
697 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
698 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
700 //__________________________________________________________
701 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
703 // Add a simulated digit.
704 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
707 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
710 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
713 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
719 //______________________________________________________________________
720 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
721 Int_t *tracks,Int_t *hits,Float_t *charges){
722 // Add a simulated digit to the list.
724 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
725 AliITSresponseSDD *resp = 0;
728 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
731 resp = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
732 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
736 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
743 //______________________________________________________________________
744 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun, AliCDBMetaData &md) {
746 // Store calibration in the calibration database
748 // The database must be created in an external piece of code (i.e.
749 // a configuration macro )
751 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
752 //AliError("No storage set!");
753 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
758 AliError("AliITSresponse classes are not defined - nothing done");
761 AliCDBId idRespSPD("ITS/Calib/RespSPD",firstRun, lastRun);
762 AliCDBId idRespSDD("ITS/Calib/RespSDD",firstRun, lastRun);
763 AliCDBId idRespSSD("ITS/Calib/RespSSD",firstRun, lastRun);
765 TObjArray respSPD(fNMod[0]);
766 TObjArray respSDD(fNMod[1]-fNMod[0]);
767 TObjArray respSSD(fNMod[2]-fNMod[1]);
768 respSPD.SetOwner(kFALSE);
769 respSSD.SetOwner(kFALSE);
770 respSSD.SetOwner(kFALSE);
772 Int_t index[fgkNdettypes];
773 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
775 for (Int_t j = 0; j<=i; j++ )
779 for (Int_t i = 0; i<index[0]; i++ )
780 respSPD.Add(fResponse->At(i));
782 for (Int_t i = index[0]; i<index[1]; i++ )
783 respSDD.Add(fResponse->At(i));
785 for (Int_t i = index[1]; i<index[2]; i++ )
786 respSSD.Add(fResponse->At(i));
788 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSPD, idRespSPD, &md);
790 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSDD, idRespSDD, &md);
792 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSSD, idRespSSD, &md);