]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSreconstruction.cxx
10ff47931f7cfef7e37c7da9456cd6bda5a27813
[u/mrichter/AliRoot.git] / ITS / AliITSreconstruction.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15  
16 /* $Id$ */
17
18 #include <TROOT.h>
19 #include <TFile.h>
20 #include <TSeqCollection.h>
21 #include <TString.h>
22 #include <TClonesArray.h>
23
24 #include "AliRun.h"
25 #include "AliRunLoader.h"
26
27 #include "AliITS.h"
28 #include "AliITSDetType.h"
29 #include "AliITSLoader.h"
30 #include "AliITSreconstruction.h"
31 #include "AliITSsegmentationSPD.h"
32 #include "AliITSsegmentationSDD.h"
33 #include "AliITSsegmentationSSD.h"
34 #include "AliITSClusterFinderSPD.h"
35 #include "AliITSClusterFinderSDD.h"
36 #include "AliITSClusterFinderSSD.h"
37 #include "AliITSresponseSDD.h"
38 #include "AliITSgeom.h"
39
40 ClassImp(AliITSreconstruction)
41
42 //______________________________________________________________________
43 AliITSreconstruction::AliITSreconstruction():
44  fInit(kFALSE),
45  fEnt(0),
46  fEnt0(0),
47  fITS(0x0),
48  fDfArp(kFALSE),
49  fLoader(0x0),
50  fRunLoader(0x0)
51 {
52     // Default constructor.
53     // Inputs:
54     //  none.
55     // Outputs:
56     //   none.
57     // Return:
58     //    A zero-ed constructed AliITSreconstruction class.
59     fDet[0] = fDet[1] = fDet[2] = kTRUE;
60 }
61 //______________________________________________________________________
62
63 AliITSreconstruction::AliITSreconstruction(AliRunLoader *rl):
64  fInit(kFALSE),
65  fEnt(0),
66  fEnt0(0),
67  fITS(0x0),
68  fDfArp(kFALSE),
69  fLoader(0x0),
70  fRunLoader(rl)
71 {
72   fDet[0] = fDet[1] = fDet[2] = kTRUE;
73 }
74 //______________________________________________________________________
75 AliITSreconstruction::AliITSreconstruction(const char* filename):
76  fInit(kFALSE),
77  fEnt(0),
78  fEnt0(0),
79  fITS(0x0),
80  fDfArp(kFALSE),
81  fLoader(0x0),
82  fRunLoader(0x0)
83 {
84     // Standard constructor.
85     // Inputs:
86     //  const char* filename    filename containing the digits to be
87     //                          reconstructed. If filename = 0 (nil)
88     //                          then no file is opened but a file is
89     //                          assumed to already be opened. This 
90     //                          already opened file will be used.
91     // Outputs:
92     //   none.
93     // Return:
94     //    A standardly constructed AliITSreconstruction class.
95
96     fDet[0] = fDet[1] = fDet[2] = kTRUE;
97
98     fRunLoader = AliRunLoader::Open(filename);
99     if (fRunLoader == 0x0)
100      {
101        Error("AliITSreconstruction","Can not load the session",filename);
102        return;
103      }
104     fRunLoader->LoadgAlice();
105     gAlice = fRunLoader->GetAliRun();
106
107     if(!gAlice) {
108           Error("AliITSreconstruction","gAlice not found on file. Aborting.");
109           fInit = kFALSE;
110           return;
111       } // end if !gAlice
112
113 }
114 //______________________________________________________________________
115 AliITSreconstruction::~AliITSreconstruction(){
116     //    A destroyed AliITSreconstruction class.
117     delete fRunLoader;
118     fITS      = 0;
119 }
120 //______________________________________________________________________
121 Bool_t AliITSreconstruction::Init(){
122     // Class Initilizer.
123     // Inputs:
124     //  none.
125     // Outputs:
126     //   none.
127     // Return:
128     //    kTRUE if no errors initilizing this class occurse else kFALSE
129     Info("Init","");
130     if (fRunLoader == 0x0)
131      {
132        Error("Init","Run Loader is NULL");
133        return kFALSE;
134      }
135     fRunLoader->LoadgAlice();
136     fRunLoader->LoadHeader();  
137
138     fLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
139     if(!fLoader) {
140       Error("Init","ITS loader not found");
141       fInit = kFALSE;
142     }
143
144     //Int_t retcode;
145     fITS = (AliITS*) gAlice->GetDetector("ITS");
146     if(!fITS){
147       cout << "ITS not found aborting. fITS=" << fITS << endl;
148       fInit = kFALSE;
149       return fInit;
150     } // end if !fITS
151     if(!(fITS->GetITSgeom())){
152       cout << "ITSgeom not found aborting."<< endl;
153       fInit = kFALSE;
154       return fInit;
155     } // end if !GetITSgeom()
156     // Now ready to init.
157
158     fDet[0] = fDet[1] = fDet[2] = kTRUE;
159     fEnt0 = 0;
160
161     fEnt  = gAlice->GetEventsPerRun();
162
163     fLoader->LoadDigits("read");
164     fLoader->LoadRecPoints("recreate");
165     fLoader->LoadRawClusters("recreate");
166     if (fLoader->TreeR() == 0x0) fLoader->MakeTree("R");
167     fITS->MakeBranch("R");
168     fITS->MakeBranchC();
169     fITS->SetTreeAddress();
170     fInit = InitRec();
171
172     Info("Init","  Done\n\n\n");
173
174     return fInit;
175 }
176 //______________________________________________________________________
177 Bool_t AliITSreconstruction::InitRec(){
178     // Sets up Reconstruction part of AliITSDetType..
179     // Inputs:
180     //      none.
181     // Outputs:
182     //      none.
183     // Return:
184     //      none.
185     AliITSDetType *idt;
186
187     // SPD
188     if(fDet[kSPD]){
189       Info("InitRec","SPD");
190       idt = fITS->DetType(kSPD);
191       AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)idt->GetSegmentationModel();
192       TClonesArray *digSPD = fITS->DigitsAddress(kSPD);
193       TClonesArray *recpSPD = fITS->ClustersAddress(kSPD);
194       Info("InitRec","idt = %#x; digSPD = %#x; recpSPD = %#x",idt,digSPD,recpSPD);
195       AliITSClusterFinderSPD *recSPD = new AliITSClusterFinderSPD(segSPD,digSPD,recpSPD);
196       fITS->SetReconstructionModel(kSPD,recSPD);
197     } // end if fDet[kSPD].
198     // SDD
199     if(fDet[kSDD]){
200       Info("InitRec","SDD");
201       idt = fITS->DetType(kSDD);
202       AliITSsegmentationSDD *segSDD = (AliITSsegmentationSDD*)
203                                          idt->GetSegmentationModel();
204       AliITSresponseSDD *resSDD = (AliITSresponseSDD*)
205                                          idt->GetResponseModel();
206       TClonesArray *digSDD = fITS->DigitsAddress(kSDD);
207       TClonesArray *recpSDD = fITS->ClustersAddress(kSDD);
208       AliITSClusterFinderSDD *recSDD =new AliITSClusterFinderSDD(segSDD,
209                                                    resSDD,
210                                                  digSDD,recpSDD);
211       fITS->SetReconstructionModel(kSDD,recSDD);
212     } // end if fDet[kSDD]
213     // SSD
214     if(fDet[kSSD]){
215       Info("InitRec","SSD");
216       idt = fITS->DetType(kSSD);
217       AliITSsegmentationSSD *segSSD = (AliITSsegmentationSSD*)
218                                        idt->GetSegmentationModel();
219       TClonesArray *digSSD = fITS->DigitsAddress(kSSD);
220       AliITSClusterFinderSSD *recSSD =new AliITSClusterFinderSSD(segSSD,
221                                                    digSSD);
222       fITS->SetReconstructionModel(kSSD,recSSD);
223     } // end if fDet[kSSD]
224     Info("InitRec","    Done\n");
225     return kTRUE;
226 }
227 //______________________________________________________________________ 
228 void AliITSreconstruction::Exec(const Option_t *opt){
229     // Main reconstruction function.
230     // Inputs:
231     //      Option_t * opt   list of subdetector to digitize. =0 all.
232     // Outputs:
233     //      none.
234     // Return:
235     //      none.
236     Option_t *lopt;
237     Int_t evnt;
238
239     if(strstr(opt,"All")||strstr(opt,"ALL")||strstr(opt,"ITS")||opt==0){
240       fDet[0] = fDet[1] = fDet[2] = kTRUE;
241       lopt = "All";
242     }else{
243       fDet[0] = fDet[1] = fDet[2] = kFALSE;
244       if(strstr(opt,"SPD")) fDet[kSPD] = kTRUE;
245       if(strstr(opt,"SDD")) fDet[kSDD] = kTRUE;
246       if(strstr(opt,"SSD")) fDet[kSSD] = kTRUE;
247       if(fDet[kSPD] && fDet[kSDD] && fDet[kSSD]) lopt = "All";
248       else lopt = opt;
249     } // end if strstr(opt,...)
250
251     if(!fInit){
252       cout << "Initilization Failed, Can't run Exec." << endl;
253       return;
254     } // end if !fInit
255
256     for(evnt=0;evnt<fEnt;evnt++)
257      {
258       Info("Exec","");
259       Info("Exec","Processing Event %d",evnt);
260       Info("Exec","");
261
262       fRunLoader->GetEvent(evnt);
263       if (fLoader->TreeR() == 0x0) fLoader->MakeTree("R");
264       fITS->MakeBranch("R");
265       if (fLoader->TreeC() == 0x0) fITS->MakeTreeC();
266       fITS->SetTreeAddress();
267       fITS->DigitsToRecPoints(evnt,0,lopt);
268     } // end for evnt
269 }
270 //______________________________________________________________________ 
271 void AliITSreconstruction::SetOutputFile(TString filename){
272   // Set a file name for recpoints. Used only if this file is not the file
273   // containing digits. This obj is deleted by AliRun.
274   Error("SetOutputFile","Use AliLoader::SetRecPointsFileName(TString&)instead");
275 }