1 /*******************************************************************************
2 * Copyright(c) 2003, IceCube Experiment at the South Pole. All rights reserved.
4 * Author: The IceCube RALICE-based Offline Project.
5 * Contributors are mentioned in the code where appropriate.
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 *******************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Conversion of Amanda ascii calibration data into an AliObjMatrix object
21 // containing the complete OM position, calibration, Xtalk etc... database.
22 // In addition a PDG particle database, extended with some specific Amanda
23 // entries, is provided as well.
24 // This class is derived from AliJob providing task-based processing.
25 // The main object in the job environment is an AliObjMatrix* pointer
26 // which contains the OM database.
27 // Note that the data structures are only written out if an outputfile has
28 // been specified via the SetOutputFile memberfunction.
29 // In case no outputfile has been specified, this class provides a facility
30 // to investigate/use the dbase data directly in subsequent (sub)tasks.
32 // The OM database information in the AliObjMatrix has the following structure :
34 // (j,1) : Pointer to OM with identifier "j"
35 // (j,k+1) : Pointer to a TF1* being the probability function for Xtalk
36 // with OM "j" as transmitter and OM "k" as receiver.
38 // The geometry information is directly available from the OM pointer
39 // in the form of its position and data words like "ORIENT" for orientation etc...
40 // Just use the OM memberfunction Data() to obtain a full overview.
42 // Note : Position coordinates are indicated in meters and times are in nanoseconds,
43 // in accordance with the convention used previously for Amanda.
45 // From the OM pointer also the various (de)calibration functions for
46 // ADC, LE and TOT can be obtained as TF1* pointers.
47 // The actual values of the calibration constants are stored as parameters
48 // of these (de)calibration functions and can be investigated via the
49 // usual TF1::Print() or TF1::GetParameter() facilities.
50 // The last two parameters of the Xtalk probability function have no effect
51 // on the evaluated probability value. However, these two parameters provide
52 // the minimum and maximum allowed LE differences between the transmitter
53 // and receiver hits, respectively (as can be seen from the parameter names).
55 // The (de)calibration of signals and/or determination of the Xtalk probability
56 // can be performed via the standard TF1::Eval(x) functionality, where "x"
57 // represents the input argument of the function (e.g. an uncalibrated ADC value).
59 // In general the database is not directly accessed by the user in performing
60 // physics analysis, since all the necessary information is contained in the
61 // event data itself and available via the GetSignal() memberfunction of the hits.
62 // However, specific tasks like e.g. calibration, Xtalk correction,
63 // bad module removal, noise hit removal etc... might need explicit database access.
64 // So, at the end of the example below some functionality is indicated for clarity.
65 // The user may use exactly the same procedures to obtain explicit access to the calibration
66 // functions etc... from the various OMs and/or hits within the actual event data which he/she
69 // The PDG particle database is a standard ROOT TDatabasePDG object
70 // with the following extensions :
80 // fiberlaser 10002100
89 // gSystem->Load("ralice");
90 // gSystem->Load("icepack");
91 // gSystem->Load("iceconvert");
93 // IceCal2Root q("IceCal2Root","Amacalib to IcePack data structure conversion");
95 // // The Amacalib input filename
96 // q.SetAmacalibFile("amacalib_amanda2_2003.txt");
98 // // Output file for the event structures
99 // q.SetOutputFile("calib2003.root");
101 // ///////////////////////////////////////////////////////////////////
102 // // Here the user can specify his/her sub-tasks to be executed
103 // // after the database structures have been filled and before the
104 // // data is written out.
105 // // Sub-tasks (i.e. a user classes derived from TTask) are entered
108 // // MyTask1 task1("task1","Some modifications to specific OMs");
109 // // MyTask2 task2("task2","Removal of specific OMs");
110 // // MyTask3 task3("task3","Add private objects to the output file");
115 // // The sub-tasks will be executed in the order as they are entered.
116 // ///////////////////////////////////////////////////////////////////
118 // // Perform the conversion and execute subtasks (if any)
121 // // Outline of dbase usage for (de)calibration and Xtalk
123 // AliObjMatrix* omdb=q.GetOMdbase();
124 // IceAOM* om=(IceAOM*)omdb->GetObject(9,1); // Pointer to OM 9
125 // om->Data(); // Overview of generic module parameters
126 // TF1* fcal=0; // Calibration function
127 // TF1* fdecal=0; // De-calibration function
128 // fcal=om->GetCalFunction("ADC");
129 // Float_t adc=248; // Uncalibrated ADC
130 // Float_t cadc=0; // Calibrated ADC
131 // if (fcal) cadc=fcal->Eval(adc);
132 // fcal=om->GetCalFunction("TOT");
133 // Float_t tot=1538; // Uncalibrated TOT
134 // Float_t ctot=0; // Calibrated TOT
135 // if (fcal) ctot=fcal->Eval(tot);
136 // fdecal=om->GetDecalFunction("LE");
137 // Float_t le=21697; // Uncalibrated LE
138 // Float_t cle=0; // Calibrated LE
139 // if (fcal) cle=fcal->Eval(le);
141 // // Xtalk probability between (trans) OM 90 and (rec) OM 113
142 // // for a transmitter signal of uncalibrated amplitude "adc".
143 // TF1* fxtalkp=(TF1*)omdb->GetObject(90,113+1);
146 // if (fxtalkp) prob=fxtalkp->Eval(adc);
148 //--- Author: Nick van Eijndhoven 09-aug-2005 Utrecht University
149 //- Modified: NvE $Date$ Utrecht University
150 ///////////////////////////////////////////////////////////////////////////
152 #include "IceCal2Root.h"
153 #include "Rstrstream.h"
155 ClassImp(IceCal2Root) // Class implementation to enable ROOT I/O
157 IceCal2Root::IceCal2Root(const char* name,const char* title) : AliJob(name,title)
159 // Default constructor.
167 ///////////////////////////////////////////////////////////////////////////
168 IceCal2Root::~IceCal2Root()
170 // Default destructor.
184 ///////////////////////////////////////////////////////////////////////////
185 void IceCal2Root::SetAmacalibFile(TString name)
187 // Set the name of the Amacalib input file.
188 fAmacalFileName=name;
190 ///////////////////////////////////////////////////////////////////////////
191 void IceCal2Root::SetOutputFile(TString name)
193 // Set the name of the ROOT output file.
196 ///////////////////////////////////////////////////////////////////////////
197 TDatabasePDG* IceCal2Root::GetPDG()
199 // Provide pointer to the PDG database
202 ///////////////////////////////////////////////////////////////////////////
203 AliObjMatrix* IceCal2Root::GetOMdbase()
205 // Provide pointer to the OM geometry, calib. etc... database
208 ///////////////////////////////////////////////////////////////////////////
209 void IceCal2Root::Exec(Option_t* opt)
211 // Job to convert the ascii database info into the IcePack structure.
215 // 1) This class is derived from AliJob, allowing a task based processing.
216 // After conversion of the ascii dbase data into the IcePack structure,
217 // the processing of all available sub-tasks (if any) is invoked.
218 // This provides a facility to investigate/use the dbase data in
219 // subsequent (sub)tasks processing before the final data structures
221 // 2) The main object in this job environment is an AliObjMatrix* pointer
222 // which contains the OM database.
224 if (fAmacalFileName=="")
226 cout << " *IceCal2Root Exec* No amacalib input file specified." << endl;
231 fInput.open(fAmacalFileName.Data());
235 cout << " *IceCal2Root Exec* Bad input file : " << fAmacalFileName.Data() << endl;
244 if (fRootFileName != "")
246 fOutfile=new TFile(fRootFileName.Data(),"RECREATE","Calibration data in IcePack structure");
249 // The OM database object
256 fOmdb=new AliObjMatrix();
257 fOmdb->SetNameTitle("Cal-OMDBASE","The OM geometry, calib. etc... database");
261 // Create the particle database and extend it with some F2000 specific definitions
262 if (fPdg) delete fPdg;
263 fPdg=new TDatabasePDG();
264 fPdg->SetNameTitle("PDG-DBASE","The extended PDG particle database");
265 Double_t me=fPdg->GetParticle(11)->Mass();
266 fPdg->AddParticle("brems" ,"brems" ,0,1,0,0,"none",10001001,0,0);
267 fPdg->AddParticle("deltae" ,"deltae" ,me,1,0,-3,"Lepton",10001002,0,0);
268 fPdg->AddParticle("pairprod","pairprod",0,1,0,0,"none",10001003,0,0);
269 fPdg->AddParticle("nucl_int","nucl_Int",0,1,0,0,"none",10001004,0,0);
270 fPdg->AddParticle("mu_pair" ,"mu_pair" ,0,1,0,0,"none",10001005,0,0);
271 fPdg->AddParticle("hadrons" ,"hadrons" ,0,1,0,0,"none",10001006,0,0);
272 fPdg->AddParticle("fiberlaser","fiberlaser",0,1,0,0,"none",10002100,0,0);
273 fPdg->AddParticle("n2laser" ,"n2laser" ,0,1,0,0,"none",10002101,0,0);
274 fPdg->AddParticle("yaglaser" ,"yaglaser" ,0,1,0,0,"none",10002201,0,0);
275 fPdg->AddParticle("z_primary","z_primary",0,1,0,0,"none",10003000,0,0);
276 fPdg->AddParticle("a_primary","a_primary",0,1,0,0,"none",10003500,0,0);
278 // Initialise the job working environment
279 SetMainObject(fOmdb);
281 if (fOutfile) AddObject(fOutfile);
283 cout << " ***" << endl;
284 cout << " *** Start processing of job " << GetName() << " ***" << endl;
285 cout << " ***" << endl;
286 cout << " Amacalib input file : " << fAmacalFileName.Data() << endl;
287 if (fOutfile) cout << " ROOT output file : " << fOutfile->GetName() << endl;
293 // Invoke all available sub-tasks (if any)
297 // Write the datastructures to the output file
301 if (fOmdb) fOmdb->Write();
302 if (fPdg) fPdg->Write();
305 // Flush remaining memory resident data to the output file
306 if (fOutfile) fOutfile->Write();
308 ///////////////////////////////////////////////////////////////////////////
309 void IceCal2Root::GetCalibData()
311 // Obtain all the geometry, calibration and Xtalk data.
313 // Prescription of the various (de)calibration functions
314 TF1 fadccal("fadccal","(x-[1])*[0]");
315 TF1 fadcdecal("fadcdecal","(x/[0])+[1]");
316 fadccal.SetParName(0,"BETA-ADC");
317 fadccal.SetParName(1,"PED-ADC");
318 fadcdecal.SetParName(0,"BETA-ADC");
319 fadcdecal.SetParName(1,"PED-ADC");
321 TF1 ftdccal("ftdccal","(x*[0])-[1]-([0]-1.)*32767.-[2]/sqrt([3])");
322 TF1 ftdcdecal("ftdcdecal","(x+([0]-1.)*32767.+[1]+[2]/sqrt([3]))/[0]");
323 ftdccal.SetParName(0,"BETA-TDC");
324 ftdccal.SetParName(1,"T0");
325 ftdccal.SetParName(2,"ALPHA-TDC");
326 ftdccal.SetParName(3,"ADC-SLEW");
327 ftdcdecal.SetParName(0,"BETA-TDC");
328 ftdcdecal.SetParName(1,"T0");
329 ftdcdecal.SetParName(2,"ALPHA-TDC");
330 ftdcdecal.SetParName(3,"ADC-SLEW");
332 TF1 ftotcal("ftotcal","x*[0]");
333 TF1 ftotdecal("ftotdecal","x/[0]");
334 ftotcal.SetParName(0,"BETA-TOT");
335 ftotdecal.SetParName(0,"BETA-TOT");
337 // The cross talk probability function
338 TF1 fxtalkp("fxtalkp","(1.+[2]-[2]+[3]-[3])/(1.+exp(([0]-x)/[1]))");
339 fxtalkp.SetParName(0,"C");
340 fxtalkp.SetParName(1,"B");
341 fxtalkp.SetParName(2,"dLE-min");
342 fxtalkp.SetParName(3,"dLE-max");
344 // The basic OM contents
347 // Slots to hold the various (de)calibration functions
348 om.SetSlotName("ADC",1);
349 om.SetSlotName("LE",2);
350 om.SetSlotName("TOT",3);
351 // Slots with hardware parameters
352 om.SetSlotName("TYPE",4);
353 om.SetSlotName("ORIENT",5);
354 om.SetSlotName("THRESH",6);
355 om.SetSlotName("SENSIT",7);
357 fInput.seekg(0); // Position at beginning of file
358 fInput >> dec; // Make sure all integers starting with 0 are taken in decimal format
361 Int_t jmod,type,serial,string,ix,iy,iz,ori;
365 Double_t pos[3]={0,0,0};
366 Float_t ped,beta,alpha;
370 Float_t c,b,dlemin,dlemax;
376 if (s == "P") // Read the Geom data
378 fInput >> jmod >> type >> serial >> string >> ix >> iy >> iz >> ori;
379 omx=(IceAOM*)fOmdb->GetObject(jmod,1);
383 omx->SetUniqueID(jmod);
384 fOmdb->EnterObject(jmod,1,omx);
386 pos[0]=double(ix)/1000.;
387 pos[1]=double(iy)/1000.;
388 pos[2]=double(iz)/1000.;
389 omx->SetPosition(pos,"car");
391 if (ori==2) costh=-1;
392 omx->SetSignal(type,4);
393 omx->SetSignal(costh,5);
394 omx->SetSignal(thresh,6);
395 omx->SetSignal(sensit,7);
397 else if (s == "T") // Read the Time calibration constants
399 fInput >> jmod >> ped >> beta >> alpha >> pol;
400 omx=(IceAOM*)fOmdb->GetObject(jmod,1);
404 omx->SetUniqueID(jmod);
405 fOmdb->EnterObject(jmod,1,omx);
408 omx->SetCalFunction(&ftdccal,2);
409 omx->SetDecalFunction(&ftdcdecal,2);
410 omx->SetCalFunction(&ftotcal,3);
411 omx->SetDecalFunction(&ftotdecal,3);
413 // Flag time slots of bad OMs as dead and don't provide time (de)calib functions
414 if (ped<-1e5 || beta<=0 || alpha<0)
418 omx->SetCalFunction(0,2);
419 omx->SetDecalFunction(0,2);
420 omx->SetCalFunction(0,3);
421 omx->SetDecalFunction(0,3);
424 fcal=omx->GetCalFunction(2);
425 fdecal=omx->GetDecalFunction(2);
428 fcal->SetParameter(0,beta);
429 fcal->SetParameter(1,ped);
430 fcal->SetParameter(2,alpha);
431 fcal->SetParameter(3,1.e20);
435 fdecal->SetParameter(0,beta);
436 if (!beta) fdecal->SetParameter(0,1);
437 fdecal->SetParameter(1,ped);
438 fdecal->SetParameter(2,alpha);
439 fdecal->SetParameter(3,1.e20);
442 fcal=omx->GetCalFunction(3);
443 fdecal=omx->GetDecalFunction(3);
446 fcal->SetParameter(0,beta);
450 fdecal->SetParameter(0,beta);
453 else if (s == "A") // Read the Amplitude calibration constants
455 fInput >> jmod >> ped >> beta >> totped >> pol;
456 omx=(IceAOM*)fOmdb->GetObject(jmod,1);
460 omx->SetUniqueID(jmod);
461 fOmdb->EnterObject(jmod,1,omx);
464 omx->SetCalFunction(&fadccal,1);
465 omx->SetDecalFunction(&fadcdecal,1);
467 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
468 if (ped<-1e5 || beta<=0)
471 omx->SetCalFunction(0,1);
472 omx->SetDecalFunction(0,1);
477 omx->SetCalFunction(0,3);
478 omx->SetDecalFunction(0,3);
481 fcal=omx->GetCalFunction(1);
482 fdecal=omx->GetDecalFunction(1);
485 fcal->SetParameter(0,beta);
486 fcal->SetParameter(1,ped);
490 fdecal->SetParameter(0,beta);
491 if (!beta) fdecal->SetParameter(0,1);
492 fdecal->SetParameter(1,ped);
495 else if (s == "K") // Read the cross talk probability constants
497 fInput >> jtrans >> jrec >> c >> b >> dlemin >> dlemax;
498 omx=(IceAOM*)fOmdb->GetObject(jtrans,1);
502 omx->SetUniqueID(jtrans);
503 fOmdb->EnterObject(jtrans,1,omx);
506 TF1* fx=new TF1(fxtalkp);
507 fx->SetParameter(0,c);
510 fx->SetParameter(1,b);
514 fx->SetParameter(1,1);
516 fx->SetParameter(2,dlemin);
517 fx->SetParameter(3,dlemax);
518 fOmdb->EnterObject(jtrans,jrec+1,fx);
520 else // Skip this line
522 fInput.ignore(99999,'\n');
526 ///////////////////////////////////////////////////////////////////////////