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