tempory macro to work in trunk with new methods to connect to input container
[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"
2f8ed7ab 49#include "AliITSHLTforSDD.h"
fcf95fc7 50#include "AliITSCalibrationSSD.h"
88128115 51#include "AliITSNoiseSSDv2.h"
52#include "AliITSGainSSDv2.h"
53#include "AliITSBadChannelsSSDv2.h"
fb4dfab9 54#include "AliITSNoiseSSD.h"
55#include "AliITSGainSSD.h"
56#include "AliITSBadChannelsSSD.h"
57#include "AliITSCalibrationSSD.h"
7d62fb64 58#include "AliITSsegmentationSPD.h"
59#include "AliITSsegmentationSDD.h"
60#include "AliITSsegmentationSSD.h"
61#include "AliITSsimulation.h"
62#include "AliITSsimulationSPD.h"
63#include "AliITSsimulationSDD.h"
64#include "AliITSsimulationSSD.h"
65
66
67const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
8ba39da9 68const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
69const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
70const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
3b9df642 71
72ClassImp(AliITSDetTypeSim)
73
74//----------------------------------------------------------------------
75AliITSDetTypeSim::AliITSDetTypeSim():
76TObject(),
3b9df642 77fSimulation(), // [NDet]
78fSegmentation(), // [NDet]
fcf95fc7 79fCalibration(), // [NMod]
ced4d9bc 80fSSDCalibration(0),
3b9df642 81fPreProcess(), // [] e.g. Fill fHitModule with hits
82fPostProcess(), // [] e.g. Wright Raw data
3b9df642 83fNSDigits(0), //! number of SDigits
e6b4e6b9 84fSDigits("AliITSpListItem",1000),
3b9df642 85fNDigits(0), //! number of Digits
023ae34b 86fRunNumber(0), //! Run number (to access DB)
3b9df642 87fDigits(), //! [NMod][NDigits]
cd2a0045 88fSimuPar(0),
979b5a5f 89fDDLMapSDD(0),
3b9df642 90fHitClassName(), // String with Hit class name.
91fSDigClassName(),// String with SDigit class name.
023ae34b 92fDigClassName(), // String with digit class name.
93fLoader(0), // local pointer to loader
2f8ed7ab 94fFirstcall(kTRUE),
95fIsHLTmodeC(0){ // flag
3b9df642 96 // Default Constructor
97 // Inputs:
98 // none.
99 // Outputs:
100 // none.
101 // Return:
102 // A properly zero-ed AliITSDetTypeSim class.
023ae34b 103
7d62fb64 104 fSimulation = new TObjArray(fgkNdettypes);
105 fSegmentation = new TObjArray(fgkNdettypes);
1964ae5f 106 fSegmentation->SetOwner(kTRUE);
7d62fb64 107 fDigits = new TObjArray(fgkNdettypes);
108 fNDigits = new Int_t[fgkNdettypes];
979b5a5f 109 fDDLMapSDD=new AliITSDDLModuleMapSDD();
cd2a0045 110 fSimuPar= new AliITSSimuParam();
ced4d9bc 111 fSSDCalibration=new AliITSCalibrationSSD();
8ba39da9 112 fNMod[0] = fgkDefaultNModulesSPD;
113 fNMod[1] = fgkDefaultNModulesSDD;
114 fNMod[2] = fgkDefaultNModulesSSD;
115 SetRunNumber();
3b9df642 116}
117//----------------------------------------------------------------------
118AliITSDetTypeSim::~AliITSDetTypeSim(){
119 // Destructor
120 // Inputs:
121 // none.
122 // Outputs:
123 // none.
124 // Return:
125 // Nothing.
023ae34b 126
7d62fb64 127 if(fSimulation){
023ae34b 128 fSimulation->Delete();
129 delete fSimulation;
7d62fb64 130 }
023ae34b 131 fSimulation = 0;
7d62fb64 132 if(fSegmentation){
023ae34b 133 fSegmentation->Delete();
134 delete fSegmentation;
7d62fb64 135 }
023ae34b 136 fSegmentation = 0;
b17dae48 137 if(fCalibration && fRunNumber<0){
bb292d31 138
023ae34b 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
2f8ed7ab 186fFirstcall(source.fFirstcall),
187fIsHLTmodeC(source.fIsHLTmodeC)
7537d03c 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){
b27af87f 284 seg = new AliITSsegmentationSDD();
285 AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
286 if(cal->IsAMAt20MHz()){
287 seg->SetPadSize(seg->Dpz(0),20.);
288 seg->SetNPads(seg->Npz()/2,128);
289 }
023ae34b 290 }else {
d24bc9d6 291 seg = new AliITSsegmentationSSD();
023ae34b 292 }
293 SetSegmentationModel(idet,seg);
294}
7d62fb64 295//______________________________________________________________________
023ae34b 296void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
297 AliITSsegmentation *seg){
7d62fb64 298
299 //Set segmentation model for detector type
fcf95fc7 300 if(fSegmentation==0x0){
1964ae5f 301 fSegmentation = new TObjArray(fgkNdettypes);
302 fSegmentation->SetOwner(kTRUE);
303 }
7d62fb64 304 fSegmentation->AddAt(seg,dettype);
7d62fb64 305}
306//______________________________________________________________________
307AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
7d62fb64 308 //Get segmentation model for detector type
309
310 if(fSegmentation==0) {
023ae34b 311 Warning("GetSegmentationModel","fSegmentation is 0!");
312 return 0;
7d62fb64 313 }
314 return (AliITSsegmentation*)(fSegmentation->At(dettype));
7d62fb64 315}
316//_______________________________________________________________________
317AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
023ae34b 318 //Get segmentation model by module number
319 if(GetITSgeom()==0){
320 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
321 return 0;
322 }
323 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 324}
325//_______________________________________________________________________
fcf95fc7 326void AliITSDetTypeSim::CreateCalibrationArray() {
023ae34b 327 //Create the container of calibration functions with correct size
328 if (fCalibration) {
329 Warning("CreateCalibration","pointer to calibration object exists\n");
330 fCalibration->Delete();
331 delete fCalibration;
332 }
8ba39da9 333
023ae34b 334 Int_t nModTot = GetITSgeom()->GetIndexMax();
335 fCalibration = new TObjArray(nModTot);
336 fCalibration->SetOwner(kTRUE);
337 fCalibration->Clear();
8ba39da9 338}
339//_______________________________________________________________________
fcf95fc7 340void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
023ae34b 341 //Set response model for modules
8ba39da9 342
023ae34b 343 if (fCalibration==0) CreateCalibrationArray();
8ba39da9 344
023ae34b 345 if (fCalibration->At(iMod)!=0)
346 delete (AliITSCalibration*) fCalibration->At(iMod);
347 fCalibration->AddAt(resp, iMod);
8ba39da9 348}
7d62fb64 349//______________________________________________________________________
fcf95fc7 350void AliITSDetTypeSim::ResetCalibrationArray(){
023ae34b 351 //resets response array
352 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
bb292d31 353 /*
023ae34b 354 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
355 GetITSgeom()->GetStartSPD()))->GetResponse();
023ae34b 356 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
357 GetITSgeom()->GetStartSSD()))->GetResponse();
358 if(rspd) delete rspd;
023ae34b 359 if(rssd) delete rssd;
bb292d31 360 */
023ae34b 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);
2f8ed7ab 442 AliCDBEntry *hltforSDD = AliCDBManager::Instance()->Get("ITS/Calib/HLTforSDD");
2ebd5518 443 //AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
028a3709 444 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
fb4dfab9 445 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
028a3709 446 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
447 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
448 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
fb4dfab9 449
fb4dfab9 450 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
2f8ed7ab 451 !drSpSDD || !ddlMapSDD || !hltforSDD || !mapTSDD){
fb4dfab9 452 AliFatal("Calibration object retrieval failed! ");
453 return kFALSE;
454 }
bb292d31 455
06232459 456
b17dae48 457 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
458 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 459 entrySPD->SetOwner(kTRUE);
06232459 460
fcf95fc7 461
b17dae48 462 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
463 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 464 entrySDD->SetOwner(kTRUE);
06232459 465
18da6e54 466 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
467 if(!isCacheActive)drSpSDD->SetObject(NULL);
468 drSpSDD->SetOwner(kTRUE);
469
979b5a5f 470 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
471 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
472 ddlMapSDD->SetOwner(kTRUE);
473
2f8ed7ab 474 AliITSHLTforSDD* hltsdd=(AliITSHLTforSDD*)hltforSDD->GetObject();
475 if(!isCacheActive)hltforSDD->SetObject(NULL);
476 hltforSDD->SetOwner(kTRUE);
477
2ebd5518 478// TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
479// if(!isCacheActive)mapASDD->SetObject(NULL);
480// mapASDD->SetOwner(kTRUE);
028a3709 481
482 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
483 if(!isCacheActive)mapTSDD->SetObject(NULL);
484 mapTSDD->SetOwner(kTRUE);
485
fb4dfab9 486 /*
b17dae48 487 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
488 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 489 entrySSD->SetOwner(kTRUE);
fb4dfab9 490 */
491
88128115 492 TObject *emptyssd = 0; TString ssdobjectname = 0;
493 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
494 emptyssd = (TObject *)entryNoiseSSD->GetObject();
495 ssdobjectname = emptyssd->GetName();
496 if(ssdobjectname=="TObjArray") {
497 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
498 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
499 }
500 else if(ssdobjectname=="AliITSNoiseSSDv2")
501 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
fb4dfab9 502 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
503 entryNoiseSSD->SetOwner(kTRUE);
504
88128115 505 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
506 emptyssd = (TObject *)entryGainSSD->GetObject();
507 ssdobjectname = emptyssd->GetName();
508 if(ssdobjectname=="Gain") {
509 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
510 ReadOldSSDGain(gainSSDOld, gainSSD);
511 }
512 else if(ssdobjectname=="AliITSGainSSDv2")
513 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
fb4dfab9 514 if(!isCacheActive)entryGainSSD->SetObject(NULL);
515 entryGainSSD->SetOwner(kTRUE);
516
88128115 517 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
518 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
519 ssdobjectname = emptyssd->GetName();
520 if(ssdobjectname=="TObjArray") {
521 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
522 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
523 }
524 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
525 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
fb4dfab9 526 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
527 entryBadChannelsSSD->SetOwner(kTRUE);
06232459 528
88128115 529 /*AliITSNoiseSSDv2 *noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
530 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
531 entryNoiseSSD->SetOwner(kTRUE);
532
533 AliITSGainSSDv2 *gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
534 if(!isCacheActive)entryGainSSD->SetObject(NULL);
535 entryGainSSD->SetOwner(kTRUE);
536
537 AliITSBadChannelsSSDv2 *badchannelsSSD =
538 (AliITSBadChannelsSSDv2 *)entryBadChannelsSSD->GetObject();
539 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
540 entryBadChannelsSSD->SetOwner(kTRUE);*/
541
b17dae48 542 // DB entries are deleted. In this way metadeta objects are deleted as well
543 if(!isCacheActive){
544 delete entrySPD;
545 delete entrySDD;
fb4dfab9 546 delete entryNoiseSSD;
547 delete entryGainSSD;
548 delete entryBadChannelsSSD;
2ebd5518 549// delete mapASDD;
2f8ed7ab 550 delete hltforSDD;
028a3709 551 delete mapTSDD;
18da6e54 552 delete drSpSDD;
979b5a5f 553 delete ddlMapSDD;
b17dae48 554 }
fcf95fc7 555
b17dae48 556 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
557
bb292d31 558 if ((!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
2f8ed7ab 559 || (!hltsdd) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
8ba39da9 560 AliWarning("Can not get calibration from calibration database !");
561 return kFALSE;
562 }
fb4dfab9 563
b17dae48 564 fNMod[0] = calSPD->GetEntries();
565 fNMod[1] = calSDD->GetEntries();
ced4d9bc 566 // fNMod[2] = noiseSSD->GetEntries();
8ba39da9 567 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
568 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 569 AliITSCalibration* cal;
8ba39da9 570 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 571 cal = (AliITSCalibration*) calSPD->At(i);
b17dae48 572 SetCalibrationModel(i, cal);
18da6e54 573 }
140e5249 574
575 fDDLMapSDD->SetDDLMap(ddlsdd);
2f8ed7ab 576 fIsHLTmodeC=hltsdd->IsHLTmodeC();
946db678 577
578 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
579 Int_t iddl,icarlos;
580 Int_t iMod = i + fgkDefaultNModulesSPD;
581 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
582 if(iddl<0){
583 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
946db678 584 calsdddead->SetBad();
585 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
586 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
587 arrdrsp->AddDriftSpeed(driftspdef);
588 calsdddead->SetDriftSpeed(0,arrdrsp);
589 calsdddead->SetDriftSpeed(1,arrdrsp);
590 SetCalibrationModel(iMod, calsdddead);
591 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
592 }else{
140e5249 593 cal = (AliITSCalibration*) calSDD->At(i);
140e5249 594 Int_t i0=2*i;
595 Int_t i1=1+2*i;
596 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
2ebd5518 597// AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
140e5249 598 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
599 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
2ebd5518 600 // AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
140e5249 601 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
602 cal->SetDriftSpeed(0,arr0);
603 cal->SetDriftSpeed(1,arr1);
2ebd5518 604// cal->SetMapA(0,ma0);
605// cal->SetMapA(1,ma1);
140e5249 606 cal->SetMapT(0,mt0);
607 cal->SetMapT(1,mt1);
608 SetCalibrationModel(iMod, cal);
609 }
610 }
946db678 611
ced4d9bc 612 fSSDCalibration->SetNoise(noiseSSD);
613 fSSDCalibration->SetGain(gainSSD);
88128115 614 fSSDCalibration->SetBadChannels(badChannelsSSD);
ced4d9bc 615 //fSSDCalibration->FillBadChipMap();
616
617
ced4d9bc 618
8ba39da9 619 return kTRUE;
7d62fb64 620}
7d62fb64 621//_______________________________________________________________________
622void AliITSDetTypeSim::SetDefaultSimulation(){
7d62fb64 623 //Set default simulation for detector type
624
023ae34b 625 if(GetITSgeom()==0){
626 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
8ba39da9 627 return;
628 }
fcf95fc7 629 if(fCalibration==0){
630 Warning("SetDefaultSimulation","fCalibration is 0!");
7d62fb64 631 return;
632 }
fcf95fc7 633 if(fSegmentation==0){
634 Warning("SetDefaultSimulation","fSegmentation is 0!");
635 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
023ae34b 636 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
637 Warning("SetDefaultSimulation",
638 "Segmentation not defined for det %d - Default taken\n!",i);
639 SetDefaultSegmentation(i);
1964ae5f 640 }
7d62fb64 641 AliITSsimulation* sim;
642
643 for(Int_t idet=0;idet<fgkNdettypes;idet++){
644 //SPD
645 if(idet==0){
023ae34b 646 sim = GetSimulationModel(idet);
7d62fb64 647 if(!sim){
8ba39da9 648 sim = new AliITSsimulationSPD(this);
7d62fb64 649 SetSimulationModel(idet,sim);
7d62fb64 650 }
651 }
652 //SDD
653 if(idet==1){
654 sim = GetSimulationModel(idet);
655 if(!sim){
8ba39da9 656 sim = new AliITSsimulationSDD(this);
7d62fb64 657 SetSimulationModel(idet,sim);
023ae34b 658 }
7d62fb64 659 }
660 //SSD
661 if(idet==2){
662 sim = GetSimulationModel(idet);
663 if(!sim){
8ba39da9 664 sim = new AliITSsimulationSSD(this);
7d62fb64 665 SetSimulationModel(idet,sim);
7d62fb64 666 }
7d62fb64 667 }
668
669 }
670}
7d62fb64 671//___________________________________________________________________
a6e0ebfe 672void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, const Char_t* name){
023ae34b 673 // Set branch address for the ITS summable digits Trees.
7d62fb64 674 char branchname[30];
675
676 if(!treeS){
677 return;
678 }
7d62fb64 679 TBranch *branch;
680 sprintf(branchname,"%s",name);
681 branch = treeS->GetBranch(branchname);
e6b4e6b9 682 TClonesArray *sdigi = &fSDigits;
683 if (branch) branch->SetAddress(&sdigi);
7d62fb64 684
685}
686//___________________________________________________________________
a6e0ebfe 687void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, const Char_t* name){
7d62fb64 688 // Set branch address for the digit Trees.
689
690 const char *det[3] = {"SPD","SDD","SSD"};
691 TBranch *branch;
692
693 char branchname[30];
694
695 if(!treeD){
696 return;
697 }
698 if(!fDigits){
699 fDigits = new TObjArray(fgkNdettypes);
700 }
701 for(Int_t i=0;i<fgkNdettypes;i++){
a6e0ebfe 702 const Char_t* digclass = GetDigitClassName(i);
7d62fb64 703 if(digclass==0x0){
704 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
705 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
706 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
707 digclass = GetDigitClassName(i);
708 }
709 TString classn = digclass;
710 if(!(fDigits->At(i))){
711 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 712 }else{
7d62fb64 713 ResetDigits(i);
714 }
715
716 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
717 else sprintf(branchname,"%sDigits%d",name,i+1);
718 if(fDigits){
719 branch = treeD->GetBranch(branchname);
720 if(branch) branch->SetAddress(&((*fDigits)[i]));
721 }
722 }
3b9df642 723
3b9df642 724}
7d62fb64 725//___________________________________________________________________
726void AliITSDetTypeSim::ResetDigits(){
023ae34b 727 // Reset number of digits and the digits array for the ITS detector.
7d62fb64 728
729 if(!fDigits){
730 Error("ResetDigits","fDigits is null!");
731 return;
732 }
733 for(Int_t i=0;i<fgkNdettypes;i++){
734 ResetDigits(i);
735 }
736}
737//___________________________________________________________________
738void AliITSDetTypeSim::ResetDigits(Int_t branch){
739 // Reset number of digits and the digits array for this branch.
740
741 if(fDigits->At(branch)){
742 ((TClonesArray*)fDigits->At(branch))->Clear();
743 }
744 if(fNDigits) fNDigits[branch]=0;
745
746}
747
748
749
750//_______________________________________________________________________
751void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
752 // Standard Summable digits to Digits function.
023ae34b 753 if(!GetITSgeom()){
754 Warning("SDigitsToDigits","GetITSgeom() is null!!");
7d62fb64 755 return;
756 }
757
758 const char *all = strstr(opt,"All");
759 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
760 strstr(opt,"SSD")};
761 if( !det[0] && !det[1] && !det[2] ) all = "All";
762 else all = 0;
763 static Bool_t setDef = kTRUE;
764 if(setDef) SetDefaultSimulation();
765 setDef = kFALSE;
766
767 AliITSsimulation *sim =0;
768 TTree* trees = fLoader->TreeS();
769 if( !(trees && GetSDigits()) ){
770 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
771 return;
772 }
773 sprintf(name,"%s",name);
774 TBranch* brchSDigits = trees->GetBranch(name);
775
776 Int_t id;
023ae34b 777 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
778 id = GetITSgeom()->GetModuleType(module);
7d62fb64 779 if (!all && !det[id]) continue;
780 sim = (AliITSsimulation*)GetSimulationModel(id);
781 if(!sim){
782 Error("SDigit2Digits","The simulation class was not "
783 "instanciated for module %d type %s!",module,
023ae34b 784 GetITSgeom()->GetModuleTypeName(module));
7d62fb64 785 exit(1);
786 }
787 sim->InitSimulationModule(module,gAlice->GetEvNumber());
788
e6b4e6b9 789 fSDigits.Clear();
7d62fb64 790 brchSDigits->GetEvent(module);
e6b4e6b9 791 sim->AddSDigitsToModule(&fSDigits,0);
7d62fb64 792 sim->FinishSDigitiseModule();
793 fLoader->TreeD()->Fill();
794 ResetDigits();
795 }
796 fLoader->TreeD()->GetEntries();
797 fLoader->TreeD()->AutoSave();
798 fLoader->TreeD()->Reset();
799}
7d62fb64 800//_________________________________________________________
023ae34b 801void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
7d62fb64 802 //Adds the module full of summable digits to the summable digits tree.
023ae34b 803
e6b4e6b9 804 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
7d62fb64 805}
806//__________________________________________________________
023ae34b 807void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
7d62fb64 808 // Add a simulated digit.
023ae34b 809
7d62fb64 810 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
811 switch(branch){
812 case 0:
813 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
814 break;
815 case 1:
816 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
817 break;
818 case 2:
819 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
820 break;
023ae34b 821 }
7d62fb64 822}
3b9df642 823//______________________________________________________________________
7d62fb64 824void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
83ec5e27 825 Int_t *tracks,Int_t *hits,Float_t *charges,
826 Int_t sigexpanded){
7d62fb64 827 // Add a simulated digit to the list.
828
829 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
7d62fb64 830 switch(branch){
831 case 0:
832 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
833 break;
834 case 1:
7d62fb64 835 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
83ec5e27 836 hits,charges,sigexpanded);
7d62fb64 837 break;
838 case 2:
839 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
840 break;
841 }
3b9df642 842}
8ba39da9 843//______________________________________________________________________
023ae34b 844void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
845 AliCDBMetaData &md) {
8ba39da9 846 // Store calibration in the calibration database
8ba39da9 847 // The database must be created in an external piece of code (i.e.
848 // a configuration macro )
849
850 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
06232459 851 AliWarning("No storage set! Will use dummy one");
162637e4 852 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
8ba39da9 853 }
854
fcf95fc7 855 if (!fCalibration) {
856 AliError("AliITSCalibration classes are not defined - nothing done");
8ba39da9 857 return;
858 }
6727e2db 859 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
fcf95fc7 860 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
861 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
8ba39da9 862
863 TObjArray respSPD(fNMod[0]);
864 TObjArray respSDD(fNMod[1]-fNMod[0]);
865 TObjArray respSSD(fNMod[2]-fNMod[1]);
866 respSPD.SetOwner(kFALSE);
867 respSSD.SetOwner(kFALSE);
868 respSSD.SetOwner(kFALSE);
869
870 Int_t index[fgkNdettypes];
871 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
872 index[i] = 0;
873 for (Int_t j = 0; j<=i; j++ )
874 index[i]+=fNMod[j];
875 }
876
877 for (Int_t i = 0; i<index[0]; i++ )
fcf95fc7 878 respSPD.Add(fCalibration->At(i));
8ba39da9 879
880 for (Int_t i = index[0]; i<index[1]; i++ )
fcf95fc7 881 respSDD.Add(fCalibration->At(i));
8ba39da9 882
883 for (Int_t i = index[1]; i<index[2]; i++ )
fcf95fc7 884 respSSD.Add(fCalibration->At(i));
8ba39da9 885
06232459 886 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
887 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
888 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
8ba39da9 889}
890
88128115 891//______________________________________________________________________
892void AliITSDetTypeSim::ReadOldSSDNoise(TObjArray *array,
893 AliITSNoiseSSDv2 *noiseSSD) {
894 //Reads the old SSD calibration object and converts it to the new format
895 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
896 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
897
3dd31ed2 898 Int_t gNMod = array->GetEntries();
88128115 899 cout<<"Converting old calibration object for noise..."<<endl;
900
901 //NOISE
902 Double_t noise = 0.0;
3dd31ed2 903 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
88128115 904 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
905 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
906 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
907 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
908 noiseSSD->AddNoiseP(iModule,iStrip,noise);
909 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
910 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
911 }//loop over strips
912 }//loop over modules
913}
914
915//______________________________________________________________________
916void AliITSDetTypeSim::ReadOldSSDBadChannels(TObjArray *array,
917 AliITSBadChannelsSSDv2 *badChannelsSSD) {
918 //Reads the old SSD calibration object and converts it to the new format
f9e8ab3f 919 Int_t nMod = array->GetEntries();
88128115 920 cout<<"Converting old calibration object for bad channels..."<<endl;
f9e8ab3f 921 for (Int_t iModule = 0; iModule < nMod; iModule++) {
88128115 922 //for (Int_t iModule = 0; iModule < 1; iModule++) {
923 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
924 TArrayI arrayPSide = bad->GetBadPChannelsList();
925 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
926 badChannelsSSD->AddBadChannelP(iModule,
927 iPCounter,
928 (Char_t)arrayPSide.At(iPCounter));
929
930 TArrayI arrayNSide = bad->GetBadNChannelsList();
931 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
932 badChannelsSSD->AddBadChannelN(iModule,
933 iNCounter,
934 (Char_t)arrayNSide.At(iNCounter));
935
936 }//loop over modules
937}
938
939//______________________________________________________________________
940void AliITSDetTypeSim::ReadOldSSDGain(TObjArray *array,
941 AliITSGainSSDv2 *gainSSD) {
942 //Reads the old SSD calibration object and converts it to the new format
943
f9e8ab3f 944 Int_t nMod = array->GetEntries();
88128115 945 cout<<"Converting old calibration object for gain..."<<endl;
946
947 //GAIN
f9e8ab3f 948 for (Int_t iModule = 0; iModule < nMod; iModule++) {
88128115 949 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
950 TArrayF arrayPSide = gainModule->GetGainP();
951 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
952 gainSSD->AddGainP(iModule,
953 iPCounter,
954 arrayPSide.At(iPCounter));
955 TArrayF arrayNSide = gainModule->GetGainN();
956 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
957 gainSSD->AddGainN(iModule,
958 iNCounter,
959 arrayNSide.At(iNCounter));
960 }//loop over modules
961}
8ba39da9 962