]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/IceLinefit.cxx
26-sep-2007 NvE AliTrack extended with GetNsignals for a specific signal class.
[u/mrichter/AliRoot.git] / RALICE / icepack / IceLinefit.cxx
1 /*******************************************************************************
2  * Copyright(c) 2003, IceCube Experiment at the South Pole. All rights reserved.
3  *
4  * Author: The IceCube RALICE-based Offline 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.
12  * The authors make no claims about the suitability of this software for
13  * any purpose. It is provided "as is" without express or implied warranty.
14  *******************************************************************************/
15
16 // $Id$
17
18 ///////////////////////////////////////////////////////////////////////////
19 // Class IceLinefit
20 // TTask derived class to perform a linefit track reconstruction.
21 //
22 // In case an event has been rejected by an AliEventSelector (based) processor,
23 // this task (and its sub-tasks) is not executed.
24 //
25 // The procedure is based on the method described in the Amanda publication
26 // in Nuclear Instruments and Methods A524 (2004) 179-180.
27 // To prevent waisting CPU time in trying to reconstruct (high-energy) cascade
28 // events, or to select specifically reconstruction of low multiplicity events,
29 // the user may invoke the memberfunctions SetMaxModA() and SetMinModA.
30 // This allows selection of events for processing with a certain maximum
31 // and/or minimum number of good Amanda OMs firing.
32 // By default the minimum and maximum are set to 0 and 999, respectively,
33 // in the constructor, which implies no multiplicity selection. 
34 // The maximum number of good hits per Amanda OM to be used for the reconstruction
35 // can be specified via the memberfunction SetMaxHitsA().
36 // By default all good hits of each Amanda OM are used but the user may want
37 // to restrict this number to the first n hits of each Amanda OM to account
38 // for possible noise and/or afterpulse signals that are not recognised by the
39 // hit cleaning procedure.
40 //
41 // Information about the actual parameter settings can be found in the event
42 // structure itself via the device named "IceLinefit".
43 //
44 // The reconstructed track is stored in the IceEvent structure with as
45 // default "IceLinefit" as the name of the track.
46 // This track name identifier can be modified by the user via the
47 // SetTrackName() memberfunction. This will allow unique identification
48 // of tracks which are produced when re-processing existing data with
49 // different criteria.
50 // The track 3-momentum is set to the reconstructed velocity, normalised
51 // to 1 GeV. The mass and charge of the track are left 0.
52 // The r0 and t0 can be obtained from the reference point of the track,
53 // whereas the t0 ia also available from the track timestamp .
54 // By default the charge of the produced tracks is set to 0, since
55 // no distinction can be made between positive or negative tracks.
56 // However, the user can define the track charge by invokation
57 // of the memberfunction SetCharge().
58 // This facility may be used to distinguish tracks produced by the
59 // various reconstruction algorithms in a (3D) colour display
60 // (see the class AliHelix for further details).
61 // The value of beta=v/c for the reconstructed velocity is available
62 // from the fitdetails as stored for the reconstructed track. 
63 //
64 // For further details the user is referred to NIM A524 (2004) 169.
65 //
66 // Note : This algorithm works best on data which has been calibrated
67 //        (IceCalibrate), cross talk corrected (IceXtalk) and cleaned
68 //        from noise hits etc. (IceCleanHits).
69 //
70 //--- Author: Nick van Eijndhoven 10-mar-2006 Utrecht University
71 //- Modified: NvE $Date$ Utrecht University
72 ///////////////////////////////////////////////////////////////////////////
73  
74 #include "IceLinefit.h"
75 #include "Riostream.h"
76
77 ClassImp(IceLinefit) // Class implementation to enable ROOT I/O
78
79 IceLinefit::IceLinefit(const char* name,const char* title) : TTask(name,title)
80 {
81 // Default constructor.
82  fMaxmodA=999;
83  fMinmodA=0;
84  fMaxhitsA=0;
85  fTrackname="IceLinefit";
86  fCharge=0;
87 }
88 ///////////////////////////////////////////////////////////////////////////
89 IceLinefit::~IceLinefit()
90 {
91 // Default destructor.
92 }
93 ///////////////////////////////////////////////////////////////////////////
94 void IceLinefit::SetMaxModA(Int_t nmax)
95 {
96 // Set the maximum number of good Amanda modules that may have fired
97 // in order to process this event.
98 // This allows suppression of processing (high-energy) cascade events
99 // with this linefit tracking to prevent waisting cpu time for cases
100 // in which tracking doesn't make sense anyhow.
101 // Furthermore it allows selection of low multiplicity events for processing.
102 // By default the maximum number of Amanda modules is set to 999 in the ctor,
103 // which implies no selection on maximum module multiplicity.
104 // See also the memberfunction SetMinModA().
105  fMaxmodA=nmax;
106 }
107 ///////////////////////////////////////////////////////////////////////////
108 void IceLinefit::SetMinModA(Int_t nmin)
109 {
110 // Set the minimum number of good Amanda modules that must have fired
111 // in order to process this event.
112 // This allows selection of a minimal multiplicity for events to be processed.
113 // By default the minimum number of Amanda modules is set to 0 in the ctor,
114 // which implies no selection on minimum module multiplicity.
115 // See also the memberfunction SetMaxModA().
116  fMinmodA=nmin;
117 }
118 ///////////////////////////////////////////////////////////////////////////
119 void IceLinefit::SetMaxHitsA(Int_t nmax)
120 {
121 // Set the maximum number of good hits per Amanda module to be processed.
122 //
123 // Special values :
124 // nmax = 0 : No maximum limit set; all good hits will be processed
125 //      < 0 : No hits will be processed
126 //
127 // In case the user selects a maximum number of good hits per module, all the
128 // hits of each module will be ordered w.r.t. increasing hit time (LE).
129 // This allows selection of processing e.g. only the first good hits etc...
130 // By default the maximum number of hits per Amanda modules is set to 0 in the ctor,
131 // which implies just processing all good hits without any maximum limit.
132  fMaxhitsA=nmax;
133 }
134 ///////////////////////////////////////////////////////////////////////////
135 void IceLinefit::SetTrackName(TString s)
136 {
137 // Set (alternative) name identifier for the produced first guess tracks.
138 // This allows unique identification of (newly) produced linefit tracks
139 // in case of re-processing of existing data with different criteria.
140 // By default the produced first guess tracks have the name "IceLinefit"
141 // which is set in the constructor of this class.
142  fTrackname=s;
143 }
144 ///////////////////////////////////////////////////////////////////////////
145 void IceLinefit::SetCharge(Float_t charge)
146 {
147 // Set user defined charge for the produced first guess tracks.
148 // This allows identification of these tracks on color displays.
149 // By default the produced first guess tracks have charge=0
150 // which is set in the constructor of this class.
151  fCharge=charge;
152 }
153 ///////////////////////////////////////////////////////////////////////////
154 void IceLinefit::Exec(Option_t* opt)
155 {
156 // Implementation of the linefit reconstruction.
157
158  TString name=opt;
159  AliJob* parent=(AliJob*)(gROOT->GetListOfTasks()->FindObject(name.Data()));
160
161  if (!parent) return;
162
163  IceEvent* evt=(IceEvent*)parent->GetObject("IceEvent");
164  if (!evt) return;
165
166  // Only process accepted events
167  AliDevice* seldev=(AliDevice*)evt->GetDevice("AliEventSelector");
168  if (seldev)
169  {
170   if (seldev->GetSignal("Select") < 0.1) return;
171  }
172
173  // Enter the reco parameters as a device in the event
174  AliSignal params;
175  params.SetNameTitle("IceLinefit","IceLinefit reco parameters");
176  params.SetSlotName("MaxmodA",1);
177  params.SetSlotName("MinmodA",2);
178  params.SetSlotName("MaxhitsA",3);
179
180  params.SetSignal(fMaxmodA,1);
181  params.SetSignal(fMinmodA,2);
182  params.SetSignal(fMaxhitsA,3);
183
184  evt->AddDevice(params);
185
186  if (fMaxhitsA<0) return;
187
188  // Fetch all fired Amanda OMs for this event
189  TObjArray* aoms=evt->GetDevices("IceAOM");
190  if (!aoms) return;
191  Int_t naoms=aoms->GetEntries();
192  if (!naoms) return;
193
194  // Check for the minimum and/or maximum number of good fired Amanda OMs
195  Int_t ngood=0;
196  for (Int_t iom=0; iom<naoms; iom++)
197  {
198   IceGOM* omx=(IceGOM*)aoms->At(iom);
199   if (!omx) continue;
200   if (omx->GetDeadValue("ADC") || omx->GetDeadValue("LE") || omx->GetDeadValue("TOT")) continue;
201   ngood++;
202  } 
203  if (ngood<fMinmodA || ngood>fMaxmodA) return;
204
205  const Float_t c=0.299792; // Light speed in vacuum in meters per ns
206
207  AliSignal* sx=0;
208  Ali3Vector rom,sumr;
209  Ali3Vector rt,sumrt;
210  Float_t thit;
211  Float_t sumt=0,sumt2=0;
212  TObjArray hits;
213  TObjArray* ordered;
214  Int_t nh;
215
216  // Loop over all OMs and hits to determine the linefit parameters.
217  // Also all the used hits are recorded for association with the track.
218  for (Int_t iom=0; iom<naoms; iom++)
219  {
220   IceGOM* omx=(IceGOM*)aoms->At(iom);
221   if (!omx) continue;
222   if (omx->GetDeadValue("LE")) continue;
223   rom=(Ali3Vector)omx->GetPosition();
224   // Use the specified good hits of this OM
225   ordered=0;
226   if (fMaxhitsA>0 && omx->GetNhits()>fMaxhitsA) ordered=omx->SortHits("LE",1,0,7);
227   nh=0;
228   for (Int_t ih=1; ih<=omx->GetNhits(); ih++)
229   {
230    if (ordered)
231    {
232     if (nh>=fMaxhitsA) break;
233     sx=(AliSignal*)ordered->At(ih-1);
234    }
235    else
236    {
237     sx=omx->GetHit(ih);
238    }
239    if (!sx) continue;
240    if (sx->GetDeadValue("ADC") || sx->GetDeadValue("LE") || sx->GetDeadValue("TOT")) continue;
241
242    thit=sx->GetSignal("LE",7);
243    rt=rom*thit;
244    sumr+=rom;
245    sumrt+=rt;
246    sumt+=thit;
247    sumt2+=thit*thit;
248
249    // Record this hit for association with the track
250    hits.Add(sx);
251    nh++;
252   }
253  }
254
255  Int_t nused=hits.GetEntries();
256  if (!nused) return;
257
258  sumr/=float(nused);
259  sumrt/=float(nused);
260  sumt/=float(nused);
261  sumt2/=float(nused);
262
263  Ali3Vector v;
264  Ali3Vector temp;
265  temp=sumr*sumt;
266  v=sumrt-temp;
267  Float_t dum=sumt2-(sumt*sumt);
268  if (dum) v/=dum;
269
270  Float_t beta=v.GetNorm()/c;
271  AliSignal fitstats;
272  fitstats.SetNameTitle("Fitstats","Fit stats for IceLinefit");
273  fitstats.SetSlotName("Beta",1);
274  fitstats.SetSignal(beta,1);
275
276  Ali3Vector r;
277  temp=v*sumt;
278  r=sumr-temp;
279
280  AliTrack t; 
281  t.SetNameTitle(fTrackname.Data(),"IceLinefit linefit track");
282  t.SetCharge(fCharge);
283  evt->AddTrack(t);
284  AliTrack* trk=evt->GetTrack(evt->GetNtracks());
285  if (!trk) return;
286
287  trk->SetId(evt->GetNtracks(1)+1);
288
289  Ali3Vector p;
290  Float_t vec[3];
291  v.GetVector(vec,"sph");
292  vec[0]=1;
293  p.SetVector(vec,"sph");
294
295  AliPosition r0;
296  r0.SetPosition(r);
297  r0.SetTimestamp((AliTimestamp&)*evt);
298  AliTimestamp* t0=r0.GetTimestamp();
299  t0->Add(0,0,(int)sumt);
300
301  trk->Set3Momentum(p);
302  trk->SetReferencePoint(r0);
303  trk->SetTimestamp(*t0);
304  trk->SetFitDetails(fitstats);
305
306  // Link the used hits to the track (and vice versa)
307  for (Int_t i=0; i<nused; i++)
308  {
309   sx=(AliSignal*)hits.At(i);
310   if (sx) sx->AddTrack(*trk);
311  } 
312 }
313 ///////////////////////////////////////////////////////////////////////////