]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/IceCalibrate.cxx
12-sep-2006 NvE Memberfunctions GetNslots and AddNamedSlot introduced and various
[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  // All OMs with a signal
103  TObjArray* mods=evt->GetDevices("IceGOM");
104
105  Int_t nmods=mods->GetEntries();
106  if (!nmods) return;
107
108  IceGOM* ome=0; // The event OM pointer
109  IceGOM* omd=0; // The database OM pointer
110  Int_t id=0;
111  Float_t adc=0,le=0,tot=0;    // Uncalibrated values
112  Float_t cadc=0,cle=0,ctot=0; // Calibrated values
113  TF1* fcal=0;
114  TF1* fdecal=0;
115  TString slotname;
116
117  for (Int_t imod=0; imod<nmods; imod++)
118  {
119   ome=(IceGOM*)mods->At(imod);
120   if (!ome) continue;
121
122   id=ome->GetUniqueID();
123
124   omd=0;
125   if (fOmdb) omd=(IceGOM*)fOmdb->GetObject(id,1);
126
127   // Set global OM constants
128   if (omd)
129   {
130    ome->SetPosition((Ali3Vector&)omd->GetPosition());
131    for (Int_t ind=1; ind<=omd->GetNnames(); ind++)
132    {
133     slotname=omd->GetSlotName(ind);
134     ome->AddNamedSlot(slotname);
135    }
136    for (Int_t isd=1; isd<=omd->GetNvalues(); isd++)
137    {
138     ome->SetSignal(omd->GetSignal(isd),omd->GetSlotName(isd));
139    }
140   }
141
142   // Make signals of bad modules available
143   ome->SetAlive("ADC");
144   ome->SetAlive("LE");
145   ome->SetAlive("TOT");
146
147   // (De)calibrate all hit signals for this OM
148   for (Int_t ithit=1; ithit<=ome->GetNhits(); ithit++)
149   {
150    AliSignal* sx=ome->GetHit(ithit);
151    if (!sx) continue;
152
153    // ADC (de)calibration
154    adc=sx->GetSignal("ADC",-7); // Get uncalibrated signal
155    fcal=0;
156    fdecal=0;
157    if (omd)
158    {
159     fcal=omd->GetCalFunction("ADC");
160     fdecal=omd->GetDecalFunction("ADC");
161    }
162    if (fcal) // Store calibrated signal
163    {
164     cadc=fcal->Eval(adc);
165     sx->SetSignal(cadc,"ADC");
166    }
167    else // Store uncalibrated signal
168    {
169     sx->SetSignal(adc,"ADC");
170    }
171
172    // LE (TDC) (de)calibration
173    le=sx->GetSignal("LE",-7); // Get uncalibrated signal
174    fcal=0;
175    fdecal=0;
176    if (omd)
177    {
178     fcal=omd->GetCalFunction("LE");
179     fdecal=omd->GetDecalFunction("LE");
180    }
181    // Store the hit-specific ADC dependent (de)calibration function in the hit itself
182    sx->SetCalFunction(fcal,"LE");
183    sx->SetDecalFunction(fdecal,"LE");
184    fcal=sx->GetCalFunction("LE");
185    fdecal=sx->GetDecalFunction("LE");
186    if (adc>0)
187    {
188     if (fcal) fcal->SetParameter(3,adc);
189     if (fdecal) fdecal->SetParameter(3,adc);
190    }
191    else
192    {
193     if (fcal) fcal->SetParameter(3,1.e20);
194     if (fdecal) fdecal->SetParameter(3,1.e20);
195    }
196    if (fcal) // Store calibrated signal
197    {
198     cle=fcal->Eval(le);
199     sx->SetSignal(cle,"LE");
200     sx->SetCalFunction(0,"LE");
201     sx->SetDecalFunction(fdecal,"LE");
202    }
203    else // Store uncalibrated signal
204    {
205     sx->SetSignal(le,"LE");
206     sx->SetCalFunction(fcal,"LE");
207     sx->SetDecalFunction(0,"LE");
208    }
209
210    // TOT (de)calibration
211    tot=sx->GetSignal("TOT",-7); // Get uncalibrated signal
212    fcal=0;
213    fdecal=0;
214    if (omd)
215    {
216     fcal=omd->GetCalFunction("TOT");
217     fdecal=omd->GetDecalFunction("TOT");
218    }
219    if (fcal) // Store calibrated signal
220    {
221     ctot=fcal->Eval(tot);
222     sx->SetSignal(ctot,"TOT");
223    }
224    else // Store uncalibrated signal
225    {
226     sx->SetSignal(tot,"TOT");
227    }
228   } // End of loop over hits of the OM
229
230   // Set bad OM flags according to dbase info
231   if (omd)
232   {  
233    if (omd->GetDeadValue("ADC")) ome->SetDead("ADC");
234    if (omd->GetDeadValue("LE")) ome->SetDead("LE");
235    if (omd->GetDeadValue("TOT")) ome->SetDead("TOT");
236   }
237
238   // Store ADC (de)calibration function in this OM according to dbase info
239   fcal=0;
240   fdecal=0;
241   if (omd)
242   {
243    fcal=omd->GetCalFunction("ADC");
244    fdecal=omd->GetDecalFunction("ADC");
245   }
246   if (fcal) // Calibrated ADC signals were stored
247   {
248    ome->SetCalFunction(0,"ADC");
249    ome->SetDecalFunction(fdecal,"ADC");
250   }
251   else // Uncalibrated ADC signals were stored
252   {
253    ome->SetCalFunction(fcal,"ADC");
254    ome->SetDecalFunction(0,"ADC");
255   }
256
257   // Store ADC independent LE (de)calibration function in this OM according to dbase info
258   fcal=0;
259   fdecal=0;
260   if (omd)
261   {
262    fcal=omd->GetCalFunction("LE");
263    fdecal=omd->GetDecalFunction("LE");
264   }
265   if (fcal) // Calibrated LE signals were stored
266   {
267    ome->SetCalFunction(0,"LE");
268    ome->SetDecalFunction(fdecal,"LE");
269   }
270   else // Uncalibrated LE signals were stored
271   {
272    ome->SetCalFunction(fcal,"LE");
273    ome->SetDecalFunction(0,"LE");
274   }
275
276   // Store TOT (de)calibration function in this OM according to dbase info
277   fcal=0;
278   fdecal=0;
279   if (omd)
280   {
281    fcal=omd->GetCalFunction("TOT");
282    fdecal=omd->GetDecalFunction("TOT");
283   }
284   if (fcal) // Calibrated TOT signals were stored
285   {
286    ome->SetCalFunction(0,"TOT");
287    ome->SetDecalFunction(fdecal,"TOT");
288   }
289   else // Uncalibrated TOT signals were stored
290   {
291    ome->SetCalFunction(fcal,"TOT");
292    ome->SetDecalFunction(0,"TOT");
293   }
294  } // End of loop over OM's of the event
295 }
296 ///////////////////////////////////////////////////////////////////////////