Added protection in case gGeoManager is a null pointer
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeSim.cxx
CommitLineData
3b9df642 1/***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17 $Id$
18*/
19
fcf95fc7 20
7d62fb64 21/////////////////////////////////////////////////////////////////////
22// Base simulation functions for ITS //
23// //
24// //
25/////////////////////////////////////////////////////////////////////
26#include "TBranch.h"
27#include "TClonesArray.h"
28#include "TObjArray.h"
29#include "TTree.h"
30
31#include "AliRun.h"
8ba39da9 32
33#include "AliCDBManager.h"
34#include "AliCDBId.h"
35#include "AliCDBStorage.h"
36#include "AliCDBEntry.h"
37#include "AliCDBMetaData.h"
38
7d62fb64 39#include "AliITSdigit.h"
40#include "AliITSdigitSPD.h"
41#include "AliITSdigitSDD.h"
42#include "AliITSdigitSSD.h"
3b9df642 43#include "AliITSDetTypeSim.h"
7d62fb64 44#include "AliITSpListItem.h"
fcf95fc7 45#include "AliITSresponseSDD.h"
46#include "AliITSCalibrationSDD.h"
028a3709 47#include "AliITSMapSDD.h"
18da6e54 48#include "AliITSDriftSpeedArraySDD.h"
140e5249 49#include "AliITSDriftSpeedSDD.h"
fcf95fc7 50#include "AliITSCalibrationSSD.h"
fb4dfab9 51#include "AliITSNoiseSSD.h"
52#include "AliITSGainSSD.h"
53#include "AliITSBadChannelsSSD.h"
54#include "AliITSCalibrationSSD.h"
7d62fb64 55#include "AliITSsegmentationSPD.h"
56#include "AliITSsegmentationSDD.h"
57#include "AliITSsegmentationSSD.h"
58#include "AliITSsimulation.h"
59#include "AliITSsimulationSPD.h"
60#include "AliITSsimulationSDD.h"
61#include "AliITSsimulationSSD.h"
62
63
64const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
8ba39da9 65const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
66const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
67const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
3b9df642 68
69ClassImp(AliITSDetTypeSim)
70
71//----------------------------------------------------------------------
72AliITSDetTypeSim::AliITSDetTypeSim():
73TObject(),
3b9df642 74fSimulation(), // [NDet]
75fSegmentation(), // [NDet]
fcf95fc7 76fCalibration(), // [NMod]
3b9df642 77fPreProcess(), // [] e.g. Fill fHitModule with hits
78fPostProcess(), // [] e.g. Wright Raw data
3b9df642 79fNSDigits(0), //! number of SDigits
80fSDigits(), //! [NMod][NSDigits]
81fNDigits(0), //! number of Digits
023ae34b 82fRunNumber(0), //! Run number (to access DB)
3b9df642 83fDigits(), //! [NMod][NDigits]
979b5a5f 84fDDLMapSDD(0),
3b9df642 85fHitClassName(), // String with Hit class name.
86fSDigClassName(),// String with SDigit class name.
023ae34b 87fDigClassName(), // String with digit class name.
88fLoader(0), // local pointer to loader
89fFirstcall(kTRUE){ // flag
3b9df642 90 // Default Constructor
91 // Inputs:
92 // none.
93 // Outputs:
94 // none.
95 // Return:
96 // A properly zero-ed AliITSDetTypeSim class.
023ae34b 97
7d62fb64 98 fSimulation = new TObjArray(fgkNdettypes);
99 fSegmentation = new TObjArray(fgkNdettypes);
1964ae5f 100 fSegmentation->SetOwner(kTRUE);
7d62fb64 101 fSDigits = new TClonesArray("AliITSpListItem",1000);
102 fDigits = new TObjArray(fgkNdettypes);
103 fNDigits = new Int_t[fgkNdettypes];
979b5a5f 104 fDDLMapSDD=new AliITSDDLModuleMapSDD();
8ba39da9 105 fNMod[0] = fgkDefaultNModulesSPD;
106 fNMod[1] = fgkDefaultNModulesSDD;
107 fNMod[2] = fgkDefaultNModulesSSD;
108 SetRunNumber();
3b9df642 109}
110//----------------------------------------------------------------------
111AliITSDetTypeSim::~AliITSDetTypeSim(){
112 // Destructor
113 // Inputs:
114 // none.
115 // Outputs:
116 // none.
117 // Return:
118 // Nothing.
023ae34b 119
7d62fb64 120 if(fSimulation){
023ae34b 121 fSimulation->Delete();
122 delete fSimulation;
7d62fb64 123 }
023ae34b 124 fSimulation = 0;
7d62fb64 125 if(fSegmentation){
023ae34b 126 fSegmentation->Delete();
127 delete fSegmentation;
7d62fb64 128 }
023ae34b 129 fSegmentation = 0;
b17dae48 130 if(fCalibration && fRunNumber<0){
023ae34b 131 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
132 GetITSgeom()->GetStartSPD()))->GetResponse();
133 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
134 GetITSgeom()->GetStartSDD()))->GetResponse();
135 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
136 GetITSgeom()->GetStartSSD()))->GetResponse();
137 if(rspd) delete rspd;
138 if(rsdd) delete rsdd;
139 if(rssd) delete rssd;
140 fCalibration->Delete();
141 delete fCalibration;
7d62fb64 142 }
023ae34b 143 fCalibration = 0;
7d62fb64 144 if(fPreProcess){
023ae34b 145 fPreProcess->Delete();
146 delete fPreProcess;
7d62fb64 147 }
023ae34b 148 fPreProcess = 0;
7d62fb64 149 if(fPostProcess){
023ae34b 150 fPostProcess->Delete();
151 delete fPostProcess;
7d62fb64 152 }
023ae34b 153 fPostProcess = 0;
979b5a5f 154 if(fDDLMapSDD) delete fDDLMapSDD;
2a476797 155 if(fNDigits) delete [] fNDigits;
023ae34b 156 fNDigits = 0;
157 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
158 fLoader = 0; // Not deleting it.
7d62fb64 159 if (fSDigits) {
023ae34b 160 fSDigits->Delete();
161 delete fSDigits;
7d62fb64 162 }
023ae34b 163 fSDigits=0;
7d62fb64 164 if (fDigits) {
165 fDigits->Delete();
166 delete fDigits;
7d62fb64 167 }
023ae34b 168 fDigits=0;
3b9df642 169}
170//----------------------------------------------------------------------
7537d03c 171AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
172fSimulation(source.fSimulation), // [NDet]
173fSegmentation(source.fSegmentation), // [NDet]
174fCalibration(source.fCalibration), // [NMod]
175fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
176fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
177fNSDigits(source.fNSDigits), //! number of SDigits
178fSDigits(source.fSDigits), //! [NMod][NSDigits]
179fNDigits(source.fNDigits), //! number of Digits
180fRunNumber(source.fRunNumber), //! Run number (to access DB)
181fDigits(source.fDigits), //! [NMod][NDigits]
979b5a5f 182fDDLMapSDD(source.fDDLMapSDD),
7537d03c 183fHitClassName(source.fHitClassName), // String with Hit class name.
184fSDigClassName(source.fSDigClassName),// String with SDigit class name.
185fDigClassName(), // String with digit class name.
186fLoader(source.fLoader), // local pointer to loader
187fFirstcall(source.fFirstcall)
188{
7d62fb64 189 // Copy Constructor for object AliITSDetTypeSim not allowed
7537d03c 190 for(Int_t i=0;i<fgkNdettypes;i++){
191 fDigClassName[i] = source.fDigClassName[i];
192 }
3b9df642 193}
194//----------------------------------------------------------------------
7d62fb64 195AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
3b9df642 196 // The = operator for object AliITSDetTypeSim
7d62fb64 197
7537d03c 198 this->~AliITSDetTypeSim();
199 new(this) AliITSDetTypeSim(source);
200 return *this;
3b9df642 201}
7d62fb64 202
023ae34b 203//______________________________________________________________________
204void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
205 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
206 //
207 // Inputs:
208 // AliITSgoem *geom The AliITSgeom object to be used.
209 // Output:
210 // none.
211 // Return:
212 // none.
213 if(!fLoader){
214 Error("SetITSgeom","No pointer to loader - nothing done");
215 return;
216 }
217 else {
218 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
219 }
220
221}
222//______________________________________________________________________
223void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
224 // Sets the local copy of the AliITSLoader, and passes on the
225 // AliITSgeom object as needed.
226 // Inputs
227 // AliITSLoader *loader pointer to AliITSLoader for local use
228 // Outputs:
229 // none.
230 // Return:
231 // none.
232
233 if(fLoader==loader) return; // Same do nothing
234 if(fLoader){ // alread have an existing loader
235 Error("SetLoader",
236 "Already have an exisiting loader ptr=%p Nothing done",
237 fLoader);
238 } // end if
239 fLoader = loader;
240}
3b9df642 241//______________________________________________________________________
7d62fb64 242void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
243
244 //Set simulation model for detector type
245
246 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
247 fSimulation->AddAt(sim,dettype);
248}
249//______________________________________________________________________
250AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
251
252 //Get simulation model for detector type
253 if(fSimulation==0) {
254 Warning("GetSimulationModel","fSimulation is 0!");
255 return 0;
256 }
257 return (AliITSsimulation*)(fSimulation->At(dettype));
258}
259//______________________________________________________________________
260AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
261
262 //Get simulation model by module number
023ae34b 263 if(GetITSgeom()==0) {
264 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
7d62fb64 265 return 0;
266 }
267
023ae34b 268 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 269}
fcf95fc7 270//_______________________________________________________________________
1964ae5f 271void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
023ae34b 272 // Set default segmentation model objects
273 AliITSsegmentation *seg;
1964ae5f 274
023ae34b 275 if(fSegmentation==0x0){
276 fSegmentation = new TObjArray(fgkNdettypes);
277 fSegmentation->SetOwner(kTRUE);
278 }
279 if(GetSegmentationModel(idet))
280 delete (AliITSsegmentation*)fSegmentation->At(idet);
281 if(idet==0){
d24bc9d6 282 seg = new AliITSsegmentationSPD();
023ae34b 283 }else if(idet==1){
d24bc9d6 284 seg = new AliITSsegmentationSDD();
023ae34b 285 }else {
d24bc9d6 286 seg = new AliITSsegmentationSSD();
023ae34b 287 }
288 SetSegmentationModel(idet,seg);
289}
7d62fb64 290//______________________________________________________________________
023ae34b 291void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
292 AliITSsegmentation *seg){
7d62fb64 293
294 //Set segmentation model for detector type
fcf95fc7 295 if(fSegmentation==0x0){
1964ae5f 296 fSegmentation = new TObjArray(fgkNdettypes);
297 fSegmentation->SetOwner(kTRUE);
298 }
7d62fb64 299 fSegmentation->AddAt(seg,dettype);
7d62fb64 300}
301//______________________________________________________________________
302AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
7d62fb64 303 //Get segmentation model for detector type
304
305 if(fSegmentation==0) {
023ae34b 306 Warning("GetSegmentationModel","fSegmentation is 0!");
307 return 0;
7d62fb64 308 }
309 return (AliITSsegmentation*)(fSegmentation->At(dettype));
7d62fb64 310}
311//_______________________________________________________________________
312AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
023ae34b 313 //Get segmentation model by module number
314 if(GetITSgeom()==0){
315 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
316 return 0;
317 }
318 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 319}
320//_______________________________________________________________________
fcf95fc7 321void AliITSDetTypeSim::CreateCalibrationArray() {
023ae34b 322 //Create the container of calibration functions with correct size
323 if (fCalibration) {
324 Warning("CreateCalibration","pointer to calibration object exists\n");
325 fCalibration->Delete();
326 delete fCalibration;
327 }
8ba39da9 328
023ae34b 329 Int_t nModTot = GetITSgeom()->GetIndexMax();
330 fCalibration = new TObjArray(nModTot);
331 fCalibration->SetOwner(kTRUE);
332 fCalibration->Clear();
8ba39da9 333}
334//_______________________________________________________________________
fcf95fc7 335void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
023ae34b 336 //Set response model for modules
8ba39da9 337
023ae34b 338 if (fCalibration==0) CreateCalibrationArray();
8ba39da9 339
023ae34b 340 if (fCalibration->At(iMod)!=0)
341 delete (AliITSCalibration*) fCalibration->At(iMod);
342 fCalibration->AddAt(resp, iMod);
8ba39da9 343}
7d62fb64 344//______________________________________________________________________
fcf95fc7 345void AliITSDetTypeSim::ResetCalibrationArray(){
023ae34b 346 //resets response array
347 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
348 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
349 GetITSgeom()->GetStartSPD()))->GetResponse();
350 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
351 GetITSgeom()->GetStartSDD()))->GetResponse();
352 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
353 GetITSgeom()->GetStartSSD()))->GetResponse();
354 if(rspd) delete rspd;
355 if(rsdd) delete rsdd;
356 if(rssd) delete rssd;
357 fCalibration->Clear();
358 }else if (fCalibration && fRunNumber>=0){
359 fCalibration->Clear();
360 }
7d62fb64 361}
362//______________________________________________________________________
363void AliITSDetTypeSim::ResetSegmentation(){
023ae34b 364 //Resets segmentation array
365 if(fSegmentation) fSegmentation->Clear();
7d62fb64 366}
7d62fb64 367//_______________________________________________________________________
fcf95fc7 368AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
023ae34b 369 //Get response model for module number iMod
8ba39da9 370
023ae34b 371 if(fCalibration==0) {
372 AliError("fCalibration is 0!");
373 return 0;
374 }
fcf95fc7 375 return (AliITSCalibration*)(fCalibration->At(iMod));
7d62fb64 376}
377//_______________________________________________________________________
378void AliITSDetTypeSim::SetDefaults(){
023ae34b 379 //Set defaults for segmentation and response
380
381 if(GetITSgeom()==0){
382 Warning("SetDefaults","GetITSgeom() is 0!");
383 return;
384 } // end if
385 if (fCalibration==0) {
386 CreateCalibrationArray();
387 } // end if
388
389 ResetSegmentation();
390 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
391
392 for(Int_t idet=0;idet<fgkNdettypes;idet++){
393 //SPD
394 if(idet==0){
395 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
396 const char *kData0=(GetCalibrationModel(GetITSgeom()->GetStartSPD()))->DataType();
397 if (strstr(kData0,"real")) {
398 SetDigitClassName(idet,"AliITSdigit");
399 }else {
400 SetDigitClassName(idet,"AliITSdigitSPD");
401 } // end if
402 } // end if idet==0
403 //SDD
404 if(idet==1){
405 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
406 AliITSCalibrationSDD* rsp =
407 (AliITSCalibrationSDD*)GetCalibrationModel(
408 GetITSgeom()->GetStartSDD());
409 const char *kopt = ((AliITSresponseSDD*)rsp->GetResponse())->
410 ZeroSuppOption();
20f3f947 411 if(!strstr(kopt,"ZS")) {
412 SetDigitClassName(idet,"AliITSdigit");
023ae34b 413 }else {
20f3f947 414 SetDigitClassName(idet,"AliITSdigitSDD");
023ae34b 415 } // end if
416 } // end if idet==1
417 //SSD
418 if(idet==2){
419 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
420 const char *kData2 = (GetCalibrationModel(
421 GetITSgeom()->GetStartSSD())->DataType());
422 if (strstr(kData2,"real")) {
423 SetDigitClassName(idet,"AliITSdigit");
424 }else {
425 SetDigitClassName(idet,"AliITSdigitSSD");
426 } // end if
427 } // end if idet==2
428 }// end for idet
8ba39da9 429}
8ba39da9 430//______________________________________________________________________
431Bool_t AliITSDetTypeSim::GetCalibration() {
432 // Get Default calibration if a storage is not defined.
7d62fb64 433
b17dae48 434 if(!fFirstcall){
435 AliITSCalibration* cal = GetCalibrationModel(0);
436 if(cal)return kTRUE;
437 }
438 else {
439 fFirstcall = kFALSE;
440 }
441
442 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
443 Int_t run=GetRunNumber();
b17dae48 444
445 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
446 Bool_t isCacheActive = kTRUE;
447 if(GetRunNumber()<0){
448 isCacheActive=kFALSE;
449 fCalibration->SetOwner(kTRUE);
450 }
451 else{
452 fCalibration->SetOwner(kFALSE);
453 }
454
455 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
456
6727e2db 457 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
b17dae48 458 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
18da6e54 459 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
979b5a5f 460 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
028a3709 461 AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
462 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
fb4dfab9 463 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
028a3709 464 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
465 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
466 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
fb4dfab9 467
b17dae48 468 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
469 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
470 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 471
fb4dfab9 472 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
979b5a5f 473 !entry2SPD || !entry2SDD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD ||!mapTSDD){
fb4dfab9 474 AliFatal("Calibration object retrieval failed! ");
475 return kFALSE;
476 }
8ba39da9 477
028a3709 478// if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
479// !entry2SPD || !entry2SDD || !entry2SSD){
480// AliFatal("Calibration object retrieval failed! ");
481// return kFALSE;
482// }
06232459 483
b17dae48 484 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
485 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 486 entrySPD->SetOwner(kTRUE);
06232459 487
fcf95fc7 488 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
b17dae48 489 if(!isCacheActive)entry2SPD->SetObject(NULL);
fcf95fc7 490 entry2SPD->SetOwner(kTRUE);
491
b17dae48 492 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
493 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 494 entrySDD->SetOwner(kTRUE);
06232459 495
fcf95fc7 496 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
b17dae48 497 if(!isCacheActive)entry2SDD->SetObject(NULL);
fcf95fc7 498 entry2SDD->SetOwner(kTRUE);
499
18da6e54 500 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
501 if(!isCacheActive)drSpSDD->SetObject(NULL);
502 drSpSDD->SetOwner(kTRUE);
503
979b5a5f 504 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
505 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
506 ddlMapSDD->SetOwner(kTRUE);
507
028a3709 508 TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
509 if(!isCacheActive)mapASDD->SetObject(NULL);
510 mapASDD->SetOwner(kTRUE);
511
512 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
513 if(!isCacheActive)mapTSDD->SetObject(NULL);
514 mapTSDD->SetOwner(kTRUE);
515
fb4dfab9 516 /*
b17dae48 517 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
518 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 519 entrySSD->SetOwner(kTRUE);
fb4dfab9 520 */
521
522 TObjArray *noiseSSD = (TObjArray *)entryNoiseSSD->GetObject();
523 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
524 entryNoiseSSD->SetOwner(kTRUE);
525
526 TObjArray *gainSSD = (TObjArray *)entryGainSSD->GetObject();
527 if(!isCacheActive)entryGainSSD->SetObject(NULL);
528 entryGainSSD->SetOwner(kTRUE);
529
530 TObjArray *badchannelsSSD = (TObjArray *)entryBadChannelsSSD->GetObject();
531 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
532 entryBadChannelsSSD->SetOwner(kTRUE);
06232459 533
fcf95fc7 534 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
b17dae48 535 if(!isCacheActive)entry2SSD->SetObject(NULL);
fcf95fc7 536 entry2SSD->SetOwner(kTRUE);
537
b17dae48 538 // DB entries are deleted. In this way metadeta objects are deleted as well
539 if(!isCacheActive){
540 delete entrySPD;
541 delete entrySDD;
fb4dfab9 542 delete entryNoiseSSD;
543 delete entryGainSSD;
544 delete entryBadChannelsSSD;
b17dae48 545 delete entry2SPD;
546 delete entry2SDD;
547 delete entry2SSD;
028a3709 548 delete mapASDD;
549 delete mapTSDD;
18da6e54 550 delete drSpSDD;
979b5a5f 551 delete ddlMapSDD;
b17dae48 552 }
fcf95fc7 553
b17dae48 554 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
555
979b5a5f 556 if ((!pSPD)||(!pSDD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
028a3709 557 || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badchannelsSSD)) {
8ba39da9 558 AliWarning("Can not get calibration from calibration database !");
559 return kFALSE;
560 }
fb4dfab9 561
b17dae48 562 fNMod[0] = calSPD->GetEntries();
563 fNMod[1] = calSDD->GetEntries();
fb4dfab9 564 fNMod[2] = noiseSSD->GetEntries();
8ba39da9 565 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
566 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 567 AliITSCalibration* cal;
8ba39da9 568 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 569 cal = (AliITSCalibration*) calSPD->At(i);
570 cal->SetResponse(pSPD);
571 SetCalibrationModel(i, cal);
18da6e54 572 }
140e5249 573
574 fDDLMapSDD->SetDDLMap(ddlsdd);
575 for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
576 for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
577 Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
578 if(iMod==-1) continue;
6cc25d49 579 Int_t i=iMod - fgkDefaultNModulesSPD;
140e5249 580 cal = (AliITSCalibration*) calSDD->At(i);
581 cal->SetResponse((AliITSresponse*)pSDD);
582 Int_t i0=2*i;
583 Int_t i1=1+2*i;
584 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
585 AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
586 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
587 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
588 AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
589 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
590 cal->SetDriftSpeed(0,arr0);
591 cal->SetDriftSpeed(1,arr1);
592 cal->SetMapA(0,ma0);
593 cal->SetMapA(1,ma1);
594 cal->SetMapT(0,mt0);
595 cal->SetMapT(1,mt1);
596 SetCalibrationModel(iMod, cal);
597 }
598 }
8ba39da9 599 for (Int_t i=0; i<fNMod[2]; i++) {
fb4dfab9 600 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
601 calibSSD->SetResponse((AliITSresponse*)pSSD);
602
603 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
604 calibSSD->SetNoise(noise);
605 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
606 calibSSD->SetGain(gain);
607 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
608 calibSSD->SetBadChannels(bad);
609
6cc25d49 610 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
fb4dfab9 611 SetCalibrationModel(iMod, calibSSD);
612
8ba39da9 613 }
8ba39da9 614 return kTRUE;
7d62fb64 615}
7d62fb64 616//_______________________________________________________________________
617void AliITSDetTypeSim::SetDefaultSimulation(){
7d62fb64 618 //Set default simulation for detector type
619
023ae34b 620 if(GetITSgeom()==0){
621 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
8ba39da9 622 return;
623 }
fcf95fc7 624 if(fCalibration==0){
625 Warning("SetDefaultSimulation","fCalibration is 0!");
7d62fb64 626 return;
627 }
fcf95fc7 628 if(fSegmentation==0){
629 Warning("SetDefaultSimulation","fSegmentation is 0!");
630 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
023ae34b 631 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
632 Warning("SetDefaultSimulation",
633 "Segmentation not defined for det %d - Default taken\n!",i);
634 SetDefaultSegmentation(i);
1964ae5f 635 }
7d62fb64 636 AliITSsimulation* sim;
637
638 for(Int_t idet=0;idet<fgkNdettypes;idet++){
639 //SPD
640 if(idet==0){
023ae34b 641 sim = GetSimulationModel(idet);
7d62fb64 642 if(!sim){
8ba39da9 643 sim = new AliITSsimulationSPD(this);
7d62fb64 644 SetSimulationModel(idet,sim);
7d62fb64 645 }
646 }
647 //SDD
648 if(idet==1){
649 sim = GetSimulationModel(idet);
650 if(!sim){
8ba39da9 651 sim = new AliITSsimulationSDD(this);
7d62fb64 652 SetSimulationModel(idet,sim);
023ae34b 653 }
7d62fb64 654 }
655 //SSD
656 if(idet==2){
657 sim = GetSimulationModel(idet);
658 if(!sim){
8ba39da9 659 sim = new AliITSsimulationSSD(this);
7d62fb64 660 SetSimulationModel(idet,sim);
7d62fb64 661 }
7d62fb64 662 }
663
664 }
665}
7d62fb64 666//___________________________________________________________________
667void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
023ae34b 668 // Set branch address for the ITS summable digits Trees.
7d62fb64 669 char branchname[30];
670
671 if(!treeS){
672 return;
673 }
b17dae48 674 if (fSDigits == 0x0){
7d62fb64 675 fSDigits = new TClonesArray("AliITSpListItem",1000);
676 }
677 TBranch *branch;
678 sprintf(branchname,"%s",name);
679 branch = treeS->GetBranch(branchname);
680 if (branch) branch->SetAddress(&fSDigits);
681
682}
683//___________________________________________________________________
684void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
685 // Set branch address for the digit Trees.
686
687 const char *det[3] = {"SPD","SDD","SSD"};
688 TBranch *branch;
689
690 char branchname[30];
691
692 if(!treeD){
693 return;
694 }
695 if(!fDigits){
696 fDigits = new TObjArray(fgkNdettypes);
697 }
698 for(Int_t i=0;i<fgkNdettypes;i++){
699 Char_t* digclass = GetDigitClassName(i);
700 if(digclass==0x0){
701 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
702 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
703 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
704 digclass = GetDigitClassName(i);
705 }
706 TString classn = digclass;
707 if(!(fDigits->At(i))){
708 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 709 }else{
7d62fb64 710 ResetDigits(i);
711 }
712
713 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
714 else sprintf(branchname,"%sDigits%d",name,i+1);
715 if(fDigits){
716 branch = treeD->GetBranch(branchname);
717 if(branch) branch->SetAddress(&((*fDigits)[i]));
718 }
719 }
3b9df642 720
3b9df642 721}
7d62fb64 722//___________________________________________________________________
723void AliITSDetTypeSim::ResetDigits(){
023ae34b 724 // Reset number of digits and the digits array for the ITS detector.
7d62fb64 725
726 if(!fDigits){
727 Error("ResetDigits","fDigits is null!");
728 return;
729 }
730 for(Int_t i=0;i<fgkNdettypes;i++){
731 ResetDigits(i);
732 }
733}
734//___________________________________________________________________
735void AliITSDetTypeSim::ResetDigits(Int_t branch){
736 // Reset number of digits and the digits array for this branch.
737
738 if(fDigits->At(branch)){
739 ((TClonesArray*)fDigits->At(branch))->Clear();
740 }
741 if(fNDigits) fNDigits[branch]=0;
742
743}
744
745
746
747//_______________________________________________________________________
748void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
749 // Standard Summable digits to Digits function.
023ae34b 750 if(!GetITSgeom()){
751 Warning("SDigitsToDigits","GetITSgeom() is null!!");
7d62fb64 752 return;
753 }
754
755 const char *all = strstr(opt,"All");
756 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
757 strstr(opt,"SSD")};
758 if( !det[0] && !det[1] && !det[2] ) all = "All";
759 else all = 0;
760 static Bool_t setDef = kTRUE;
761 if(setDef) SetDefaultSimulation();
762 setDef = kFALSE;
763
764 AliITSsimulation *sim =0;
765 TTree* trees = fLoader->TreeS();
766 if( !(trees && GetSDigits()) ){
767 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
768 return;
769 }
770 sprintf(name,"%s",name);
771 TBranch* brchSDigits = trees->GetBranch(name);
772
773 Int_t id;
023ae34b 774 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
775 id = GetITSgeom()->GetModuleType(module);
7d62fb64 776 if (!all && !det[id]) continue;
777 sim = (AliITSsimulation*)GetSimulationModel(id);
778 if(!sim){
779 Error("SDigit2Digits","The simulation class was not "
780 "instanciated for module %d type %s!",module,
023ae34b 781 GetITSgeom()->GetModuleTypeName(module));
7d62fb64 782 exit(1);
783 }
784 sim->InitSimulationModule(module,gAlice->GetEvNumber());
785
786 fSDigits->Clear();
787 brchSDigits->GetEvent(module);
788 sim->AddSDigitsToModule(fSDigits,0);
789 sim->FinishSDigitiseModule();
790 fLoader->TreeD()->Fill();
791 ResetDigits();
792 }
793 fLoader->TreeD()->GetEntries();
794 fLoader->TreeD()->AutoSave();
795 fLoader->TreeD()->Reset();
796}
7d62fb64 797//_________________________________________________________
023ae34b 798void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
7d62fb64 799 //Adds the module full of summable digits to the summable digits tree.
023ae34b 800
7d62fb64 801 TClonesArray &lsdig = *fSDigits;
802 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
803}
804//__________________________________________________________
805void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
806 // Add a real digit - as coming from data.
023ae34b 807
7d62fb64 808 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
809 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
810}
811//__________________________________________________________
023ae34b 812void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
7d62fb64 813 // Add a simulated digit.
023ae34b 814
7d62fb64 815 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
816 switch(branch){
817 case 0:
818 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
819 break;
820 case 1:
821 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
822 break;
823 case 2:
824 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
825 break;
023ae34b 826 }
7d62fb64 827}
3b9df642 828//______________________________________________________________________
7d62fb64 829void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
830 Int_t *tracks,Int_t *hits,Float_t *charges){
831 // Add a simulated digit to the list.
832
833 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
fcf95fc7 834 AliITSCalibrationSDD *resp = 0;
7d62fb64 835 switch(branch){
836 case 0:
837 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
838 break;
839 case 1:
023ae34b 840 resp = (AliITSCalibrationSDD*)GetCalibrationModel(
841 GetITSgeom()->GetStartSDD());
7d62fb64 842 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
843 hits,charges,resp);
844 break;
845 case 2:
846 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
847 break;
848 }
3b9df642 849}
8ba39da9 850//______________________________________________________________________
023ae34b 851void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
852 AliCDBMetaData &md) {
8ba39da9 853 // Store calibration in the calibration database
8ba39da9 854 // The database must be created in an external piece of code (i.e.
855 // a configuration macro )
856
857 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
06232459 858 AliWarning("No storage set! Will use dummy one");
8ba39da9 859 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
8ba39da9 860 }
861
fcf95fc7 862 if (!fCalibration) {
863 AliError("AliITSCalibration classes are not defined - nothing done");
8ba39da9 864 return;
865 }
6727e2db 866 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
fcf95fc7 867 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
868 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
8ba39da9 869
870 TObjArray respSPD(fNMod[0]);
871 TObjArray respSDD(fNMod[1]-fNMod[0]);
872 TObjArray respSSD(fNMod[2]-fNMod[1]);
873 respSPD.SetOwner(kFALSE);
874 respSSD.SetOwner(kFALSE);
875 respSSD.SetOwner(kFALSE);
876
877 Int_t index[fgkNdettypes];
878 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
879 index[i] = 0;
880 for (Int_t j = 0; j<=i; j++ )
881 index[i]+=fNMod[j];
882 }
883
884 for (Int_t i = 0; i<index[0]; i++ )
fcf95fc7 885 respSPD.Add(fCalibration->At(i));
8ba39da9 886
887 for (Int_t i = index[0]; i<index[1]; i++ )
fcf95fc7 888 respSDD.Add(fCalibration->At(i));
8ba39da9 889
890 for (Int_t i = index[1]; i<index[2]; i++ )
fcf95fc7 891 respSSD.Add(fCalibration->At(i));
8ba39da9 892
06232459 893 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
894 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
895 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
8ba39da9 896}
897
898