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(){
115 fSimulation->Delete();
121 fSegmentation->Delete();
122 delete fSegmentation;
133 if(fGeom) delete fGeom;
136 fPreProcess->Delete();
142 fPostProcess->Delete();
149 fLoader->GetModulesFolder()->Remove(this);
164 //----------------------------------------------------------------------
165 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source){
166 // Copy Constructor for object AliITSDetTypeSim not allowed
167 if(this==&source) return;
168 Error("Copy constructor",
169 "You are not allowed to make a copy of the AliITSDetTypeSim");
174 //----------------------------------------------------------------------
175 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
176 // The = operator for object AliITSDetTypeSim
178 if(&source==this) return *this;
179 Error("operator=","You are not allowed to make a copy of the AliITSDetTypeSIm");
185 //______________________________________________________________________
186 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
188 //Set simulation model for detector type
190 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
191 fSimulation->AddAt(sim,dettype);
193 //______________________________________________________________________
194 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
196 //Get simulation model for detector type
198 Warning("GetSimulationModel","fSimulation is 0!");
201 return (AliITSsimulation*)(fSimulation->At(dettype));
203 //______________________________________________________________________
204 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
206 //Get simulation model by module number
208 Warning("GetSimulationModelByModule","fGeom is 0!");
212 return GetSimulationModel(fGeom->GetModuleType(module));
214 //_____________________________________________________________________
215 void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
216 // Set default segmentation model objects
217 AliITSsegmentation *seg;
218 if(fSegmentation==0x0){
219 fSegmentation = new TObjArray(fgkNdettypes);
220 fSegmentation->SetOwner(kTRUE);
222 if(GetSegmentationModel(idet))delete (AliITSsegmentation*)fSegmentation->At(idet);
224 seg = new AliITSsegmentationSPD(fGeom);
227 AliITSresponse* res = GetResponseModel(fGeom->GetStartSDD());
228 seg = new AliITSsegmentationSDD(fGeom,res);
231 seg = new AliITSsegmentationSSD(fGeom);
233 SetSegmentationModel(idet,seg);
236 //______________________________________________________________________
237 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
239 //Set segmentation model for detector type
240 if(fSegmentation==0x0) {
241 fSegmentation = new TObjArray(fgkNdettypes);
242 fSegmentation->SetOwner(kTRUE);
244 fSegmentation->AddAt(seg,dettype);
247 //______________________________________________________________________
248 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
250 //Get segmentation model for detector type
252 if(fSegmentation==0) {
253 Warning("GetSegmentationModel","fSegmentation is 0!");
256 return (AliITSsegmentation*)(fSegmentation->At(dettype));
259 //_______________________________________________________________________
260 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
262 //Get segmentation model by module number
264 Warning("GetSegmentationModelByModule","fGeom is 0!");
267 return GetSegmentationModel(fGeom->GetModuleType(module));
270 //_______________________________________________________________________
271 void AliITSDetTypeSim::CreateResponses() {
273 //Create the container of response functions with correct size
280 for (Int_t i=0; i<fgkNdettypes; i++) nModTot += fNMod[i];
281 fResponse = new TObjArray(nModTot);
282 fResponse->SetOwner(kTRUE);
286 //_______________________________________________________________________
287 void AliITSDetTypeSim::SetResponseModel(Int_t iMod, AliITSresponse *resp){
289 //Set response model for modules
291 if (fResponse==0) CreateResponses();
293 if (fResponse->At(iMod)!=0)
294 delete (AliITSresponse*) fResponse->At(iMod);
295 fResponse->AddAt(resp, iMod);
299 //_______________________________________________________________________
300 void AliITSDetTypeSim::SetResponse(Int_t dettype, Int_t iMod, AliITSresponse *resp){
302 //Set response for the module iMod of type dettype
303 if (fResponse==0) CreateResponses();
305 Int_t nModBefore = 0;
306 for (Int_t i=0; i<dettype; i++) nModBefore += fNMod[i];
308 if (fResponse->At(nModBefore+iMod) != 0)
309 delete (AliITSresponse*) fResponse->At(nModBefore+iMod);
310 fResponse->AddAt(resp, nModBefore+iMod);
314 //______________________________________________________________________
315 void AliITSDetTypeSim::ResetResponse(){
317 //resets response array
322 //______________________________________________________________________
323 void AliITSDetTypeSim::ResetSegmentation(){
325 //Resets segmentation array
326 if(fSegmentation)fSegmentation->Clear();
329 //_______________________________________________________________________
330 AliITSresponse* AliITSDetTypeSim::GetResponseModel(Int_t iMod){
331 //Get response model for module number iMod
334 AliError("fResponse is 0!");
338 return (AliITSresponse*)(fResponse->At(iMod));
341 //_______________________________________________________________________
342 void AliITSDetTypeSim::SetDefaults(){
344 //Set defaults for segmentation and response
348 Warning("SetDefaults","fGeom is 0!");
352 if (fResponse==0) CreateResponses();
358 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
360 for(Int_t idet=0;idet<fgkNdettypes;idet++){
363 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
364 const char *kData0=(GetResponseModel(fGeom->GetStartSPD()))->DataType();
365 if (strstr(kData0,"real")) {
366 SetDigitClassName(idet,"AliITSdigit");
369 SetDigitClassName(idet,"AliITSdigitSPD");
374 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
375 const char *kopt = GetResponseModel(fGeom->GetStartSDD())->ZeroSuppOption();
376 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) {
377 SetDigitClassName(idet,"AliITSdigit");
380 SetDigitClassName(idet,"AliITSdigitSDD");
386 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
387 const char *kData2 = (GetResponseModel(fGeom->GetStartSSD())->DataType());
388 if (strstr(kData2,"real")) {
389 SetDigitClassName(idet,"AliITSdigit");
392 SetDigitClassName(idet,"AliITSdigitSSD");
399 //______________________________________________________________________
400 Bool_t AliITSDetTypeSim::GetCalibration() {
401 // Get Default calibration if a storage is not defined.
404 Bool_t deleteManager = kFALSE;
405 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
406 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
407 deleteManager = kTRUE;
409 AliCDBStorage *storage = AliCDBManager::Instance()->GetDefaultStorage();
411 AliCDBEntry *entrySPD = storage->Get("ITS/Calib/RespSPD", fRunNumber);
412 TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
413 entrySPD->SetObject(NULL);
414 entrySPD->SetOwner(kTRUE);
415 AliCDBEntry *entrySDD = storage->Get("ITS/Calib/RespSDD", fRunNumber);
416 TObjArray *respSDD = (TObjArray *)entrySDD->GetObject();
417 entrySDD->SetObject(NULL);
418 entrySDD->SetOwner(kTRUE);
419 AliCDBEntry *entrySSD = storage->Get("ITS/Calib/RespSSD", fRunNumber);
420 TObjArray *respSSD = (TObjArray *)entrySSD->GetObject();
421 entrySSD->SetObject(NULL);
422 entrySSD->SetOwner(kTRUE);
423 // DB entries are dleted. In this waymetadeta objects are deleted as well
428 AliCDBManager::Instance()->Destroy();
429 AliCDBManager::Instance()->UnsetDefaultStorage();
430 storage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
433 if ((! respSPD)||(! respSDD)||(! respSSD)) {
434 AliWarning("Can not get calibration from calibration database !");
437 fNMod[0] = respSPD->GetEntries();
438 fNMod[1] = respSDD->GetEntries();
439 fNMod[2] = respSSD->GetEntries();
440 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
441 fNMod[0], fNMod[1], fNMod[2]));
443 for (Int_t i=0; i<fNMod[0]; i++) {
444 AliITSresponse* res = (AliITSresponse*) respSPD->At(i);
445 SetResponseModel(i, res);
447 for (Int_t i=0; i<fNMod[1]; i++) {
448 AliITSresponse* res = (AliITSresponse*) respSDD->At(i);
449 Int_t iMod = i + fNMod[0];
450 SetResponseModel(iMod, res);
452 for (Int_t i=0; i<fNMod[2]; i++) {
453 AliITSresponse* res = (AliITSresponse*) respSSD->At(i);
454 Int_t iMod = i + fNMod[0] + fNMod[1];
455 SetResponseModel(iMod, res);
463 //_______________________________________________________________________
464 void AliITSDetTypeSim::SetDefaultSimulation(){
466 //Set default simulation for detector type
470 Warning("SetDefaultSimulation","fGeom is 0!\n");
474 Warning("SetDefaultSimulation","fResponse is 0!\n");
477 if(fSegmentation ==0){
478 Warning("SetDefaultSimulation","fSegmentation is 0!\n");
479 for(Int_t i=0;i<fgkNdettypes;i++)SetDefaultSegmentation(i);
482 for(Int_t i=0;i<fgkNdettypes;i++){
483 if(!GetSegmentationModel(i)){
484 Warning("SetDefaultSimulation","Segmentation not defined for det %d - Default taken\n");
485 SetDefaultSegmentation(i);
489 AliITSsimulation* sim;
491 for(Int_t idet=0;idet<fgkNdettypes;idet++){
494 sim = GetSimulationModel(idet);
496 sim = new AliITSsimulationSPD(this);
497 SetSimulationModel(idet,sim);
499 sim->SetDetType(this);
500 sim->SetSegmentationModel(0,(AliITSsegmentationSPD*)GetSegmentationModel(idet));
506 sim = GetSimulationModel(idet);
508 sim = new AliITSsimulationSDD(this);
509 SetSimulationModel(idet,sim);
511 sim->SetDetType(this);
512 sim->SetSegmentationModel(1,(AliITSsegmentationSDD*)GetSegmentationModel(idet));
520 sim = GetSimulationModel(idet);
522 sim = new AliITSsimulationSSD(this);
523 SetSimulationModel(idet,sim);
526 sim->SetDetType(this);
527 sim->SetSegmentationModel(2,(AliITSsegmentationSSD*)GetSegmentationModel(idet));
539 //___________________________________________________________________
540 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
541 // Set branch address for the ITS summable digits Trees.
548 if (fSDigits == 0x0){
549 fSDigits = new TClonesArray("AliITSpListItem",1000);
552 sprintf(branchname,"%s",name);
553 branch = treeS->GetBranch(branchname);
554 if (branch) branch->SetAddress(&fSDigits);
557 //___________________________________________________________________
558 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
559 // Set branch address for the digit Trees.
561 const char *det[3] = {"SPD","SDD","SSD"};
570 fDigits = new TObjArray(fgkNdettypes);
572 for(Int_t i=0;i<fgkNdettypes;i++){
573 Char_t* digclass = GetDigitClassName(i);
575 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
576 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
577 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
578 digclass = GetDigitClassName(i);
580 TString classn = digclass;
581 if(!(fDigits->At(i))){
582 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
587 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
588 else sprintf(branchname,"%sDigits%d",name,i+1);
590 branch = treeD->GetBranch(branchname);
591 if(branch) branch->SetAddress(&((*fDigits)[i]));
596 //___________________________________________________________________
597 void AliITSDetTypeSim::ResetDigits(){
598 // Reset number of digits and the digits array for the ITS detector.
602 Error("ResetDigits","fDigits is null!");
605 for(Int_t i=0;i<fgkNdettypes;i++){
609 //___________________________________________________________________
610 void AliITSDetTypeSim::ResetDigits(Int_t branch){
611 // Reset number of digits and the digits array for this branch.
613 if(fDigits->At(branch)){
614 ((TClonesArray*)fDigits->At(branch))->Clear();
616 if(fNDigits) fNDigits[branch]=0;
622 //_______________________________________________________________________
623 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
624 // Standard Summable digits to Digits function.
626 Warning("SDigitsToDigits","fGeom is null!!");
630 const char *all = strstr(opt,"All");
631 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
633 if( !det[0] && !det[1] && !det[2] ) all = "All";
635 static Bool_t setDef = kTRUE;
636 if(setDef) SetDefaultSimulation();
639 AliITSsimulation *sim =0;
640 TTree* trees = fLoader->TreeS();
641 if( !(trees && GetSDigits()) ){
642 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
645 sprintf(name,"%s",name);
646 TBranch* brchSDigits = trees->GetBranch(name);
649 for(Int_t module=0;module<fGeom->GetIndexMax();module++){
650 id = fGeom->GetModuleType(module);
651 if (!all && !det[id]) continue;
652 sim = (AliITSsimulation*)GetSimulationModel(id);
653 printf("module=%d name=%s\n",module,sim->ClassName());
655 Error("SDigit2Digits","The simulation class was not "
656 "instanciated for module %d type %s!",module,
657 fGeom->GetModuleTypeName(module));
660 sim->InitSimulationModule(module,gAlice->GetEvNumber());
663 brchSDigits->GetEvent(module);
664 sim->AddSDigitsToModule(fSDigits,0);
665 sim->FinishSDigitiseModule();
666 fLoader->TreeD()->Fill();
669 fLoader->TreeD()->GetEntries();
670 fLoader->TreeD()->AutoSave();
671 fLoader->TreeD()->Reset();
676 //_________________________________________________________
677 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
679 //Adds the module full of summable digits to the summable digits tree.
680 TClonesArray &lsdig = *fSDigits;
681 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
683 //__________________________________________________________
684 void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
685 // Add a real digit - as coming from data.
686 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
687 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
689 //__________________________________________________________
690 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
692 // Add a simulated digit.
693 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
696 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
699 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
702 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
708 //______________________________________________________________________
709 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
710 Int_t *tracks,Int_t *hits,Float_t *charges){
711 // Add a simulated digit to the list.
713 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
714 AliITSresponseSDD *resp = 0;
717 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
720 resp = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
721 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
725 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
732 //______________________________________________________________________
733 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun, AliCDBMetaData &md) {
735 // Store calibration in the calibration database
737 // The database must be created in an external piece of code (i.e.
738 // a configuration macro )
740 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
741 //AliError("No storage set!");
742 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
747 AliError("AliITSresponse classes are not defined - nothing done");
750 AliCDBId idRespSPD("ITS/Calib/RespSPD",firstRun, lastRun);
751 AliCDBId idRespSDD("ITS/Calib/RespSDD",firstRun, lastRun);
752 AliCDBId idRespSSD("ITS/Calib/RespSSD",firstRun, lastRun);
754 TObjArray respSPD(fNMod[0]);
755 TObjArray respSDD(fNMod[1]-fNMod[0]);
756 TObjArray respSSD(fNMod[2]-fNMod[1]);
757 respSPD.SetOwner(kFALSE);
758 respSSD.SetOwner(kFALSE);
759 respSSD.SetOwner(kFALSE);
761 Int_t index[fgkNdettypes];
762 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
764 for (Int_t j = 0; j<=i; j++ )
768 for (Int_t i = 0; i<index[0]; i++ )
769 respSPD.Add(fResponse->At(i));
771 for (Int_t i = index[0]; i<index[1]; i++ )
772 respSDD.Add(fResponse->At(i));
774 for (Int_t i = index[1]; i<index[2]; i++ )
775 respSSD.Add(fResponse->At(i));
777 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSPD, idRespSPD, &md);
779 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSDD, idRespSDD, &md);
781 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSSD, idRespSSD, &md);