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