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