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