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