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 "AliITSNoiseSSDv2.h"
51 #include "AliITSGainSSDv2.h"
52 #include "AliITSBadChannelsSSDv2.h"
53 #include "AliITSNoiseSSD.h"
54 #include "AliITSGainSSD.h"
55 #include "AliITSBadChannelsSSD.h"
56 #include "AliITSCalibrationSSD.h"
57 #include "AliITSsegmentationSPD.h"
58 #include "AliITSsegmentationSDD.h"
59 #include "AliITSsegmentationSSD.h"
60 #include "AliITSsimulation.h"
61 #include "AliITSsimulationSPD.h"
62 #include "AliITSsimulationSDD.h"
63 #include "AliITSsimulationSSD.h"
66 const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
67 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
68 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
69 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
71 ClassImp(AliITSDetTypeSim)
73 //----------------------------------------------------------------------
74 AliITSDetTypeSim::AliITSDetTypeSim():
76 fSimulation(), // [NDet]
77 fSegmentation(), // [NDet]
78 fCalibration(), // [NMod]
80 fPreProcess(), // [] e.g. Fill fHitModule with hits
81 fPostProcess(), // [] e.g. Wright Raw data
82 fNSDigits(0), //! number of SDigits
83 fSDigits("AliITSpListItem",1000),
84 fNDigits(0), //! number of Digits
85 fRunNumber(0), //! Run number (to access DB)
86 fDigits(), //! [NMod][NDigits]
89 fHitClassName(), // String with Hit class name.
90 fSDigClassName(),// String with SDigit class name.
91 fDigClassName(), // String with digit class name.
92 fLoader(0), // local pointer to loader
93 fFirstcall(kTRUE){ // flag
94 // Default Constructor
100 // A properly zero-ed AliITSDetTypeSim class.
102 fSimulation = new TObjArray(fgkNdettypes);
103 fSegmentation = new TObjArray(fgkNdettypes);
104 fSegmentation->SetOwner(kTRUE);
105 fDigits = new TObjArray(fgkNdettypes);
106 fNDigits = new Int_t[fgkNdettypes];
107 fDDLMapSDD=new AliITSDDLModuleMapSDD();
108 fSimuPar= new AliITSSimuParam();
109 fSSDCalibration=new AliITSCalibrationSSD();
110 fNMod[0] = fgkDefaultNModulesSPD;
111 fNMod[1] = fgkDefaultNModulesSDD;
112 fNMod[2] = fgkDefaultNModulesSSD;
115 //----------------------------------------------------------------------
116 AliITSDetTypeSim::~AliITSDetTypeSim(){
126 fSimulation->Delete();
131 fSegmentation->Delete();
132 delete fSegmentation;
135 if(fCalibration && fRunNumber<0){
136 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
137 GetITSgeom()->GetStartSPD()))->GetResponse();
138 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
139 GetITSgeom()->GetStartSSD()))->GetResponse();
140 if(rspd) delete rspd;
141 if(rssd) delete rssd;
142 fCalibration->Delete();
146 if(fSSDCalibration) delete fSSDCalibration;
148 fPreProcess->Delete();
153 fPostProcess->Delete();
157 if(fSimuPar) delete fSimuPar;
158 if(fDDLMapSDD) delete fDDLMapSDD;
159 if(fNDigits) delete [] fNDigits;
161 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
162 fLoader = 0; // Not deleting it.
170 //----------------------------------------------------------------------
171 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
172 fSimulation(source.fSimulation), // [NDet]
173 fSegmentation(source.fSegmentation), // [NDet]
174 fCalibration(source.fCalibration), // [NMod]
175 fSSDCalibration(source.fSSDCalibration),
176 fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
177 fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
178 fNSDigits(source.fNSDigits), //! number of SDigits
179 fSDigits(*((TClonesArray*)source.fSDigits.Clone())),
180 fNDigits(source.fNDigits), //! number of Digits
181 fRunNumber(source.fRunNumber), //! Run number (to access DB)
182 fDigits(source.fDigits), //! [NMod][NDigits]
183 fSimuPar(source.fSimuPar),
184 fDDLMapSDD(source.fDDLMapSDD),
185 fHitClassName(source.fHitClassName), // String with Hit class name.
186 fSDigClassName(source.fSDigClassName),// String with SDigit class name.
187 fDigClassName(), // String with digit class name.
188 fLoader(source.fLoader), // local pointer to loader
189 fFirstcall(source.fFirstcall)
191 // Copy Constructor for object AliITSDetTypeSim not allowed
192 for(Int_t i=0;i<fgkNdettypes;i++){
193 fDigClassName[i] = source.fDigClassName[i];
196 //----------------------------------------------------------------------
197 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
198 // The = operator for object AliITSDetTypeSim
200 this->~AliITSDetTypeSim();
201 new(this) AliITSDetTypeSim(source);
205 //______________________________________________________________________
206 void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
207 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
210 // AliITSgoem *geom The AliITSgeom object to be used.
216 Error("SetITSgeom","No pointer to loader - nothing done");
220 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
224 //______________________________________________________________________
225 void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
226 // Sets the local copy of the AliITSLoader, and passes on the
227 // AliITSgeom object as needed.
229 // AliITSLoader *loader pointer to AliITSLoader for local use
235 if(fLoader==loader) return; // Same do nothing
236 if(fLoader){ // alread have an existing loader
238 "Already have an exisiting loader ptr=%p Nothing done",
243 //______________________________________________________________________
244 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
246 //Set simulation model for detector type
248 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
249 fSimulation->AddAt(sim,dettype);
251 //______________________________________________________________________
252 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
254 //Get simulation model for detector type
256 Warning("GetSimulationModel","fSimulation is 0!");
259 return (AliITSsimulation*)(fSimulation->At(dettype));
261 //______________________________________________________________________
262 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
264 //Get simulation model by module number
265 if(GetITSgeom()==0) {
266 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
270 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
272 //_______________________________________________________________________
273 void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
274 // Set default segmentation model objects
275 AliITSsegmentation *seg;
277 if(fSegmentation==0x0){
278 fSegmentation = new TObjArray(fgkNdettypes);
279 fSegmentation->SetOwner(kTRUE);
281 if(GetSegmentationModel(idet))
282 delete (AliITSsegmentation*)fSegmentation->At(idet);
284 seg = new AliITSsegmentationSPD();
286 seg = new AliITSsegmentationSDD();
288 seg = new AliITSsegmentationSSD();
290 SetSegmentationModel(idet,seg);
292 //______________________________________________________________________
293 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
294 AliITSsegmentation *seg){
296 //Set segmentation model for detector type
297 if(fSegmentation==0x0){
298 fSegmentation = new TObjArray(fgkNdettypes);
299 fSegmentation->SetOwner(kTRUE);
301 fSegmentation->AddAt(seg,dettype);
303 //______________________________________________________________________
304 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
305 //Get segmentation model for detector type
307 if(fSegmentation==0) {
308 Warning("GetSegmentationModel","fSegmentation is 0!");
311 return (AliITSsegmentation*)(fSegmentation->At(dettype));
313 //_______________________________________________________________________
314 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
315 //Get segmentation model by module number
317 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
320 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
322 //_______________________________________________________________________
323 void AliITSDetTypeSim::CreateCalibrationArray() {
324 //Create the container of calibration functions with correct size
326 Warning("CreateCalibration","pointer to calibration object exists\n");
327 fCalibration->Delete();
331 Int_t nModTot = GetITSgeom()->GetIndexMax();
332 fCalibration = new TObjArray(nModTot);
333 fCalibration->SetOwner(kTRUE);
334 fCalibration->Clear();
336 //_______________________________________________________________________
337 void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
338 //Set response model for modules
340 if (fCalibration==0) CreateCalibrationArray();
342 if (fCalibration->At(iMod)!=0)
343 delete (AliITSCalibration*) fCalibration->At(iMod);
344 fCalibration->AddAt(resp, iMod);
346 //______________________________________________________________________
347 void AliITSDetTypeSim::ResetCalibrationArray(){
348 //resets response array
349 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
350 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
351 GetITSgeom()->GetStartSPD()))->GetResponse();
352 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
353 GetITSgeom()->GetStartSSD()))->GetResponse();
354 if(rspd) delete rspd;
355 if(rssd) delete rssd;
356 fCalibration->Clear();
357 }else if (fCalibration && fRunNumber>=0){
358 fCalibration->Clear();
361 //______________________________________________________________________
362 void AliITSDetTypeSim::ResetSegmentation(){
363 //Resets segmentation array
364 if(fSegmentation) fSegmentation->Clear();
366 //_______________________________________________________________________
367 AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
368 //Get response model for module number iMod
370 if(fCalibration==0) {
371 AliError("fCalibration is 0!");
374 if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
375 return (AliITSCalibration*)fCalibration->At(iMod);
377 Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
378 fSSDCalibration->SetModule(i);
379 return (AliITSCalibration*)fSSDCalibration;
383 //_______________________________________________________________________
384 void AliITSDetTypeSim::SetDefaults(){
385 //Set defaults for segmentation and response
388 Warning("SetDefaults","GetITSgeom() is 0!");
391 if (fCalibration==0) {
392 CreateCalibrationArray();
396 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
398 SetDigitClassName(0,"AliITSdigitSPD");
399 SetDigitClassName(1,"AliITSdigitSDD");
400 SetDigitClassName(2,"AliITSdigitSSD");
402 for(Int_t idet=0;idet<fgkNdettypes;idet++){
403 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
406 //______________________________________________________________________
407 Bool_t AliITSDetTypeSim::GetCalibration() {
408 // Get Default calibration if a storage is not defined.
411 AliITSCalibration* cal = GetCalibrationModel(0);
418 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
419 Int_t run=GetRunNumber();
421 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
422 Bool_t isCacheActive = kTRUE;
423 if(GetRunNumber()<0){
424 isCacheActive=kFALSE;
425 fCalibration->SetOwner(kTRUE);
428 fCalibration->SetOwner(kFALSE);
431 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
433 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
434 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
435 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
436 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
437 AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
438 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
439 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
440 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
441 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
442 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
444 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
445 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
447 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
448 !entry2SPD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD ||!mapTSDD){
449 AliFatal("Calibration object retrieval failed! ");
453 // if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
454 // !entry2SPD || !entry2SSD){
455 // AliFatal("Calibration object retrieval failed! ");
459 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
460 if(!isCacheActive)entrySPD->SetObject(NULL);
461 entrySPD->SetOwner(kTRUE);
463 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
464 if(!isCacheActive)entry2SPD->SetObject(NULL);
465 entry2SPD->SetOwner(kTRUE);
467 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
468 if(!isCacheActive)entrySDD->SetObject(NULL);
469 entrySDD->SetOwner(kTRUE);
471 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
472 if(!isCacheActive)drSpSDD->SetObject(NULL);
473 drSpSDD->SetOwner(kTRUE);
475 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
476 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
477 ddlMapSDD->SetOwner(kTRUE);
479 TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
480 if(!isCacheActive)mapASDD->SetObject(NULL);
481 mapASDD->SetOwner(kTRUE);
483 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
484 if(!isCacheActive)mapTSDD->SetObject(NULL);
485 mapTSDD->SetOwner(kTRUE);
488 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
489 if(!isCacheActive)entrySSD->SetObject(NULL);
490 entrySSD->SetOwner(kTRUE);
493 TObject *emptyssd = 0; TString ssdobjectname = 0;
494 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
495 emptyssd = (TObject *)entryNoiseSSD->GetObject();
496 ssdobjectname = emptyssd->GetName();
497 if(ssdobjectname=="TObjArray") {
498 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
499 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
501 else if(ssdobjectname=="AliITSNoiseSSDv2")
502 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
503 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
504 entryNoiseSSD->SetOwner(kTRUE);
506 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
507 emptyssd = (TObject *)entryGainSSD->GetObject();
508 ssdobjectname = emptyssd->GetName();
509 if(ssdobjectname=="Gain") {
510 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
511 ReadOldSSDGain(gainSSDOld, gainSSD);
513 else if(ssdobjectname=="AliITSGainSSDv2")
514 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
515 if(!isCacheActive)entryGainSSD->SetObject(NULL);
516 entryGainSSD->SetOwner(kTRUE);
518 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
519 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
520 ssdobjectname = emptyssd->GetName();
521 if(ssdobjectname=="TObjArray") {
522 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
523 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
525 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
526 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
527 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
528 entryBadChannelsSSD->SetOwner(kTRUE);
530 /*AliITSNoiseSSDv2 *noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
531 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
532 entryNoiseSSD->SetOwner(kTRUE);
534 AliITSGainSSDv2 *gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
535 if(!isCacheActive)entryGainSSD->SetObject(NULL);
536 entryGainSSD->SetOwner(kTRUE);
538 AliITSBadChannelsSSDv2 *badchannelsSSD =
539 (AliITSBadChannelsSSDv2 *)entryBadChannelsSSD->GetObject();
540 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
541 entryBadChannelsSSD->SetOwner(kTRUE);*/
543 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
544 if(!isCacheActive)entry2SSD->SetObject(NULL);
545 entry2SSD->SetOwner(kTRUE);
547 // DB entries are deleted. In this way metadeta objects are deleted as well
551 delete entryNoiseSSD;
553 delete entryBadChannelsSSD;
562 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
564 if ((!pSPD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
565 || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
566 AliWarning("Can not get calibration from calibration database !");
570 fNMod[0] = calSPD->GetEntries();
571 fNMod[1] = calSDD->GetEntries();
572 // fNMod[2] = noiseSSD->GetEntries();
573 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
574 fNMod[0], fNMod[1], fNMod[2]));
575 AliITSCalibration* cal;
576 for (Int_t i=0; i<fNMod[0]; i++) {
577 cal = (AliITSCalibration*) calSPD->At(i);
578 cal->SetResponse(pSPD);
579 SetCalibrationModel(i, cal);
582 fDDLMapSDD->SetDDLMap(ddlsdd);
584 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
586 Int_t iMod = i + fgkDefaultNModulesSPD;
587 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
589 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
590 calsdddead->SetBad();
591 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
592 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
593 arrdrsp->AddDriftSpeed(driftspdef);
594 calsdddead->SetDriftSpeed(0,arrdrsp);
595 calsdddead->SetDriftSpeed(1,arrdrsp);
596 SetCalibrationModel(iMod, calsdddead);
597 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
599 cal = (AliITSCalibration*) calSDD->At(i);
602 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
603 AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
604 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
605 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
606 AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
607 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
608 cal->SetDriftSpeed(0,arr0);
609 cal->SetDriftSpeed(1,arr1);
614 SetCalibrationModel(iMod, cal);
618 fSSDCalibration->SetResponse((AliITSresponse*)pSSD);
619 fSSDCalibration->SetNoise(noiseSSD);
620 fSSDCalibration->SetGain(gainSSD);
621 fSSDCalibration->SetBadChannels(badChannelsSSD);
622 //fSSDCalibration->FillBadChipMap();
626 for (Int_t i=0; i<fNMod[2]; i++) {
627 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
628 calibSSD->SetResponse((AliITSresponse*)pSSD);
630 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
631 calibSSD->SetNoise(noise);
632 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
633 calibSSD->SetGain(gain);
634 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
635 calibSSD->SetBadChannels(bad);
637 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
638 SetCalibrationModel(iMod, calibSSD);
646 //_______________________________________________________________________
647 void AliITSDetTypeSim::SetDefaultSimulation(){
648 //Set default simulation for detector type
651 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
655 Warning("SetDefaultSimulation","fCalibration is 0!");
658 if(fSegmentation==0){
659 Warning("SetDefaultSimulation","fSegmentation is 0!");
660 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
661 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
662 Warning("SetDefaultSimulation",
663 "Segmentation not defined for det %d - Default taken\n!",i);
664 SetDefaultSegmentation(i);
666 AliITSsimulation* sim;
668 for(Int_t idet=0;idet<fgkNdettypes;idet++){
671 sim = GetSimulationModel(idet);
673 sim = new AliITSsimulationSPD(this);
674 SetSimulationModel(idet,sim);
679 sim = GetSimulationModel(idet);
681 sim = new AliITSsimulationSDD(this);
682 SetSimulationModel(idet,sim);
687 sim = GetSimulationModel(idet);
689 sim = new AliITSsimulationSSD(this);
690 SetSimulationModel(idet,sim);
696 //___________________________________________________________________
697 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
698 // Set branch address for the ITS summable digits Trees.
705 sprintf(branchname,"%s",name);
706 branch = treeS->GetBranch(branchname);
707 TClonesArray *sdigi = &fSDigits;
708 if (branch) branch->SetAddress(&sdigi);
711 //___________________________________________________________________
712 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
713 // Set branch address for the digit Trees.
715 const char *det[3] = {"SPD","SDD","SSD"};
724 fDigits = new TObjArray(fgkNdettypes);
726 for(Int_t i=0;i<fgkNdettypes;i++){
727 Char_t* digclass = GetDigitClassName(i);
729 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
730 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
731 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
732 digclass = GetDigitClassName(i);
734 TString classn = digclass;
735 if(!(fDigits->At(i))){
736 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
741 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
742 else sprintf(branchname,"%sDigits%d",name,i+1);
744 branch = treeD->GetBranch(branchname);
745 if(branch) branch->SetAddress(&((*fDigits)[i]));
750 //___________________________________________________________________
751 void AliITSDetTypeSim::ResetDigits(){
752 // Reset number of digits and the digits array for the ITS detector.
755 Error("ResetDigits","fDigits is null!");
758 for(Int_t i=0;i<fgkNdettypes;i++){
762 //___________________________________________________________________
763 void AliITSDetTypeSim::ResetDigits(Int_t branch){
764 // Reset number of digits and the digits array for this branch.
766 if(fDigits->At(branch)){
767 ((TClonesArray*)fDigits->At(branch))->Clear();
769 if(fNDigits) fNDigits[branch]=0;
775 //_______________________________________________________________________
776 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
777 // Standard Summable digits to Digits function.
779 Warning("SDigitsToDigits","GetITSgeom() is null!!");
783 const char *all = strstr(opt,"All");
784 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
786 if( !det[0] && !det[1] && !det[2] ) all = "All";
788 static Bool_t setDef = kTRUE;
789 if(setDef) SetDefaultSimulation();
792 AliITSsimulation *sim =0;
793 TTree* trees = fLoader->TreeS();
794 if( !(trees && GetSDigits()) ){
795 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
798 sprintf(name,"%s",name);
799 TBranch* brchSDigits = trees->GetBranch(name);
802 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
803 id = GetITSgeom()->GetModuleType(module);
804 if (!all && !det[id]) continue;
805 sim = (AliITSsimulation*)GetSimulationModel(id);
807 Error("SDigit2Digits","The simulation class was not "
808 "instanciated for module %d type %s!",module,
809 GetITSgeom()->GetModuleTypeName(module));
812 sim->InitSimulationModule(module,gAlice->GetEvNumber());
815 brchSDigits->GetEvent(module);
816 sim->AddSDigitsToModule(&fSDigits,0);
817 sim->FinishSDigitiseModule();
818 fLoader->TreeD()->Fill();
821 fLoader->TreeD()->GetEntries();
822 fLoader->TreeD()->AutoSave();
823 fLoader->TreeD()->Reset();
825 //_________________________________________________________
826 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
827 //Adds the module full of summable digits to the summable digits tree.
829 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
831 //__________________________________________________________
832 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
833 // Add a simulated digit.
835 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
838 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
841 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
844 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
848 //______________________________________________________________________
849 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
850 Int_t *tracks,Int_t *hits,Float_t *charges,
852 // Add a simulated digit to the list.
854 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
857 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
860 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
861 hits,charges,sigexpanded);
864 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
868 //______________________________________________________________________
869 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
870 AliCDBMetaData &md) {
871 // Store calibration in the calibration database
872 // The database must be created in an external piece of code (i.e.
873 // a configuration macro )
875 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
876 AliWarning("No storage set! Will use dummy one");
877 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
881 AliError("AliITSCalibration classes are not defined - nothing done");
884 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
885 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
886 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
888 TObjArray respSPD(fNMod[0]);
889 TObjArray respSDD(fNMod[1]-fNMod[0]);
890 TObjArray respSSD(fNMod[2]-fNMod[1]);
891 respSPD.SetOwner(kFALSE);
892 respSSD.SetOwner(kFALSE);
893 respSSD.SetOwner(kFALSE);
895 Int_t index[fgkNdettypes];
896 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
898 for (Int_t j = 0; j<=i; j++ )
902 for (Int_t i = 0; i<index[0]; i++ )
903 respSPD.Add(fCalibration->At(i));
905 for (Int_t i = index[0]; i<index[1]; i++ )
906 respSDD.Add(fCalibration->At(i));
908 for (Int_t i = index[1]; i<index[2]; i++ )
909 respSSD.Add(fCalibration->At(i));
911 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
912 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
913 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
916 //______________________________________________________________________
917 void AliITSDetTypeSim::ReadOldSSDNoise(TObjArray *array,
918 AliITSNoiseSSDv2 *noiseSSD) {
919 //Reads the old SSD calibration object and converts it to the new format
920 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
921 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
923 Int_t fNMod = array->GetEntries();
924 cout<<"Converting old calibration object for noise..."<<endl;
927 Double_t noise = 0.0;
928 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
929 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
930 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
931 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
932 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
933 noiseSSD->AddNoiseP(iModule,iStrip,noise);
934 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
935 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
940 //______________________________________________________________________
941 void AliITSDetTypeSim::ReadOldSSDBadChannels(TObjArray *array,
942 AliITSBadChannelsSSDv2 *badChannelsSSD) {
943 //Reads the old SSD calibration object and converts it to the new format
944 Int_t fNMod = array->GetEntries();
945 cout<<"Converting old calibration object for bad channels..."<<endl;
946 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
947 //for (Int_t iModule = 0; iModule < 1; iModule++) {
948 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
949 TArrayI arrayPSide = bad->GetBadPChannelsList();
950 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
951 badChannelsSSD->AddBadChannelP(iModule,
953 (Char_t)arrayPSide.At(iPCounter));
955 TArrayI arrayNSide = bad->GetBadNChannelsList();
956 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
957 badChannelsSSD->AddBadChannelN(iModule,
959 (Char_t)arrayNSide.At(iNCounter));
964 //______________________________________________________________________
965 void AliITSDetTypeSim::ReadOldSSDGain(TObjArray *array,
966 AliITSGainSSDv2 *gainSSD) {
967 //Reads the old SSD calibration object and converts it to the new format
969 Int_t fNMod = array->GetEntries();
970 cout<<"Converting old calibration object for gain..."<<endl;
973 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
974 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
975 TArrayF arrayPSide = gainModule->GetGainP();
976 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
977 gainSSD->AddGainP(iModule,
979 arrayPSide.At(iPCounter));
980 TArrayF arrayNSide = gainModule->GetGainN();
981 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
982 gainSSD->AddGainN(iModule,
984 arrayNSide.At(iNCounter));