Update of Macros
[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 "AliITSresponseSDD.h"
46#include "AliITSCalibrationSDD.h"
028a3709 47#include "AliITSMapSDD.h"
18da6e54 48#include "AliITSDriftSpeedArraySDD.h"
140e5249 49#include "AliITSDriftSpeedSDD.h"
fcf95fc7 50#include "AliITSCalibrationSSD.h"
fb4dfab9 51#include "AliITSNoiseSSD.h"
52#include "AliITSGainSSD.h"
53#include "AliITSBadChannelsSSD.h"
54#include "AliITSCalibrationSSD.h"
7d62fb64 55#include "AliITSsegmentationSPD.h"
56#include "AliITSsegmentationSDD.h"
57#include "AliITSsegmentationSSD.h"
58#include "AliITSsimulation.h"
59#include "AliITSsimulationSPD.h"
60#include "AliITSsimulationSDD.h"
61#include "AliITSsimulationSSD.h"
62
63
64const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
8ba39da9 65const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
66const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
67const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
3b9df642 68
69ClassImp(AliITSDetTypeSim)
70
71//----------------------------------------------------------------------
72AliITSDetTypeSim::AliITSDetTypeSim():
73TObject(),
3b9df642 74fSimulation(), // [NDet]
75fSegmentation(), // [NDet]
fcf95fc7 76fCalibration(), // [NMod]
3b9df642 77fPreProcess(), // [] e.g. Fill fHitModule with hits
78fPostProcess(), // [] e.g. Wright Raw data
3b9df642 79fNSDigits(0), //! number of SDigits
e6b4e6b9 80fSDigits("AliITSpListItem",1000),
3b9df642 81fNDigits(0), //! number of Digits
023ae34b 82fRunNumber(0), //! Run number (to access DB)
3b9df642 83fDigits(), //! [NMod][NDigits]
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();
8ba39da9 104 fNMod[0] = fgkDefaultNModulesSPD;
105 fNMod[1] = fgkDefaultNModulesSDD;
106 fNMod[2] = fgkDefaultNModulesSSD;
107 SetRunNumber();
3b9df642 108}
109//----------------------------------------------------------------------
110AliITSDetTypeSim::~AliITSDetTypeSim(){
111 // Destructor
112 // Inputs:
113 // none.
114 // Outputs:
115 // none.
116 // Return:
117 // Nothing.
023ae34b 118
7d62fb64 119 if(fSimulation){
023ae34b 120 fSimulation->Delete();
121 delete fSimulation;
7d62fb64 122 }
023ae34b 123 fSimulation = 0;
7d62fb64 124 if(fSegmentation){
023ae34b 125 fSegmentation->Delete();
126 delete fSegmentation;
7d62fb64 127 }
023ae34b 128 fSegmentation = 0;
b17dae48 129 if(fCalibration && fRunNumber<0){
023ae34b 130 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
131 GetITSgeom()->GetStartSPD()))->GetResponse();
132 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
133 GetITSgeom()->GetStartSDD()))->GetResponse();
134 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
135 GetITSgeom()->GetStartSSD()))->GetResponse();
136 if(rspd) delete rspd;
137 if(rsdd) delete rsdd;
138 if(rssd) delete rssd;
139 fCalibration->Delete();
140 delete fCalibration;
7d62fb64 141 }
023ae34b 142 fCalibration = 0;
7d62fb64 143 if(fPreProcess){
023ae34b 144 fPreProcess->Delete();
145 delete fPreProcess;
7d62fb64 146 }
023ae34b 147 fPreProcess = 0;
7d62fb64 148 if(fPostProcess){
023ae34b 149 fPostProcess->Delete();
150 delete fPostProcess;
7d62fb64 151 }
023ae34b 152 fPostProcess = 0;
979b5a5f 153 if(fDDLMapSDD) delete fDDLMapSDD;
2a476797 154 if(fNDigits) delete [] fNDigits;
023ae34b 155 fNDigits = 0;
156 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
157 fLoader = 0; // Not deleting it.
e6b4e6b9 158 fSDigits.Delete();
7d62fb64 159 if (fDigits) {
160 fDigits->Delete();
161 delete fDigits;
7d62fb64 162 }
023ae34b 163 fDigits=0;
3b9df642 164}
165//----------------------------------------------------------------------
7537d03c 166AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
167fSimulation(source.fSimulation), // [NDet]
168fSegmentation(source.fSegmentation), // [NDet]
169fCalibration(source.fCalibration), // [NMod]
170fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
171fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
172fNSDigits(source.fNSDigits), //! number of SDigits
e6b4e6b9 173fSDigits(*((TClonesArray*)source.fSDigits.Clone())),
7537d03c 174fNDigits(source.fNDigits), //! number of Digits
175fRunNumber(source.fRunNumber), //! Run number (to access DB)
176fDigits(source.fDigits), //! [NMod][NDigits]
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();
345 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
346 GetITSgeom()->GetStartSDD()))->GetResponse();
347 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
348 GetITSgeom()->GetStartSSD()))->GetResponse();
349 if(rspd) delete rspd;
350 if(rsdd) delete rsdd;
351 if(rssd) delete rssd;
352 fCalibration->Clear();
353 }else if (fCalibration && fRunNumber>=0){
354 fCalibration->Clear();
355 }
7d62fb64 356}
357//______________________________________________________________________
358void AliITSDetTypeSim::ResetSegmentation(){
023ae34b 359 //Resets segmentation array
360 if(fSegmentation) fSegmentation->Clear();
7d62fb64 361}
7d62fb64 362//_______________________________________________________________________
fcf95fc7 363AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
023ae34b 364 //Get response model for module number iMod
8ba39da9 365
023ae34b 366 if(fCalibration==0) {
367 AliError("fCalibration is 0!");
368 return 0;
369 }
fcf95fc7 370 return (AliITSCalibration*)(fCalibration->At(iMod));
7d62fb64 371}
372//_______________________________________________________________________
373void AliITSDetTypeSim::SetDefaults(){
023ae34b 374 //Set defaults for segmentation and response
375
376 if(GetITSgeom()==0){
377 Warning("SetDefaults","GetITSgeom() is 0!");
378 return;
379 } // end if
380 if (fCalibration==0) {
381 CreateCalibrationArray();
382 } // end if
383
384 ResetSegmentation();
385 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
386
387 for(Int_t idet=0;idet<fgkNdettypes;idet++){
388 //SPD
389 if(idet==0){
390 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
391 const char *kData0=(GetCalibrationModel(GetITSgeom()->GetStartSPD()))->DataType();
392 if (strstr(kData0,"real")) {
393 SetDigitClassName(idet,"AliITSdigit");
394 }else {
395 SetDigitClassName(idet,"AliITSdigitSPD");
396 } // end if
397 } // end if idet==0
398 //SDD
399 if(idet==1){
400 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
401 AliITSCalibrationSDD* rsp =
402 (AliITSCalibrationSDD*)GetCalibrationModel(
403 GetITSgeom()->GetStartSDD());
404 const char *kopt = ((AliITSresponseSDD*)rsp->GetResponse())->
405 ZeroSuppOption();
20f3f947 406 if(!strstr(kopt,"ZS")) {
407 SetDigitClassName(idet,"AliITSdigit");
023ae34b 408 }else {
20f3f947 409 SetDigitClassName(idet,"AliITSdigitSDD");
023ae34b 410 } // end if
411 } // end if idet==1
412 //SSD
413 if(idet==2){
414 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
415 const char *kData2 = (GetCalibrationModel(
416 GetITSgeom()->GetStartSSD())->DataType());
417 if (strstr(kData2,"real")) {
418 SetDigitClassName(idet,"AliITSdigit");
419 }else {
420 SetDigitClassName(idet,"AliITSdigitSSD");
421 } // end if
422 } // end if idet==2
423 }// end for idet
8ba39da9 424}
8ba39da9 425//______________________________________________________________________
426Bool_t AliITSDetTypeSim::GetCalibration() {
427 // Get Default calibration if a storage is not defined.
7d62fb64 428
b17dae48 429 if(!fFirstcall){
430 AliITSCalibration* cal = GetCalibrationModel(0);
431 if(cal)return kTRUE;
432 }
433 else {
434 fFirstcall = kFALSE;
435 }
436
437 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
438 Int_t run=GetRunNumber();
b17dae48 439
440 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
441 Bool_t isCacheActive = kTRUE;
442 if(GetRunNumber()<0){
443 isCacheActive=kFALSE;
444 fCalibration->SetOwner(kTRUE);
445 }
446 else{
447 fCalibration->SetOwner(kFALSE);
448 }
449
450 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
451
6727e2db 452 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
b17dae48 453 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
18da6e54 454 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
979b5a5f 455 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
028a3709 456 AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
457 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
fb4dfab9 458 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
028a3709 459 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
460 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
461 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
fb4dfab9 462
b17dae48 463 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
464 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
465 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 466
fb4dfab9 467 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
979b5a5f 468 !entry2SPD || !entry2SDD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD ||!mapTSDD){
fb4dfab9 469 AliFatal("Calibration object retrieval failed! ");
470 return kFALSE;
471 }
8ba39da9 472
028a3709 473// if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
474// !entry2SPD || !entry2SDD || !entry2SSD){
475// AliFatal("Calibration object retrieval failed! ");
476// return kFALSE;
477// }
06232459 478
b17dae48 479 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
480 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 481 entrySPD->SetOwner(kTRUE);
06232459 482
fcf95fc7 483 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
b17dae48 484 if(!isCacheActive)entry2SPD->SetObject(NULL);
fcf95fc7 485 entry2SPD->SetOwner(kTRUE);
486
b17dae48 487 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
488 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 489 entrySDD->SetOwner(kTRUE);
06232459 490
fcf95fc7 491 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
b17dae48 492 if(!isCacheActive)entry2SDD->SetObject(NULL);
fcf95fc7 493 entry2SDD->SetOwner(kTRUE);
494
18da6e54 495 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
496 if(!isCacheActive)drSpSDD->SetObject(NULL);
497 drSpSDD->SetOwner(kTRUE);
498
979b5a5f 499 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
500 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
501 ddlMapSDD->SetOwner(kTRUE);
502
028a3709 503 TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
504 if(!isCacheActive)mapASDD->SetObject(NULL);
505 mapASDD->SetOwner(kTRUE);
506
507 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
508 if(!isCacheActive)mapTSDD->SetObject(NULL);
509 mapTSDD->SetOwner(kTRUE);
510
fb4dfab9 511 /*
b17dae48 512 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
513 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 514 entrySSD->SetOwner(kTRUE);
fb4dfab9 515 */
516
517 TObjArray *noiseSSD = (TObjArray *)entryNoiseSSD->GetObject();
518 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
519 entryNoiseSSD->SetOwner(kTRUE);
520
521 TObjArray *gainSSD = (TObjArray *)entryGainSSD->GetObject();
522 if(!isCacheActive)entryGainSSD->SetObject(NULL);
523 entryGainSSD->SetOwner(kTRUE);
524
525 TObjArray *badchannelsSSD = (TObjArray *)entryBadChannelsSSD->GetObject();
526 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
527 entryBadChannelsSSD->SetOwner(kTRUE);
06232459 528
fcf95fc7 529 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
b17dae48 530 if(!isCacheActive)entry2SSD->SetObject(NULL);
fcf95fc7 531 entry2SSD->SetOwner(kTRUE);
532
b17dae48 533 // DB entries are deleted. In this way metadeta objects are deleted as well
534 if(!isCacheActive){
535 delete entrySPD;
536 delete entrySDD;
fb4dfab9 537 delete entryNoiseSSD;
538 delete entryGainSSD;
539 delete entryBadChannelsSSD;
b17dae48 540 delete entry2SPD;
541 delete entry2SDD;
542 delete entry2SSD;
028a3709 543 delete mapASDD;
544 delete mapTSDD;
18da6e54 545 delete drSpSDD;
979b5a5f 546 delete ddlMapSDD;
b17dae48 547 }
fcf95fc7 548
b17dae48 549 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
550
979b5a5f 551 if ((!pSPD)||(!pSDD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
028a3709 552 || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badchannelsSSD)) {
8ba39da9 553 AliWarning("Can not get calibration from calibration database !");
554 return kFALSE;
555 }
fb4dfab9 556
b17dae48 557 fNMod[0] = calSPD->GetEntries();
558 fNMod[1] = calSDD->GetEntries();
fb4dfab9 559 fNMod[2] = noiseSSD->GetEntries();
8ba39da9 560 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
561 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 562 AliITSCalibration* cal;
8ba39da9 563 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 564 cal = (AliITSCalibration*) calSPD->At(i);
565 cal->SetResponse(pSPD);
566 SetCalibrationModel(i, cal);
18da6e54 567 }
140e5249 568
569 fDDLMapSDD->SetDDLMap(ddlsdd);
946db678 570
571 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
572 Int_t iddl,icarlos;
573 Int_t iMod = i + fgkDefaultNModulesSPD;
574 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
575 if(iddl<0){
576 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
577 calsdddead->SetResponse(pSDD);
578 calsdddead->SetBad();
579 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
580 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
581 arrdrsp->AddDriftSpeed(driftspdef);
582 calsdddead->SetDriftSpeed(0,arrdrsp);
583 calsdddead->SetDriftSpeed(1,arrdrsp);
584 SetCalibrationModel(iMod, calsdddead);
585 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
586 }else{
140e5249 587 cal = (AliITSCalibration*) calSDD->At(i);
946db678 588 cal->SetResponse(pSDD);
140e5249 589 Int_t i0=2*i;
590 Int_t i1=1+2*i;
591 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
592 AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
593 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
594 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
595 AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
596 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
597 cal->SetDriftSpeed(0,arr0);
598 cal->SetDriftSpeed(1,arr1);
599 cal->SetMapA(0,ma0);
600 cal->SetMapA(1,ma1);
601 cal->SetMapT(0,mt0);
602 cal->SetMapT(1,mt1);
603 SetCalibrationModel(iMod, cal);
604 }
605 }
946db678 606
8ba39da9 607 for (Int_t i=0; i<fNMod[2]; i++) {
fb4dfab9 608 AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
609 calibSSD->SetResponse((AliITSresponse*)pSSD);
610
611 AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
612 calibSSD->SetNoise(noise);
613 AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
614 calibSSD->SetGain(gain);
615 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
616 calibSSD->SetBadChannels(bad);
617
6cc25d49 618 Int_t iMod = i + fgkDefaultNModulesSPD + fgkDefaultNModulesSDD;
fb4dfab9 619 SetCalibrationModel(iMod, calibSSD);
620
8ba39da9 621 }
8ba39da9 622 return kTRUE;
7d62fb64 623}
7d62fb64 624//_______________________________________________________________________
625void AliITSDetTypeSim::SetDefaultSimulation(){
7d62fb64 626 //Set default simulation for detector type
627
023ae34b 628 if(GetITSgeom()==0){
629 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
8ba39da9 630 return;
631 }
fcf95fc7 632 if(fCalibration==0){
633 Warning("SetDefaultSimulation","fCalibration is 0!");
7d62fb64 634 return;
635 }
fcf95fc7 636 if(fSegmentation==0){
637 Warning("SetDefaultSimulation","fSegmentation is 0!");
638 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
023ae34b 639 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
640 Warning("SetDefaultSimulation",
641 "Segmentation not defined for det %d - Default taken\n!",i);
642 SetDefaultSegmentation(i);
1964ae5f 643 }
7d62fb64 644 AliITSsimulation* sim;
645
646 for(Int_t idet=0;idet<fgkNdettypes;idet++){
647 //SPD
648 if(idet==0){
023ae34b 649 sim = GetSimulationModel(idet);
7d62fb64 650 if(!sim){
8ba39da9 651 sim = new AliITSsimulationSPD(this);
7d62fb64 652 SetSimulationModel(idet,sim);
7d62fb64 653 }
654 }
655 //SDD
656 if(idet==1){
657 sim = GetSimulationModel(idet);
658 if(!sim){
8ba39da9 659 sim = new AliITSsimulationSDD(this);
7d62fb64 660 SetSimulationModel(idet,sim);
023ae34b 661 }
7d62fb64 662 }
663 //SSD
664 if(idet==2){
665 sim = GetSimulationModel(idet);
666 if(!sim){
8ba39da9 667 sim = new AliITSsimulationSSD(this);
7d62fb64 668 SetSimulationModel(idet,sim);
7d62fb64 669 }
7d62fb64 670 }
671
672 }
673}
7d62fb64 674//___________________________________________________________________
675void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
023ae34b 676 // Set branch address for the ITS summable digits Trees.
7d62fb64 677 char branchname[30];
678
679 if(!treeS){
680 return;
681 }
7d62fb64 682 TBranch *branch;
683 sprintf(branchname,"%s",name);
684 branch = treeS->GetBranch(branchname);
e6b4e6b9 685 TClonesArray *sdigi = &fSDigits;
686 if (branch) branch->SetAddress(&sdigi);
7d62fb64 687
688}
689//___________________________________________________________________
690void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
691 // Set branch address for the digit Trees.
692
693 const char *det[3] = {"SPD","SDD","SSD"};
694 TBranch *branch;
695
696 char branchname[30];
697
698 if(!treeD){
699 return;
700 }
701 if(!fDigits){
702 fDigits = new TObjArray(fgkNdettypes);
703 }
704 for(Int_t i=0;i<fgkNdettypes;i++){
705 Char_t* digclass = GetDigitClassName(i);
706 if(digclass==0x0){
707 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
708 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
709 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
710 digclass = GetDigitClassName(i);
711 }
712 TString classn = digclass;
713 if(!(fDigits->At(i))){
714 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 715 }else{
7d62fb64 716 ResetDigits(i);
717 }
718
719 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
720 else sprintf(branchname,"%sDigits%d",name,i+1);
721 if(fDigits){
722 branch = treeD->GetBranch(branchname);
723 if(branch) branch->SetAddress(&((*fDigits)[i]));
724 }
725 }
3b9df642 726
3b9df642 727}
7d62fb64 728//___________________________________________________________________
729void AliITSDetTypeSim::ResetDigits(){
023ae34b 730 // Reset number of digits and the digits array for the ITS detector.
7d62fb64 731
732 if(!fDigits){
733 Error("ResetDigits","fDigits is null!");
734 return;
735 }
736 for(Int_t i=0;i<fgkNdettypes;i++){
737 ResetDigits(i);
738 }
739}
740//___________________________________________________________________
741void AliITSDetTypeSim::ResetDigits(Int_t branch){
742 // Reset number of digits and the digits array for this branch.
743
744 if(fDigits->At(branch)){
745 ((TClonesArray*)fDigits->At(branch))->Clear();
746 }
747 if(fNDigits) fNDigits[branch]=0;
748
749}
750
751
752
753//_______________________________________________________________________
754void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
755 // Standard Summable digits to Digits function.
023ae34b 756 if(!GetITSgeom()){
757 Warning("SDigitsToDigits","GetITSgeom() is null!!");
7d62fb64 758 return;
759 }
760
761 const char *all = strstr(opt,"All");
762 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
763 strstr(opt,"SSD")};
764 if( !det[0] && !det[1] && !det[2] ) all = "All";
765 else all = 0;
766 static Bool_t setDef = kTRUE;
767 if(setDef) SetDefaultSimulation();
768 setDef = kFALSE;
769
770 AliITSsimulation *sim =0;
771 TTree* trees = fLoader->TreeS();
772 if( !(trees && GetSDigits()) ){
773 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
774 return;
775 }
776 sprintf(name,"%s",name);
777 TBranch* brchSDigits = trees->GetBranch(name);
778
779 Int_t id;
023ae34b 780 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
781 id = GetITSgeom()->GetModuleType(module);
7d62fb64 782 if (!all && !det[id]) continue;
783 sim = (AliITSsimulation*)GetSimulationModel(id);
784 if(!sim){
785 Error("SDigit2Digits","The simulation class was not "
786 "instanciated for module %d type %s!",module,
023ae34b 787 GetITSgeom()->GetModuleTypeName(module));
7d62fb64 788 exit(1);
789 }
790 sim->InitSimulationModule(module,gAlice->GetEvNumber());
791
e6b4e6b9 792 fSDigits.Clear();
7d62fb64 793 brchSDigits->GetEvent(module);
e6b4e6b9 794 sim->AddSDigitsToModule(&fSDigits,0);
7d62fb64 795 sim->FinishSDigitiseModule();
796 fLoader->TreeD()->Fill();
797 ResetDigits();
798 }
799 fLoader->TreeD()->GetEntries();
800 fLoader->TreeD()->AutoSave();
801 fLoader->TreeD()->Reset();
802}
7d62fb64 803//_________________________________________________________
023ae34b 804void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
7d62fb64 805 //Adds the module full of summable digits to the summable digits tree.
023ae34b 806
e6b4e6b9 807 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
7d62fb64 808}
809//__________________________________________________________
810void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
811 // Add a real digit - as coming from data.
023ae34b 812
7d62fb64 813 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
814 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
815}
816//__________________________________________________________
023ae34b 817void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
7d62fb64 818 // Add a simulated digit.
023ae34b 819
7d62fb64 820 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
821 switch(branch){
822 case 0:
823 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
824 break;
825 case 1:
826 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
827 break;
828 case 2:
829 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
830 break;
023ae34b 831 }
7d62fb64 832}
3b9df642 833//______________________________________________________________________
7d62fb64 834void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
835 Int_t *tracks,Int_t *hits,Float_t *charges){
836 // Add a simulated digit to the list.
837
838 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
fcf95fc7 839 AliITSCalibrationSDD *resp = 0;
7d62fb64 840 switch(branch){
841 case 0:
842 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
843 break;
844 case 1:
023ae34b 845 resp = (AliITSCalibrationSDD*)GetCalibrationModel(
846 GetITSgeom()->GetStartSDD());
7d62fb64 847 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
848 hits,charges,resp);
849 break;
850 case 2:
851 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
852 break;
853 }
3b9df642 854}
8ba39da9 855//______________________________________________________________________
023ae34b 856void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
857 AliCDBMetaData &md) {
8ba39da9 858 // Store calibration in the calibration database
8ba39da9 859 // The database must be created in an external piece of code (i.e.
860 // a configuration macro )
861
862 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
06232459 863 AliWarning("No storage set! Will use dummy one");
8ba39da9 864 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
8ba39da9 865 }
866
fcf95fc7 867 if (!fCalibration) {
868 AliError("AliITSCalibration classes are not defined - nothing done");
8ba39da9 869 return;
870 }
6727e2db 871 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
fcf95fc7 872 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
873 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
8ba39da9 874
875 TObjArray respSPD(fNMod[0]);
876 TObjArray respSDD(fNMod[1]-fNMod[0]);
877 TObjArray respSSD(fNMod[2]-fNMod[1]);
878 respSPD.SetOwner(kFALSE);
879 respSSD.SetOwner(kFALSE);
880 respSSD.SetOwner(kFALSE);
881
882 Int_t index[fgkNdettypes];
883 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
884 index[i] = 0;
885 for (Int_t j = 0; j<=i; j++ )
886 index[i]+=fNMod[j];
887 }
888
889 for (Int_t i = 0; i<index[0]; i++ )
fcf95fc7 890 respSPD.Add(fCalibration->At(i));
8ba39da9 891
892 for (Int_t i = index[0]; i<index[1]; i++ )
fcf95fc7 893 respSDD.Add(fCalibration->At(i));
8ba39da9 894
895 for (Int_t i = index[1]; i<index[2]; i++ )
fcf95fc7 896 respSSD.Add(fCalibration->At(i));
8ba39da9 897
06232459 898 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
899 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
900 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
8ba39da9 901}
902
903