]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSDetTypeRec.cxx
28e050aa7ecb65cefca961da88c2e4054900a0f9
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeRec.cxx
1 /***************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Conributors 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
20 ////////////////////////////////////////////////////////////////////////
21 // This class defines the "Standard" reconstruction for the ITS       // 
22 // detector.                                                          //
23 //                                                                    //
24 ////////////////////////////////////////////////////////////////////////
25 #include "TObjArray.h"
26 #include "TTree.h"
27
28 #include "AliCDBManager.h"
29 #include "AliCDBStorage.h"
30 #include "AliCDBEntry.h"
31 #include "AliITSClusterFinder.h"
32 #include "AliITSClusterFinderV2.h"
33 #include "AliITSClusterFinderV2SPD.h"
34 #include "AliITSClusterFinderV2SDD.h"
35 #include "AliITSClusterFinderV2SSD.h"
36 #include "AliITSClusterFinderSPD.h"
37 #include "AliITSClusterFinderSDD.h"
38 #include "AliITSClusterFinderSSD.h"
39 #include "AliITSDetTypeRec.h"
40 #include "AliITSgeom.h"
41 #include "AliITSRawCluster.h"
42 #include "AliITSRawClusterSPD.h"
43 #include "AliITSRawClusterSDD.h"
44 #include "AliITSRawClusterSSD.h"
45 #include "AliITSRecPoint.h"
46 #include "AliITSCalibrationSDD.h"
47 #include "AliITSMapSDD.h"
48 #include "AliITSDriftSpeedArraySDD.h"
49 #include "AliITSCalibrationSSD.h"
50 #include "AliITSNoiseSSD.h"
51 #include "AliITSGainSSD.h"
52 #include "AliITSBadChannelsSSD.h"
53 #include "AliITSPedestalSSD.h"
54 #include "AliITSsegmentationSPD.h"
55 #include "AliITSsegmentationSDD.h"
56 #include "AliITSsegmentationSSD.h"
57 #include "AliLog.h"
58
59
60 const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
61 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD =  240;
62 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSDD =  260;
63 const Int_t AliITSDetTypeRec::fgkDefaultNModulesSSD = 1698;
64
65 ClassImp(AliITSDetTypeRec)
66
67 //________________________________________________________________
68 AliITSDetTypeRec::AliITSDetTypeRec(): TObject(),
69 fNMod(0),
70 fITSgeom(0),
71 fReconstruction(0),
72 fSegmentation(0),
73 fCalibration(0),
74 fPreProcess(0),
75 fPostProcess(0),
76 fDigits(0),
77 fDDLMapSDD(0),
78 fNdtype(0),
79 fCtype(0),
80 fNctype(0),
81 fRecPoints(0),
82 fNRecPoints(0),
83 fSelectedVertexer(),
84 fFirstcall(kTRUE){
85     // Standard Constructor
86     // Inputs:
87     //    none.
88     // Outputs:
89     //    none.
90     // Return:
91     //   
92
93   fReconstruction = new TObjArray(fgkNdettypes);
94   fDigits = new TObjArray(fgkNdettypes);
95   for(Int_t i=0; i<3; i++){
96     fClusterClassName[i]=0;
97     fDigClassName[i]=0;
98     fRecPointClassName[i]=0;
99   }
100   fDDLMapSDD=new AliITSDDLModuleMapSDD();
101   fNdtype = new Int_t[fgkNdettypes];
102   fCtype = new TObjArray(fgkNdettypes);
103   fNctype = new Int_t[fgkNdettypes];
104   fNMod = new Int_t [fgkNdettypes];
105   fNMod[0] = fgkDefaultNModulesSPD;
106   fNMod[1] = fgkDefaultNModulesSDD;
107   fNMod[2] = fgkDefaultNModulesSSD;
108   fRecPoints = new TClonesArray("AliITSRecPoint",3000);
109   fNRecPoints = 0;
110   
111   for(Int_t i=0;i<fgkNdettypes;i++){
112     fNdtype[i]=0;
113     fNctype[i]=0;
114   }
115   
116   SelectVertexer(" "); 
117 }
118
119 //______________________________________________________________________
120 AliITSDetTypeRec::AliITSDetTypeRec(const AliITSDetTypeRec & rec):TObject(rec),
121 fNMod(rec.fNMod),
122 fITSgeom(rec.fITSgeom),
123 fReconstruction(rec.fReconstruction),
124 fSegmentation(rec.fSegmentation),
125 fCalibration(rec.fCalibration),
126 fPreProcess(rec.fPreProcess),
127 fPostProcess(rec.fPostProcess),
128 fDigits(rec.fDigits),
129 fDDLMapSDD(rec.fDDLMapSDD),
130 fNdtype(rec.fNdtype),
131 fCtype(rec.fCtype),
132 fNctype(rec.fNctype),
133 fRecPoints(rec.fRecPoints),
134 fNRecPoints(rec.fNRecPoints),
135 fSelectedVertexer(rec.fSelectedVertexer),
136 fFirstcall(rec.fFirstcall)
137 {
138
139   // Copy constructor. 
140
141 }
142 //______________________________________________________________________
143 AliITSDetTypeRec& AliITSDetTypeRec::operator=(const AliITSDetTypeRec& source){
144     // Assignment operator. 
145     this->~AliITSDetTypeRec();
146     new(this) AliITSDetTypeRec(source);
147     return *this;
148
149 }
150
151 //_____________________________________________________________________
152 AliITSDetTypeRec::~AliITSDetTypeRec(){
153   //Destructor
154
155   if(fReconstruction){
156     fReconstruction->Delete();
157     delete fReconstruction;
158     fReconstruction = 0;
159   }
160   if(fSegmentation){
161     fSegmentation->Delete();
162     delete fSegmentation;
163     fSegmentation = 0;
164   }
165   if(fCalibration){
166     if(!(AliCDBManager::Instance()->GetCacheFlag())) {
167       AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSPD()))->GetResponse();    
168       AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSDD()))->GetResponse();
169       AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSSD()))->GetResponse();
170       if(rspd) delete rspd;
171       if(rsdd) delete rsdd;
172       if(rssd) delete rssd;
173       fCalibration->Delete();
174       delete fCalibration;
175       fCalibration = 0;
176     }
177   }
178   if(fPreProcess) delete fPreProcess;
179   if(fPostProcess) delete fPostProcess;
180   if(fDDLMapSDD) delete fDDLMapSDD;
181   if(fDigits){
182     fDigits->Delete();
183     delete fDigits;
184     fDigits=0;
185   }
186   if(fRecPoints){
187     fRecPoints->Delete();
188     delete fRecPoints;
189     fRecPoints=0;
190   }
191   if(fCtype) {
192     fCtype->Delete();
193     delete fCtype;
194     fCtype = 0;
195   }
196   delete [] fNctype;
197   delete [] fNdtype;
198   delete [] fNMod;
199   
200   if (fITSgeom) delete fITSgeom;
201  
202 }
203
204 //___________________________________________________________________
205 void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder *clf){
206
207   //Set reconstruction model for detector type
208
209   if(fReconstruction==0) fReconstruction = new TObjArray(fgkNdettypes);
210   if(fReconstruction->At(dettype)!=0) delete fReconstruction->At(dettype);
211   fReconstruction->AddAt(clf,dettype);
212 }
213 //______________________________________________________________________
214 AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype){
215
216   //Get reconstruction model for detector type
217   if(fReconstruction==0)  {
218     Warning("GetReconstructionModel","fReconstruction is 0!");
219     return 0;     
220   }
221   return (AliITSClusterFinder*)fReconstruction->At(dettype);
222 }
223
224 //______________________________________________________________________
225 void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
226    
227   //Set segmentation model for detector type
228   
229   if(fSegmentation==0) fSegmentation = new TObjArray(fgkNdettypes);
230   if(fSegmentation->At(dettype)!=0) delete fSegmentation->At(dettype);
231   fSegmentation->AddAt(seg,dettype);
232
233 }
234 //______________________________________________________________________
235 AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype){
236
237   //Get segmentation model for detector type
238    
239    if(fSegmentation==0) {
240      Warning("GetSegmentationModel","fSegmentation is 0!");
241      return 0; 
242    } 
243    return (AliITSsegmentation*)fSegmentation->At(dettype);
244
245 }
246 //_______________________________________________________________________
247 void AliITSDetTypeRec::SetCalibrationModel(Int_t iMod, AliITSCalibration *cal){
248
249   //Set calibration (response) for the module iMod of type dettype
250   if (fCalibration==0) {
251     fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
252     fCalibration->SetOwner(kTRUE);
253     fCalibration->Clear();
254   }
255
256   if (fCalibration->At(iMod) != 0)
257     delete (AliITSCalibration*) fCalibration->At(iMod);
258   fCalibration->AddAt(cal,iMod);
259
260 }
261 //_______________________________________________________________________
262 AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod){
263   
264   //Get calibration model for module type
265   
266   if(fCalibration==0) {
267     Warning("GetalibrationModel","fCalibration is 0!");
268     return 0; 
269   }  
270
271   return (AliITSCalibration*)fCalibration->At(iMod);
272 }
273
274 //______________________________________________________________________
275 void AliITSDetTypeRec::SetTreeAddressD(TTree *treeD){
276     // Set branch address for the tree of digits.
277
278     const char *det[4] = {"SPD","SDD","SSD","ITS"};
279     TBranch *branch;
280     Char_t* digclass;
281     Int_t i;
282     char branchname[30];
283
284     if(!treeD) return;
285     if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
286     for (i=0; i<fgkNdettypes; i++) {
287         digclass = GetDigitClassName(i);
288         if(!(fDigits->At(i))) {
289             fDigits->AddAt(new TClonesArray(digclass,1000),i);
290         }else{
291             ResetDigits(i);
292         } 
293         if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
294         else  sprintf(branchname,"%sDigits%d",det[3],i+1);
295         if (fDigits) {
296             branch = treeD->GetBranch(branchname);
297             if (branch) branch->SetAddress(&((*fDigits)[i]));
298         } 
299     } 
300 }
301
302 //_______________________________________________________________________
303 TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree *tree, const char* name, 
304                                        const char *classname, 
305                                        void* address,Int_t size, 
306                                        Int_t splitlevel)
307
308 //
309 // Makes branch in given tree and diverts them to a separate file
310 // 
311 //
312 //
313     
314   if (tree == 0x0) {
315     Error("MakeBranchInTree","Making Branch %s Tree is NULL",name);
316     return 0x0;
317   }
318   TBranch *branch = tree->GetBranch(name);
319   if (branch) {  
320     return branch;
321   }
322   if (classname){
323     branch = tree->Branch(name,classname,address,size,splitlevel);
324   }
325   else {
326     branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
327   }
328   
329   return branch;
330 }
331
332 //____________________________________________________________________
333 void AliITSDetTypeRec::SetDefaults(){
334   
335   //Set defaults for segmentation and response
336
337   if(!GetITSgeom()){
338     Warning("SetDefaults","null pointer to AliITSgeomGeom !");
339     return;
340   }
341
342   AliITSsegmentation* seg;
343   if(!GetCalibration()) {AliFatal("Exit");exit(0);}  
344
345   for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
346     if(dettype==0){
347       seg = new AliITSsegmentationSPD();
348       SetSegmentationModel(dettype,seg);
349       SetDigitClassName(dettype,"AliITSdigitSPD");
350       SetClusterClassName(dettype,"AliITSRawClusterSPD");
351
352     }
353     if(dettype==1){
354       AliITSCalibrationSDD* res=(AliITSCalibrationSDD*) GetCalibrationModel(GetITSgeom()->GetStartSDD()); 
355       seg = new AliITSsegmentationSDD();
356       SetSegmentationModel(dettype,seg);
357       const char *kopt = ((AliITSresponseSDD*)res->GetResponse())->ZeroSuppOption();
358       if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) SetDigitClassName(dettype,"AliITSdigit");
359       else SetDigitClassName(dettype,"AliITSdigitSDD");
360       SetClusterClassName(dettype,"AliITSRawClusterSDD");
361
362     }
363     if(dettype==2){
364       AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD();
365       seg2->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
366       seg2->SetAnglesLay5(0.0075,0.0275); // strip angels rad P and N side.
367       seg2->SetAnglesLay6(0.0275,0.0075); // strip angels rad P and N side.
368       SetSegmentationModel(dettype,seg2);
369       SetDigitClassName(dettype,"AliITSdigitSSD");
370       SetClusterClassName(dettype,"AliITSRawClusterSSD");
371     }
372   }
373   
374 }
375 //______________________________________________________________________
376 Bool_t AliITSDetTypeRec::GetCalibration() {
377   // Get Default calibration if a storage is not defined.
378
379   if(!fFirstcall){
380     AliITSCalibration* cal = GetCalibrationModel(0);
381     if(cal)return kTRUE;
382   }
383   else {
384     fFirstcall = kFALSE;
385   }
386
387   //  SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
388   //  Int_t run=GetRunNumber();
389
390   Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
391   if (fCalibration==0) {
392     fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
393     fCalibration->SetOwner(!cacheStatus);
394     fCalibration->Clear();
395   }
396
397   AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
398   AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
399  
400  //  AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
401     AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
402     AliCDBEntry *entryPedestalSSD = AliCDBManager::Instance()->Get("ITS/Calib/PedestalSSD");
403     AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
404     AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
405
406   AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD");
407   AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD");
408   AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD");
409   AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD");
410   AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
411   AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
412   AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD");
413
414   if(!entrySPD || !entrySDD || !entryNoiseSSD || !entryGainSSD || 
415      !entryPedestalSSD || !entryBadChannelsSSD || 
416      !entry2SPD || !entry2SDD || !entry2SSD || !drSpSDD || !ddlMapSDD || !mapASDD || !mapTSDD){
417     AliFatal("Calibration object retrieval failed! ");
418     return kFALSE;
419   }     
420
421   TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
422   if(!cacheStatus)entrySPD->SetObject(NULL);
423   entrySPD->SetOwner(kTRUE);
424  
425   AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
426   if(!cacheStatus)entry2SPD->SetObject(NULL);
427   entry2SPD->SetOwner(kTRUE);
428     
429   TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
430   if(!cacheStatus)entrySDD->SetObject(NULL);
431   entrySDD->SetOwner(kTRUE);
432  
433   AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
434   if(!cacheStatus)entry2SDD->SetObject(NULL);
435   entry2SDD->SetOwner(kTRUE);
436
437   TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
438   if(!cacheStatus)drSpSDD->SetObject(NULL);
439   drSpSDD->SetOwner(kTRUE);
440
441   AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
442   if(!cacheStatus)ddlMapSDD->SetObject(NULL);
443   ddlMapSDD->SetOwner(kTRUE);
444
445   TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
446   if(!cacheStatus)mapASDD->SetObject(NULL);
447   mapASDD->SetOwner(kTRUE);
448
449   TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
450   if(!cacheStatus)mapTSDD->SetObject(NULL);
451   mapTSDD->SetOwner(kTRUE);
452
453   TObjArray *noiseSSD = (TObjArray *)entryNoiseSSD->GetObject();
454   if(!cacheStatus)entryNoiseSSD->SetObject(NULL);
455   entryNoiseSSD->SetOwner(kTRUE);
456
457   TObjArray *pedestalSSD = (TObjArray *)entryPedestalSSD->GetObject();
458   if(!cacheStatus)entryPedestalSSD->SetObject(NULL);
459   entryPedestalSSD->SetOwner(kTRUE);
460
461   TObjArray *gainSSD = (TObjArray *)entryGainSSD->GetObject();
462   if(!cacheStatus)entryGainSSD->SetObject(NULL);
463   entryGainSSD->SetOwner(kTRUE);
464
465   TObjArray *badchannelsSSD = (TObjArray *)entryBadChannelsSSD->GetObject();
466   if(!cacheStatus)entryBadChannelsSSD->SetObject(NULL);
467   entryBadChannelsSSD->SetOwner(kTRUE);
468
469   AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
470   if(!cacheStatus)entry2SSD->SetObject(NULL);
471   entry2SSD->SetOwner(kTRUE);
472
473   // DB entries are deleted. In this way metadeta objects are deleted as well
474   if(!cacheStatus){
475     delete entrySPD;
476     delete entrySDD;
477     delete entryNoiseSSD;
478     delete entryPedestalSSD;
479     delete entryGainSSD;
480     delete entryBadChannelsSSD;
481     delete entry2SPD;
482     delete entry2SDD;
483     delete entry2SSD;
484     delete mapASDD;
485     delete mapTSDD;
486     delete drSpSDD;
487     delete ddlMapSDD;
488   }
489
490   if ((!pSPD)||(!pSDD)||(!pSSD) || (!calSPD) || (!calSDD) || (!drSp) || (!ddlsdd)
491       || (!mapAn) || (!mapT) || (!noiseSSD)|| (!gainSSD)|| (!badchannelsSSD)) {
492     AliWarning("Can not get calibration from calibration database !");
493     return kFALSE;
494   }
495
496   fNMod[0] = calSPD->GetEntries();
497   fNMod[1] = calSDD->GetEntries();
498   fNMod[2] = noiseSSD->GetEntries();
499   AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
500                fNMod[0], fNMod[1], fNMod[2]));
501   AliITSCalibration* cal;
502   for (Int_t i=0; i<fNMod[0]; i++) {
503     cal = (AliITSCalibration*) calSPD->At(i);
504     cal->SetResponse((AliITSresponse*)pSPD);
505     SetCalibrationModel(i, cal);
506   }
507   for (Int_t i=0; i<fNMod[1]; i++) {
508     cal = (AliITSCalibration*) calSDD->At(i);
509     cal->SetResponse((AliITSresponse*)pSDD);
510     Int_t i0=2*i;
511     Int_t i1=1+2*i;
512     AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
513     AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
514     AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
515     AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
516     AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
517     AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
518     cal->SetDriftSpeed(0,arr0);
519     cal->SetDriftSpeed(1,arr1);
520     cal->SetMapA(0,ma0);
521     cal->SetMapA(1,ma1);
522     cal->SetMapT(0,mt0);
523     cal->SetMapT(1,mt1);
524     fDDLMapSDD->SetDDLMap(ddlsdd);
525     Int_t iMod = i + fNMod[0];
526     SetCalibrationModel(iMod, cal);
527   }
528   for (Int_t i=0; i<fNMod[2]; i++) {
529
530     AliITSCalibrationSSD *calibSSD = new AliITSCalibrationSSD();
531     calibSSD->SetResponse((AliITSresponse*)pSSD);
532     
533     AliITSNoiseSSD *noise = (AliITSNoiseSSD*) (noiseSSD->At(i));
534     calibSSD->SetNoise(noise);
535     AliITSPedestalSSD *pedestal = (AliITSPedestalSSD*) (pedestalSSD->At(i));
536     calibSSD->SetPedestal(pedestal);
537     AliITSGainSSD *gain = (AliITSGainSSD*) (gainSSD->At(i));
538     calibSSD->SetGain(gain);
539     AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (badchannelsSSD->At(i));
540     calibSSD->SetBadChannels(bad);
541
542     Int_t iMod = i + fNMod[0] + fNMod[1];
543     SetCalibrationModel(iMod, calibSSD);
544  }
545
546   return kTRUE;
547 }
548
549
550 //________________________________________________________________
551 void AliITSDetTypeRec::SetDefaultClusterFinders(){
552   
553   //set defaults for standard cluster finder
554
555   if(!GetITSgeom()){
556     Warning("SetDefaults","null pointer to AliITSgeom!");
557     return;
558   }
559
560   AliITSClusterFinder *clf; 
561
562   for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
563     //SPD
564     if(dettype==0){
565       if(!GetReconstructionModel(dettype)){
566         TClonesArray *dig0 = DigitsAddress(0);
567         TClonesArray *rec0 = ClustersAddress(0);
568         clf = new AliITSClusterFinderSPD(this,dig0,rec0);
569         SetReconstructionModel(dettype,clf);
570
571       }
572     }
573    
574     //SDD
575     if(dettype==1){
576       if(!GetReconstructionModel(dettype)){
577         TClonesArray *dig1 = DigitsAddress(1);
578         TClonesArray *rec1 = ClustersAddress(1);
579         clf = new AliITSClusterFinderSDD(this,dig1,rec1);
580         SetReconstructionModel(dettype,clf);
581       }
582
583     }
584     //SSD
585     if(dettype==2){
586       if(!GetReconstructionModel(dettype)){
587         TClonesArray* dig2 = DigitsAddress(2);
588         clf = new AliITSClusterFinderSSD(this,dig2);
589         SetReconstructionModel(dettype,clf);
590       }
591     }
592
593  }
594  
595   
596 }
597
598 //________________________________________________________________
599 void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata){
600
601   //Set defaults for cluster finder V2
602
603   if(!GetITSgeom()){
604     Warning("SetDefaults","Null pointer to AliITSgeom !");
605     return;
606   }
607
608   AliITSClusterFinder *clf; 
609
610   for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
611     //SPD
612     if(dettype==0){
613       if(!GetReconstructionModel(dettype)){
614         clf = new AliITSClusterFinderV2SPD(this);
615         clf->InitGeometry();
616         if(!rawdata) clf->SetDigits(DigitsAddress(0));
617         SetReconstructionModel(dettype,clf);
618
619       }
620     }
621     //SDD
622     if(dettype==1){
623       if(!GetReconstructionModel(dettype)){
624         clf = new AliITSClusterFinderV2SDD(this);
625         clf->InitGeometry();
626         if(!rawdata) clf->SetDigits(DigitsAddress(1));
627         SetReconstructionModel(dettype,clf);
628       }
629
630     }
631
632     //SSD
633     if(dettype==2){
634       if(!GetReconstructionModel(dettype)){
635         clf = new AliITSClusterFinderV2SSD(this);
636         clf->InitGeometry();
637         if(!rawdata) clf->SetDigits(DigitsAddress(2));
638         SetReconstructionModel(dettype,clf);
639       }
640     }
641
642  }
643    
644 }
645 //______________________________________________________________________
646 void AliITSDetTypeRec::MakeBranch(TTree* tree, Option_t* option){
647
648   //Creates branches for clusters and recpoints
649   Bool_t cR = (strstr(option,"R")!=0);
650   Bool_t cRF = (strstr(option,"RF")!=0);
651   
652   if(cRF)cR = kFALSE;
653
654   if(cR) MakeBranchR(tree);
655   if(cRF) MakeBranchRF(tree);
656
657 }
658
659 //___________________________________________________________________
660 void AliITSDetTypeRec::AddCluster(Int_t id, AliITSRawCluster *c){
661
662   // Adds a raw cluster to the list
663   TClonesArray &lc = *((TClonesArray*)fCtype->At(id));  
664   switch(id){
665   case 0:
666     new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
667     break;
668   case 1:
669     new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
670     break;
671   case 2:
672     new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
673     break;
674   } 
675 }
676 //___________________________________________________________________
677 void AliITSDetTypeRec::ResetDigits(){
678   // Reset number of digits and the digits array for the ITS detector.
679   
680   if(!fDigits) return;
681   for(Int_t i=0;i<fgkNdettypes;i++){
682     ResetDigits(i);
683   }
684 }
685 //___________________________________________________________________
686 void AliITSDetTypeRec::ResetDigits(Int_t branch){
687   // Reset number of digits and the digits array for this branch.
688   
689   if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
690   if(fNdtype) fNdtype[branch]=0;
691
692 }
693
694 //__________________________________________________________________
695 void AliITSDetTypeRec::ResetClusters(){
696
697   //Resets number of clusters and the cluster array 
698   for(Int_t i=0;i<fgkNdettypes;i++){
699     ResetClusters(i);
700   }
701 }
702
703 //__________________________________________________________________
704 void AliITSDetTypeRec::ResetClusters(Int_t i){
705
706   //Resets number of clusters and the cluster array for this branch
707
708   if (fCtype->At(i))    ((TClonesArray*)fCtype->At(i))->Clear();
709   if (fNctype)  fNctype[i]=0;
710 }
711 //__________________________________________________________________
712 void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
713
714   //Creates tree branches for recpoints
715   // Inputs:
716   //      cont char *file  File name where RecPoints branch is to be written
717   //                       to. If blank it write the SDigits to the same
718   //                       file in which the Hits were found.
719
720   Int_t buffsz = 4000;
721   char branchname[30];
722
723   // only one branch for rec points for all detector types
724   Bool_t oFast= (strstr(opt,"Fast")!=0);
725   
726   Char_t detname[10] = "ITS";
727  
728   
729   if(oFast){
730     sprintf(branchname,"%sRecPointsF",detname);
731   } else {
732     sprintf(branchname,"%sRecPoints",detname);
733   }
734   
735   if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
736   if (treeR)
737     MakeBranchInTree(treeR,branchname,0,&fRecPoints,buffsz,99);
738 }
739 //______________________________________________________________________
740 void AliITSDetTypeRec::SetTreeAddressR(TTree *treeR){
741     // Set branch address for the Reconstructed points Trees.
742     // Inputs:
743     //      TTree *treeR   Tree containing the RecPoints.
744     // Outputs:
745     //      none.
746     // Return:
747
748     char branchname[30];
749     Char_t namedet[10]="ITS";
750
751     if(!treeR) return;
752     if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
753     TBranch *branch;
754     sprintf(branchname,"%sRecPoints",namedet);
755     branch = treeR->GetBranch(branchname);
756     if (branch) {
757       branch->SetAddress(&fRecPoints);
758     }else {
759       sprintf(branchname,"%sRecPointsF",namedet);
760       branch = treeR->GetBranch(branchname);
761       if (branch) {
762         branch->SetAddress(&fRecPoints);
763       }
764
765     }
766 }
767 //____________________________________________________________________
768 void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
769     // Add a reconstructed space point to the list
770     // Inputs:
771     //      const AliITSRecPoint &r RecPoint class to be added to the tree
772     //                              of reconstructed points TreeR.
773     // Outputs:
774     //      none.
775     // Return:
776     //      none.
777
778     TClonesArray &lrecp = *fRecPoints;
779     new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
780 }
781
782 //______________________________________________________________________
783 void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Bool_t v2){
784   // cluster finding and reconstruction of space points
785   // the condition below will disappear when the geom class will be
786   // initialized for all versions - for the moment it is only for v5 !
787   // 7 is the SDD beam test version
788   // Inputs:
789   //      TTree *treeD     Digits tree
790   //      TTree *treeR     Clusters tree
791   //      Int_t lastentry  Offset for module when not all of the modules
792   //                       are processed.
793   //      Option_t *opt    String indicating which ITS sub-detectors should
794   //                       be processed. If ="All" then all of the ITS
795   //                       sub detectors are processed.
796
797   const char *all = strstr(opt,"All");
798   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
799                         strstr(opt,"SSD")};
800   if(!v2) {
801     SetDefaultClusterFinders();
802     AliInfo("Original cluster finder has been selected\n");
803   }
804   else   { 
805     SetDefaultClusterFindersV2();
806     AliInfo("V2 cluster finder has been selected \n");
807   }
808
809   AliITSClusterFinder *rec     = 0;
810   Int_t id,module,first=0;
811   for(module=0;module<GetITSgeom()->GetIndexMax();module++){
812       id       = GetITSgeom()->GetModuleType(module);
813       if (!all && !det[id]) continue;
814       if(det[id]) first = GetITSgeom()->GetStartDet(id);
815       rec = (AliITSClusterFinder*)GetReconstructionModel(id);
816       TClonesArray *itsDigits  = DigitsAddress(id);
817       if (!rec)
818           AliFatal("The reconstruction class was not instanciated!");
819       ResetDigits();  // MvL: Not sure we neeed this when rereading anyways
820       if (all) {
821           treeD->GetEvent(lastentry+module);
822       }else {
823           treeD->GetEvent(lastentry+(module-first));
824       }
825       Int_t ndigits = itsDigits->GetEntriesFast();
826       if(ndigits>0){
827         rec->SetDetTypeRec(this);
828         rec->SetDigits(DigitsAddress(id));
829         //      rec->SetClusters(ClustersAddress(id));
830         rec->FindRawClusters(module);
831       } // end if
832       treeR->Fill();
833       ResetRecPoints();
834       ResetClusters();
835   } 
836 }
837 //______________________________________________________________________
838 void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Option_t *opt){
839   // cluster finding and reconstruction of space points
840   // the condition below will disappear when the geom class will be
841   // initialized for all versions - for the moment it is only for v5 !
842   // 7 is the SDD beam test version
843   // Inputs:
844   //      AliRawReader *rawReader  Pointer to the raw-data reader
845   //      TTree *treeR             Clusters tree
846   // Outputs:
847   //      none.
848   // Return:
849   //      none.
850   const char *all = strstr(opt,"All");
851   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
852                         strstr(opt,"SSD")};
853   AliITSClusterFinderV2 *rec     = 0;
854   Int_t id=0;
855
856   TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
857   TBranch *branch = treeR->Branch("ITSRecPoints",&array);
858   delete array;
859  
860   TClonesArray** clusters = new TClonesArray*[GetITSgeom()->GetIndexMax()]; 
861   for (Int_t iModule = 0; iModule < GetITSgeom()->GetIndexMax(); iModule++) {
862     clusters[iModule] = NULL;
863   }
864   for(id=0;id<3;id++){
865     if (!all && !det[id]) continue;
866     rec = (AliITSClusterFinderV2*)GetReconstructionModel(id);
867     if (!rec)
868       AliFatal("The reconstruction class was not instanciated");
869     rec->SetDetTypeRec(this);
870     rec->RawdataToClusters(rawReader,clusters);    
871   } 
872   Int_t nClusters =0;
873   TClonesArray *emptyArray=new TClonesArray("AliITSRecPoint");
874   for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
875     id = GetITSgeom()->GetModuleType(iModule);
876     if (!all && !det[id]) continue;
877     array = clusters[iModule];
878     if(!array){
879       AliDebug(1,Form("data for module %d missing!",iModule));
880       array = emptyArray;
881     }
882     branch->SetAddress(&array);
883     treeR->Fill();
884     nClusters+=array->GetEntriesFast();
885
886     if (array != emptyArray) {
887       array->Delete();
888       delete array;
889     }
890   }
891   delete emptyArray;
892
893   delete[] clusters;
894   Info("DigitsToRecPoints", "total number of found recpoints in ITS: %d\n", 
895        nClusters);
896   
897 }
898
899