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();
287 AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
288 if(cal->IsAMAt20MHz()){
289 seg->SetPadSize(seg->Dpz(0),20.);
290 seg->SetNPads(seg->Npz()/2,128);
293 seg = new AliITSsegmentationSSD();
295 SetSegmentationModel(idet,seg);
297 //______________________________________________________________________
298 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
299 AliITSsegmentation *seg){
301 //Set segmentation model for detector type
302 if(fSegmentation==0x0){
303 fSegmentation = new TObjArray(fgkNdettypes);
304 fSegmentation->SetOwner(kTRUE);
306 fSegmentation->AddAt(seg,dettype);
308 //______________________________________________________________________
309 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
310 //Get segmentation model for detector type
312 if(fSegmentation==0) {
313 Warning("GetSegmentationModel","fSegmentation is 0!");
316 return (AliITSsegmentation*)(fSegmentation->At(dettype));
318 //_______________________________________________________________________
319 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
320 //Get segmentation model by module number
322 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
325 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
327 //_______________________________________________________________________
328 void AliITSDetTypeSim::CreateCalibrationArray() {
329 //Create the container of calibration functions with correct size
331 Warning("CreateCalibration","pointer to calibration object exists\n");
332 fCalibration->Delete();
336 Int_t nModTot = GetITSgeom()->GetIndexMax();
337 fCalibration = new TObjArray(nModTot);
338 fCalibration->SetOwner(kTRUE);
339 fCalibration->Clear();
341 //_______________________________________________________________________
342 void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
343 //Set response model for modules
345 if (fCalibration==0) CreateCalibrationArray();
347 if (fCalibration->At(iMod)!=0)
348 delete (AliITSCalibration*) fCalibration->At(iMod);
349 fCalibration->AddAt(resp, iMod);
351 //______________________________________________________________________
352 void AliITSDetTypeSim::ResetCalibrationArray(){
353 //resets response array
354 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
355 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
356 GetITSgeom()->GetStartSPD()))->GetResponse();
357 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
358 GetITSgeom()->GetStartSSD()))->GetResponse();
359 if(rspd) delete rspd;
360 if(rssd) delete rssd;
361 fCalibration->Clear();
362 }else if (fCalibration && fRunNumber>=0){
363 fCalibration->Clear();
366 //______________________________________________________________________
367 void AliITSDetTypeSim::ResetSegmentation(){
368 //Resets segmentation array
369 if(fSegmentation) fSegmentation->Clear();
371 //_______________________________________________________________________
372 AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
373 //Get response model for module number iMod
375 if(fCalibration==0) {
376 AliError("fCalibration is 0!");
379 if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
380 return (AliITSCalibration*)fCalibration->At(iMod);
382 Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
383 fSSDCalibration->SetModule(i);
384 return (AliITSCalibration*)fSSDCalibration;
388 //_______________________________________________________________________
389 void AliITSDetTypeSim::SetDefaults(){
390 //Set defaults for segmentation and response
393 Warning("SetDefaults","GetITSgeom() is 0!");
396 if (fCalibration==0) {
397 CreateCalibrationArray();
401 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
403 SetDigitClassName(0,"AliITSdigitSPD");
404 SetDigitClassName(1,"AliITSdigitSDD");
405 SetDigitClassName(2,"AliITSdigitSSD");
407 for(Int_t idet=0;idet<fgkNdettypes;idet++){
408 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
411 //______________________________________________________________________
412 Bool_t AliITSDetTypeSim::GetCalibration() {
413 // Get Default calibration if a storage is not defined.
416 AliITSCalibration* cal = GetCalibrationModel(0);
423 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
424 Int_t run=GetRunNumber();
426 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
427 Bool_t isCacheActive = kTRUE;
428 if(GetRunNumber()<0){
429 isCacheActive=kFALSE;
430 fCalibration->SetOwner(kTRUE);
433 fCalibration->SetOwner(kFALSE);
436 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
438 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
439 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
440 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
441 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
442 //AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
443 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
444 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
445 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
446 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
447 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
449 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
451 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
452 !entry2SPD || !drSpSDD || !ddlMapSDD || !mapTSDD){
453 AliFatal("Calibration object retrieval failed! ");
457 // if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
458 // !entry2SPD || !entry2SSD){
459 // AliFatal("Calibration object retrieval failed! ");
463 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
464 if(!isCacheActive)entrySPD->SetObject(NULL);
465 entrySPD->SetOwner(kTRUE);
467 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
468 if(!isCacheActive)entry2SPD->SetObject(NULL);
469 entry2SPD->SetOwner(kTRUE);
471 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
472 if(!isCacheActive)entrySDD->SetObject(NULL);
473 entrySDD->SetOwner(kTRUE);
475 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
476 if(!isCacheActive)drSpSDD->SetObject(NULL);
477 drSpSDD->SetOwner(kTRUE);
479 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
480 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
481 ddlMapSDD->SetOwner(kTRUE);
483 // TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
484 // if(!isCacheActive)mapASDD->SetObject(NULL);
485 // mapASDD->SetOwner(kTRUE);
487 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
488 if(!isCacheActive)mapTSDD->SetObject(NULL);
489 mapTSDD->SetOwner(kTRUE);
492 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
493 if(!isCacheActive)entrySSD->SetObject(NULL);
494 entrySSD->SetOwner(kTRUE);
497 TObject *emptyssd = 0; TString ssdobjectname = 0;
498 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
499 emptyssd = (TObject *)entryNoiseSSD->GetObject();
500 ssdobjectname = emptyssd->GetName();
501 if(ssdobjectname=="TObjArray") {
502 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
503 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
505 else if(ssdobjectname=="AliITSNoiseSSDv2")
506 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
507 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
508 entryNoiseSSD->SetOwner(kTRUE);
510 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
511 emptyssd = (TObject *)entryGainSSD->GetObject();
512 ssdobjectname = emptyssd->GetName();
513 if(ssdobjectname=="Gain") {
514 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
515 ReadOldSSDGain(gainSSDOld, gainSSD);
517 else if(ssdobjectname=="AliITSGainSSDv2")
518 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
519 if(!isCacheActive)entryGainSSD->SetObject(NULL);
520 entryGainSSD->SetOwner(kTRUE);
522 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
523 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
524 ssdobjectname = emptyssd->GetName();
525 if(ssdobjectname=="TObjArray") {
526 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
527 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
529 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
530 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
531 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
532 entryBadChannelsSSD->SetOwner(kTRUE);
534 /*AliITSNoiseSSDv2 *noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
535 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
536 entryNoiseSSD->SetOwner(kTRUE);
538 AliITSGainSSDv2 *gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
539 if(!isCacheActive)entryGainSSD->SetObject(NULL);
540 entryGainSSD->SetOwner(kTRUE);
542 AliITSBadChannelsSSDv2 *badchannelsSSD =
543 (AliITSBadChannelsSSDv2 *)entryBadChannelsSSD->GetObject();
544 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
545 entryBadChannelsSSD->SetOwner(kTRUE);*/
547 // DB entries are deleted. In this way metadeta objects are deleted as well
551 delete entryNoiseSSD;
553 delete entryBadChannelsSSD;
561 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
563 if ((!pSPD)|| (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
564 || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
565 AliWarning("Can not get calibration from calibration database !");
569 fNMod[0] = calSPD->GetEntries();
570 fNMod[1] = calSDD->GetEntries();
571 // fNMod[2] = noiseSSD->GetEntries();
572 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
573 fNMod[0], fNMod[1], fNMod[2]));
574 AliITSCalibration* cal;
575 for (Int_t i=0; i<fNMod[0]; i++) {
576 cal = (AliITSCalibration*) calSPD->At(i);
577 cal->SetResponse(pSPD);
578 SetCalibrationModel(i, cal);
581 fDDLMapSDD->SetDDLMap(ddlsdd);
583 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
585 Int_t iMod = i + fgkDefaultNModulesSPD;
586 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
588 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
589 calsdddead->SetBad();
590 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
591 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
592 arrdrsp->AddDriftSpeed(driftspdef);
593 calsdddead->SetDriftSpeed(0,arrdrsp);
594 calsdddead->SetDriftSpeed(1,arrdrsp);
595 SetCalibrationModel(iMod, calsdddead);
596 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
598 cal = (AliITSCalibration*) calSDD->At(i);
601 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
602 // AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
603 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
604 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
605 // AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
606 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
607 cal->SetDriftSpeed(0,arr0);
608 cal->SetDriftSpeed(1,arr1);
609 // cal->SetMapA(0,ma0);
610 // cal->SetMapA(1,ma1);
613 SetCalibrationModel(iMod, cal);
617 fSSDCalibration->SetNoise(noiseSSD);
618 fSSDCalibration->SetGain(gainSSD);
619 fSSDCalibration->SetBadChannels(badChannelsSSD);
620 //fSSDCalibration->FillBadChipMap();
624 for (Int_t i=0; i<fNMod[2]; i++) {
625 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
626 calibSSD->SetResponse((AliITSresponse*)pSSD);
628 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
629 calibSSD->SetNoise(noise);
630 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
631 calibSSD->SetGain(gain);
632 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
633 calibSSD->SetBadChannels(bad);
635 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
636 SetCalibrationModel(iMod, calibSSD);
644 //_______________________________________________________________________
645 void AliITSDetTypeSim::SetDefaultSimulation(){
646 //Set default simulation for detector type
649 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
653 Warning("SetDefaultSimulation","fCalibration is 0!");
656 if(fSegmentation==0){
657 Warning("SetDefaultSimulation","fSegmentation is 0!");
658 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
659 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
660 Warning("SetDefaultSimulation",
661 "Segmentation not defined for det %d - Default taken\n!",i);
662 SetDefaultSegmentation(i);
664 AliITSsimulation* sim;
666 for(Int_t idet=0;idet<fgkNdettypes;idet++){
669 sim = GetSimulationModel(idet);
671 sim = new AliITSsimulationSPD(this);
672 SetSimulationModel(idet,sim);
677 sim = GetSimulationModel(idet);
679 sim = new AliITSsimulationSDD(this);
680 SetSimulationModel(idet,sim);
685 sim = GetSimulationModel(idet);
687 sim = new AliITSsimulationSSD(this);
688 SetSimulationModel(idet,sim);
694 //___________________________________________________________________
695 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
696 // Set branch address for the ITS summable digits Trees.
703 sprintf(branchname,"%s",name);
704 branch = treeS->GetBranch(branchname);
705 TClonesArray *sdigi = &fSDigits;
706 if (branch) branch->SetAddress(&sdigi);
709 //___________________________________________________________________
710 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
711 // Set branch address for the digit Trees.
713 const char *det[3] = {"SPD","SDD","SSD"};
722 fDigits = new TObjArray(fgkNdettypes);
724 for(Int_t i=0;i<fgkNdettypes;i++){
725 Char_t* digclass = GetDigitClassName(i);
727 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
728 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
729 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
730 digclass = GetDigitClassName(i);
732 TString classn = digclass;
733 if(!(fDigits->At(i))){
734 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
739 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
740 else sprintf(branchname,"%sDigits%d",name,i+1);
742 branch = treeD->GetBranch(branchname);
743 if(branch) branch->SetAddress(&((*fDigits)[i]));
748 //___________________________________________________________________
749 void AliITSDetTypeSim::ResetDigits(){
750 // Reset number of digits and the digits array for the ITS detector.
753 Error("ResetDigits","fDigits is null!");
756 for(Int_t i=0;i<fgkNdettypes;i++){
760 //___________________________________________________________________
761 void AliITSDetTypeSim::ResetDigits(Int_t branch){
762 // Reset number of digits and the digits array for this branch.
764 if(fDigits->At(branch)){
765 ((TClonesArray*)fDigits->At(branch))->Clear();
767 if(fNDigits) fNDigits[branch]=0;
773 //_______________________________________________________________________
774 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
775 // Standard Summable digits to Digits function.
777 Warning("SDigitsToDigits","GetITSgeom() is null!!");
781 const char *all = strstr(opt,"All");
782 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
784 if( !det[0] && !det[1] && !det[2] ) all = "All";
786 static Bool_t setDef = kTRUE;
787 if(setDef) SetDefaultSimulation();
790 AliITSsimulation *sim =0;
791 TTree* trees = fLoader->TreeS();
792 if( !(trees && GetSDigits()) ){
793 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
796 sprintf(name,"%s",name);
797 TBranch* brchSDigits = trees->GetBranch(name);
800 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
801 id = GetITSgeom()->GetModuleType(module);
802 if (!all && !det[id]) continue;
803 sim = (AliITSsimulation*)GetSimulationModel(id);
805 Error("SDigit2Digits","The simulation class was not "
806 "instanciated for module %d type %s!",module,
807 GetITSgeom()->GetModuleTypeName(module));
810 sim->InitSimulationModule(module,gAlice->GetEvNumber());
813 brchSDigits->GetEvent(module);
814 sim->AddSDigitsToModule(&fSDigits,0);
815 sim->FinishSDigitiseModule();
816 fLoader->TreeD()->Fill();
819 fLoader->TreeD()->GetEntries();
820 fLoader->TreeD()->AutoSave();
821 fLoader->TreeD()->Reset();
823 //_________________________________________________________
824 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
825 //Adds the module full of summable digits to the summable digits tree.
827 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
829 //__________________________________________________________
830 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
831 // Add a simulated digit.
833 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
836 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
839 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
842 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
846 //______________________________________________________________________
847 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
848 Int_t *tracks,Int_t *hits,Float_t *charges,
850 // Add a simulated digit to the list.
852 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
855 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
858 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
859 hits,charges,sigexpanded);
862 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
866 //______________________________________________________________________
867 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
868 AliCDBMetaData &md) {
869 // Store calibration in the calibration database
870 // The database must be created in an external piece of code (i.e.
871 // a configuration macro )
873 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
874 AliWarning("No storage set! Will use dummy one");
875 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
879 AliError("AliITSCalibration classes are not defined - nothing done");
882 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
883 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
884 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
886 TObjArray respSPD(fNMod[0]);
887 TObjArray respSDD(fNMod[1]-fNMod[0]);
888 TObjArray respSSD(fNMod[2]-fNMod[1]);
889 respSPD.SetOwner(kFALSE);
890 respSSD.SetOwner(kFALSE);
891 respSSD.SetOwner(kFALSE);
893 Int_t index[fgkNdettypes];
894 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
896 for (Int_t j = 0; j<=i; j++ )
900 for (Int_t i = 0; i<index[0]; i++ )
901 respSPD.Add(fCalibration->At(i));
903 for (Int_t i = index[0]; i<index[1]; i++ )
904 respSDD.Add(fCalibration->At(i));
906 for (Int_t i = index[1]; i<index[2]; i++ )
907 respSSD.Add(fCalibration->At(i));
909 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
910 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
911 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
914 //______________________________________________________________________
915 void AliITSDetTypeSim::ReadOldSSDNoise(TObjArray *array,
916 AliITSNoiseSSDv2 *noiseSSD) {
917 //Reads the old SSD calibration object and converts it to the new format
918 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
919 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
921 Int_t fNMod = array->GetEntries();
922 cout<<"Converting old calibration object for noise..."<<endl;
925 Double_t noise = 0.0;
926 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
927 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
928 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
929 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
930 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
931 noiseSSD->AddNoiseP(iModule,iStrip,noise);
932 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
933 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
938 //______________________________________________________________________
939 void AliITSDetTypeSim::ReadOldSSDBadChannels(TObjArray *array,
940 AliITSBadChannelsSSDv2 *badChannelsSSD) {
941 //Reads the old SSD calibration object and converts it to the new format
942 Int_t fNMod = array->GetEntries();
943 cout<<"Converting old calibration object for bad channels..."<<endl;
944 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
945 //for (Int_t iModule = 0; iModule < 1; iModule++) {
946 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
947 TArrayI arrayPSide = bad->GetBadPChannelsList();
948 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
949 badChannelsSSD->AddBadChannelP(iModule,
951 (Char_t)arrayPSide.At(iPCounter));
953 TArrayI arrayNSide = bad->GetBadNChannelsList();
954 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
955 badChannelsSSD->AddBadChannelN(iModule,
957 (Char_t)arrayNSide.At(iNCounter));
962 //______________________________________________________________________
963 void AliITSDetTypeSim::ReadOldSSDGain(TObjArray *array,
964 AliITSGainSSDv2 *gainSSD) {
965 //Reads the old SSD calibration object and converts it to the new format
967 Int_t fNMod = array->GetEntries();
968 cout<<"Converting old calibration object for gain..."<<endl;
971 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
972 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
973 TArrayF arrayPSide = gainModule->GetGainP();
974 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
975 gainSSD->AddGainP(iModule,
977 arrayPSide.At(iPCounter));
978 TArrayF arrayNSide = gainModule->GetGainN();
979 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
980 gainSSD->AddGainN(iModule,
982 arrayNSide.At(iNCounter));