1 #include "SvtMatchedTree.h"
11 #include "TStopwatch.h"
12 #include "StThreeVectorF.hh"
13 #include "StMatrixF.hh"
19 #include "TProcessID.h"
21 #include "StPrimaryVertex.h"
22 #include "StBFChain.h"
23 #include "TGeoMatrix.h"
24 #include "St_db_Maker/St_db_Maker.h"
25 #include "tables/St_svtWafersPosition_Table.h"
26 #include "tables/St_ssdWafersPosition_Table.h"
27 #include "tables/St_Survey_Table.h"
28 #include "StSvtPool/EventT/EventT.h"
29 #include "StSsdDbMaker/StSsdDbMaker.h"
30 #include "StSvtDbMaker/StSvtDbMaker.h"
32 SvtMatchedTree::SvtMatchedTree(
const Char_t *name) :
StMaker(name),fFile(0), fTree(0), fEvent(0) {
38 Int_t SvtMatchedTree::Init() {
44 fFile = fTree->GetCurrentFile();
51 void SvtMatchedTree::SetTree() {
57 Int_t branchStyle = 1;
58 if (split < 0) {branchStyle = 0; split = -1-split;}
61 TTree::SetMaxTreeSize(1000*Long64_t(2000000000));
63 if (fMinNoHits > 0) FName += Form(
"_%i_%f2.1_",fMinNoHits,fpCut);
64 FName += gSystem->BaseName(chain->GetFileIn().Data());
65 FName.ReplaceAll(
"st_physics",
"");
66 FName.ReplaceAll(
".event",
"");
67 FName.ReplaceAll(
".daq",
".root");
68 fFile =
new TFile(FName,
"RECREATE",
"TTree with SVT + SSD hits and tracks");
69 fFile->SetCompressionLevel(comp);
71 fTree =
new TTree(
"T",
"TTree with SVT + SSD hits and tracks");
72 fTree->SetAutoSave(1000000000);
74 if (split) bufsize /= 4;
76 TTree::SetBranchStyle(branchStyle);
77 TBranch *branch = fTree->Branch(
"EventT", &fEvent, bufsize,split);
78 branch->SetAutoDelete(kFALSE);
82 if (! EventT::RotMatrices()) MakeListOfRotations();
84 if (pEvent && pEvent->primaryVertex() && !fEvent->Build(pEvent,fMinNoHits,fpCut)) fTree->Fill();
88 void SvtMatchedTree::Print(Option_t *opt)
const {
89 if (! EventT::RotMatrices())
return;
90 TIter next(EventT::RotMatrices());
91 TGeoHMatrix *comb = 0;
92 while ((comb = (TGeoHMatrix *) next())) {
94 sscanf(comb->GetName()+1,
"%04i",&Id);
95 Int_t Ladder = Id%100;
96 Int_t Layer = Id/1000;
if (Layer > 7) Layer = 7;
97 Int_t Wafer = (Id - 1000*Layer)/100;
98 cout << comb->GetName() <<
"\tLayer/Ladder/Wafer = " << Layer <<
"/" << Ladder <<
"/" << Wafer << endl;
100 cout <<
"=================================" << endl;
104 void SvtMatchedTree::MakeListOfRotations() {
105 if (EventT::RotMatrices())
return;
106 THashList *rotMHash =
new THashList(100,0);
107 rotMHash->SetOwner(kFALSE);
108 EventT::SetRotMatrices(rotMHash);
110 for (Int_t i = 0; i < 2; i++) {
111 if (i == 0 && gStSvtDbMaker) hash = gStSvtDbMaker->GetRotations();
112 if (i == 1 && gStSsdDbMaker) hash = gStSsdDbMaker->GetRotations();
113 if (! hash)
continue;
116 while ((comb = (TGeoHMatrix *) next())) rotMHash->Add(comb);
119 TDataSet *set = GetDataBase(
"Geometry/ssd");
120 St_Survey *SsdOnGlobal = (St_Survey *) set->
Find(
"SsdOnGlobal");
121 if (! SsdOnGlobal) {cout <<
"SsdOnGlobal has not been found" << endl;
return;}
122 TGeoHMatrix GL, LS,SG,LA,WG;
123 Survey_st *OnGlobal = SsdOnGlobal->GetTable();
124 GL.SetRotation(&OnGlobal->r00);
125 GL.SetTranslation(&OnGlobal->t0);
128 St_Survey *SsdSectorsOnGlobal = (St_Survey *) set->
Find(
"SsdSectorsOnGlobal");
129 if (! SsdSectorsOnGlobal) {cout <<
"SsdSectorsOnGlobal has not been found" << endl;
return;}
130 St_Survey *SsdLaddersOnSectors = (St_Survey *) set->
Find(
"SsdLaddersOnSectors");
131 if (! SsdLaddersOnSectors) {cout <<
"SsdLaddersOnSectors has not been found" << endl;
return;}
132 St_Survey *SsdWafersOnLadders = (St_Survey *) set->
Find(
"SsdWafersOnLadders");
133 if (! SsdWafersOnLadders) {cout <<
"SsdWafersOnLadders has not been found" << endl;
return;}
134 Survey_st *SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
135 Survey_st *LaddersOnSectors = SsdLaddersOnSectors->GetTable();
136 Survey_st *WafersOnLadders = SsdWafersOnLadders->GetTable();
137 Int_t NoSectors = SsdSectorsOnGlobal->GetNRows();
138 Int_t NoLadders = SsdLaddersOnSectors->GetNRows();
139 Int_t NoWafers = SsdWafersOnLadders->GetNRows();
141 for (Int_t i = 0; i < NoWafers; i++,WafersOnLadders++) {
142 Int_t Id = WafersOnLadders->Id;
143 TGeoHMatrix *comb = (TGeoHMatrix *) rotMHash->FindObject(Form(
"R%04i",Id));
145 comb =
new TGeoHMatrix(Form(
"R%04i",Id));
146 Int_t layer = Id/1000;
147 if (layer > 7) layer = 7;
148 Int_t ladder = Id%100;
149 TGeoHMatrix *WL = (TGeoHMatrix *) rotMHash->FindObject(Form(
"WL%04i",Id));
151 WL =
new TGeoHMatrix(Form(
"WL%04i",Id));
152 WL->SetRotation(&WafersOnLadders->r00);
153 WL->SetTranslation(&WafersOnLadders->t0);
156 LaddersOnSectors = SsdLaddersOnSectors->GetTable();
159 for (Int_t l = 0; l < NoLadders; l++, LaddersOnSectors++) {
161 Ladder = LaddersOnSectors->Id%100;
162 if (Ladder == ladder) {
163 Sector = LaddersOnSectors->Id/100;
164 LS.SetRotation(&LaddersOnSectors->r00);
165 LS.SetTranslation(&LaddersOnSectors->t0);
170 if (Sector <= 0 || Sector > 4) {cout <<
"Sector has not been defined" << endl;
continue;}
171 SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
173 for (Int_t s = 0; s <NoSectors; s++, SectorsOnGlobal++) {
175 if (SectorsOnGlobal->Id != Sector)
continue;
177 SG.SetRotation(&SectorsOnGlobal->r00);
178 SG.SetTranslation(&SectorsOnGlobal->t0);
181 if (! sector) {cout <<
"Sector\t" << Sector <<
" has not been found" << endl;
continue;}
184 WG = GL * SG * LS * (*WL);
185 ssdWafersPosition_st row;
191 row.num_chip = (num-1)%16 + 1;
194 Double_t *r = WG.GetRotationMatrix();
195 row.driftDirection[0] = r[0]; row.normalDirection[0] = r[1]; row.transverseDirection[0] = r[2];
196 row.driftDirection[1] = r[3]; row.normalDirection[1] = r[4]; row.transverseDirection[1] = r[5];
197 row.driftDirection[2] = r[6]; row.normalDirection[2] = r[7]; row.transverseDirection[2] = r[8];
199 TVector3 d(row.driftDirection); norm = 1/d.Mag(); d *= norm;
200 TVector3 t(row.transverseDirection); norm = 1/t.Mag(); t *= norm;
201 TVector3 n(row.normalDirection);
202 TVector3 c = d.Cross(t);
203 if (c.Dot(n) < 0) c *= -1;
204 d.GetXYZ(row.driftDirection);
205 t.GetXYZ(row.transverseDirection);
206 c.GetXYZ(row.normalDirection);
208 Double_t *wgtr = WG.GetTranslation();
210 memcpy(row.centerPosition,wgtr, 3*
sizeof(Double_t));
212 row.driftDirection[0], row.transverseDirection[0], row.normalDirection[0],
213 row.driftDirection[1], row.transverseDirection[1], row.normalDirection[1],
214 row.driftDirection[2], row.transverseDirection[2], row.normalDirection[2]};
215 Double_t tr[3] = {row.centerPosition[0],
216 row.centerPosition[1],
217 row.centerPosition[2]};
218 comb->SetRotation(rot);
219 comb->SetTranslation(tr);
223 set = GetDataBase(
"Geometry/svt");
224 St_Survey *WaferOnLadder = (St_Survey *) set->
Find(
"WaferOnLadder");
225 St_Survey *LadderOnSurvey = (St_Survey *) set->
Find(
"LadderOnSurvey");
226 St_Survey *LadderOnShell = (St_Survey *) set->
Find(
"LadderOnShell");
227 St_Survey *ShellOnGlobal = (St_Survey *) set->
Find(
"ShellOnGlobal");
228 Int_t NW = WaferOnLadder->GetNRows();
229 Int_t NL = LadderOnSurvey->GetNRows();
230 Survey_st *waferOnLadder = WaferOnLadder->GetTable();
231 Survey_st *shellOnGlobal0 = ShellOnGlobal->GetTable(0);
232 Survey_st *shellOnGlobal1 = ShellOnGlobal->GetTable(1);
233 TGeoHMatrix LSU, LSH, SHG[2];
234 SHG[0].SetRotation(&shellOnGlobal0->r00);
235 SHG[0].SetTranslation(&shellOnGlobal0->t0);
236 SHG[1].SetRotation(&shellOnGlobal1->r00);
237 SHG[1].SetTranslation(&shellOnGlobal1->t0);
239 for (Int_t i = 0; i < NW; i++, waferOnLadder++) {
240 Int_t
id = waferOnLadder->Id;
241 Int_t wbarrel =
id/1000;
242 Int_t wwafer = (
id - 1000*wbarrel)/100;
243 Int_t wladder =
id%100;
244 Int_t wlayer = 2*wbarrel + wladder%2 - 1;
246 Int_t Id = 1000*wlayer + 100*wwafer + wladder;
247 TGeoHMatrix *comb = (TGeoHMatrix *) rotMHash->FindObject(Form(
"R%04i",Id));
249 comb =
new TGeoHMatrix(Form(
"R%04i",Id));
251 Survey_st *ladderOnSurvey = LadderOnSurvey->GetTable();
252 Survey_st *ladderOnShell = LadderOnShell->GetTable();
253 for ( Int_t j = 0; j < NL; j++, ladderOnSurvey++, ladderOnShell++) {
254 Int_t Idl = ladderOnSurvey->Id;
255 Int_t lladder = Idl%100;
256 if( wladder != lladder )
continue;
257 LSH.SetRotation(&ladderOnShell->r00);
258 LSH.SetTranslation(&ladderOnShell->t0);
260 if( (wbarrel == 1 && wladder <= 4) || (wbarrel == 2 && wladder <= 6) || (wbarrel == 3 && wladder <= 8) ) Shell = 0;
262 TGeoHMatrix *WL = (TGeoHMatrix *) rotMHash->FindObject(Form(
"WL%04i",Id));
265 wL.SetRotation(&waferOnLadder->r00);
266 wL.SetTranslation(&waferOnLadder->t0);
267 WL =
new TGeoHMatrix();
268 LSU.SetRotation(&ladderOnSurvey->r00);
269 LSU.SetTranslation(&ladderOnSurvey->t0);
271 WL->SetName(Form(
"WL%04i",Id));
275 WG = GL * SHG[Shell] * LSH * (*WL);
276 Double_t *r = WG.GetRotationMatrix();
278 for (
int l = 0; l < 9; l++) {
279 if (TMath::Abs(r[l]) >= 1.000001) fail++;
282 cout <<
"===============" << waferOnLadder->Id <<
" "<<
id <<
" " << Id <<endl;
283 cout <<
"WG\t"; WG.Print();
285 svtWafersPosition_st row;
286 row.driftDirection[0] = r[0]; row.normalDirection[0] = r[1]; row.transverseDirection[0] = r[2];
287 row.driftDirection[1] = r[3]; row.normalDirection[1] = r[4]; row.transverseDirection[1] = r[5];
288 row.driftDirection[2] = r[6]; row.normalDirection[2] = r[7]; row.transverseDirection[2] = r[8];
290 TVector3 d(row.driftDirection); norm = 1/d.Mag(); d *= norm;
291 TVector3 t(row.transverseDirection); norm = 1/t.Mag(); t *= norm;
292 TVector3 n(row.normalDirection);
293 TVector3 c = d.Cross(t);
294 if (c.Dot(n) < 0) c *= -1;
295 d.GetXYZ(row.driftDirection);
296 t.GetXYZ(row.transverseDirection);
297 c.GetXYZ(row.normalDirection);
299 row.ID = 100*wwafer + wladder + 1000*wlayer;
300 Double_t *wgtr = WG.GetTranslation();
301 memcpy(row.centerPosition,wgtr, 3*
sizeof(Double_t));
303 row.driftDirection[0], row.transverseDirection[0], row.normalDirection[0],
304 row.driftDirection[1], row.transverseDirection[1], row.normalDirection[1],
305 row.driftDirection[2], row.transverseDirection[2], row.normalDirection[2]};
306 Double_t tr[3] = {row.centerPosition[0],
307 row.centerPosition[1],
308 row.centerPosition[2]};
309 comb->SetRotation(rot);
310 comb->SetTranslation(tr);
318 TIter next(rotMHash);
321 while ((comb = (TGeoHMatrix *) next())) {
322 TString Name(comb->GetName());
323 if (Name.BeginsWith(
"R")) {
324 TGeoHMatrix *WL = (TGeoHMatrix *) rotMHash->FindObject(Form(
"WL%s",Name.Data()+1));
326 cout << Form(
"WL%s",Name.Data()+1) <<
" has not been found" << endl;
335 if (gDirectory != fFile) {
virtual TDataSet * Find(const char *path) const