44 #define CORRECT_RAFT_DIRECTION
47 #define ADDPRIMTRACKHITS
51 #include "StEventTypes.h"
52 #include "StLaserAnalysisMaker.h"
54 #include "LaserEvent.h"
55 #include "StTpcDb/StTpcDb.h"
56 #include "TGeoMatrix.h"
59 #include "TRSymMatrix.h"
60 #include "StDetectorDbMaker/StDetectorDbClock.h"
61 #define PrPP(A,B) if (Debug()) {LOG_INFO << "::StLaserAnalysisMaker" << (#A) << "\t" << (#B) << " = \t" << (B) << endm;}
64 static const Int_t NS = 12;
65 static const Int_t NB = 6;
66 static const Int_t NM = 7;
67 static LaserB *Lasers[NS][NB][NM];
69 static Int_t NoBeams = 0;
72 static TGeoHMatrix *Traft[14];
73 static TGeoHMatrix *Raft2Tpc[14];
74 static TGeoHMatrix *Bundles2Tpc[14][6];
75 static TGeoHMatrix *Mirrors2Tpc[14][6][7];
77 Int_t StLaserAnalysisMaker::Init(){
78 if (! IsActive())
return kStOk;
80 TFile *f = GetTFile();
83 f =
new TFile(
"StLaserAnalysisMaker.root",
"recreate");
89 m_laser =
new TTree(
"laser",
"Tpc laser track tree");
90 m_laser->SetAutoSave(100000000);
92 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,34,10)
98 if (split) bufsize /= 4;
99 Int_t branchStyle = 1;
100 if (split < 0) {branchStyle = 0; split = -1-split;}
101 TTree::SetBranchStyle(branchStyle);
102 m_laser->Branch(
"event",
"LaserEvent",&event, bufsize, split);
104 return StMaker::Init();
107 Int_t StLaserAnalysisMaker::InitRun(Int_t run){
108 const Int_t numSectors = 24;
110 Double_t dGamma = 720./numSectors;
112 TGeoHMatrix TpcHalf[2];
113 Double_t rotHalfs[18] = {
114 0, 1, 0, -1, 0, 0, 0, 0, 1,
115 0, -1, 0, -1, 0, 0, 0, 0, -1
117 for (Int_t half = east; half <= west; half++) TpcHalf[half].SetRotation(&rotHalfs[9*half]);
118 TGeoHMatrix RotSec[24];
119 for (sector = 1; sector <= numSectors; sector++) {
120 if (sector > 12) gamma = (numSectors-sector)*dGamma;
121 else gamma = sector*dGamma;
122 RotSec[sector-1].RotateZ(-gamma);
124 #ifdef CORRECT_RAFT_DIRECTION
125 Double_t zWheel = (229.71+1.7780);
127 Double_t ZWheel[2] = {-zWheel, zWheel};
128 Double_t RDWheel[2] = { 190.5802, 190.5705};
134 cout <<
" TpcHalf(east) "; StTpcDb::instance()->TpcHalf(east).Print();
135 cout <<
" TpcHalf(west) "; StTpcDb::instance()->TpcHalf(west).Print();
137 for (sector = 1; sector <= 12; sector++) {
139 cout <<
"Sector " << sector <<
" ===========" << endl;
142 TGeoHMatrix ET = RotSec[sector+12-1].Inverse()*StTpcDb::instance()->TpcHalf(east)*RotSec[sector+12-1];
if (Debug()) ET.Print();
143 ET.LocalToMaster(xyzDSE.xyz(), xyzTE.xyz()); PrPP(InitRun,xyzTE);
144 TGeoHMatrix EW = RotSec[sector -1].Inverse()*StTpcDb::instance()->TpcHalf(west)*RotSec[sector -1];
if (Debug()) EW.Print();
145 EW.LocalToMaster(xyzDSW.xyz(), xyzTW.xyz()); PrPP(InitRun,xyzTW);
151 Double_t alpha = - unit.y();
152 Double_t beta = unit.x();
153 StThreeVectorD tra = sum; tra.xyz()[0] -= 0.5*(RDWheel[0]+RDWheel[1]); PrPP(InitRun,tra);
155 TGeoHMatrix S2R(Form(
"S2R_%i",sector));
156 S2R.RotateX(alpha*180/TMath::Pi());
157 S2R.RotateY(beta*180/TMath::Pi());
158 S2R.SetTranslation(tra.xyz());
if (Debug()) {cout <<
"S2R "; S2R.Print();}
160 S2R.MasterToLocalVect(unit.xyz(),unitR.xyz()); PrPP(InitRun,unitR);
161 if (Debug()) {cout <<
"RotSecO[" << sector-1 <<
"]:"; RotSec[sector-1].Print();}
162 R = RotSec[sector-1]*S2R;
if (Debug()) {cout <<
"R:"; R.Print();}
163 RotSec[sector-1] = R;
if (Debug()) {cout <<
"RotSecM[" << sector-1 <<
"]:"; RotSec[sector-1].Print();}
164 if (Debug()) {cout <<
"RotSecO[" << sector+12-1 <<
"]:"; RotSec[sector+12-1].Print();}
166 TGeoHMatrix R = RotSec[sector+12-1]*S2R;
if (Debug()) {cout <<
"R:"; R.Print();}
167 RotSec[sector+12-1] = R;
if (Debug()) {cout <<
"RotSecM[" << sector+12-1 <<
"]:"; RotSec[sector+12-1].Print();}
170 memset (LaserBeams, 0, NS*NB*NM*
sizeof(
LaserRaft*));
172 memset(Traft, 0, 14*
sizeof(TGeoHMatrix *));
173 memset(Raft2Tpc, 0, 14*
sizeof(TGeoHMatrix *));
174 memset(Bundles2Tpc, 0, 14*6*
sizeof(TGeoHMatrix *));
175 memset(Mirrors2Tpc, 0, 14*6*7*
sizeof(TGeoHMatrix *));
176 Double_t y0[12] = { 0.0373, -0.0104, -0.0081, -0.0092, 0.0000, 0.0492, 0.0008, -0.0123, 0.0281, 0.0210, -0.0102, -0.0627};
177 Double_t y1[12] = { 0.0088, -0.0033, 0.0000, -0.0045, 0.0000, 0.0079, 0.0006, -0.0013, 0.0068, 0.0052, -0.0033, -0.0168};
178 Double_t z0[12] = {-0.0414, 0.0363, -0.1394, 0.0508, 0.0000, 0.0241, -0.0331, 0.0689, -0.1474, -0.0469, 0.1104, 0.0203};
179 Double_t z1[12] = {-0.0002, -0.0001, -0.0089, -0.0002, 0.0000, -0.0000, -0.0002, -0.0000, 0.0003, 0.0031, 0.0007, 0.0002};
180 for (Int_t i = 0; i < NoRaftPositions; i++) {
181 if (! RaftPositions[i].Sector)
continue;
182 Int_t raft = RaftPositions[i].Raft;
183 Traft[raft-1] =
new TGeoHMatrix(Form(
"Raft%0i",raft));
184 Traft[raft-1]->RotateX(RaftPositions[i].alpha*180/TMath::Pi());
185 Traft[raft-1]->RotateY(RaftPositions[i].beta*180/TMath::Pi());
186 Traft[raft-1]->RotateZ(RaftPositions[i].gamma*180/TMath::Pi());
187 StThreeVectorD xyzRaft(RaftPositions[i].X,RaftPositions[i].Y,RaftPositions[i].Z - 0.05465 + 0.1022-0.0530);
188 if (RaftPositions[i].Sector <= 12) xyzRaft.setY(xyzRaft.y() - 0.0480 - 0.0095 - 0.0028);
189 else xyzRaft.setY(xyzRaft.y() + 0.0328 + 0.0118 + 0.0032);
190 Int_t s = (RaftPositions[i].Sector-1)/2;
191 xyzRaft.setY(xyzRaft.y() + y0[s] + y1[s]);
192 xyzRaft.setZ(xyzRaft.z() + z0[s] + z1[s]);
193 Traft[raft-1]->SetTranslation(xyzRaft.xyz());
195 RaftPositions[i].Print();
196 Traft[raft-1]->Print();
199 for (Int_t r = 0; r < 14; r++) {
200 Int_t sector = Bundles[r][0].Sector;
201 if (! sector)
continue;
202 Int_t raft = Bundles[r][0].Raft;
204 if (sector > 12) half = east;
205 Raft2Tpc[raft-1] =
new TGeoHMatrix(Form(
"Raft%iToTpc",raft));
206 *Raft2Tpc[raft-1] = RotSec[sector-1] * TpcHalf[half] * (*Traft[raft-1]);
207 for (Int_t b = 0; b < 6; b++) {
208 Int_t bundle = Bundles[r][b].Bundle;
210 rotB.SetTranslation(&Bundles[r][b].X);
211 Bundles2Tpc[raft-1][bundle-1] =
new TGeoHMatrix(Form(
"BundleR%iB%i",raft,bundle));
212 *Bundles2Tpc[raft-1][bundle-1] = *Raft2Tpc[raft-1] * rotB;
213 for (Int_t m = 0; m < 7; m++) {
214 if (Mirrors[r][b][m].Sector < 2)
continue;
216 if (! local)
continue;
217 Int_t mirror = Mirrors[r][b][m].Mirror;
219 LaserBeams[NoBeams]->Sector = local->Sector;
220 LaserBeams[NoBeams]->Raft = local->Raft;
221 LaserBeams[NoBeams]->Bundle = local->Bundle;
222 LaserBeams[NoBeams]->Mirror = local->Mirror;
223 #ifdef CORRECT_LASER_POSITIONS
224 LaserBeams[NoBeams]->XyzB =
StThreeVectorD(Mirrors[r][b][m].X+Mirrors[r][b][m].dX,
225 Mirrors[r][b][m].Y+Mirrors[r][b][m].dY,
226 Mirrors[r][b][m].Z+Mirrors[r][b][m].dZ);
232 Double_t theta = Bundles[r][b].ThetaZ + Mirrors[r][b][m].ThetaZ;
233 Double_t phi = Bundles[r][b].Phi + Mirrors[r][b][m].Phi;
235 rotM.SetTranslation(LaserBeams[NoBeams]->XyzB.xyz());
236 Mirrors2Tpc[raft-1][bundle-1][mirror-1] =
new TGeoHMatrix(Form(
"MirrorR%iB%iM%i",raft,bundle,mirror));
237 *Mirrors2Tpc[raft-1][bundle-1][mirror-1] = *Bundles2Tpc[raft-1][bundle-1] * rotM;
239 LaserBeams[NoBeams]->dirB =
StThreeVectorD(-TMath::Cos(phi)*TMath::Cos(theta),
240 -TMath::Sin(phi)*TMath::Cos(theta),
242 rotB.LocalToMaster(LaserBeams[NoBeams]->XyzB.xyz(), LaserBeams[NoBeams]->XyzU.xyz());
243 rotB.LocalToMasterVect(LaserBeams[NoBeams]->dirB.xyz(), LaserBeams[NoBeams]->dirU.xyz());
244 Raft2Tpc[raft-1]->LocalToMaster(LaserBeams[NoBeams]->XyzU.xyz(),LaserBeams[NoBeams]->XyzL.xyz());
245 Raft2Tpc[raft-1]->LocalToMasterVect(LaserBeams[NoBeams]->dirU.xyz(),LaserBeams[NoBeams]->dirL.xyz());
246 LaserBeams[NoBeams]->Theta = LaserBeams[NoBeams]->dirL.theta();
247 LaserBeams[NoBeams]->Phi = LaserBeams[NoBeams]->dirL.phi();
250 Raft2Tpc[raft-1]->Print();
251 LaserBeams[NoBeams]->Print();
258 memset(Lasers, 0, NS*NB*NM*
sizeof(
LaserB *));
259 const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
261 for (Int_t i = 0; i < NoBeams; i++) {
262 if (! LaserBeams[i])
continue;
263 Int_t s = LaserBeams[i]->Sector/2 - 1;
264 if (s < 0 || s >= NS)
continue;
265 Int_t b = LaserBeams[i]->Bundle - 1;
266 if (b < 0 || b >= NB)
continue;
267 Int_t m = LaserBeams[i]->Mirror - 1;
268 if (m < 0 || m >= NM)
continue;
269 theLaser =
new LaserB(*LaserBeams[i]);
270 Lasers[s][b][m] = theLaser;
271 Tpc2Global.LocalToMaster(theLaser->XyzL.xyz(),theLaser->XyzG.xyz());
272 Tpc2Global.LocalToMasterVect(theLaser->dirL.xyz(),theLaser->dirG.xyz());
273 gStTpcDb->SupS2Tpc(theLaser->Sector).MasterToLocal(theLaser->XyzL.xyz(),theLaser->XyzS.xyz());
274 gStTpcDb->SupS2Tpc(theLaser->Sector).MasterToLocalVect(theLaser->dirL.xyz(),theLaser->dirS.xyz());
275 theLaser->PhiG = theLaser->dirG.phi();
276 theLaser->ThetaG = theLaser->dirG.theta();
277 theLaser->IsValid = 0;
280 if (theLaser->Sector == 2 && theLaser->Bundle == 3 && theLaser->Mirror == 5)
continue;
281 if (theLaser->Sector == 4 && theLaser->Bundle == 4)
continue;
282 if (theLaser->Sector == 8)
continue;
283 if (theLaser->Sector == 10)
continue;
284 if (theLaser->Sector == 12 && theLaser->Bundle == 4 && theLaser->Mirror == 4)
continue;
285 if (theLaser->Sector == 12 && theLaser->Bundle == 4 && theLaser->Mirror == 5)
continue;
286 if (theLaser->Sector == 14 && theLaser->Bundle == 4 && theLaser->Mirror == 4)
continue;
287 if (theLaser->Sector == 16 && theLaser->Bundle == 4 && theLaser->Mirror == 5)
continue;
288 if (theLaser->Sector == 16 && theLaser->Bundle == 4 && theLaser->Mirror == 5)
continue;
289 if (theLaser->Sector == 18 && theLaser->Bundle == 2)
continue;
290 if (theLaser->Sector == 22 && theLaser->Bundle == 3)
continue;
291 if (theLaser->Sector == 22 && theLaser->Bundle == 4)
continue;
292 if (theLaser->Sector == 24 && theLaser->Bundle == 2 && theLaser->Mirror == 6)
continue;
294 theLaser->IsValid = 1;
296 LaserBeams[i]->Print();
303 void StLaserAnalysisMaker::Clear(
const Option_t *option){
304 if (event)
event->Clear(
"C");
314 event->SetHeader(EvtHddr->GetEventNumber(), EvtHddr->GetRunNumber(), EvtHddr->GetDate(), EvtHddr->GetTime(),
315 gStTpcDb->Electronics()->tZero(), gStTpcDb->DriftVelocity(24,0), gStTpcDb->Electronics()->samplingFrequency(),
316 EvtHddr->GetInputTriggerMask());
317 event->SetDVWest(gStTpcDb->DriftVelocity(1,0));
318 event->SetDVEast(gStTpcDb->DriftVelocity(13,0));
320 event->SetScaleY(gStTpcDb->ScaleY());
322 event->GetHeader()->SetDriftDistance(gStTpcDb->Dimensions()->gatingGridZ());
323 event->GetHeader()->SetInnerSectorzOffset(gStTpcDb->Dimensions()->zInnerOffset());
324 event->GetHeader()->SetOuterSectorzOffset(gStTpcDb->Dimensions()->zOuterOffset());
325 event->GetHeader()->SettriggerTimeOffset(gStTpcDb->triggerTimeOffset());
326 event->GetHeader()->SetBField(pEvent->runInfo()->magneticField());
328 double freq = dbclock->getCurrentFrequency()/1000000.0;
329 event->GetHeader()->SetOnlClock(freq);
331 UInt_t nvtx = pEvent->numberOfPrimaryVertices();
332 for (UInt_t i = 0; i < nvtx; i++) {
333 event->AddVertex(pEvent->primaryVertex(i));
335 StSPtrVecTrackNode& trackNode = pEvent->trackNodes();
336 UInt_t nTracks = trackNode.size();
338 for (
unsigned int i=0; i < nTracks; i++) {
342 if (! gTrack)
continue;
343 if (!gTrack->dcaGeometry())
continue;
344 Int_t key = gTrack->key();
348 if (g3.mag() < 10)
continue;
352 StPtrVecHit hvec = gTrack->detectorInfo()->hits();
357 Int_t sector = -1, s = -1;
359 Double_t dZ, dZmin = 9999;
361 Double_t dPhi, dPhimin = 999;
365 for (
unsigned int j=0; j<hvec.size(); j++) {
366 if (hvec[j]->detector() != kTpcId)
continue;
367 tpcHit =
static_cast<StTpcHit *
> (hvec[j]);
368 #ifndef __TRACKHITS__
369 #ifdef ADDPRIMTRACKHITS
371 event->AddHit(tpcHit, key);
374 event->AddHit(tpcHit,key);
376 if (tpcHit->position().perp() > rMax) {
377 rMax = tpcHit->position().perp();
382 if (jmax < 0 || rMax < 120)
goto ADDTRACK;
383 tpcHit =
static_cast<StTpcHit *
> (hvec[jmax]);
385 sector = tpcHit->sector();
386 if (pTrack)
goto ADDTRACK;
387 if (2*(sector/2) != sector)
goto ADDTRACK;
389 if (s < 0 || s >= NS)
goto ADDTRACK;
392 for (b = 0; b < NB; b++) {
393 if (! Lasers[s][b][0])
continue;
394 dZ = TMath::Abs(tpcHit->position().z() - Lasers[s][b][0]->XyzG.z());
395 if (dZ < dZmin) {bundle = b; dZmin = dZ;}
397 if (bundle < 0 || dZmin > 15)
goto ADDTRACK;
401 for (m = 0; m < NM; m++) {
402 if (! Lasers[s][bundle][m])
continue;
403 dPhi = TMath::Abs(Lasers[s][bundle][m]->PhiG - g3.phi());
404 if (dPhi < dPhimin) {
409 if (mmax < 0 || dPhimin > 0.1)
goto ADDTRACK;
410 theLaser = Lasers[s][bundle][mmax];
412 t =
event->AddTrack(sector,gTrack,theLaser,tpcHit->position().z());
414 Int_t raft = theLaser->Raft;
415 Int_t bundle = theLaser->Bundle;
416 Int_t mirror = theLaser->Mirror;
417 if (raft > 0 && raft <= 14 &&
418 bundle > 0 && bundle <= 6 &&
419 mirror > 0 && mirror <= 7) {
420 t->SetPredictions(Raft2Tpc[raft-1], Bundles2Tpc[raft-1][bundle-1], Mirrors2Tpc[raft-1][bundle-1][mirror-1]);
421 if (theLaser->IsValid)
event->AddTrackFit(t);
428 static const Double_t sigma = 0.0385;
429 for (Int_t k = 0; k < 11; k++) {
437 for (Int_t i = 0; i < N; i++) {
438 if (! fit->Flag[i]) {
439 Double_t dev = fit->Y[i]/sigma;
441 Double_t a[2] = {1./sigma, fit->X[i]/sigma};
445 Int_t ndf = A.GetNrows() - 2;
447 TRSymMatrix S(A,TRArray::kATxA);
if (Debug()) cout <<
"S: " << S << endl;
448 TRVector B(A,TRArray::kATxB,Y);
if (Debug()) cout <<
"B: " << B << endl;
449 TRSymMatrix SInv(S,TRArray::kInvertedA);
if (Debug()) cout <<
"SInv: " << SInv << endl;
450 if (! SInv.IsValid()) {
break;}
451 TRVector X(SInv,TRArray::kSxA,B);
if (Debug()) cout <<
"X: " << X << endl;
453 R -=
TRVector(A,TRArray::kAxB,X);
if (Debug()) cout <<
"R: " << R << endl;
454 Double_t chisq = R*R;
455 Double_t prob = TMath::Prob(chisq,ndf);
460 fit->dslope = SInv[2];
461 fit->doffset = SInv[0];
464 if (Debug()) fit->Print();
466 TClonesArray &tracks = *
event->Tracks();
467 Int_t Ntrack =
event->GetNtrack();
468 for (Int_t i = 0; i < Ntrack; i++) {
470 if (t->Flag == 2 && t->Laser.Sector == 2*(k+1)) {
480 for (Int_t i = 0; i < N; i++) {
481 if (! fit->Flag[i]) {
483 Double_t RR = TMath::Abs(R[j]);
502 for (Int_t s = 0; s < NS; s++)
503 for (Int_t b = 0; b < NB; b++)
504 for (Int_t m = 0; m < NM; m++) SafeDelete(Lasers[s][b][m]);
507 TSeqCollection *files = gROOT->GetListOfFiles();
511 while ((f = (TFile *) next())) {
512 TString name(gSystem->BaseName(f->GetName()));
513 if (name ==
"StLaserAnalysis.root") {
bool fit()
Perform linear fits in zx- and zy-plane.
virtual void Clear(Option_t *option="")
User defined functions.