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