]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/IceCalibrate.cxx
27-oct-2005 NvE Memberfunction GetX to access individual vector components also intro...
[u/mrichter/AliRoot.git] / RALICE / icepack / IceCalibrate.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 IceCalibrate
20 // TTask derived class to perform the various calibrations.
21 //
22 // This task takes the current event in memory and uses the attached
23 // OM database to access the various calibration functions.
24 // A specific OM database may be attached by means of the SetOMdbase()
25 // or SetCalibFile() memberfunctions.
26 // Further details about the OM database can be found in the docs
27 // of IceCal2Root.
28 //
29 // In the calibration procedure, all event data in memory is scanned and
30 // replaced by calibrated data if a calibration function is present.
31 // When data is succesfully calibrated, the corresponding de-calibration
32 // function is stored in the event data at the appropriate place to allow
33 // access to uncalibrated data as well (see AliSignal::GetSignal for 
34 // further details).
35 // When the input event in memory already contained calibrated data
36 // (i.e. de-calibration functions are present in the event data), the event
37 // data is first de-calibrated (using the corresponding de-calibration functions
38 // contained in the event data) before the new calibration is performed.
39 // In case no corresponding calibration function is present, the calibration
40 // of those specific data will not be performed.
41 // This implies that running this task on calibrated data without having
42 // attached an OM database, will result in fully de-calibrated data. 
43 // In case an OM slot was flagged as bad in the OM database, this flag
44 // will be copied into the event data for the corresponding OM.
45 //
46 //--- Author: Nick van Eijndhoven 18-sep-2005 Utrecht University
47 //- Modified: NvE $Date$ Utrecht University
48 ///////////////////////////////////////////////////////////////////////////
49  
50 #include "IceCalibrate.h"
51 #include "Riostream.h"
52
53 ClassImp(IceCalibrate) // Class implementation to enable ROOT I/O
54
55 IceCalibrate::IceCalibrate(const char* name,const char* title) : TTask(name,title)
56 {
57 // Default constructor.
58  fCalfile=0;
59  fOmdb=0;
60 }
61 ///////////////////////////////////////////////////////////////////////////
62 IceCalibrate::~IceCalibrate()
63 {
64 // Default destructor.
65  if (fCalfile)
66  {
67   delete fCalfile;
68   fCalfile=0;
69  }
70 }
71 ///////////////////////////////////////////////////////////////////////////
72 void IceCalibrate::SetOMdbase(AliObjMatrix* omdb)
73 {
74 // Set the pointer to the OM database.
75 // Note : this will overrule a previously attached database. 
76  fOmdb=omdb;
77 }
78 ///////////////////////////////////////////////////////////////////////////
79 void IceCalibrate::SetCalibFile(TString name)
80 {
81 // Set the calibration ROOT file as created with IceCal2Root.
82 // Note : this will overrule a previously attached database. 
83  fCalfile=new TFile(name.Data());
84  if (fCalfile)
85  {
86   fOmdb=(AliObjMatrix*)fCalfile->Get("Cal-OMDBASE");
87  }
88 }
89 ///////////////////////////////////////////////////////////////////////////
90 void IceCalibrate::Exec(Option_t* opt)
91 {
92 // Implementation of the various calibration procedures.
93
94  TString name=opt;
95  AliJob* parent=(AliJob*)(gROOT->GetListOfTasks()->FindObject(name.Data()));
96
97  if (!parent) return;
98
99  IceEvent* evt=(IceEvent*)parent->GetObject("IceEvent");
100  if (!evt) return;
101
102  IceGOM* ome=0; // The event OM pointer
103  IceGOM* omd=0; // The database OM pointer
104  Int_t id=0;
105  Float_t sig=0;
106  Float_t sigc=0;
107  TF1* fcal=0;
108  TF1* fdecal=0;
109
110  Int_t ndev=evt->GetNdevices();
111  for (Int_t idev=1; idev<=ndev; idev++)
112  {
113   ome=(IceGOM*)evt->GetDevice(idev);
114   if (!ome) continue;
115
116   id=ome->GetUniqueID();
117
118   omd=0;
119   if (fOmdb) omd=(IceGOM*)fOmdb->GetObject(id,1);
120
121   // Set global OM constants
122   if (omd)
123   {
124    ome->SetPosition((Ali3Vector&)omd->GetPosition());
125    for (Int_t isd=4; isd<17; isd++)
126    {
127     ome->SetSignal(omd->GetSignal(isd),isd);
128    }
129   }
130   else
131   {
132    for (Int_t ise=8; ise<17; ise++)
133    {
134     ome->SetSignal(0,ise);
135    }
136    ome->SetSignal(1,8);
137    ome->SetSignal(1,12);
138    ome->SetSignal(1,15);
139   }
140
141   // Make signals of bad modules available
142   ome->SetAlive("ADC");
143   ome->SetAlive("LE");
144   ome->SetAlive("TOT");
145
146   // (De)calibrate all hit signals for this OM
147   for (Int_t ithit=1; ithit<=ome->GetNhits(); ithit++)
148   {
149    AliSignal* sx=ome->GetHit(ithit);
150    if (!sx) continue;
151
152    // ADC (de)calibration
153    sig=sx->GetSignal("ADC",-7); // Get uncalibrated signal
154    fcal=0;
155    fdecal=0;
156    if (omd)
157    {
158     fcal=omd->GetCalFunction("ADC");
159     fdecal=omd->GetDecalFunction("ADC");
160    }
161    if (fcal) // Store calibrated signal
162    {
163     sigc=fcal->Eval(sig);
164     sx->SetSignal(sigc,"ADC");
165     ome->SetCalFunction(0,"ADC");
166     ome->SetDecalFunction(fdecal,"ADC");
167    }
168    else // Store uncalibrated signal
169    {
170     sx->SetSignal(sig,"ADC");
171     ome->SetCalFunction(fcal,"ADC");
172     ome->SetDecalFunction(0,"ADC");
173    }
174
175    // LE (TDC) (de)calibration
176    sig=sx->GetSignal("LE",-7); // Get uncalibrated signal
177    fcal=0;
178    fdecal=0;
179    if (omd)
180    {
181     fcal=omd->GetCalFunction("LE");
182     fdecal=omd->GetDecalFunction("LE");
183    }
184    // Store the ADC independent (de)calibration function in the OM
185    if (fcal)
186    {
187     ome->SetCalFunction(0,"LE");
188     ome->SetDecalFunction(fdecal,"LE");
189    }
190    else
191    {
192     ome->SetCalFunction(fcal,"LE");
193     ome->SetDecalFunction(0,"LE");
194    }
195    // Store the hit-specific ADC dependent (de)calibration function in the hit itself
196    sx->SetCalFunction(fcal,"LE");
197    sx->SetDecalFunction(fdecal,"LE");
198    fcal=sx->GetCalFunction("LE");
199    fdecal=sx->GetDecalFunction("LE");
200    sigc=sx->GetSignal("ADC",-7);
201    if (sigc>0)
202    {
203     if (fcal) fcal->SetParameter(3,sigc);
204     if (fdecal) fdecal->SetParameter(3,sigc);
205    }
206    else
207    {
208     if (fcal) fcal->SetParameter(3,1.e20);
209     if (fdecal) fdecal->SetParameter(3,1.e20);
210    }
211    if (fcal) // Store calibrated signal
212    {
213     sigc=fcal->Eval(sig);
214     sx->SetSignal(sigc,"LE");
215     sx->SetCalFunction(0,"LE");
216     sx->SetDecalFunction(fdecal,"LE");
217    }
218    else // Store uncalibrated signal
219    {
220     sx->SetSignal(sig,"LE");
221     sx->SetCalFunction(fcal,"LE");
222     sx->SetDecalFunction(0,"LE");
223    }
224
225    // TOT (de)calibration
226    sig=sx->GetSignal("TOT",-7); // Get uncalibrated signal
227    fcal=0;
228    fdecal=0;
229    if (omd)
230    {
231     fcal=omd->GetCalFunction("TOT");
232     fdecal=omd->GetDecalFunction("TOT");
233    }
234    if (fcal) // Store calibrated signal
235    {
236     sigc=fcal->Eval(sig);
237     sx->SetSignal(sigc,"TOT");
238     ome->SetCalFunction(0,"TOT");
239     ome->SetDecalFunction(fdecal,"TOT");
240    }
241    else // Store uncalibrated signal
242    {
243     sx->SetSignal(sig,"TOT");
244     ome->SetCalFunction(fcal,"TOT");
245     ome->SetDecalFunction(0,"TOT");
246    }
247   }
248
249   if (omd)
250   {  
251    if (omd->GetDeadValue("ADC")) ome->SetDead("ADC");
252    if (omd->GetDeadValue("LE")) ome->SetDead("LE");
253    if (omd->GetDeadValue("TOT")) ome->SetDead("TOT");
254   }
255  }
256 }
257 ///////////////////////////////////////////////////////////////////////////