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);
92 fSDigits = new TClonesArray("AliITSpListItem",1000);
93 fDigits = new TObjArray(fgkNdettypes);
94 fNDigits = new Int_t[fgkNdettypes];
96 fNMod[0] = fgkDefaultNModulesSPD;
97 fNMod[1] = fgkDefaultNModulesSDD;
98 fNMod[2] = fgkDefaultNModulesSSD;
102 //----------------------------------------------------------------------
103 AliITSDetTypeSim::~AliITSDetTypeSim(){
112 if(fGeom) delete fGeom;
114 fSimulation->Delete();
120 fSegmentation->Delete();
121 delete fSegmentation;
133 fPreProcess->Delete();
139 fPostProcess->Delete();
146 fLoader->GetModulesFolder()->Remove(this);
161 //----------------------------------------------------------------------
162 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source){
163 // Copy Constructor for object AliITSDetTypeSim not allowed
164 if(this==&source) return;
165 Error("Copy constructor",
166 "You are not allowed to make a copy of the AliITSDetTypeSim");
171 //----------------------------------------------------------------------
172 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
173 // The = operator for object AliITSDetTypeSim
175 if(&source==this) return *this;
176 Error("operator=","You are not allowed to make a copy of the AliITSDetTypeSIm");
182 //______________________________________________________________________
183 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
185 //Set simulation model for detector type
187 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
188 fSimulation->AddAt(sim,dettype);
190 //______________________________________________________________________
191 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
193 //Get simulation model for detector type
195 Warning("GetSimulationModel","fSimulation is 0!");
198 return (AliITSsimulation*)(fSimulation->At(dettype));
200 //______________________________________________________________________
201 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
203 //Get simulation model by module number
205 Warning("GetSimulationModelByModule","fGeom is 0!");
209 return GetSimulationModel(fGeom->GetModuleType(module));
211 //______________________________________________________________________
212 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
214 //Set segmentation model for detector type
215 if(fSegmentation==0x0) fSegmentation = new TObjArray(fgkNdettypes);
216 fSegmentation->AddAt(seg,dettype);
219 //______________________________________________________________________
220 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
222 //Get segmentation model for detector type
224 if(fSegmentation==0) {
225 Warning("GetSegmentationModel","fSegmentation is 0!");
228 return (AliITSsegmentation*)(fSegmentation->At(dettype));
231 //_______________________________________________________________________
232 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
234 //Get segmentation model by module number
236 Warning("GetSegmentationModelByModule","fGeom is 0!");
239 return GetSegmentationModel(fGeom->GetModuleType(module));
242 //_______________________________________________________________________
243 void AliITSDetTypeSim::CreateResponses() {
245 //Create the container of response functions with correct size
252 for (Int_t i=0; i<fgkNdettypes; i++) nModTot += fNMod[i];
253 fResponse = new TObjArray(nModTot);
254 fResponse->SetOwner(kTRUE);
258 //_______________________________________________________________________
259 void AliITSDetTypeSim::SetResponseModel(Int_t iMod, AliITSresponse *resp){
261 //Set response model for modules
263 if (fResponse==0) CreateResponses();
265 if (fResponse->At(iMod)!=0)
266 delete (AliITSresponse*) fResponse->At(iMod);
267 fResponse->AddAt(resp, iMod);
271 //_______________________________________________________________________
272 void AliITSDetTypeSim::SetResponse(Int_t dettype, Int_t iMod, AliITSresponse *resp){
274 //Set response for the module iMod of type dettype
275 if (fResponse==0) CreateResponses();
277 Int_t nModBefore = 0;
278 for (Int_t i=0; i<dettype; i++) nModBefore += fNMod[i];
280 if (fResponse->At(nModBefore+iMod) != 0)
281 delete (AliITSresponse*) fResponse->At(nModBefore+iMod);
282 fResponse->AddAt(resp, nModBefore+iMod);
286 //______________________________________________________________________
287 void AliITSDetTypeSim::ResetResponse(){
289 //resets response array
294 //______________________________________________________________________
295 void AliITSDetTypeSim::ResetSegmentation(){
297 //Resets segmentation array
299 for(Int_t i=0;i<fgkNdettypes;i++){
300 if(fSegmentation->At(i))
301 delete (AliITSsegmentation*)fSegmentation->At(i);
306 //_______________________________________________________________________
307 AliITSresponse* AliITSDetTypeSim::GetResponseModel(Int_t iMod){
308 //Get response model for module number iMod
311 AliError("fResponse is 0!");
315 return (AliITSresponse*)(fResponse->At(iMod));
318 //_______________________________________________________________________
319 void AliITSDetTypeSim::SetDefaults(){
321 //Set defaults for segmentation and response
325 Warning("SetDefaults","fGeom is 0!");
329 if (fResponse==0) CreateResponses();
331 AliITSsegmentation* seg;
336 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
338 for(Int_t idet=0;idet<fgkNdettypes;idet++){
341 if(!GetSegmentationModel(idet)){
342 seg = new AliITSsegmentationSPD(fGeom);
343 SetSegmentationModel(idet,seg);
345 const char *kData0=(GetResponseModel(fGeom->GetStartSPD()))->DataType();
346 if (strstr(kData0,"real")) {
347 SetDigitClassName(idet,"AliITSdigit");
350 SetDigitClassName(idet,"AliITSdigitSPD");
355 if(!GetSegmentationModel(idet)){
356 res = GetResponseModel(fGeom->GetStartSDD());
357 seg = new AliITSsegmentationSDD(fGeom,res);
358 SetSegmentationModel(idet,seg);
360 const char *kopt = GetResponseModel(fGeom->GetStartSDD())->ZeroSuppOption();
361 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) {
362 SetDigitClassName(idet,"AliITSdigit");
365 SetDigitClassName(idet,"AliITSdigitSDD");
371 if(!GetSegmentationModel(idet)){
372 seg = new AliITSsegmentationSSD(fGeom);
373 SetSegmentationModel(idet,seg);
375 const char *kData2 = (GetResponseModel(fGeom->GetStartSSD())->DataType());
376 if (strstr(kData2,"real")) {
377 SetDigitClassName(idet,"AliITSdigit");
380 SetDigitClassName(idet,"AliITSdigitSSD");
387 //______________________________________________________________________
388 Bool_t AliITSDetTypeSim::GetCalibration() {
389 // Get Default calibration if a storage is not defined.
391 Bool_t deleteManager = kFALSE;
392 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
393 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
394 deleteManager = kTRUE;
396 AliCDBStorage *storage = AliCDBManager::Instance()->GetDefaultStorage();
398 AliCDBEntry *entrySPD = storage->Get("ITS/Calib/RespSPD", fRunNumber);
399 TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
400 entrySPD->SetObject(NULL);
401 entrySPD->SetOwner(kTRUE);
402 AliCDBEntry *entrySDD = storage->Get("ITS/Calib/RespSDD", fRunNumber);
403 TObjArray *respSDD = (TObjArray *)entrySDD->GetObject();
404 entrySDD->SetObject(NULL);
405 entrySDD->SetOwner(kTRUE);
406 AliCDBEntry *entrySSD = storage->Get("ITS/Calib/RespSSD", fRunNumber);
407 TObjArray *respSSD = (TObjArray *)entrySSD->GetObject();
408 entrySSD->SetObject(NULL);
409 entrySSD->SetOwner(kTRUE);
410 // DB entries are dleted. In this waymetadeta objects are deleted as well
415 AliCDBManager::Instance()->Destroy();
416 AliCDBManager::Instance()->RemoveDefaultStorage();
417 storage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
420 if ((! respSPD)||(! respSDD)||(! respSSD)) {
421 AliWarning("Can not get calibration from calibration database !");
424 fNMod[0] = respSPD->GetEntries();
425 fNMod[1] = respSDD->GetEntries();
426 fNMod[2] = respSSD->GetEntries();
427 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
428 fNMod[0], fNMod[1], fNMod[2]));
430 for (Int_t i=0; i<fNMod[0]; i++) {
431 res = (AliITSresponse*) respSPD->At(i);
432 SetResponseModel(i, res);
434 for (Int_t i=0; i<fNMod[1]; i++) {
435 res = (AliITSresponse*) respSDD->At(i);
436 Int_t iMod = i + fNMod[0];
437 SetResponseModel(iMod, res);
439 for (Int_t i=0; i<fNMod[2]; i++) {
440 res = (AliITSresponse*) respSSD->At(i);
441 Int_t iMod = i + fNMod[0] + fNMod[1];
442 SetResponseModel(iMod, res);
450 //_______________________________________________________________________
451 void AliITSDetTypeSim::SetDefaultSimulation(){
453 //Set default simulation for detector type
456 Warning("SetDefaultSimulation","fGeom is 0!");
460 Warning("SetDefaultSimulation","fResponse is 0!");
464 AliITSsimulation* sim;
466 for(Int_t idet=0;idet<fgkNdettypes;idet++){
469 sim = GetSimulationModel(idet);
472 sim = new AliITSsimulationSPD(this);
473 SetSimulationModel(idet,sim);
475 // loop over all SPD modules
476 Int_t nSPD = fGeom->GetStartSDD()-fGeom->GetStartSPD();
477 for(Int_t nsp=fGeom->GetStartSPD();nsp<nSPD;nsp++){
478 sim->SetResponseModel(nsp,GetResponseModel(nsp));
480 sim->SetSegmentationModel(0,(AliITSsegmentationSPD*)GetSegmentationModel(idet));
486 sim = GetSimulationModel(idet);
488 sim = new AliITSsimulationSDD(this);
489 SetSimulationModel(idet,sim);
491 Int_t nSDD = fGeom->GetStartSSD()-fGeom->GetStartSDD();
492 for(Int_t nsd=fGeom->GetStartSDD();nsd<nSDD;nsd++){
493 sim->SetResponseModel(nsd,GetResponseModel(nsd));
496 sim->SetSegmentationModel(1,(AliITSsegmentationSDD*)GetSegmentationModel(idet));
503 sim = GetSimulationModel(idet);
505 sim = new AliITSsimulationSSD(this);
506 SetSimulationModel(idet,sim);
510 Int_t nSSD = fGeom->GetLastSSD()-fGeom->GetStartSSD()+1;
511 for(Int_t nss=fGeom->GetStartSSD();nss<nSSD;nss++){
512 sim->SetResponseModel(nss,GetResponseModel(nss));
515 sim->SetResponseModel(fGeom->GetStartSSD(),(AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD()));
516 sim->SetSegmentationModel(2,(AliITSsegmentationSSD*)GetSegmentationModel(idet));
530 //___________________________________________________________________
531 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
532 // Set branch address for the ITS summable digits Trees.
539 if (fSDigits == 0x0){
540 fSDigits = new TClonesArray("AliITSpListItem",1000);
543 sprintf(branchname,"%s",name);
544 branch = treeS->GetBranch(branchname);
545 if (branch) branch->SetAddress(&fSDigits);
548 //___________________________________________________________________
549 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
550 // Set branch address for the digit Trees.
552 const char *det[3] = {"SPD","SDD","SSD"};
561 fDigits = new TObjArray(fgkNdettypes);
563 for(Int_t i=0;i<fgkNdettypes;i++){
564 Char_t* digclass = GetDigitClassName(i);
566 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
567 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
568 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
569 digclass = GetDigitClassName(i);
571 TString classn = digclass;
572 if(!(fDigits->At(i))){
573 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
578 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
579 else sprintf(branchname,"%sDigits%d",name,i+1);
581 branch = treeD->GetBranch(branchname);
582 if(branch) branch->SetAddress(&((*fDigits)[i]));
587 //___________________________________________________________________
588 void AliITSDetTypeSim::ResetDigits(){
589 // Reset number of digits and the digits array for the ITS detector.
593 Error("ResetDigits","fDigits is null!");
596 for(Int_t i=0;i<fgkNdettypes;i++){
600 //___________________________________________________________________
601 void AliITSDetTypeSim::ResetDigits(Int_t branch){
602 // Reset number of digits and the digits array for this branch.
604 if(fDigits->At(branch)){
605 ((TClonesArray*)fDigits->At(branch))->Clear();
607 if(fNDigits) fNDigits[branch]=0;
613 //_______________________________________________________________________
614 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
615 // Standard Summable digits to Digits function.
617 Warning("SDigitsToDigits","fGeom is null!!");
621 const char *all = strstr(opt,"All");
622 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
624 if( !det[0] && !det[1] && !det[2] ) all = "All";
626 static Bool_t setDef = kTRUE;
627 if(setDef) SetDefaultSimulation();
630 AliITSsimulation *sim =0;
631 TTree* trees = fLoader->TreeS();
632 if( !(trees && GetSDigits()) ){
633 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
636 sprintf(name,"%s",name);
637 TBranch* brchSDigits = trees->GetBranch(name);
640 for(Int_t module=0;module<fGeom->GetIndexMax();module++){
641 id = fGeom->GetModuleType(module);
642 if (!all && !det[id]) continue;
643 sim = (AliITSsimulation*)GetSimulationModel(id);
644 printf("module=%d name=%s\n",module,sim->ClassName());
646 Error("SDigit2Digits","The simulation class was not "
647 "instanciated for module %d type %s!",module,
648 fGeom->GetModuleTypeName(module));
651 sim->InitSimulationModule(module,gAlice->GetEvNumber());
654 brchSDigits->GetEvent(module);
655 sim->AddSDigitsToModule(fSDigits,0);
656 sim->FinishSDigitiseModule();
657 fLoader->TreeD()->Fill();
660 fLoader->TreeD()->GetEntries();
661 fLoader->TreeD()->AutoSave();
662 fLoader->TreeD()->Reset();
667 //_________________________________________________________
668 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
670 //Adds the module full of summable digits to the summable digits tree.
671 TClonesArray &lsdig = *fSDigits;
672 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
674 //__________________________________________________________
675 void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
676 // Add a real digit - as coming from data.
677 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
678 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
680 //__________________________________________________________
681 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
683 // Add a simulated digit.
684 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
687 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
690 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
693 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
699 //______________________________________________________________________
700 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
701 Int_t *tracks,Int_t *hits,Float_t *charges){
702 // Add a simulated digit to the list.
704 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
705 AliITSresponseSDD *resp = 0;
708 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
711 resp = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
712 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
716 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
723 //______________________________________________________________________
724 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun, AliCDBMetaData &md) {
726 // Store calibration in the calibration database
728 // The database must be created in an external piece of code (i.e.
729 // a configuration macro )
731 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
732 //AliError("No storage set!");
733 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
738 AliError("AliITSresponse classes are not defined - nothing done");
741 AliCDBId idRespSPD("ITS/Calib/RespSPD",firstRun, lastRun);
742 AliCDBId idRespSDD("ITS/Calib/RespSDD",firstRun, lastRun);
743 AliCDBId idRespSSD("ITS/Calib/RespSSD",firstRun, lastRun);
745 TObjArray respSPD(fNMod[0]);
746 TObjArray respSDD(fNMod[1]-fNMod[0]);
747 TObjArray respSSD(fNMod[2]-fNMod[1]);
748 respSPD.SetOwner(kFALSE);
749 respSSD.SetOwner(kFALSE);
750 respSSD.SetOwner(kFALSE);
752 Int_t index[fgkNdettypes];
753 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
755 for (Int_t j = 0; j<=i; j++ )
759 for (Int_t i = 0; i<index[0]; i++ )
760 respSPD.Add(fResponse->At(i));
762 for (Int_t i = index[0]; i<index[1]; i++ )
763 respSDD.Add(fResponse->At(i));
765 for (Int_t i = index[1]; i<index[2]; i++ )
766 respSSD.Add(fResponse->At(i));
768 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSPD, idRespSPD, &md);
770 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSDD, idRespSDD, &md);
772 AliCDBManager::Instance()->GetDefaultStorage()->Put(&respSSD, idRespSSD, &md);