]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSFindClustersV2.cxx
Transition to NewIO
[u/mrichter/AliRoot.git] / ITS / AliITSFindClustersV2.cxx
CommitLineData
ab4429d9 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/*
17$Log$
88cb7938 18Revision 1.3.4.2 2002/12/11 10:00:15 hristov
19Merging with v3-09-04 (P.Skowronski)
20
21Revision 1.3.4.1 2002/11/26 16:58:52 hristov
22Merging NewIO with v3-09-04
23
24Revision 1.3 2002/10/14 14:57:00 hristov
25Merging the VirtualMC branch to the main development branch (HEAD)
26
b9d0a01d 27Revision 1.2.2.1 2002/10/14 13:14:08 hristov
28Updating VirtualMC to v3-09-02
29
30Revision 1.2 2002/09/23 13:25:52 hristov
31Typo corrected (HP)
32
357da3b7 33Revision 1.1 2002/09/09 17:36:05 nilsen
34new TTask to replace non-working AliITSFindClusterV2.C macro.
35
ab4429d9 36*/
37#include <TROOT.h>
38#include <TFile.h>
39#include <TTree.h>
40#include <TBranch.h>
41#include <TClonesArray.h>
42#include <TParticle.h>
43
44#include "AliRun.h"
45#include "AliHeader.h"
46
47#include "AliITS.h"
48#include "AliITSRecPoint.h"
49#include "AliITSFindClustersV2.h"
50#include "AliITSclusterV2.h"
51#include "AliITSgeom.h"
52
53ClassImp(AliITSFindClustersV2)
54
55//______________________________________________________________________
56AliITSFindClustersV2::AliITSFindClustersV2(){
57 // Default constructor.
58 // Inputs:
59 // none.
60 // Outputs:
61 // none.
62 // Return:
63 // A zero-ed constructed AliITSFindClustersV2 class.
64
65 fAr = 0;
66 fDeletfAr = kFALSE; // fAr=0 dont't delete it.
67 fGeom = 0;
68 fInFileName = 0;
69 fOutFileName = 0;
70 fIn = 0;
71 fOut = 0;
72 fSlowFast = kFALSE; // slow simulation
73 fInit = kFALSE; // Init failed
74}
75//______________________________________________________________________
76AliITSFindClustersV2::AliITSFindClustersV2(const TString infile,
88cb7938 77 const TString outfile){
ab4429d9 78 // Standard constructor.
79 // Inputs:
80 // const TString infile Input file name where the RecPoints are
81 // to be read from.
82 // const TString outfile Output file where V2 tracking clulsters
83 // are to be written. if =="" writen to the
84 // same file as input.
85 // Outputs:
86 // none.
87 // Return:
88 // A standardly constructed AliITSFindClustersV2 class.
89
90 fAr = 0;
91 fDeletfAr = kFALSE; // fAr=0 dont't delete it.
92 fGeom = 0;
93 fInFileName = 0;
94 fOutFileName = 0;
95 fIn = 0;
96 fOut = 0;
97 fSlowFast = kFALSE; // slow simulation
98 fInit = kFALSE; // Init failed
99
100 fInFileName = new TString(infile);
101 if(outfile.CompareTo("")!=0){
102 fOutFileName = new TString(outfile);
103 } // end if outfile.CompareeTo("")!=0
104
105 if(fOutFileName!=0){
106 fIn = new TFile(fInFileName->Data(),"READ");
107 fOut = new TFile(fOutFileName->Data(),"UPDATE");
108 }else{ // open fIn file for update
109 fIn = new TFile(fInFileName->Data(),"UPDATE");
110 } // end if
111
112 fAr = (AliRun*) fIn->Get("gAlice");
113 if(!fAr){
114 Warning("AliITSFindClusterV2",
115 "Can't fine gAlice in file %s. Aborting.",fIn->GetName());
116 return;
117 } // end if !fAr
118 fDeletfAr = kTRUE; // Since gAlice was read in, delete it.
119
120 AliITS *its = (AliITS*) fAr->GetModule("ITS");
121 if(!its){
122 Warning("AliITSFindClusterV2",
123 "Can't fine the ITS in gAlice. Aborting.");
124 return;
125 } // end if !its
126 fGeom = its->GetITSgeom();
127 if(!fGeom){
128 Warning("AliITSFindClusterV2",
129 "Can't fine the ITS geometry in gAlice. Aborting.");
130 return;
131 } // end if !fGeom
132
133 if(fOut) fOut->cd();
134 fInit = kTRUE;
135}
136//______________________________________________________________________
137AliITSFindClustersV2::AliITSFindClustersV2(TFile *in,
138 TFile *out){
139 // Standard constructor.
140 // Inputs:
141 // const TFile *in Input file where the RecPoints are
142 // to be read from.
143 // const Tfile *out Output file where V2 tracking clulsters
144 // are to be written. if ==0 writen to the
145 // same file as input.
146 // Outputs:
147 // none.
148 // Return:
149 // A standardly constructed AliITSFindClustersV2 class.
150
151 fAr = 0;
152 fDeletfAr = kFALSE; // fAr=0 dont't delete it.
153 fGeom = 0;
154 fInFileName = 0;
155 fOutFileName = 0;
156 fIn = 0;
157 fOut = 0;
158 fSlowFast = kFALSE; // slow simulation
159 fInit = kFALSE; // Init failed
160
161 fIn = in;
162 fOut = out;
163 fAr = (AliRun*) fIn->Get("gAlice");
164 if(!fAr){
165 Warning("AliITSFindClusterV2",
166 "Can't fine gAlice in file %s. Aborting.",fIn->GetName());
167 return;
168 } // end if !fAr
169 fDeletfAr = kTRUE; // Since gAlice was read in, delete it.
170 AliITS *its = (AliITS*) fAr->GetModule("ITS");
171 if(!its){
172 Warning("AliITSFindClusterV2",
173 "Can't fine the ITS in gAlice. Aborting.");
174 return;
175 } // end if !its
176 fGeom = its->GetITSgeom();
177 if(!fGeom){
178 Warning("AliITSFindClusterV2",
179 "Can't fine the ITS geometry in gAlice. Aborting.");
180 return;
181 } // end if !fGeom
182
183 if(fOut) fOut->cd();
184 fInit = kTRUE;
185}
186//______________________________________________________________________
187AliITSFindClustersV2::AliITSFindClustersV2(AliRun *ar,
188 const TString outfile){
189 // Standard constructor.
190 // Inputs:
191 // const TString infile Input file name where the RecPoints are
192 // to be read from.
193 // const TString outfile Output file where V2 tracking clulsters
194 // are to be written. if =="" writen to the
195 // same file as input.
196 // Outputs:
197 // none.
198 // Return:
199 // A standardly constructed AliITSFindClustersV2 class.
200
201 fAr = 0;
202 fDeletfAr = kFALSE; // fAr=0 dont't delete it.
203 fGeom = 0;
204 fInFileName = 0;
205 fOutFileName = 0;
206 fIn = 0;
207 fOut = 0;
208 fSlowFast = kFALSE; // slow simulation
209 fInit = kFALSE; // Init failed
210
211 if(outfile.CompareTo("")!=0){
212 fOutFileName = new TString(outfile);
213 } // end if outfile.CompareeTo("")!=0
214
215 if(fOutFileName!=0){
216 fOut = new TFile(fOutFileName->Data(),"UPDATE");
217 } // end if
218
219 fAr = ar;
220 if(!fAr){
221 Warning("AliITSFindClusterV2",
222 "ar==0. Aborting.");
223 return;
224 } // end if !fAr
225 AliITS *its = (AliITS*) fAr->GetModule("ITS");
226 if(!its){
227 Warning("AliITSFindClusterV2",
228 "Can't fine the ITS in gAlice. Aborting.");
229 return;
230 } // end if !its
231 fGeom = its->GetITSgeom();
232 if(!fGeom){
233 Warning("AliITSFindClusterV2",
234 "Can't fine the ITS geometry in gAlice. Aborting.");
235 return;
236 } // end if !fGeom
237
238 if(fOut) fOut->cd();
239 fInit = kTRUE;
240}
241//______________________________________________________________________
242AliITSFindClustersV2::~AliITSFindClustersV2(){
243 // Default constructor.
244 // Inputs:
245 // none.
246 // Outputs:
247 // none.
248 // Return:
249 // A destroyed AliITSFindclustersV2 class.
250
251 fGeom = 0; // Deleted when AliRun/ITS is deleted.
252 if(fInFileName!=0){ // input file opened by AliITSFindClustersV2
253 if(fIn!=0){
254 if(fIn->IsOpen()) fIn->Close();
255 delete fIn;
256 fIn = 0;
257 } // end if
258 delete fInFileName;
259 fInFileName = 0;
260 } // end if
261
262 if(fOutFileName!=0){ // input file opened by AliITSFindClustersV2
263 if(fOut!=0){
264 if(fOut->IsOpen()) fOut->Close();
265 delete fOut;
266 fOut = 0;
267 } // end if
268 delete fOutFileName;
269 fOutFileName = 0;
270 } // end if
271 if(fDeletfAr && !fAr){
272 cout << "deleting fAr."<< endl;
273 delete fAr;
274 fAr = 0;
275 cout << "fAr deleted OK."<< endl;
276 } // end if fDeletfAr
277}
278//______________________________________________________________________
279void AliITSFindClustersV2::Exec(const Option_t *opt){
280 // Main FindclustersV2 function.
281 // Inputs:
282 // Option_t * opt list of subdetector to digitize. =0 all.
283 // Outputs:
284 // none.
285 // Return:
286 // none.
287 Char_t name[50];
288
289 if(!fInit){
290 Warning("Exec","Initilization not succesfull. Aborting.");
291 return;
292 } // end if !fInit
293
294 fGeom->Write();
295
296 fAr->GetEvent(0);
297 TTree *pTree = fAr->TreeR();
298 if(!pTree){
299 Warning("Exec","Error getting TreeR. TreeR=%p",pTree);
300 return;
301 } // end if !pTree
302 TBranch *branch = 0;
303 if(fSlowFast) sprintf(name,"ITSRecPointsF");
304 else sprintf(name,"ITSRecPoints");
305 branch = pTree->GetBranch(name);
306 if(!branch){
357da3b7 307 Warning("Exec","Can't find branch %s in TreeR fSlowFast=%d",
ab4429d9 308 name,fSlowFast);
309 return;
310 } // end if !branch
311 TClonesArray *points = new TClonesArray("AliITSRecPoint",10000);
312 branch->SetAddress(&points);
313 Int_t nentr = (Int_t) branch->GetEntries();
314
315 if(fOut) fOut->cd();
316 TClonesArray *cluster = new TClonesArray("AliITSclusterV2",10000);
317 sprintf(name,"TreeC_ITS_%d",fAr->GetHeader()->GetEvent());
318 TTree *cTree = new TTree(name,"ITS clusters");
319 cTree->Branch("Clusters",&cluster);
320 TClonesArray &cl = *cluster;
321
322 Float_t lp[5];
323 Int_t lab[6];
324 Int_t i,j,lay,lad,det,nclusters=0,ncl;
325 Float_t kmip,x,y,zshift,yshift;
326 Double_t rot[9];
327 AliITSRecPoint *p;
328 TParticle *part;
329
330 for(i=0;i<nentr;i++){
331 points->Clear();
332 branch->GetEvent(i);
333 ncl = points->GetEntriesFast();
334 if(ncl<=0) {
335 cTree->Fill();
336 continue;
337 } // end if ncl<=0
338 nclusters += ncl;
339 fGeom->GetModuleId(i,lay,lad,det);
340 fGeom->GetTrans(i,x,y,zshift);
341 fGeom->GetRotMatrix(i,rot);
342 yshift = x*rot[0] + y*rot[1];
343 kmip = 1.0; // fGeom->GetModuletype(i)==kSPD
344 if(fGeom->GetModuleType(i)==kSDD) kmip = 280.0;
345 if(fGeom->GetModuleType(i)==kSSD) kmip = 38.0;
346 for(j=0;j<ncl;j++){
347 p = (AliITSRecPoint*)(points->UncheckedAt(j));
348 lp[0] = - (p->GetX() + yshift);
349 if(lay==1) lp[0] = -lp[0];
350 lp[1] = p->GetZ() + zshift;
351 lp[2] = p->GetSigmaX2();
352 lp[3] = p->GetSigmaZ2();
353 lp[4] = p->GetQ()/kmip;
354 lab[0] = p->GetLabel(0);
355 lab[1] = p->GetLabel(1);
356 lab[2] = p->GetLabel(2);
357 lab[3] = i;
358 lad = lab[0];
359 if(lad>=0){
360 part = (TParticle*) fAr->Particle(lad);
361 lad = -3;
362 while(part->P() < 0.005){
363 if(part->GetFirstMother()<0){
364 Warning("Exec","Primary momentum: %e",part->P());
365 break;
366 } // end if part->GetFirstMother()<0
367 lad = part->GetFirstMother();
368 part = (TParticle*) fAr->Particle(lad);
369 } // end while part->P() < 0.005
370 if(lab[1]<0) lab[1] = lad;
371 else if(lab[2]<0) lab[2] = lad;
372 else Warning("Exec","No empty lables!");
373 } // end if lab>=0
374 new(cl[j]) AliITSclusterV2(lab,lp);
375 } // end for j
376 cTree->Fill();
377 cluster->Delete();
378 points->Delete();
379 } // end for i
380 cTree->Write();
381
382 delete cTree;
383 delete cluster;
384 delete points;
385}