]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFAlignment.cxx
Add protection against failed retrieval of the CDB cal object
[u/mrichter/AliRoot.git] / TOF / AliTOFAlignment.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line 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. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14 ***************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.11  2006/09/19 14:31:26  cvetan
19 Bugfixes and clean-up of alignment object classes. Introduction of so called symbolic names used to identify the alignable volumes (Raffaele and Cvetan)
20
21 Revision 1.10  2006/08/22 13:26:05  arcelli
22 removal of effective c++ warnings (C.Zampolli)
23
24 Revision 1.9  2006/08/10 14:46:54  decaro
25 TOF raw data format: updated version
26
27 Revision 1.8  2006/05/04 19:41:42  hristov
28 Possibility for partial TOF geometry (S.Arcelli)
29
30 Revision 1.7  2006/04/27 13:13:29  hristov
31 Moving the destructor to the implementation file
32
33 Revision 1.6  2006/04/20 22:30:49  hristov
34 Coding conventions (Annalisa)
35
36 Revision 1.5  2006/04/16 22:29:05  hristov
37 Coding conventions (Annalisa)
38
39 Revision 1.4  2006/04/05 08:35:38  hristov
40 Coding conventions (S.Arcelli, C.Zampolli)
41
42 Revision 1.3  2006/03/31 13:49:07  arcelli
43 Removing some junk printout
44
45 Revision 1.2  2006/03/31 11:26:30  arcelli
46  changing CDB Ids according to standard convention
47
48 Revision 1.1  2006/03/28 14:54:48  arcelli
49 class for TOF alignment
50
51 author: Silvia Arcelli, arcelli@bo.infn.it
52 */  
53
54 /////////////////////////////////////////////////////////
55 //                                                     //
56 //            Class for alignment procedure            //
57 //                                                     //
58 //                                                     //
59 //                                                     //
60 /////////////////////////////////////////////////////////
61
62 #include <Rtypes.h>
63
64 #include "TRandom.h"
65
66 #include "AliLog.h"
67 #include "AliAlignObj.h"
68 #include "AliAlignObjAngles.h"
69 #include "AliCDBManager.h"
70 #include "AliCDBMetaData.h"
71 #include "AliCDBId.h"
72 #include "AliCDBEntry.h"
73 #include "AliTOFAlignment.h"
74
75 ClassImp(AliTOFAlignment)
76
77 //_____________________________________________________________________________
78 AliTOFAlignment::AliTOFAlignment():
79   TTask("AliTOFAlignment",""),
80   fNTOFAlignObj(0),
81   fTOFAlignObjArray(0x0)
82  { 
83   //AliTOFalignment main Ctor
84
85 }
86 //_____________________________________________________________________________
87 AliTOFAlignment::AliTOFAlignment(const AliTOFAlignment &t):
88   TTask("AliTOFAlignment",""),
89   fNTOFAlignObj(0),
90   fTOFAlignObjArray(0x0)
91
92   //AliTOFAlignment copy Ctor
93
94   fNTOFAlignObj=t.fNTOFAlignObj;
95   fTOFAlignObjArray=t.fTOFAlignObjArray;
96
97 }
98
99 //_____________________________________________________________________________
100 AliTOFAlignment& AliTOFAlignment::operator=(const AliTOFAlignment &t){ 
101   //AliTOFAlignment assignment operator
102
103   this->fNTOFAlignObj=t.fNTOFAlignObj;
104   this->fTOFAlignObjArray=t.fTOFAlignObjArray;
105   return *this;
106
107 }
108
109 //_____________________________________________________________________________
110 AliTOFAlignment::~AliTOFAlignment() {delete fTOFAlignObjArray;}
111
112 //_____________________________________________________________________________
113 void AliTOFAlignment::Smear( Float_t *tr, Float_t *rot)
114 {
115   //Introduce Random Offset/Tilts
116   fTOFAlignObjArray = new TObjArray(kMaxAlignObj);
117   Float_t dx, dy, dz;  // shifts
118   Float_t dpsi, dtheta, dphi; // angular displacements
119   TRandom *rnd   = new TRandom(1567);
120  
121   Int_t nSMTOF = 18;
122   AliAlignObj::ELayerID iLayer = AliAlignObj::kInvalidLayer;
123   UShort_t iIndex=0; //dummy volume index
124   //  AliAlignObj::ELayerID iLayer = AliAlignObj::kTOF;
125   //  Int_t iIndex=1; //dummy volume index
126   UShort_t dvoluid = AliAlignObj::LayerToVolUID(iLayer,iIndex); //dummy volume identity 
127   Int_t i;
128   for (i = 0; i<nSMTOF ; i++) {
129     Char_t  path[100];
130     sprintf(path,"/ALIC_1/B077_1/BSEGMO%i_1/BTOF%i_1",i,i);
131
132     dx = (rnd->Gaus(0.,1.))*tr[0];
133     dy = (rnd->Gaus(0.,1.))*tr[1];
134     dz = (rnd->Gaus(0.,1.))*tr[2];
135     dpsi   = rot[0];
136     dtheta = rot[1];
137     dphi   = rot[2];
138     AliAlignObjAngles *o =new AliAlignObjAngles(path, dvoluid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
139     fTOFAlignObjArray->Add(o);
140   }
141
142   fNTOFAlignObj=fTOFAlignObjArray->GetEntries();
143   AliInfo(Form("Number of Alignable Volumes: %d",fNTOFAlignObj));
144   delete rnd;
145 }
146
147 //_____________________________________________________________________________
148 void AliTOFAlignment::Align( Float_t *tr, Float_t *rot)
149 {
150   //Introduce Offset/Tilts
151
152   fTOFAlignObjArray = new TObjArray(kMaxAlignObj);
153   Float_t dx, dy, dz;  // shifts
154   Float_t dpsi, dtheta, dphi; // angular displacements
155
156
157   Int_t nSMTOF = 18;
158   AliAlignObj::ELayerID iLayer = AliAlignObj::kInvalidLayer;
159   UShort_t iIndex=0; //dummy volume index
160   //  AliAlignObj::ELayerID iLayer = AliAlignObj::kTOF;
161   //  Int_t iIndex=1; //dummy volume index
162   UShort_t dvoluid = AliAlignObj::LayerToVolUID(iLayer,iIndex); //dummy volume identity 
163   Int_t i;
164   for (i = 0; i<nSMTOF ; i++) {
165
166     Char_t  path[100];
167     sprintf(path,"/ALIC_1/B077_1/BSEGMO%i_1/BTOF%i_1",i,i);
168     dx = tr[0];
169     dy = tr[1];
170     dz = tr[2];
171     dpsi   = rot[0];
172     dtheta = rot[1];
173     dphi   = rot[2];
174     
175     AliAlignObjAngles *o =new AliAlignObjAngles(path, dvoluid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE);
176     fTOFAlignObjArray->Add(o);
177   }
178   fNTOFAlignObj=fTOFAlignObjArray->GetEntries();
179   AliInfo(Form("Number of Alignable Volumes: %d",fNTOFAlignObj));
180 }
181 //_____________________________________________________________________________
182 void AliTOFAlignment::WriteParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
183 {
184   //Write Align Par on CDB
185   AliCDBManager *man = AliCDBManager::Instance();
186   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
187   Char_t *sel1 = "AlignPar" ;
188   Char_t  out[100];
189   sprintf(out,"%s/%s",sel,sel1); 
190   AliCDBId idTOFAlign(out,minrun,maxrun);
191   AliCDBMetaData *mdTOFAlign = new AliCDBMetaData();
192   mdTOFAlign->SetResponsible("TOF");
193   AliInfo(Form("Number of Alignable Volumes: %d",fNTOFAlignObj));
194   man->Put(fTOFAlignObjArray,idTOFAlign,mdTOFAlign);
195 }
196 //_____________________________________________________________________________
197 void AliTOFAlignment::ReadParFromCDB(Char_t *sel, Int_t nrun)
198 {
199   //Read Align Par from CDB
200   AliCDBManager *man = AliCDBManager::Instance();
201   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
202   Char_t *sel1 = "AlignPar" ;
203   Char_t  out[100];
204   sprintf(out,"%s/%s",sel,sel1); 
205   AliCDBEntry *entry = man->Get(out,nrun);
206   if (!entry) { 
207     AliError(Form("Failed to get entry: %s",out));
208     return; 
209   }
210   fTOFAlignObjArray=(TObjArray*)entry->GetObject();
211   fNTOFAlignObj=fTOFAlignObjArray->GetEntries();
212   AliInfo(Form("Number of Alignable Volumes from CDB: %d",fNTOFAlignObj));
213
214 }
215 //_____________________________________________________________________________
216 void AliTOFAlignment::WriteSimParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
217 {
218   //Write Sim Align Par on CDB
219   AliCDBManager *man = AliCDBManager::Instance();
220   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
221   Char_t *sel1 = "AlignSimPar" ;
222   Char_t  out[100];
223   sprintf(out,"%s/%s",sel,sel1); 
224   AliCDBId idTOFAlign(out,minrun,maxrun);
225   AliCDBMetaData *mdTOFAlign = new AliCDBMetaData();
226   mdTOFAlign->SetResponsible("TOF");
227   AliInfo(Form("Number of Alignable Volumes: %d",fNTOFAlignObj));
228   man->Put(fTOFAlignObjArray,idTOFAlign,mdTOFAlign);
229 }
230 //_____________________________________________________________________________
231 void AliTOFAlignment::ReadSimParFromCDB(Char_t *sel, Int_t nrun){
232   //Read Sim Align Par from CDB
233   AliCDBManager *man = AliCDBManager::Instance();
234   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
235   Char_t *sel1 = "AlignSimPar" ;
236   Char_t  out[100];
237   sprintf(out,"%s/%s",sel,sel1); 
238   AliCDBEntry *entry = man->Get(out,nrun);
239   fTOFAlignObjArray=(TObjArray*)entry->GetObject();
240   fNTOFAlignObj=fTOFAlignObjArray->GetEntries();
241   AliInfo(Form("Number of Alignable Volumes from CDB: %d",fNTOFAlignObj));
242
243 }
244 //_____________________________________________________________________________
245 void AliTOFAlignment::WriteOnCDBforDC()
246 {
247   //Write Align Par on CDB for DC06
248   AliCDBManager *man = AliCDBManager::Instance();
249   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
250   AliCDBId idTOFAlign("TOF/Align/Data",0,0);
251   AliCDBMetaData *mdTOFAlign = new AliCDBMetaData();
252   mdTOFAlign->SetComment("Alignment objects for ideal geometry, i.e. applying them to TGeo has to leave geometry unchanged");
253   mdTOFAlign->SetResponsible("TOF");
254   AliInfo(Form("Number of Alignable Volumes: %d",fNTOFAlignObj));
255   man->Put(fTOFAlignObjArray,idTOFAlign,mdTOFAlign);
256 }
257 //_____________________________________________________________________________
258 void AliTOFAlignment::ReadFromCDBforDC()
259 {
260   //Read Sim Align Par from CDB for DC06
261   AliCDBManager *man = AliCDBManager::Instance();
262   if(!man->IsDefaultStorageSet())man->SetDefaultStorage("local://$ALICE_ROOT");
263   AliCDBEntry *entry = man->Get("TOF/Align/Data",0);
264   fTOFAlignObjArray=(TObjArray*)entry->GetObject();
265   fNTOFAlignObj=fTOFAlignObjArray->GetEntries();
266   AliInfo(Form("Number of Alignable Volumes from CDB: %d",fNTOFAlignObj));
267
268 }