]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/IceCalibrate.cxx
31-may-2007 NvE Memberfunctions GetNdevices, GetIdDevice and ShowDevices of AliEvent
[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 // Information about the actual parameter settings can be found in the event
47 // structure itself via the device named "IceCalibrate".
48 //
49 //--- Author: Nick van Eijndhoven 18-sep-2005 Utrecht University
50 //- Modified: NvE $Date$ Utrecht University
51 ///////////////////////////////////////////////////////////////////////////
52  
53 #include "IceCalibrate.h"
54 #include "Riostream.h"
55
56 ClassImp(IceCalibrate) // Class implementation to enable ROOT I/O
57
58 IceCalibrate::IceCalibrate(const char* name,const char* title) : TTask(name,title)
59 {
60 // Default constructor.
61  fCalfile=0;
62  fOmdb=0;
63 }
64 ///////////////////////////////////////////////////////////////////////////
65 IceCalibrate::~IceCalibrate()
66 {
67 // Default destructor.
68  if (fCalfile)
69  {
70   delete fCalfile;
71   fCalfile=0;
72  }
73 }
74 ///////////////////////////////////////////////////////////////////////////
75 void IceCalibrate::SetOMdbase(AliObjMatrix* omdb)
76 {
77 // Set the pointer to the OM database.
78 // Note : this will overrule a previously attached database. 
79  fOmdb=omdb;
80 }
81 ///////////////////////////////////////////////////////////////////////////
82 void IceCalibrate::SetCalibFile(TString name)
83 {
84 // Set the calibration ROOT file as created with IceCal2Root.
85 // Note : this will overrule a previously attached database. 
86  fCalfile=new TFile(name.Data());
87 }
88 ///////////////////////////////////////////////////////////////////////////
89 void IceCalibrate::Exec(Option_t* opt)
90 {
91 // Implementation of the various calibration procedures.
92
93  TString name=opt;
94  AliJob* parent=(AliJob*)(gROOT->GetListOfTasks()->FindObject(name.Data()));
95
96  if (!parent) return;
97
98  IceEvent* evt=(IceEvent*)parent->GetObject("IceEvent");
99  if (!evt) return;
100
101  Int_t mudaq=0;
102  Int_t twrdaq=0;
103  AliSignal* daq=(AliSignal*)evt->GetDevice("Daq");
104  mudaq=daq->GetSignal("Muon");
105  twrdaq=daq->GetSignal("TWR");
106
107  if (fCalfile)
108  {
109   if (mudaq)
110   {
111    fOmdb=(AliObjMatrix*)fCalfile->Get("MuDaq-OMDBASE");
112    // Next statement for compatibility with old calibration file format
113    if (!fOmdb) fOmdb=(AliObjMatrix*)fCalfile->Get("Cal-OMDBASE");
114   }
115   if (twrdaq) fOmdb=(AliObjMatrix*)fCalfile->Get("TWRDaq-OMDBASE");
116  }
117
118  // Storage of the used parameters in the IceCalibrate device
119  AliSignal params;
120  params.SetNameTitle("IceCalibrate","IceCalibrate processor parameters");
121  params.SetSlotName("Omdb",1);
122
123  if (fOmdb) params.SetSignal(1,1);
124
125  evt->AddDevice(params);
126
127  // All OMs with a signal
128  TObjArray* mods=evt->GetDevices("IceGOM");
129
130  Int_t nmods=mods->GetEntries();
131  if (!nmods) return;
132
133  IceGOM* ome=0; // The event OM pointer
134  IceGOM* omd=0; // The database OM pointer
135  Int_t id=0;
136  Float_t adc=0,le=0,tot=0;    // Uncalibrated values
137  Float_t cadc=0,cle=0,ctot=0; // Calibrated values
138  TF1* fcal=0;
139  TF1* fdecal=0;
140  TString slotname;
141
142  for (Int_t imod=0; imod<nmods; imod++)
143  {
144   ome=(IceGOM*)mods->At(imod);
145   if (!ome) continue;
146
147   id=ome->GetUniqueID();
148
149   omd=0;
150   if (fOmdb) omd=(IceGOM*)fOmdb->GetObject(id,1);
151
152   // Set global OM constants
153   if (omd)
154   {
155    ome->SetPosition((Ali3Vector&)omd->GetPosition());
156    for (Int_t ind=1; ind<=omd->GetNnames(); ind++)
157    {
158     slotname=omd->GetSlotName(ind);
159     ome->AddNamedSlot(slotname);
160    }
161    for (Int_t isd=1; isd<=omd->GetNvalues(); isd++)
162    {
163     ome->SetSignal(omd->GetSignal(isd),omd->GetSlotName(isd));
164    }
165   }
166
167   // Make signals of bad modules available
168   ome->SetAlive("ADC");
169   ome->SetAlive("LE");
170   ome->SetAlive("TOT");
171
172   // (De)calibrate all hit signals for this OM
173   for (Int_t ithit=1; ithit<=ome->GetNhits(); ithit++)
174   {
175    AliSignal* sx=ome->GetHit(ithit);
176    if (!sx) continue;
177
178    // ADC (de)calibration
179    adc=sx->GetSignal("ADC",-7); // Get uncalibrated signal
180    fcal=0;
181    fdecal=0;
182    if (omd)
183    {
184     fcal=omd->GetCalFunction("ADC");
185     fdecal=omd->GetDecalFunction("ADC");
186    }
187    if (fcal) // Store calibrated signal
188    {
189     cadc=fcal->Eval(adc);
190     sx->SetSignal(cadc,"ADC");
191    }
192    else // Store uncalibrated signal
193    {
194     sx->SetSignal(adc,"ADC");
195    }
196
197    // LE (TDC) (de)calibration
198    le=sx->GetSignal("LE",-7); // Get uncalibrated signal
199    fcal=0;
200    fdecal=0;
201    if (omd)
202    {
203     fcal=omd->GetCalFunction("LE");
204     fdecal=omd->GetDecalFunction("LE");
205    }
206
207    // MuDaq only : Store the hit-specific ADC dependent (de)calibration function in the hit itself
208    if (mudaq)
209    {
210     sx->SetCalFunction(fcal,"LE");
211     sx->SetDecalFunction(fdecal,"LE");
212     fcal=sx->GetCalFunction("LE");
213     fdecal=sx->GetDecalFunction("LE");
214     if (adc>0)
215     {
216      if (fcal) fcal->SetParameter(3,adc);
217      if (fdecal) fdecal->SetParameter(3,adc);
218     }
219     else
220     {
221      if (fcal) fcal->SetParameter(3,1.e20);
222      if (fdecal) fdecal->SetParameter(3,1.e20);
223     }
224    }
225
226    if (fcal) // Store calibrated signal
227    {
228     cle=fcal->Eval(le);
229     sx->SetSignal(cle,"LE");
230     if (mudaq) // MuDaq only
231     {
232      sx->SetCalFunction(0,"LE");
233      sx->SetDecalFunction(fdecal,"LE");
234     }
235    }
236    else // Store uncalibrated signal
237    {
238     sx->SetSignal(le,"LE");
239     if (mudaq) // MuDaq only
240     {
241      sx->SetCalFunction(fcal,"LE");
242      sx->SetDecalFunction(0,"LE");
243     }
244    }
245
246    // TOT (de)calibration
247    tot=sx->GetSignal("TOT",-7); // Get uncalibrated signal
248    fcal=0;
249    fdecal=0;
250    if (omd)
251    {
252     fcal=omd->GetCalFunction("TOT");
253     fdecal=omd->GetDecalFunction("TOT");
254    }
255    if (fcal) // Store calibrated signal
256    {
257     ctot=fcal->Eval(tot);
258     sx->SetSignal(ctot,"TOT");
259    }
260    else // Store uncalibrated signal
261    {
262     sx->SetSignal(tot,"TOT");
263    }
264   } // End of loop over hits of the OM
265
266   // Set bad OM flags according to dbase info
267   if (omd)
268   {  
269    if (omd->GetDeadValue("ADC")) ome->SetDead("ADC");
270    if (omd->GetDeadValue("LE")) ome->SetDead("LE");
271    if (omd->GetDeadValue("TOT")) ome->SetDead("TOT");
272   }
273
274   // Store ADC (de)calibration function in this OM according to dbase info
275   fcal=0;
276   fdecal=0;
277   if (omd)
278   {
279    fcal=omd->GetCalFunction("ADC");
280    fdecal=omd->GetDecalFunction("ADC");
281   }
282   if (fcal) // Calibrated ADC signals were stored
283   {
284    ome->SetCalFunction(0,"ADC");
285    ome->SetDecalFunction(fdecal,"ADC");
286   }
287   else // Uncalibrated ADC signals were stored
288   {
289    ome->SetCalFunction(fcal,"ADC");
290    ome->SetDecalFunction(0,"ADC");
291   }
292
293   // Store LE (de)calibration function in this OM according to dbase info
294   // Note for MuDaq only : This is the ADC independent function.
295   //                       The ADC dependent calibration function is in the hits themselves
296   fcal=0;
297   fdecal=0;
298   if (omd)
299   {
300    fcal=omd->GetCalFunction("LE");
301    fdecal=omd->GetDecalFunction("LE");
302   }
303   if (fcal) // Calibrated LE signals were stored
304   {
305    ome->SetCalFunction(0,"LE");
306    ome->SetDecalFunction(fdecal,"LE");
307   }
308   else // Uncalibrated LE signals were stored
309   {
310    ome->SetCalFunction(fcal,"LE");
311    ome->SetDecalFunction(0,"LE");
312   }
313
314   // Store TOT (de)calibration function in this OM according to dbase info
315   fcal=0;
316   fdecal=0;
317   if (omd)
318   {
319    fcal=omd->GetCalFunction("TOT");
320    fdecal=omd->GetDecalFunction("TOT");
321   }
322   if (fcal) // Calibrated TOT signals were stored
323   {
324    ome->SetCalFunction(0,"TOT");
325    ome->SetDecalFunction(fdecal,"TOT");
326   }
327   else // Uncalibrated TOT signals were stored
328   {
329    ome->SetCalFunction(fcal,"TOT");
330    ome->SetDecalFunction(0,"TOT");
331   }
332  } // End of loop over OM's of the event
333 }
334 ///////////////////////////////////////////////////////////////////////////