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