1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Conributors 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 **************************************************************************/
20 ////////////////////////////////////////////////////////////////////////
21 // This class defines the "Standard" reconstruction for the ITS //
24 ////////////////////////////////////////////////////////////////////////
25 #include "TObjArray.h"
28 #include "AliCDBManager.h"
29 #include "AliCDBEntry.h"
30 #include "AliITSClusterFinder.h"
31 #include "AliITSClusterFinderV2SPD.h"
32 #include "AliITSClusterFinderV2SDD.h"
33 #include "AliITSClusterFinderV2SSD.h"
34 #include "AliITSDetTypeRec.h"
35 #include "AliITSDDLModuleMapSDD.h"
36 #include "AliITSRecPoint.h"
37 #include "AliITSRecPointContainer.h"
38 #include "AliITSCalibrationSDD.h"
39 #include "AliITSMapSDD.h"
40 #include "AliITSCalibrationSSD.h"
41 #include "AliITSNoiseSSDv2.h"
42 #include "AliITSGainSSDv2.h"
43 #include "AliITSBadChannelsSSDv2.h"
44 #include "AliITSNoiseSSD.h"
45 #include "AliITSGainSSD.h"
46 #include "AliITSBadChannelsSSD.h"
47 #include "AliITSresponseSDD.h"
48 #include "AliITSsegmentationSPD.h"
49 #include "AliITSsegmentationSDD.h"
50 #include "AliITSsegmentationSSD.h"
52 #include "AliITSRawStreamSPD.h"
53 #include "AliITSTriggerConditions.h"
54 #include "AliITSFOSignalsSPD.h"
55 #include "AliRunLoader.h"
56 #include "AliDataLoader.h"
57 #include "AliITSLoader.h"
59 class AliITSDriftSpeedArraySDD;
60 class AliITSCorrMapSDD;
61 class AliITSRecoParam;
63 const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
64 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD = 240;
65 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSDD = 260;
66 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSSD = 1698;
68 ClassImp(AliITSDetTypeRec)
70 //________________________________________________________________
71 AliITSDetTypeRec::AliITSDetTypeRec(): TObject(),
79 fTriggerConditions(0),
89 fFastOrFiredMap(1200){
90 // Standard Constructor
98 fReconstruction = new TObjArray(fgkNdettypes);
99 fDigits = new TObjArray(fgkNdettypes);
100 for(Int_t i=0; i<3; i++){
103 fSSDCalibration=new AliITSCalibrationSSD();
104 fNMod = new Int_t [fgkNdettypes];
105 fNMod[0] = fgkDefaultNModulesSPD;
106 fNMod[1] = fgkDefaultNModulesSDD;
107 fNMod[2] = fgkDefaultNModulesSSD;
108 fRecPoints = new TClonesArray("AliITSRecPoint",3000);
114 //______________________________________________________________________
115 AliITSDetTypeRec::AliITSDetTypeRec(const AliITSDetTypeRec & rec):TObject(rec),
117 fITSgeom(rec.fITSgeom),
118 fReconstruction(rec.fReconstruction),
119 fSegmentation(rec.fSegmentation),
120 fCalibration(rec.fCalibration),
121 fSSDCalibration(rec.fSSDCalibration),
122 fSPDDead(rec.fSPDDead),
123 fTriggerConditions(rec.fTriggerConditions),
124 fDigits(rec.fDigits),
125 fFOSignals(rec.fFOSignals),
126 fDDLMapSDD(rec.fDDLMapSDD),
127 fRespSDD(rec.fRespSDD),
128 fAveGainSDD(rec.fAveGainSDD),
129 fRecPoints(rec.fRecPoints),
130 fNRecPoints(rec.fNRecPoints),
131 fFirstcall(rec.fFirstcall),
132 fLoadOnlySPDCalib(rec.fLoadOnlySPDCalib),
133 fFastOrFiredMap(rec.fFastOrFiredMap){
138 //______________________________________________________________________
139 AliITSDetTypeRec& AliITSDetTypeRec::operator=(const AliITSDetTypeRec& source){
140 // Assignment operator.
141 this->~AliITSDetTypeRec();
142 new(this) AliITSDetTypeRec(source);
147 //_____________________________________________________________________
148 AliITSDetTypeRec::~AliITSDetTypeRec(){
152 fReconstruction->Delete();
153 delete fReconstruction;
157 fSegmentation->Delete();
158 delete fSegmentation;
162 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
163 fCalibration->Delete();
166 if(fRespSDD) delete fRespSDD;
167 if(fDDLMapSDD) delete fDDLMapSDD;
170 if(fSSDCalibration) delete fSSDCalibration;
172 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
178 if(fTriggerConditions){
179 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
180 fTriggerConditions->Delete();
181 delete fTriggerConditions;
182 fTriggerConditions = 0;
191 fRecPoints->Delete();
197 if (fITSgeom) delete fITSgeom;
201 //___________________________________________________________________
202 void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder *clf){
204 //Set reconstruction model for detector type
206 if(fReconstruction==0) fReconstruction = new TObjArray(fgkNdettypes);
207 if(fReconstruction->At(dettype)!=0) delete fReconstruction->At(dettype);
208 fReconstruction->AddAt(clf,dettype);
210 //______________________________________________________________________
211 AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype) const{
213 //Get reconstruction model for detector type
214 if(fReconstruction==0) {
215 Warning("GetReconstructionModel","fReconstruction is 0!");
218 return (AliITSClusterFinder*)fReconstruction->At(dettype);
221 //______________________________________________________________________
222 void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
224 //Set segmentation model for detector type
226 if(fSegmentation==0) fSegmentation = new TObjArray(fgkNdettypes);
227 if(fSegmentation->At(dettype)!=0) delete fSegmentation->At(dettype);
228 fSegmentation->AddAt(seg,dettype);
231 //______________________________________________________________________
232 AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype) const {
234 //Get segmentation model for detector type
236 if(fSegmentation==0) {
237 Warning("GetSegmentationModel","fSegmentation is 0!");
240 return (AliITSsegmentation*)fSegmentation->At(dettype);
243 //_______________________________________________________________________
244 void AliITSDetTypeRec::SetCalibrationModel(Int_t iMod, AliITSCalibration *cal){
246 //Set calibration (response) for the module iMod of type dettype
247 if (fCalibration==0) {
248 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
249 fCalibration->SetOwner(kTRUE);
250 fCalibration->Clear();
253 if (fCalibration->At(iMod) != 0)
254 delete (AliITSCalibration*) fCalibration->At(iMod);
255 fCalibration->AddAt(cal,iMod);
258 //_______________________________________________________________________
259 void AliITSDetTypeRec::SetSPDDeadModel(Int_t iMod, AliITSCalibration *cal){
261 //Set dead pixel info for the SPD module iMod
263 fSPDDead = new TObjArray(fgkDefaultNModulesSPD);
264 fSPDDead->SetOwner(kTRUE);
268 if (fSPDDead->At(iMod) != 0)
269 delete (AliITSCalibration*) fSPDDead->At(iMod);
270 fSPDDead->AddAt(cal,iMod);
272 //_______________________________________________________________________
273 AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod) const {
275 //Get calibration model for module type
277 if(fCalibration==0) {
278 Warning("GetalibrationModel","fCalibration is 0!");
282 if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
283 return (AliITSCalibration*)fCalibration->At(iMod);
285 Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
286 fSSDCalibration->SetModule(i);
287 return (AliITSCalibration*)fSSDCalibration;
291 //_______________________________________________________________________
292 AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod) const {
294 //Get SPD dead for module iMod
297 AliWarning("fSPDDead is 0!");
300 return (AliITSCalibration*)fSPDDead->At(iMod);
302 //_______________________________________________________________________
303 AliITSTriggerConditions* AliITSDetTypeRec::GetTriggerConditions() const {
304 //Get Pixel Trigger Conditions
305 if (fTriggerConditions==0) {
306 AliWarning("fTriggerConditions is 0!");
308 return fTriggerConditions;
310 //______________________________________________________________________
311 void AliITSDetTypeRec::SetTreeAddressD(TTree* const treeD){
312 // Set branch address for the tree of digits.
314 const char *det[4] = {"SPD","SDD","SSD","ITS"};
316 const Char_t* digclass;
321 if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
322 for (i=0; i<fgkNdettypes; i++) {
323 digclass = GetDigitClassName(i);
324 if(!(fDigits->At(i))) {
325 fDigits->AddAt(new TClonesArray(digclass,1000),i);
330 if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
331 else sprintf(branchname,"%sDigits%d",det[3],i+1);
333 branch = treeD->GetBranch(branchname);
334 if (branch) branch->SetAddress(&((*fDigits)[i]));
340 //_______________________________________________________________________
341 TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree* const tree,
342 const char* name, const char *classname,
343 void* address,Int_t size,Int_t splitlevel)
346 // Makes branch in given tree and diverts them to a separate file
352 Error("MakeBranchInTree","Making Branch %s Tree is NULL",name);
355 TBranch *branch = tree->GetBranch(name);
360 branch = tree->Branch(name,classname,address,size,splitlevel);
363 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
369 //____________________________________________________________________
370 void AliITSDetTypeRec::SetDefaults(){
372 //Set defaults for segmentation and response
375 Warning("SetDefaults","null pointer to AliITSgeomGeom !");
379 AliITSsegmentation* seg;
380 if(!GetCalibration()) {AliFatal("Exit");exit(0);}
382 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
384 seg = new AliITSsegmentationSPD();
385 SetSegmentationModel(dettype,seg);
386 SetDigitClassName(dettype,"AliITSdigitSPD");
388 if(fLoadOnlySPDCalib==kFALSE){
390 seg = new AliITSsegmentationSDD();
391 AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
392 if(cal->IsAMAt20MHz()){
393 seg->SetPadSize(seg->Dpz(0),20.);
394 seg->SetNPads(seg->Npz()/2,128);
396 SetSegmentationModel(dettype,seg);
397 SetDigitClassName(dettype,"AliITSdigitSDD");
401 AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD();
402 SetSegmentationModel(dettype,seg2);
403 SetDigitClassName(dettype,"AliITSdigitSSD");
407 //______________________________________________________________________
408 Bool_t AliITSDetTypeRec::GetCalibration() {
409 // Get Default calibration if a storage is not defined.
412 AliITSCalibration* cal = GetCalibrationModel(0);
418 // SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
419 // Int_t run=GetRunNumber();
421 Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
422 if (fCalibration==0) {
423 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
424 fCalibration->SetOwner(!cacheStatus);
425 fCalibration->Clear();
428 Bool_t retCode=GetCalibrationSPD(cacheStatus);
429 if(retCode==kFALSE) return kFALSE;
431 if(fLoadOnlySPDCalib==kFALSE){
432 retCode=GetCalibrationSDD(cacheStatus);
433 if(retCode==kFALSE) return kFALSE;
434 retCode=GetCalibrationSSD(cacheStatus);
435 if(retCode==kFALSE) return kFALSE;
438 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
439 fNMod[0], fNMod[1], fNMod[2]));
442 //______________________________________________________________________
443 Bool_t AliITSDetTypeRec::GetCalibrationSPD(Bool_t cacheStatus) {
444 // Get SPD calibration objects from OCDB
445 // dead pixel are not used for local reconstruction
448 AliCDBEntry *noisySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDNoisy");
449 AliCDBEntry *deadSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
450 AliCDBEntry *pitCond = AliCDBManager::Instance()->Get("TRIGGER/SPD/PITConditions");
451 if(!noisySPD || !deadSPD || !pitCond ){
452 AliFatal("SPD Calibration object retrieval failed! ");
456 TObjArray *calNoisySPD = (TObjArray*) noisySPD->GetObject();
457 if (!cacheStatus) noisySPD->SetObject(NULL);
458 noisySPD->SetOwner(kTRUE);
460 TObjArray *calDeadSPD = (TObjArray*) deadSPD->GetObject();
461 if (!cacheStatus) deadSPD->SetObject(NULL);
462 deadSPD->SetOwner(kTRUE);
464 AliITSTriggerConditions *calPitCond = (AliITSTriggerConditions*) pitCond->GetObject();
465 if (!cacheStatus) pitCond->SetObject(NULL);
466 pitCond->SetOwner(kTRUE);
473 if ((!calNoisySPD) || (!calDeadSPD) || (!calPitCond)){
474 AliWarning("Can not get SPD calibration from calibration database !");
478 fNMod[0] = calNoisySPD->GetEntries();
480 AliITSCalibration* cal;
481 for (Int_t i=0; i<fNMod[0]; i++) {
482 cal = (AliITSCalibration*) calNoisySPD->At(i);
483 SetCalibrationModel(i, cal);
484 cal = (AliITSCalibration*) calDeadSPD->At(i);
485 SetSPDDeadModel(i, cal);
487 fTriggerConditions = calPitCond;
492 //______________________________________________________________________
493 Bool_t AliITSDetTypeRec::GetCalibrationSDD(Bool_t cacheStatus) {
494 // Get SDD calibration objects from OCDB
496 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
497 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD");
498 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD");
499 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
500 // AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
501 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD");
503 if(!entrySDD || !entry2SDD || !drSpSDD || !ddlMapSDD || !mapTSDD ){
504 AliFatal("SDD Calibration object retrieval failed! ");
510 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
511 if(!cacheStatus)entrySDD->SetObject(NULL);
512 entrySDD->SetOwner(kTRUE);
514 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
515 if(!cacheStatus)entry2SDD->SetObject(NULL);
516 entry2SDD->SetOwner(kTRUE);
518 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
519 if(!cacheStatus)drSpSDD->SetObject(NULL);
520 drSpSDD->SetOwner(kTRUE);
522 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
523 if(!cacheStatus)ddlMapSDD->SetObject(NULL);
524 ddlMapSDD->SetOwner(kTRUE);
526 // TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
527 // if(!cacheStatus)mapASDD->SetObject(NULL);
528 // mapASDD->SetOwner(kTRUE);
530 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
531 if(!cacheStatus)mapTSDD->SetObject(NULL);
532 mapTSDD->SetOwner(kTRUE);
535 // DB entries are deleted. In this way metadeta objects are deleted as well
545 if ((!pSDD)||(!calSDD) || (!drSp) || (!ddlsdd) || (!mapT) ){
546 AliWarning("Can not get SDD calibration from calibration database !");
550 fNMod[1] = calSDD->GetEntries();
554 AliITSCalibration* cal;
557 Bool_t oldMapFormat=kFALSE;
558 TObject* objmap=(TObject*)mapT->At(0);
559 TString cname(objmap->ClassName());
560 if(cname.CompareTo("AliITSMapSDD")==0){
562 AliInfo("SDD Maps converted to new format");
564 for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
565 for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
566 Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
567 if(iMod==-1) continue;
568 Int_t i=iMod - fgkDefaultNModulesSPD;
569 cal = (AliITSCalibration*) calSDD->At(i);
572 for(Int_t iAnode=0;iAnode< ((AliITSCalibrationSDD*)cal)->NOfAnodes(); iAnode++){
573 if(((AliITSCalibrationSDD*)cal)->IsBadChannel(iAnode)) continue;
574 avegain+= ((AliITSCalibrationSDD*)cal)->GetChannelGain(iAnode);
577 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
578 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
580 AliITSCorrMapSDD* mt0 = 0;
581 AliITSCorrMapSDD* mt1 = 0;
583 AliITSMapSDD* oldmap0=(AliITSMapSDD*)mapT->At(i0);
584 AliITSMapSDD* oldmap1=(AliITSMapSDD*)mapT->At(i1);
585 mt0=oldmap0->ConvertToNewFormat();
586 mt1=oldmap1->ConvertToNewFormat();
588 mt0=(AliITSCorrMapSDD*)mapT->At(i0);
589 mt1=(AliITSCorrMapSDD*)mapT->At(i1);
591 cal->SetDriftSpeed(0,arr0);
592 cal->SetDriftSpeed(1,arr1);
595 SetCalibrationModel(iMod, cal);
598 if(nGdAnodes) fAveGainSDD=avegain/nGdAnodes;
603 //______________________________________________________________________
604 Bool_t AliITSDetTypeRec::GetCalibrationSSD(Bool_t cacheStatus) {
605 // Get SSD calibration objects from OCDB
606 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
608 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
609 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
610 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
612 if(!entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD){
613 AliFatal("SSD Calibration object retrieval failed! ");
617 TObject *emptyssd = 0; TString ssdobjectname;
618 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
619 emptyssd = (TObject *)entryNoiseSSD->GetObject();
620 ssdobjectname = emptyssd->GetName();
621 if(ssdobjectname=="TObjArray") {
622 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
623 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
625 else if(ssdobjectname=="AliITSNoiseSSDv2")
626 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
627 if(!cacheStatus)entryNoiseSSD->SetObject(NULL);
628 entryNoiseSSD->SetOwner(kTRUE);
630 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
631 emptyssd = (TObject *)entryGainSSD->GetObject();
632 ssdobjectname = emptyssd->GetName();
633 if(ssdobjectname=="Gain") {
634 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
635 ReadOldSSDGain(gainSSDOld, gainSSD);
637 else if(ssdobjectname=="AliITSGainSSDv2")
638 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
639 if(!cacheStatus)entryGainSSD->SetObject(NULL);
640 entryGainSSD->SetOwner(kTRUE);
642 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
643 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
644 ssdobjectname = emptyssd->GetName();
645 if(ssdobjectname=="TObjArray") {
646 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
647 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
649 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
650 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
651 if(!cacheStatus)entryBadChannelsSSD->SetObject(NULL);
652 entryBadChannelsSSD->SetOwner(kTRUE);
654 // DB entries are deleted. In this way metadeta objects are deleted as well
656 delete entryNoiseSSD;
658 delete entryBadChannelsSSD;
661 if ((!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
662 AliWarning("Can not get SSD calibration from calibration database !");
666 fSSDCalibration->SetNoise(noiseSSD);
667 fSSDCalibration->SetGain(gainSSD);
668 fSSDCalibration->SetBadChannels(badChannelsSSD);
669 //fSSDCalibration->FillBadChipMap();
674 //________________________________________________________________
675 void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata){
677 //Set defaults for cluster finder V2
680 Warning("SetDefaults","Null pointer to AliITSgeom !");
684 AliITSClusterFinder *clf;
686 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
689 if(!GetReconstructionModel(dettype)){
690 clf = new AliITSClusterFinderV2SPD(this);
692 if(!rawdata) clf->SetDigits(DigitsAddress(0));
693 SetReconstructionModel(dettype,clf);
699 if(!GetReconstructionModel(dettype)){
700 clf = new AliITSClusterFinderV2SDD(this);
702 if(!rawdata) clf->SetDigits(DigitsAddress(1));
703 SetReconstructionModel(dettype,clf);
710 if(!GetReconstructionModel(dettype)){
711 clf = new AliITSClusterFinderV2SSD(this);
713 if(!rawdata) clf->SetDigits(DigitsAddress(2));
714 SetReconstructionModel(dettype,clf);
721 //______________________________________________________________________
722 void AliITSDetTypeRec::MakeBranch(TTree* tree, Option_t* option){
724 //Creates branches for clusters and recpoints
725 Bool_t cR = (strstr(option,"R")!=0);
726 Bool_t cRF = (strstr(option,"RF")!=0);
730 if(cR) MakeBranchR(tree);
731 if(cRF) MakeBranchRF(tree);
735 //___________________________________________________________________
736 void AliITSDetTypeRec::ResetDigits(){
737 // Reset number of digits and the digits array for the ITS detector.
740 for(Int_t i=0;i<fgkNdettypes;i++){
744 //___________________________________________________________________
745 void AliITSDetTypeRec::ResetDigits(Int_t branch){
746 // Reset number of digits and the digits array for this branch.
748 if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
751 //__________________________________________________________________
752 void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
754 //Creates tree branches for recpoints
756 // cont char *file File name where RecPoints branch is to be written
757 // to. If blank it write the SDigits to the same
758 // file in which the Hits were found.
763 // only one branch for rec points for all detector types
764 Bool_t oFast= (strstr(opt,"Fast")!=0);
766 Char_t detname[10] = "ITS";
770 sprintf(branchname,"%sRecPointsF",detname);
772 sprintf(branchname,"%sRecPoints",detname);
775 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
777 MakeBranchInTree(treeR,branchname,0,&fRecPoints,buffsz,99);
779 //______________________________________________________________________
780 void AliITSDetTypeRec::SetTreeAddressR(TTree* const treeR){
781 // Set branch address for the Reconstructed points Trees.
783 // TTree *treeR Tree containing the RecPoints.
789 Char_t namedet[10]="ITS";
792 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
794 sprintf(branchname,"%sRecPoints",namedet);
795 branch = treeR->GetBranch(branchname);
797 branch->SetAddress(&fRecPoints);
800 sprintf(branchname,"%sRecPointsF",namedet);
801 branch = treeR->GetBranch(branchname);
803 branch->SetAddress(&fRecPoints);
807 //____________________________________________________________________
808 void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
809 // Add a reconstructed space point to the list
811 // const AliITSRecPoint &r RecPoint class to be added to the tree
812 // of reconstructed points TreeR.
818 TClonesArray &lrecp = *fRecPoints;
819 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
822 //______________________________________________________________________
823 void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Int_t optCluFind){
824 // cluster finding and reconstruction of space points
825 // the condition below will disappear when the geom class will be
826 // initialized for all versions - for the moment it is only for v5 !
827 // 7 is the SDD beam test version
829 // TTree *treeD Digits tree
830 // TTree *treeR Clusters tree
831 // Int_t lastentry Offset for module when not all of the modules
833 // Option_t *opt String indicating which ITS sub-detectors should
834 // be processed. If ="All" then all of the ITS
835 // sub detectors are processed.
837 const char *all = strstr(opt,"All");
838 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
841 SetDefaultClusterFindersV2();
842 AliDebug(1,"V2 cluster finder has been selected \n");
844 SetDefaultClusterFindersV2();
845 AliInfo("Cluster Finder Option not implemented, V2 cluster finder will be used \n");
849 // Reset Fast-OR fired map
850 ResetFastOrFiredMap();
852 if (all || det[0]) { // SPD present
853 // Get the FO signals for this event
854 AliRunLoader* runLoader = AliRunLoader::Instance();
855 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
857 AliError("ITS loader is NULL.");
860 fFOSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
861 if(!fFOSignals) AliError("FO signals not retrieved");
867 AliITSClusterFinder *rec = 0;
868 Int_t id,module,first=0;
869 for(module=0;module<GetITSgeom()->GetIndexMax();module++){
870 id = GetITSgeom()->GetModuleType(module);
871 if (!all && !det[id]) continue;
872 if(det[id]) first = GetITSgeom()->GetStartDet(id);
873 rec = (AliITSClusterFinder*)GetReconstructionModel(id);
874 TClonesArray *itsDigits = DigitsAddress(id);
876 AliFatal("The reconstruction class was not instanciated!");
877 ResetDigits(); // MvL: Not sure we neeed this when rereading anyways
879 treeD->GetEvent(lastentry+module);
882 treeD->GetEvent(lastentry+(module-first));
884 Int_t ndigits = itsDigits->GetEntriesFast();
885 if (ndigits>0 || id==0) { // for SPD we always want to call FindRawClusters (to process FO signals)
886 rec->SetDetTypeRec(this);
887 rec->SetDigits(DigitsAddress(id));
888 // rec->SetClusters(ClustersAddress(id));
889 rec->FindRawClusters(module);
895 // Remove PIT in-active chips from Fast-OR fired map
896 if (all || det[0]) { // SPD present
897 RemoveFastOrFiredInActive();
898 // here removing bits which have no associated clusters
899 RemoveFastOrFiredFromDead(GetFiredChipMap(treeR));
902 //______________________________________________________________________
903 void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Option_t *opt){
904 // cluster finding and reconstruction of space points
905 // the condition below will disappear when the geom class will be
906 // initialized for all versions - for the moment it is only for v5 !
907 // 7 is the SDD beam test version
909 // AliRawReader *rawReader Pointer to the raw-data reader
910 // TTree *treeR Clusters tree
915 const char *all = strstr(opt,"All");
916 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
921 TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
922 TBranch *branch = treeR->Branch("ITSRecPoints",&array);
925 TClonesArray** clusters = new TClonesArray*[GetITSgeom()->GetIndexMax()];
926 for (Int_t iModule = 0; iModule < GetITSgeom()->GetIndexMax(); iModule++) {
927 clusters[iModule] = NULL;
930 DigitsToRecPoints(rawReader,clusters,opt);
933 TClonesArray *emptyArray=new TClonesArray("AliITSRecPoint");
934 for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
935 id = GetITSgeom()->GetModuleType(iModule);
936 if (!all && !det[id]) continue;
937 array = clusters[iModule];
939 AliDebug(1,Form("data for module %d missing!",iModule));
942 branch->SetAddress(&array);
944 nClusters+=array->GetEntriesFast();
946 if (array != emptyArray) {
954 Info("DigitsToRecPoints", "total number of found recpoints in ITS: %d\n",
958 //______________________________________________________________________
959 void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TClonesArray** clusters,Option_t *opt){
960 // cluster finding and reconstruction of space points
961 // the condition below will disappear when the geom class will be
962 // initialized for all versions - for the moment it is only for v5 !
963 // 7 is the SDD beam test version
965 // AliRawReader *rawReader Pointer to the raw-data reader
966 // TClonesArray **clusters Clusters Array
971 const char *all = strstr(opt,"All");
972 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
975 // Reset Fast-OR fired map
976 ResetFastOrFiredMap();
978 AliITSClusterFinder *rec = 0;
982 if (!all && !det[id]) continue;
983 rec = (AliITSClusterFinder*)GetReconstructionModel(id);
985 AliFatal("The reconstruction class was not instantiated");
986 rec->SetDetTypeRec(this);
987 rec->RawdataToClusters(rawReader,clusters);
990 // Remove PIT in-active chips from Fast-OR fired map
991 if (all || det[0]) { // SPD present
992 RemoveFastOrFiredInActive();
993 // here removing bits which have no associated clusters
994 if(clusters) RemoveFastOrFiredFromDead(GetFiredChipMap(clusters));
998 //______________________________________________________________________
999 void AliITSDetTypeRec::ReadOldSSDNoise(const TObjArray *array,
1000 AliITSNoiseSSDv2 *noiseSSD) {
1001 //Reads the old SSD calibration object and converts it to the new format
1002 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
1003 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
1005 Int_t gNMod = array->GetEntries();
1006 cout<<"Converting old calibration object for noise..."<<endl;
1009 Double_t noise = 0.0;
1010 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
1011 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
1012 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
1013 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
1014 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
1015 noiseSSD->AddNoiseP(iModule,iStrip,noise);
1016 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
1017 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
1019 }//loop over modules
1022 //______________________________________________________________________
1023 void AliITSDetTypeRec::ReadOldSSDBadChannels(const TObjArray *array,
1024 AliITSBadChannelsSSDv2 *badChannelsSSD) {
1025 //Reads the old SSD calibration object and converts it to the new format
1026 Int_t gNMod = array->GetEntries();
1027 cout<<"Converting old calibration object for bad channels..."<<endl;
1028 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
1029 //for (Int_t iModule = 0; iModule < 1; iModule++) {
1030 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
1031 TArrayI arrayPSide = bad->GetBadPChannelsList();
1032 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
1033 badChannelsSSD->AddBadChannelP(iModule,
1035 (Char_t)arrayPSide.At(iPCounter));
1037 TArrayI arrayNSide = bad->GetBadNChannelsList();
1038 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
1039 badChannelsSSD->AddBadChannelN(iModule,
1041 (Char_t)arrayNSide.At(iNCounter));
1043 }//loop over modules
1046 //______________________________________________________________________
1047 void AliITSDetTypeRec::ReadOldSSDGain(const TObjArray *array,
1048 AliITSGainSSDv2 *gainSSD) {
1049 //Reads the old SSD calibration object and converts it to the new format
1051 Int_t gNMod = array->GetEntries();
1052 cout<<"Converting old calibration object for gain..."<<endl;
1055 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
1056 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
1057 TArrayF arrayPSide = gainModule->GetGainP();
1058 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
1059 gainSSD->AddGainP(iModule,
1061 arrayPSide.At(iPCounter));
1062 TArrayF arrayNSide = gainModule->GetGainN();
1063 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
1064 gainSSD->AddGainN(iModule,
1066 arrayNSide.At(iNCounter));
1067 }//loop over modules
1069 //______________________________________________________________________
1070 void AliITSDetTypeRec::RemoveFastOrFiredInActive() {
1071 // Removes the chips that were in-active in the pixel trigger (from fast-or fired map)
1073 if (fTriggerConditions==NULL) {
1074 AliError("Pixel trigger conditions are missing.");
1080 while (fTriggerConditions->GetNextInActiveChip(eq,hs,chip)) {
1081 UInt_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
1082 fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
1085 //______________________________________________________________________
1086 TBits AliITSDetTypeRec::GetFiredChipMap(TClonesArray **clusters) const {
1089 // TBits of the fired chips
1092 TBits isfiredchip(1200);
1094 AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
1096 AliError("no segmentation model for SPD available, the fired chip map is empty. Exiting");
1101 for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
1102 TClonesArray *array = clusters[imod];
1103 if(!array) continue;
1104 Int_t nCluster = array->GetEntriesFast();
1107 AliITSRecPoint* cluster = (AliITSRecPoint*)array->UncheckedAt(nCluster);
1108 if (cluster->GetLayer()>1)continue;
1109 Float_t local[3]={-1,-1};
1110 local[1]=cluster->GetDetLocalX();
1111 local[0]=cluster->GetDetLocalZ();
1113 Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
1114 Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
1116 segSPD->LocalToDet(0.5,local[0],row,col);
1117 Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
1118 Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
1119 isfiredchip.SetBitNumber(chipkey,kTRUE);
1127 //______________________________________________________________________
1128 TBits AliITSDetTypeRec::GetFiredChipMap(TTree *treeR) const{
1130 // TBits of the fired chips
1132 TBits isfiredchip(1200);
1135 AliError("no treeR. fired chip map stays empty. Exiting.");
1139 AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
1140 TClonesArray *recpoints = rpcont->FetchClusters(0,treeR);
1141 if(!rpcont->GetStatusOK() || !rpcont->IsSPDActive()){
1142 AliError("no clusters. fired chip map stays empty. Exiting.");
1146 AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)GetSegmentationModel(0);
1148 for(Int_t imod =0; imod < fgkDefaultNModulesSPD; imod++){
1149 recpoints = rpcont->UncheckedGetClusters(imod);
1150 Int_t nCluster = recpoints->GetEntriesFast();
1152 // loop over clusters
1154 AliITSRecPoint* cluster = (AliITSRecPoint*)recpoints->UncheckedAt(nCluster);
1155 if (cluster->GetLayer()>1)continue;
1156 Float_t local[3]={-1,-1};
1157 local[1]=cluster->GetDetLocalX();
1158 local[0]=cluster->GetDetLocalZ();
1160 Int_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(imod);
1161 Int_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(imod);
1163 segSPD->LocalToDet(0.5,local[0],row,col);
1164 Int_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(imod,col);
1165 Int_t chipkey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
1166 isfiredchip.SetBitNumber(chipkey,kTRUE);
1172 //______________________________________________________________________
1173 void AliITSDetTypeRec::RemoveFastOrFiredFromDead(TBits firedchipmap){
1175 // resetting of the fast-or bit on cluster basis.
1176 // fast-or bits can be remnant from SPD ideal simulation (no dead channels)
1179 for(Int_t chipKey=0; chipKey<1200; chipKey++){
1180 // FO masked chips have been previously removed
1181 if(!fFastOrFiredMap.TestBitNumber(chipKey)) continue;
1182 if(!firedchipmap.TestBitNumber(chipKey)) {
1183 fFastOrFiredMap.SetBitNumber(chipKey,kFALSE);
1184 AliDebug(2,Form("removing bit in key %i \n ",chipKey));
1189 //______________________________________________________________________
1190 void AliITSDetTypeRec::SetFastOrFiredMapOnline(UInt_t eq, UInt_t hs, UInt_t chip) {
1191 // Set fast-or fired map for this chip
1192 Int_t chipKey = AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(eq,hs,chip);
1193 return SetFastOrFiredMap(chipKey);