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 **************************************************************************/
21 /////////////////////////////////////////////////////////////////////
22 // Base simulation functions for ITS //
25 /////////////////////////////////////////////////////////////////////
27 #include "TClonesArray.h"
28 #include "TObjArray.h"
33 #include "AliCDBManager.h"
35 #include "AliCDBStorage.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBMetaData.h"
39 #include "AliITSdigit.h"
40 #include "AliITSdigitSPD.h"
41 #include "AliITSdigitSDD.h"
42 #include "AliITSdigitSSD.h"
43 #include "AliITSDetTypeSim.h"
44 #include "AliITSpListItem.h"
45 #include "AliITSCalibrationSDD.h"
46 #include "AliITSMapSDD.h"
47 #include "AliITSDriftSpeedArraySDD.h"
48 #include "AliITSDriftSpeedSDD.h"
49 #include "AliITSCalibrationSSD.h"
50 #include "AliITSNoiseSSD.h"
51 #include "AliITSGainSSD.h"
52 #include "AliITSBadChannelsSSD.h"
53 #include "AliITSCalibrationSSD.h"
54 #include "AliITSsegmentationSPD.h"
55 #include "AliITSsegmentationSDD.h"
56 #include "AliITSsegmentationSSD.h"
57 #include "AliITSsimulation.h"
58 #include "AliITSsimulationSPD.h"
59 #include "AliITSsimulationSDD.h"
60 #include "AliITSsimulationSSD.h"
63 const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
64 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
65 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
66 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
68 ClassImp(AliITSDetTypeSim)
70 //----------------------------------------------------------------------
71 AliITSDetTypeSim::AliITSDetTypeSim():
73 fSimulation(), // [NDet]
74 fSegmentation(), // [NDet]
75 fCalibration(), // [NMod]
76 fPreProcess(), // [] e.g. Fill fHitModule with hits
77 fPostProcess(), // [] e.g. Wright Raw data
78 fNSDigits(0), //! number of SDigits
79 fSDigits("AliITSpListItem",1000),
80 fNDigits(0), //! number of Digits
81 fRunNumber(0), //! Run number (to access DB)
82 fDigits(), //! [NMod][NDigits]
85 fHitClassName(), // String with Hit class name.
86 fSDigClassName(),// String with SDigit class name.
87 fDigClassName(), // String with digit class name.
88 fLoader(0), // local pointer to loader
89 fFirstcall(kTRUE){ // flag
90 // Default Constructor
96 // A properly zero-ed AliITSDetTypeSim class.
98 fSimulation = new TObjArray(fgkNdettypes);
99 fSegmentation = new TObjArray(fgkNdettypes);
100 fSegmentation->SetOwner(kTRUE);
101 fDigits = new TObjArray(fgkNdettypes);
102 fNDigits = new Int_t[fgkNdettypes];
103 fDDLMapSDD=new AliITSDDLModuleMapSDD();
104 fSimuPar= new AliITSSimuParam();
105 fNMod[0] = fgkDefaultNModulesSPD;
106 fNMod[1] = fgkDefaultNModulesSDD;
107 fNMod[2] = fgkDefaultNModulesSSD;
110 //----------------------------------------------------------------------
111 AliITSDetTypeSim::~AliITSDetTypeSim(){
121 fSimulation->Delete();
126 fSegmentation->Delete();
127 delete fSegmentation;
130 if(fCalibration && fRunNumber<0){
131 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
132 GetITSgeom()->GetStartSPD()))->GetResponse();
133 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
134 GetITSgeom()->GetStartSSD()))->GetResponse();
135 if(rspd) delete rspd;
136 if(rssd) delete rssd;
137 fCalibration->Delete();
142 fPreProcess->Delete();
147 fPostProcess->Delete();
151 if(fSimuPar) delete fSimuPar;
152 if(fDDLMapSDD) delete fDDLMapSDD;
153 if(fNDigits) delete [] fNDigits;
155 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
156 fLoader = 0; // Not deleting it.
164 //----------------------------------------------------------------------
165 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
166 fSimulation(source.fSimulation), // [NDet]
167 fSegmentation(source.fSegmentation), // [NDet]
168 fCalibration(source.fCalibration), // [NMod]
169 fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
170 fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
171 fNSDigits(source.fNSDigits), //! number of SDigits
172 fSDigits(*((TClonesArray*)source.fSDigits.Clone())),
173 fNDigits(source.fNDigits), //! number of Digits
174 fRunNumber(source.fRunNumber), //! Run number (to access DB)
175 fDigits(source.fDigits), //! [NMod][NDigits]
176 fSimuPar(source.fSimuPar),
177 fDDLMapSDD(source.fDDLMapSDD),
178 fHitClassName(source.fHitClassName), // String with Hit class name.
179 fSDigClassName(source.fSDigClassName),// String with SDigit class name.
180 fDigClassName(), // String with digit class name.
181 fLoader(source.fLoader), // local pointer to loader
182 fFirstcall(source.fFirstcall)
184 // Copy Constructor for object AliITSDetTypeSim not allowed
185 for(Int_t i=0;i<fgkNdettypes;i++){
186 fDigClassName[i] = source.fDigClassName[i];
189 //----------------------------------------------------------------------
190 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
191 // The = operator for object AliITSDetTypeSim
193 this->~AliITSDetTypeSim();
194 new(this) AliITSDetTypeSim(source);
198 //______________________________________________________________________
199 void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
200 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
203 // AliITSgoem *geom The AliITSgeom object to be used.
209 Error("SetITSgeom","No pointer to loader - nothing done");
213 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
217 //______________________________________________________________________
218 void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
219 // Sets the local copy of the AliITSLoader, and passes on the
220 // AliITSgeom object as needed.
222 // AliITSLoader *loader pointer to AliITSLoader for local use
228 if(fLoader==loader) return; // Same do nothing
229 if(fLoader){ // alread have an existing loader
231 "Already have an exisiting loader ptr=%p Nothing done",
236 //______________________________________________________________________
237 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
239 //Set simulation model for detector type
241 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
242 fSimulation->AddAt(sim,dettype);
244 //______________________________________________________________________
245 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
247 //Get simulation model for detector type
249 Warning("GetSimulationModel","fSimulation is 0!");
252 return (AliITSsimulation*)(fSimulation->At(dettype));
254 //______________________________________________________________________
255 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
257 //Get simulation model by module number
258 if(GetITSgeom()==0) {
259 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
263 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
265 //_______________________________________________________________________
266 void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
267 // Set default segmentation model objects
268 AliITSsegmentation *seg;
270 if(fSegmentation==0x0){
271 fSegmentation = new TObjArray(fgkNdettypes);
272 fSegmentation->SetOwner(kTRUE);
274 if(GetSegmentationModel(idet))
275 delete (AliITSsegmentation*)fSegmentation->At(idet);
277 seg = new AliITSsegmentationSPD();
279 seg = new AliITSsegmentationSDD();
281 seg = new AliITSsegmentationSSD();
283 SetSegmentationModel(idet,seg);
285 //______________________________________________________________________
286 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
287 AliITSsegmentation *seg){
289 //Set segmentation model for detector type
290 if(fSegmentation==0x0){
291 fSegmentation = new TObjArray(fgkNdettypes);
292 fSegmentation->SetOwner(kTRUE);
294 fSegmentation->AddAt(seg,dettype);
296 //______________________________________________________________________
297 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
298 //Get segmentation model for detector type
300 if(fSegmentation==0) {
301 Warning("GetSegmentationModel","fSegmentation is 0!");
304 return (AliITSsegmentation*)(fSegmentation->At(dettype));
306 //_______________________________________________________________________
307 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
308 //Get segmentation model by module number
310 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
313 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
315 //_______________________________________________________________________
316 void AliITSDetTypeSim::CreateCalibrationArray() {
317 //Create the container of calibration functions with correct size
319 Warning("CreateCalibration","pointer to calibration object exists\n");
320 fCalibration->Delete();
324 Int_t nModTot = GetITSgeom()->GetIndexMax();
325 fCalibration = new TObjArray(nModTot);
326 fCalibration->SetOwner(kTRUE);
327 fCalibration->Clear();
329 //_______________________________________________________________________
330 void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
331 //Set response model for modules
333 if (fCalibration==0) CreateCalibrationArray();
335 if (fCalibration->At(iMod)!=0)
336 delete (AliITSCalibration*) fCalibration->At(iMod);
337 fCalibration->AddAt(resp, iMod);
339 //______________________________________________________________________
340 void AliITSDetTypeSim::ResetCalibrationArray(){
341 //resets response array
342 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
343 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
344 GetITSgeom()->GetStartSPD()))->GetResponse();
345 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
346 GetITSgeom()->GetStartSSD()))->GetResponse();
347 if(rspd) delete rspd;
348 if(rssd) delete rssd;
349 fCalibration->Clear();
350 }else if (fCalibration && fRunNumber>=0){
351 fCalibration->Clear();
354 //______________________________________________________________________
355 void AliITSDetTypeSim::ResetSegmentation(){
356 //Resets segmentation array
357 if(fSegmentation) fSegmentation->Clear();
359 //_______________________________________________________________________
360 AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
361 //Get response model for module number iMod
363 if(fCalibration==0) {
364 AliError("fCalibration is 0!");
367 return (AliITSCalibration*)(fCalibration->At(iMod));
369 //_______________________________________________________________________
370 void AliITSDetTypeSim::SetDefaults(){
371 //Set defaults for segmentation and response
374 Warning("SetDefaults","GetITSgeom() is 0!");
377 if (fCalibration==0) {
378 CreateCalibrationArray();
382 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
384 SetDigitClassName(0,"AliITSdigitSPD");
385 SetDigitClassName(1,"AliITSdigitSDD");
386 SetDigitClassName(2,"AliITSdigitSSD");
388 for(Int_t idet=0;idet<fgkNdettypes;idet++){
389 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
392 //______________________________________________________________________
393 Bool_t AliITSDetTypeSim::GetCalibration() {
394 // Get Default calibration if a storage is not defined.
397 AliITSCalibration* cal = GetCalibrationModel(0);
404 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
405 Int_t run=GetRunNumber();
407 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
408 Bool_t isCacheActive = kTRUE;
409 if(GetRunNumber()<0){
410 isCacheActive=kFALSE;
411 fCalibration->SetOwner(kTRUE);
414 fCalibration->SetOwner(kFALSE);
417 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
419 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
420 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
421 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
422 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
423 AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
424 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
425 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
426 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
427 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
428 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
430 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
431 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
433 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
434 !entry2SPD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD ||!mapTSDD){
435 AliFatal("Calibration object retrieval failed! ");
439 // if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
440 // !entry2SPD || !entry2SSD){
441 // AliFatal("Calibration object retrieval failed! ");
445 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
446 if(!isCacheActive)entrySPD->SetObject(NULL);
447 entrySPD->SetOwner(kTRUE);
449 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
450 if(!isCacheActive)entry2SPD->SetObject(NULL);
451 entry2SPD->SetOwner(kTRUE);
453 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
454 if(!isCacheActive)entrySDD->SetObject(NULL);
455 entrySDD->SetOwner(kTRUE);
457 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
458 if(!isCacheActive)drSpSDD->SetObject(NULL);
459 drSpSDD->SetOwner(kTRUE);
461 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
462 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
463 ddlMapSDD->SetOwner(kTRUE);
465 TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
466 if(!isCacheActive)mapASDD->SetObject(NULL);
467 mapASDD->SetOwner(kTRUE);
469 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
470 if(!isCacheActive)mapTSDD->SetObject(NULL);
471 mapTSDD->SetOwner(kTRUE);
474 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
475 if(!isCacheActive)entrySSD->SetObject(NULL);
476 entrySSD->SetOwner(kTRUE);
479 TObjArray *noiseSSD = (TObjArray *)entryNoiseSSD->GetObject();
480 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
481 entryNoiseSSD->SetOwner(kTRUE);
483 TObjArray *gainSSD = (TObjArray *)entryGainSSD->GetObject();
484 if(!isCacheActive)entryGainSSD->SetObject(NULL);
485 entryGainSSD->SetOwner(kTRUE);
487 TObjArray *badchannelsSSD = (TObjArray *)entryBadChannelsSSD->GetObject();
488 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
489 entryBadChannelsSSD->SetOwner(kTRUE);
491 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
492 if(!isCacheActive)entry2SSD->SetObject(NULL);
493 entry2SSD->SetOwner(kTRUE);
495 // DB entries are deleted. In this way metadeta objects are deleted as well
499 delete entryNoiseSSD;
501 delete entryBadChannelsSSD;
510 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
512 if ((!pSPD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
513 || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badchannelsSSD)) {
514 AliWarning("Can not get calibration from calibration database !");
518 fNMod[0] = calSPD->GetEntries();
519 fNMod[1] = calSDD->GetEntries();
520 fNMod[2] = noiseSSD->GetEntries();
521 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
522 fNMod[0], fNMod[1], fNMod[2]));
523 AliITSCalibration* cal;
524 for (Int_t i=0; i<fNMod[0]; i++) {
525 cal = (AliITSCalibration*) calSPD->At(i);
526 cal->SetResponse(pSPD);
527 SetCalibrationModel(i, cal);
530 fDDLMapSDD->SetDDLMap(ddlsdd);
532 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
534 Int_t iMod = i + fgkDefaultNModulesSPD;
535 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
537 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
538 calsdddead->SetBad();
539 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
540 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
541 arrdrsp->AddDriftSpeed(driftspdef);
542 calsdddead->SetDriftSpeed(0,arrdrsp);
543 calsdddead->SetDriftSpeed(1,arrdrsp);
544 SetCalibrationModel(iMod, calsdddead);
545 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
547 cal = (AliITSCalibration*) calSDD->At(i);
550 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
551 AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
552 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
553 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
554 AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
555 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
556 cal->SetDriftSpeed(0,arr0);
557 cal->SetDriftSpeed(1,arr1);
562 SetCalibrationModel(iMod, cal);
566 for (Int_t i=0; i<fNMod[2]; i++) {
567 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
568 calibSSD->SetResponse((AliITSresponse*)pSSD);
570 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
571 calibSSD->SetNoise(noise);
572 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
573 calibSSD->SetGain(gain);
574 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
575 calibSSD->SetBadChannels(bad);
577 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
578 SetCalibrationModel(iMod, calibSSD);
583 //_______________________________________________________________________
584 void AliITSDetTypeSim::SetDefaultSimulation(){
585 //Set default simulation for detector type
588 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
592 Warning("SetDefaultSimulation","fCalibration is 0!");
595 if(fSegmentation==0){
596 Warning("SetDefaultSimulation","fSegmentation is 0!");
597 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
598 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
599 Warning("SetDefaultSimulation",
600 "Segmentation not defined for det %d - Default taken\n!",i);
601 SetDefaultSegmentation(i);
603 AliITSsimulation* sim;
605 for(Int_t idet=0;idet<fgkNdettypes;idet++){
608 sim = GetSimulationModel(idet);
610 sim = new AliITSsimulationSPD(this);
611 SetSimulationModel(idet,sim);
616 sim = GetSimulationModel(idet);
618 sim = new AliITSsimulationSDD(this);
619 SetSimulationModel(idet,sim);
624 sim = GetSimulationModel(idet);
626 sim = new AliITSsimulationSSD(this);
627 SetSimulationModel(idet,sim);
633 //___________________________________________________________________
634 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
635 // Set branch address for the ITS summable digits Trees.
642 sprintf(branchname,"%s",name);
643 branch = treeS->GetBranch(branchname);
644 TClonesArray *sdigi = &fSDigits;
645 if (branch) branch->SetAddress(&sdigi);
648 //___________________________________________________________________
649 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
650 // Set branch address for the digit Trees.
652 const char *det[3] = {"SPD","SDD","SSD"};
661 fDigits = new TObjArray(fgkNdettypes);
663 for(Int_t i=0;i<fgkNdettypes;i++){
664 Char_t* digclass = GetDigitClassName(i);
666 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
667 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
668 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
669 digclass = GetDigitClassName(i);
671 TString classn = digclass;
672 if(!(fDigits->At(i))){
673 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
678 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
679 else sprintf(branchname,"%sDigits%d",name,i+1);
681 branch = treeD->GetBranch(branchname);
682 if(branch) branch->SetAddress(&((*fDigits)[i]));
687 //___________________________________________________________________
688 void AliITSDetTypeSim::ResetDigits(){
689 // Reset number of digits and the digits array for the ITS detector.
692 Error("ResetDigits","fDigits is null!");
695 for(Int_t i=0;i<fgkNdettypes;i++){
699 //___________________________________________________________________
700 void AliITSDetTypeSim::ResetDigits(Int_t branch){
701 // Reset number of digits and the digits array for this branch.
703 if(fDigits->At(branch)){
704 ((TClonesArray*)fDigits->At(branch))->Clear();
706 if(fNDigits) fNDigits[branch]=0;
712 //_______________________________________________________________________
713 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
714 // Standard Summable digits to Digits function.
716 Warning("SDigitsToDigits","GetITSgeom() is null!!");
720 const char *all = strstr(opt,"All");
721 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
723 if( !det[0] && !det[1] && !det[2] ) all = "All";
725 static Bool_t setDef = kTRUE;
726 if(setDef) SetDefaultSimulation();
729 AliITSsimulation *sim =0;
730 TTree* trees = fLoader->TreeS();
731 if( !(trees && GetSDigits()) ){
732 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
735 sprintf(name,"%s",name);
736 TBranch* brchSDigits = trees->GetBranch(name);
739 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
740 id = GetITSgeom()->GetModuleType(module);
741 if (!all && !det[id]) continue;
742 sim = (AliITSsimulation*)GetSimulationModel(id);
744 Error("SDigit2Digits","The simulation class was not "
745 "instanciated for module %d type %s!",module,
746 GetITSgeom()->GetModuleTypeName(module));
749 sim->InitSimulationModule(module,gAlice->GetEvNumber());
752 brchSDigits->GetEvent(module);
753 sim->AddSDigitsToModule(&fSDigits,0);
754 sim->FinishSDigitiseModule();
755 fLoader->TreeD()->Fill();
758 fLoader->TreeD()->GetEntries();
759 fLoader->TreeD()->AutoSave();
760 fLoader->TreeD()->Reset();
762 //_________________________________________________________
763 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
764 //Adds the module full of summable digits to the summable digits tree.
766 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
768 //__________________________________________________________
769 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
770 // Add a simulated digit.
772 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
775 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
778 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
781 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
785 //______________________________________________________________________
786 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
787 Int_t *tracks,Int_t *hits,Float_t *charges,
789 // Add a simulated digit to the list.
791 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
794 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
797 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
798 hits,charges,sigexpanded);
801 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
805 //______________________________________________________________________
806 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
807 AliCDBMetaData &md) {
808 // Store calibration in the calibration database
809 // The database must be created in an external piece of code (i.e.
810 // a configuration macro )
812 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
813 AliWarning("No storage set! Will use dummy one");
814 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
818 AliError("AliITSCalibration classes are not defined - nothing done");
821 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
822 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
823 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
825 TObjArray respSPD(fNMod[0]);
826 TObjArray respSDD(fNMod[1]-fNMod[0]);
827 TObjArray respSSD(fNMod[2]-fNMod[1]);
828 respSPD.SetOwner(kFALSE);
829 respSSD.SetOwner(kFALSE);
830 respSSD.SetOwner(kFALSE);
832 Int_t index[fgkNdettypes];
833 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
835 for (Int_t j = 0; j<=i; j++ )
839 for (Int_t i = 0; i<index[0]; i++ )
840 respSPD.Add(fCalibration->At(i));
842 for (Int_t i = index[0]; i<index[1]; i++ )
843 respSDD.Add(fCalibration->At(i));
845 for (Int_t i = index[1]; i<index[2]; i++ )
846 respSSD.Add(fCalibration->At(i));
848 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
849 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
850 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);