1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 /////////////////////////////////////////////////////////////////////
22 // Base simulation functions for ITS //
25 /////////////////////////////////////////////////////////////////////
27 #include "TClonesArray.h"
28 #include "TObjArray.h"
33 #include "AliCDBManager.h"
35 #include "AliCDBStorage.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBMetaData.h"
39 #include "AliITSdigit.h"
40 #include "AliITSdigitSPD.h"
41 #include "AliITSdigitSDD.h"
42 #include "AliITSdigitSSD.h"
43 #include "AliITSDetTypeSim.h"
44 #include "AliITSpListItem.h"
45 #include "AliITSCalibrationSDD.h"
46 #include "AliITSMapSDD.h"
47 #include "AliITSDriftSpeedArraySDD.h"
48 #include "AliITSDriftSpeedSDD.h"
49 #include "AliITSHLTforSDD.h"
50 #include "AliITSCalibrationSSD.h"
51 #include "AliITSNoiseSSDv2.h"
52 #include "AliITSGainSSDv2.h"
53 #include "AliITSBadChannelsSSDv2.h"
54 #include "AliITSNoiseSSD.h"
55 #include "AliITSGainSSD.h"
56 #include "AliITSBadChannelsSSD.h"
57 #include "AliITSCalibrationSSD.h"
58 #include "AliITSsegmentationSPD.h"
59 #include "AliITSsegmentationSDD.h"
60 #include "AliITSsegmentationSSD.h"
61 #include "AliITSsimulation.h"
62 #include "AliITSsimulationSPD.h"
63 #include "AliITSsimulationSDD.h"
64 #include "AliITSsimulationSSD.h"
67 const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
68 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
69 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
70 const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
72 ClassImp(AliITSDetTypeSim)
74 //----------------------------------------------------------------------
75 AliITSDetTypeSim::AliITSDetTypeSim():
77 fSimulation(), // [NDet]
78 fSegmentation(), // [NDet]
79 fCalibration(), // [NMod]
81 fPreProcess(), // [] e.g. Fill fHitModule with hits
82 fPostProcess(), // [] e.g. Wright Raw data
83 fNSDigits(0), //! number of SDigits
84 fSDigits("AliITSpListItem",1000),
85 fNDigits(0), //! number of Digits
86 fRunNumber(0), //! Run number (to access DB)
87 fDigits(), //! [NMod][NDigits]
90 fHitClassName(), // String with Hit class name.
91 fSDigClassName(),// String with SDigit class name.
92 fDigClassName(), // String with digit class name.
93 fLoader(0), // local pointer to loader
95 fIsHLTmodeC(0){ // flag
96 // Default Constructor
102 // A properly zero-ed AliITSDetTypeSim class.
104 fSimulation = new TObjArray(fgkNdettypes);
105 fSegmentation = new TObjArray(fgkNdettypes);
106 fSegmentation->SetOwner(kTRUE);
107 fDigits = new TObjArray(fgkNdettypes);
108 fNDigits = new Int_t[fgkNdettypes];
109 fDDLMapSDD=new AliITSDDLModuleMapSDD();
110 fSimuPar= new AliITSSimuParam();
111 fSSDCalibration=new AliITSCalibrationSSD();
112 fNMod[0] = fgkDefaultNModulesSPD;
113 fNMod[1] = fgkDefaultNModulesSDD;
114 fNMod[2] = fgkDefaultNModulesSSD;
117 //----------------------------------------------------------------------
118 AliITSDetTypeSim::~AliITSDetTypeSim(){
128 fSimulation->Delete();
133 fSegmentation->Delete();
134 delete fSegmentation;
137 if(fCalibration && fRunNumber<0){
139 fCalibration->Delete();
143 if(fSSDCalibration) delete fSSDCalibration;
145 fPreProcess->Delete();
150 fPostProcess->Delete();
154 if(fSimuPar) delete fSimuPar;
155 if(fDDLMapSDD) delete fDDLMapSDD;
156 if(fNDigits) delete [] fNDigits;
158 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
159 fLoader = 0; // Not deleting it.
167 //----------------------------------------------------------------------
168 AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source),
169 fSimulation(source.fSimulation), // [NDet]
170 fSegmentation(source.fSegmentation), // [NDet]
171 fCalibration(source.fCalibration), // [NMod]
172 fSSDCalibration(source.fSSDCalibration),
173 fPreProcess(source.fPreProcess), // [] e.g. Fill fHitModule with hits
174 fPostProcess(source.fPostProcess), // [] e.g. Wright Raw data
175 fNSDigits(source.fNSDigits), //! number of SDigits
176 fSDigits(*((TClonesArray*)source.fSDigits.Clone())),
177 fNDigits(source.fNDigits), //! number of Digits
178 fRunNumber(source.fRunNumber), //! Run number (to access DB)
179 fDigits(source.fDigits), //! [NMod][NDigits]
180 fSimuPar(source.fSimuPar),
181 fDDLMapSDD(source.fDDLMapSDD),
182 fHitClassName(source.fHitClassName), // String with Hit class name.
183 fSDigClassName(source.fSDigClassName),// String with SDigit class name.
184 fDigClassName(), // String with digit class name.
185 fLoader(source.fLoader), // local pointer to loader
186 fFirstcall(source.fFirstcall),
187 fIsHLTmodeC(source.fIsHLTmodeC)
189 // Copy Constructor for object AliITSDetTypeSim not allowed
190 for(Int_t i=0;i<fgkNdettypes;i++){
191 fDigClassName[i] = source.fDigClassName[i];
194 //----------------------------------------------------------------------
195 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
196 // The = operator for object AliITSDetTypeSim
198 this->~AliITSDetTypeSim();
199 new(this) AliITSDetTypeSim(source);
203 //______________________________________________________________________
204 void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
205 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
208 // AliITSgoem *geom The AliITSgeom object to be used.
214 Error("SetITSgeom","No pointer to loader - nothing done");
218 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
222 //______________________________________________________________________
223 void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
224 // Sets the local copy of the AliITSLoader, and passes on the
225 // AliITSgeom object as needed.
227 // AliITSLoader *loader pointer to AliITSLoader for local use
233 if(fLoader==loader) return; // Same do nothing
234 if(fLoader){ // alread have an existing loader
236 "Already have an exisiting loader ptr=%p Nothing done",
241 //______________________________________________________________________
242 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
244 //Set simulation model for detector type
246 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
247 fSimulation->AddAt(sim,dettype);
249 //______________________________________________________________________
250 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
252 //Get simulation model for detector type
254 Warning("GetSimulationModel","fSimulation is 0!");
257 return (AliITSsimulation*)(fSimulation->At(dettype));
259 //______________________________________________________________________
260 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
262 //Get simulation model by module number
263 if(GetITSgeom()==0) {
264 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
268 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
270 //_______________________________________________________________________
271 void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
272 // Set default segmentation model objects
273 AliITSsegmentation *seg;
275 if(fSegmentation==0x0){
276 fSegmentation = new TObjArray(fgkNdettypes);
277 fSegmentation->SetOwner(kTRUE);
279 if(GetSegmentationModel(idet))
280 delete (AliITSsegmentation*)fSegmentation->At(idet);
282 seg = new AliITSsegmentationSPD();
284 seg = new AliITSsegmentationSDD();
285 AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
286 if(cal->IsAMAt20MHz()){
287 seg->SetPadSize(seg->Dpz(0),20.);
288 seg->SetNPads(seg->Npz()/2,128);
291 seg = new AliITSsegmentationSSD();
293 SetSegmentationModel(idet,seg);
295 //______________________________________________________________________
296 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
297 AliITSsegmentation *seg){
299 //Set segmentation model for detector type
300 if(fSegmentation==0x0){
301 fSegmentation = new TObjArray(fgkNdettypes);
302 fSegmentation->SetOwner(kTRUE);
304 fSegmentation->AddAt(seg,dettype);
306 //______________________________________________________________________
307 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
308 //Get segmentation model for detector type
310 if(fSegmentation==0) {
311 Warning("GetSegmentationModel","fSegmentation is 0!");
314 return (AliITSsegmentation*)(fSegmentation->At(dettype));
316 //_______________________________________________________________________
317 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
318 //Get segmentation model by module number
320 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
323 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
325 //_______________________________________________________________________
326 void AliITSDetTypeSim::CreateCalibrationArray() {
327 //Create the container of calibration functions with correct size
329 Warning("CreateCalibration","pointer to calibration object exists\n");
330 fCalibration->Delete();
334 Int_t nModTot = GetITSgeom()->GetIndexMax();
335 fCalibration = new TObjArray(nModTot);
336 fCalibration->SetOwner(kTRUE);
337 fCalibration->Clear();
339 //_______________________________________________________________________
340 void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
341 //Set response model for modules
343 if (fCalibration==0) CreateCalibrationArray();
345 if (fCalibration->At(iMod)!=0)
346 delete (AliITSCalibration*) fCalibration->At(iMod);
347 fCalibration->AddAt(resp, iMod);
349 //______________________________________________________________________
350 void AliITSDetTypeSim::ResetCalibrationArray(){
351 //resets response array
352 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
354 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
355 GetITSgeom()->GetStartSPD()))->GetResponse();
356 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
357 GetITSgeom()->GetStartSSD()))->GetResponse();
358 if(rspd) delete rspd;
359 if(rssd) delete rssd;
361 fCalibration->Clear();
362 }else if (fCalibration && fRunNumber>=0){
363 fCalibration->Clear();
366 //______________________________________________________________________
367 void AliITSDetTypeSim::ResetSegmentation(){
368 //Resets segmentation array
369 if(fSegmentation) fSegmentation->Clear();
371 //_______________________________________________________________________
372 AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
373 //Get response model for module number iMod
375 if(fCalibration==0) {
376 AliError("fCalibration is 0!");
379 if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
380 return (AliITSCalibration*)fCalibration->At(iMod);
382 Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
383 fSSDCalibration->SetModule(i);
384 return (AliITSCalibration*)fSSDCalibration;
388 //_______________________________________________________________________
389 void AliITSDetTypeSim::SetDefaults(){
390 //Set defaults for segmentation and response
393 Warning("SetDefaults","GetITSgeom() is 0!");
396 if (fCalibration==0) {
397 CreateCalibrationArray();
401 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
403 SetDigitClassName(0,"AliITSdigitSPD");
404 SetDigitClassName(1,"AliITSdigitSDD");
405 SetDigitClassName(2,"AliITSdigitSSD");
407 for(Int_t idet=0;idet<fgkNdettypes;idet++){
408 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
411 //______________________________________________________________________
412 Bool_t AliITSDetTypeSim::GetCalibration() {
413 // Get Default calibration if a storage is not defined.
416 AliITSCalibration* cal = GetCalibrationModel(0);
423 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
424 Int_t run=GetRunNumber();
426 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
427 Bool_t isCacheActive = kTRUE;
428 if(GetRunNumber()<0){
429 isCacheActive=kFALSE;
430 fCalibration->SetOwner(kTRUE);
433 fCalibration->SetOwner(kFALSE);
436 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
438 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead", run);
439 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
440 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD",run);
441 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD",run);
442 AliCDBEntry *hltforSDD = AliCDBManager::Instance()->Get("ITS/Calib/HLTforSDD");
443 //AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD",run);
444 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD",run);
445 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
446 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
447 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
448 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
450 if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD ||
451 !drSpSDD || !ddlMapSDD || !hltforSDD || !mapTSDD){
452 AliFatal("Calibration object retrieval failed! ");
457 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
458 if(!isCacheActive)entrySPD->SetObject(NULL);
459 entrySPD->SetOwner(kTRUE);
462 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
463 if(!isCacheActive)entrySDD->SetObject(NULL);
464 entrySDD->SetOwner(kTRUE);
466 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
467 if(!isCacheActive)drSpSDD->SetObject(NULL);
468 drSpSDD->SetOwner(kTRUE);
470 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
471 if(!isCacheActive)ddlMapSDD->SetObject(NULL);
472 ddlMapSDD->SetOwner(kTRUE);
474 AliITSHLTforSDD* hltsdd=(AliITSHLTforSDD*)hltforSDD->GetObject();
475 if(!isCacheActive)hltforSDD->SetObject(NULL);
476 hltforSDD->SetOwner(kTRUE);
478 // TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
479 // if(!isCacheActive)mapASDD->SetObject(NULL);
480 // mapASDD->SetOwner(kTRUE);
482 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
483 if(!isCacheActive)mapTSDD->SetObject(NULL);
484 mapTSDD->SetOwner(kTRUE);
487 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
488 if(!isCacheActive)entrySSD->SetObject(NULL);
489 entrySSD->SetOwner(kTRUE);
492 TObject *emptyssd = 0; TString ssdobjectname = 0;
493 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
494 emptyssd = (TObject *)entryNoiseSSD->GetObject();
495 ssdobjectname = emptyssd->GetName();
496 if(ssdobjectname=="TObjArray") {
497 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
498 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
500 else if(ssdobjectname=="AliITSNoiseSSDv2")
501 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
502 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
503 entryNoiseSSD->SetOwner(kTRUE);
505 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
506 emptyssd = (TObject *)entryGainSSD->GetObject();
507 ssdobjectname = emptyssd->GetName();
508 if(ssdobjectname=="Gain") {
509 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
510 ReadOldSSDGain(gainSSDOld, gainSSD);
512 else if(ssdobjectname=="AliITSGainSSDv2")
513 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
514 if(!isCacheActive)entryGainSSD->SetObject(NULL);
515 entryGainSSD->SetOwner(kTRUE);
517 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
518 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
519 ssdobjectname = emptyssd->GetName();
520 if(ssdobjectname=="TObjArray") {
521 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
522 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
524 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
525 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
526 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
527 entryBadChannelsSSD->SetOwner(kTRUE);
529 /*AliITSNoiseSSDv2 *noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
530 if(!isCacheActive)entryNoiseSSD->SetObject(NULL);
531 entryNoiseSSD->SetOwner(kTRUE);
533 AliITSGainSSDv2 *gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
534 if(!isCacheActive)entryGainSSD->SetObject(NULL);
535 entryGainSSD->SetOwner(kTRUE);
537 AliITSBadChannelsSSDv2 *badchannelsSSD =
538 (AliITSBadChannelsSSDv2 *)entryBadChannelsSSD->GetObject();
539 if(!isCacheActive)entryBadChannelsSSD->SetObject(NULL);
540 entryBadChannelsSSD->SetOwner(kTRUE);*/
542 // DB entries are deleted. In this way metadeta objects are deleted as well
546 delete entryNoiseSSD;
548 delete entryBadChannelsSSD;
556 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
558 if ((!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
559 || (!hltsdd) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
560 AliWarning("Can not get calibration from calibration database !");
564 fNMod[0] = calSPD->GetEntries();
565 fNMod[1] = calSDD->GetEntries();
566 // fNMod[2] = noiseSSD->GetEntries();
567 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
568 fNMod[0], fNMod[1], fNMod[2]));
569 AliITSCalibration* cal;
570 for (Int_t i=0; i<fNMod[0]; i++) {
571 cal = (AliITSCalibration*) calSPD->At(i);
572 SetCalibrationModel(i, cal);
575 fDDLMapSDD->SetDDLMap(ddlsdd);
576 fIsHLTmodeC=hltsdd->IsHLTmodeC();
578 for (Int_t i=0; i<fgkDefaultNModulesSDD; i++) {
580 Int_t iMod = i + fgkDefaultNModulesSPD;
581 fDDLMapSDD->FindInDDLMap(iMod,iddl,icarlos);
583 AliITSCalibrationSDD* calsdddead=new AliITSCalibrationSDD();
584 calsdddead->SetBad();
585 AliITSDriftSpeedSDD* driftspdef = new AliITSDriftSpeedSDD();
586 AliITSDriftSpeedArraySDD* arrdrsp=new AliITSDriftSpeedArraySDD(1);
587 arrdrsp->AddDriftSpeed(driftspdef);
588 calsdddead->SetDriftSpeed(0,arrdrsp);
589 calsdddead->SetDriftSpeed(1,arrdrsp);
590 SetCalibrationModel(iMod, calsdddead);
591 AliWarning(Form("SDD module %d not present in DDL map: set it as dead",iMod));
593 cal = (AliITSCalibration*) calSDD->At(i);
596 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
597 // AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
598 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
599 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
600 // AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
601 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
602 cal->SetDriftSpeed(0,arr0);
603 cal->SetDriftSpeed(1,arr1);
604 // cal->SetMapA(0,ma0);
605 // cal->SetMapA(1,ma1);
608 SetCalibrationModel(iMod, cal);
612 fSSDCalibration->SetNoise(noiseSSD);
613 fSSDCalibration->SetGain(gainSSD);
614 fSSDCalibration->SetBadChannels(badChannelsSSD);
615 //fSSDCalibration->FillBadChipMap();
621 //_______________________________________________________________________
622 void AliITSDetTypeSim::SetDefaultSimulation(){
623 //Set default simulation for detector type
626 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
630 Warning("SetDefaultSimulation","fCalibration is 0!");
633 if(fSegmentation==0){
634 Warning("SetDefaultSimulation","fSegmentation is 0!");
635 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
636 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
637 Warning("SetDefaultSimulation",
638 "Segmentation not defined for det %d - Default taken\n!",i);
639 SetDefaultSegmentation(i);
641 AliITSsimulation* sim;
643 for(Int_t idet=0;idet<fgkNdettypes;idet++){
646 sim = GetSimulationModel(idet);
648 sim = new AliITSsimulationSPD(this);
649 SetSimulationModel(idet,sim);
654 sim = GetSimulationModel(idet);
656 sim = new AliITSsimulationSDD(this);
657 SetSimulationModel(idet,sim);
662 sim = GetSimulationModel(idet);
664 sim = new AliITSsimulationSSD(this);
665 SetSimulationModel(idet,sim);
671 //___________________________________________________________________
672 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
673 // Set branch address for the ITS summable digits Trees.
680 sprintf(branchname,"%s",name);
681 branch = treeS->GetBranch(branchname);
682 TClonesArray *sdigi = &fSDigits;
683 if (branch) branch->SetAddress(&sdigi);
686 //___________________________________________________________________
687 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
688 // Set branch address for the digit Trees.
690 const char *det[3] = {"SPD","SDD","SSD"};
699 fDigits = new TObjArray(fgkNdettypes);
701 for(Int_t i=0;i<fgkNdettypes;i++){
702 Char_t* digclass = GetDigitClassName(i);
704 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
705 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
706 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
707 digclass = GetDigitClassName(i);
709 TString classn = digclass;
710 if(!(fDigits->At(i))){
711 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
716 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
717 else sprintf(branchname,"%sDigits%d",name,i+1);
719 branch = treeD->GetBranch(branchname);
720 if(branch) branch->SetAddress(&((*fDigits)[i]));
725 //___________________________________________________________________
726 void AliITSDetTypeSim::ResetDigits(){
727 // Reset number of digits and the digits array for the ITS detector.
730 Error("ResetDigits","fDigits is null!");
733 for(Int_t i=0;i<fgkNdettypes;i++){
737 //___________________________________________________________________
738 void AliITSDetTypeSim::ResetDigits(Int_t branch){
739 // Reset number of digits and the digits array for this branch.
741 if(fDigits->At(branch)){
742 ((TClonesArray*)fDigits->At(branch))->Clear();
744 if(fNDigits) fNDigits[branch]=0;
750 //_______________________________________________________________________
751 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
752 // Standard Summable digits to Digits function.
754 Warning("SDigitsToDigits","GetITSgeom() is null!!");
758 const char *all = strstr(opt,"All");
759 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
761 if( !det[0] && !det[1] && !det[2] ) all = "All";
763 static Bool_t setDef = kTRUE;
764 if(setDef) SetDefaultSimulation();
767 AliITSsimulation *sim =0;
768 TTree* trees = fLoader->TreeS();
769 if( !(trees && GetSDigits()) ){
770 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
773 sprintf(name,"%s",name);
774 TBranch* brchSDigits = trees->GetBranch(name);
777 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
778 id = GetITSgeom()->GetModuleType(module);
779 if (!all && !det[id]) continue;
780 sim = (AliITSsimulation*)GetSimulationModel(id);
782 Error("SDigit2Digits","The simulation class was not "
783 "instanciated for module %d type %s!",module,
784 GetITSgeom()->GetModuleTypeName(module));
787 sim->InitSimulationModule(module,gAlice->GetEvNumber());
790 brchSDigits->GetEvent(module);
791 sim->AddSDigitsToModule(&fSDigits,0);
792 sim->FinishSDigitiseModule();
793 fLoader->TreeD()->Fill();
796 fLoader->TreeD()->GetEntries();
797 fLoader->TreeD()->AutoSave();
798 fLoader->TreeD()->Reset();
800 //_________________________________________________________
801 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
802 //Adds the module full of summable digits to the summable digits tree.
804 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
806 //__________________________________________________________
807 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
808 // Add a simulated digit.
810 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
813 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
816 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
819 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
823 //______________________________________________________________________
824 void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
825 Int_t *tracks,Int_t *hits,Float_t *charges,
827 // Add a simulated digit to the list.
829 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
832 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
835 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
836 hits,charges,sigexpanded);
839 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
843 //______________________________________________________________________
844 void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
845 AliCDBMetaData &md) {
846 // Store calibration in the calibration database
847 // The database must be created in an external piece of code (i.e.
848 // a configuration macro )
850 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
851 AliWarning("No storage set! Will use dummy one");
852 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
856 AliError("AliITSCalibration classes are not defined - nothing done");
859 AliCDBId idRespSPD("ITS/Calib/SPDDead",firstRun, lastRun);
860 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
861 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
863 TObjArray respSPD(fNMod[0]);
864 TObjArray respSDD(fNMod[1]-fNMod[0]);
865 TObjArray respSSD(fNMod[2]-fNMod[1]);
866 respSPD.SetOwner(kFALSE);
867 respSSD.SetOwner(kFALSE);
868 respSSD.SetOwner(kFALSE);
870 Int_t index[fgkNdettypes];
871 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
873 for (Int_t j = 0; j<=i; j++ )
877 for (Int_t i = 0; i<index[0]; i++ )
878 respSPD.Add(fCalibration->At(i));
880 for (Int_t i = index[0]; i<index[1]; i++ )
881 respSDD.Add(fCalibration->At(i));
883 for (Int_t i = index[1]; i<index[2]; i++ )
884 respSSD.Add(fCalibration->At(i));
886 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
887 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
888 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
891 //______________________________________________________________________
892 void AliITSDetTypeSim::ReadOldSSDNoise(TObjArray *array,
893 AliITSNoiseSSDv2 *noiseSSD) {
894 //Reads the old SSD calibration object and converts it to the new format
895 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
896 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
898 Int_t gNMod = array->GetEntries();
899 cout<<"Converting old calibration object for noise..."<<endl;
902 Double_t noise = 0.0;
903 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
904 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
905 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
906 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
907 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
908 noiseSSD->AddNoiseP(iModule,iStrip,noise);
909 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
910 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
915 //______________________________________________________________________
916 void AliITSDetTypeSim::ReadOldSSDBadChannels(TObjArray *array,
917 AliITSBadChannelsSSDv2 *badChannelsSSD) {
918 //Reads the old SSD calibration object and converts it to the new format
919 Int_t fNMod = array->GetEntries();
920 cout<<"Converting old calibration object for bad channels..."<<endl;
921 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
922 //for (Int_t iModule = 0; iModule < 1; iModule++) {
923 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
924 TArrayI arrayPSide = bad->GetBadPChannelsList();
925 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
926 badChannelsSSD->AddBadChannelP(iModule,
928 (Char_t)arrayPSide.At(iPCounter));
930 TArrayI arrayNSide = bad->GetBadNChannelsList();
931 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
932 badChannelsSSD->AddBadChannelN(iModule,
934 (Char_t)arrayNSide.At(iNCounter));
939 //______________________________________________________________________
940 void AliITSDetTypeSim::ReadOldSSDGain(TObjArray *array,
941 AliITSGainSSDv2 *gainSSD) {
942 //Reads the old SSD calibration object and converts it to the new format
944 Int_t fNMod = array->GetEntries();
945 cout<<"Converting old calibration object for gain..."<<endl;
948 for (Int_t iModule = 0; iModule < fNMod; iModule++) {
949 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
950 TArrayF arrayPSide = gainModule->GetGainP();
951 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
952 gainSSD->AddGainP(iModule,
954 arrayPSide.At(iPCounter));
955 TArrayF arrayNSide = gainModule->GetGainN();
956 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
957 gainSSD->AddGainN(iModule,
959 arrayNSide.At(iNCounter));