11 #include "StSpaceChargeEbyEMaker.h"
12 #include "StDbUtilities/StMagUtilities.h"
13 #include "StEvent/StEventTypes.h"
14 #include "StMessMgr.h"
15 #include "StTpcDb/StTpcDb.h"
16 #include "StTpcDb/StTpcDbMaker.h"
17 #include "St_db_Maker/St_db_Maker.h"
18 #include "StEvent/StDcaGeometry.h"
19 #include "StEvent/StBTofCollection.h"
20 #include "StEvent/StBTofHit.h"
21 #include "StEvent/StBTofHeader.h"
22 #include "StEvent/StBTofPidTraits.h"
23 #include "StEvent/StTrackPidTraits.h"
24 #include "StDetectorDbMaker/St_trigDetSumsC.h"
25 #include "StDetectorDbMaker/St_tpcGridLeakC.h"
26 #include "StDetectorDbMaker/St_spaceChargeCorC.h"
27 #include "StEmcUtil/geometry/StEmcGeom.h"
28 #include "StEmcUtil/projection/StEmcPosition.h"
30 #include "TUnixTime.h"
41 const float SCL = -0.015;
42 const float SCH = 0.185;
43 const float SCB = (SCH-SCL)/SCN1;
44 const float SCX = SCB/TMath::Sqrt(TMath::TwoPi());
47 const float DCL = -2.5;
48 const float DCH = 2.5;
51 const float PI2 = TMath::TwoPi();
56 const float ZL = -150.;
57 const float ZH = 150.;
60 const float GL = -0.3;
63 const float GZL = -200.;
64 const float GZH = 225.;
66 const float ZGGRID = 208.707;
68 static TF1 ga1(
"ga1",
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))");
69 static TF1 ln1(
"ln1",
"[0]+((208.707-abs(x))*[1]/100.0)",-150.,150.);
71 const unsigned int MAXVTXCANDIDATES = 256;
78 Calibmode(kFALSE), PrePassmode(kFALSE), PrePassdone(kFALSE),
79 QAmode(kFALSE), TrackInfomode(0), Asymmode(kFALSE),
80 doNtuple(kFALSE), doReset(kTRUE), doGaps(kFALSE), doSecGaps(kFALSE),
82 vtxVpdAgree(5.0), vtxPCTs(0), vtxEmcMatch(1), vtxTofMatch(0),
83 vtxMinTrks(5), minTpcHits(25),
84 reqEmcMatch(kFALSE), reqTofMatch(kFALSE), reqEmcOrTofMatch(kTRUE),
85 m_ExB(0), SCcorrection(0), GLcorrection(0), SCEWRatio(0),
86 scehist(0), timehist(0), myhist(0), myhistN(0), myhistP(0),
87 myhistE(0), myhistW(0), dczhist(0), dcehist(0), dcphist(0),
88 dcahist(0), dcahistN(0), dcahistP(0), dcahistE(0), dcahistW(0),
89 gapZhist(0), gapZhistneg(0), gapZhistpos(0), cutshist(0), ntup(0) {
93 SCALER_ERROR = 0.0007;
96 MAXDIFFE = SCALER_ERROR;
98 MAXDIFFA = 2*SCALER_ERROR;
103 memset(evts,0,SCHN*
sizeof(
int));
104 memset(times,0,SCHN*
sizeof(
int));
105 memset(evtstbin,0,SCHN*
sizeof(
float));
112 schist =
new TH1F(
"SpCh",
"Space Charge" ,SCN1,SCL,SCH);
113 schistE =
new TH1F(
"SpChE",
"Space Charge East",SCN1,SCL,SCH);
114 schistW =
new TH1F(
"SpChW",
"Space Charge West",SCN1,SCL,SCH);
115 schist ->SetDirectory(0);
116 schistE->SetDirectory(0);
117 schistW->SetDirectory(0);
118 for (
int i=0;i<SCHN;i++){
119 schists[i] =
new TH1F(Form(
"SpCh%d" ,i),
"Space Charge" ,SCN1,SCL,SCH);
120 schistsE[i] =
new TH1F(Form(
"SpChE%d",i),
"Space Charge East",SCN1,SCL,SCH);
121 schistsW[i] =
new TH1F(Form(
"SpChW%d",i),
"Space Charge West",SCN1,SCL,SCH);
122 schists[i] ->SetDirectory(0);
123 schistsE[i]->SetDirectory(0);
124 schistsW[i]->SetDirectory(0);
126 for (
int i=0; i<24; i++) {
137 memset(scS,0,24*
sizeof(
float));
138 memset(escS,0,24*
sizeof(
float));
146 memset(ntrks ,0,SCHN*
sizeof(
float));
147 memset(ntrksE,0,SCHN*
sizeof(
float));
148 memset(ntrksW,0,SCHN*
sizeof(
float));
149 memset(ntrksS,0,24*
sizeof(
float));
150 gapZfitslope = 0; gapZfitintercept = 0; gapZdivslope = 0;
151 egapZfitslope = 0; egapZfitintercept = 0; egapZdivslope = 0;
152 gapZfitslopeneg = 0; gapZfitinterceptneg = 0; gapZdivslopeneg = 0;
153 gapZfitslopepos = 0; gapZfitinterceptpos = 0; gapZdivslopepos = 0;
154 gapZfitslopeeast = 0; gapZfitintercepteast = 0; gapZdivslopeeast = 0;
155 gapZfitslopewest = 0; gapZfitinterceptwest = 0; gapZdivslopewest = 0;
156 memset(gapZfitslopeS,0,24*
sizeof(
float));
157 memset(gapZfitinterceptS,0,24*
sizeof(
float));
158 memset(gapZdivslopeS,0,24*
sizeof(
float));
159 memset(gapZfitslopenegS,0,24*
sizeof(
float));
160 memset(gapZfitinterceptnegS,0,24*
sizeof(
float));
161 memset(gapZdivslopenegS,0,24*
sizeof(
float));
162 memset(gapZfitslopeposS,0,24*
sizeof(
float));
163 memset(gapZfitinterceptposS,0,24*
sizeof(
float));
164 memset(gapZdivslopeposS,0,24*
sizeof(
float));
167 StSpaceChargeEbyEMaker::~StSpaceChargeEbyEMaker() {
171 for (
int i=0;i<SCHN;i++) {
182 if (PrePassdone) WriteTableToFile();
183 else gMessMgr->Warning(
"StSpaceChargeEbyEMaker: NO SC => NO OUTPUT");
185 if ((!Calibmode)&&(!PrePassdone)) EvalCalib();
188 gMessMgr->Warning(
"StSpaceChargeEbyEMaker: NO EVENTS => NO OUTPUT");
194 Int_t StSpaceChargeEbyEMaker::Init() {
199 Int_t attrMode = IAttr(
".gopt.sce");
200 attrMode = (attrMode ? attrMode%1000 : GetMode());
201 gMessMgr->Info() <<
"StSpaceChargeEbyEMaker mode: " << attrMode << endm;
203 case (1) : DoQAmode();
break;
204 case (2) : DoPrePassmode();
break;
205 case (3) : DoPrePassmode(); DoQAmode();
break;
206 case (4) : DoCalib();
break;
207 case (5) : DoCalib(); DoAsym();
break;
208 case (6) : DoCalib(); DoSecGaps();
break;
209 case (7) : DoCalib(); DoAsym(); DoSecGaps();
break;
210 case (10): DoNtuple();
break;
211 case (11): DoNtuple(); DontReset();
break;
212 case (12): DoNtuple(); DoQAmode();
break;
213 case (13): DoNtuple(); DontReset(); DoQAmode();
break;
214 case (20): DoNtuple(); DontReset(); DoQAmode(); DoSecGaps();
break;
215 case (50): DoTrackInfo();
break;
216 case (51): DoTrackInfo(2);
break;
217 case (52): DoTrackInfo(3);
break;
221 if (Calibmode) doReset = kFALSE;
231 if (QAmode) gMessMgr->Info(
"StSpaceChargeEbyEMaker: Initializing");
232 if (TrackInfomode) gMessMgr->Info(
"StSpaceChargeEbyEMaker: Track Info mode");
233 return StMaker::Init();
238 if (QAmode) cutshist->Fill(0);
242 if ((!Calibmode) && (tabname.Length() == 0)) SetTableName();
245 m_ExB = StMagUtilities::Instance();
247 #ifdef __NEW_MagUtilities__
248 m_ExB =
new StMagUtilities(gStTpcDb,(kSpaceChargeR2 | kGridLeak));
250 TDataSet *RunLog = GetDataBase(
"RunLog/MagFactor");
251 if (!RunLog) gMessMgr->Warning(
"StSpaceChargeEbyEMaker: No RunLog/MagFactor found.");
252 m_ExB =
new StMagUtilities(gStTpcDb,RunLog,(kSpaceChargeR2 | kGridLeak));
255 m_ExB->UndoDistortion(0,0,0);
256 lastsc = m_ExB->CurrentSpaceChargeR2();
257 lastEWRatio = m_ExB->CurrentSpaceChargeEWRatio();
260 event =
static_cast<StEvent*
>(GetInputDS(
"StEvent"));
262 gMessMgr->Warning(
"StSpaceChargeEbyEMaker: no StEvent; skipping event.");
265 if (QAmode) cutshist->Fill(1);
266 if (firstEvent<0) firstEvent =
event->id();
269 runinfo =
event->runInfo();
270 if ((!runinfo) || (runinfo->magneticField() == 0)) {
271 gMessMgr->Error(
"StSpaceChargeEbyEMaker: cannot run due to zero or unknown mag field!");
274 if ((lastsc != 0) && (runinfo) && (runinfo->magneticField() == 0))
275 gMessMgr->Warning() <<
"BE AWARE THAT A NONZERO VALUE OF SPACECHARGE\n"
276 <<
" WAS RETURNED BY DB CALL!\n (could be a local DB file or"
277 <<
" in the actual database)" << endm;
280 if (QAmode) cutshist->Fill(2);
284 unsigned int vtxCandidates[MAXVTXCANDIDATES];
285 unsigned int numVtxCandidates = 0;
286 unsigned int totVertices =
event->numberOfPrimaryVertices();
287 if (TrackInfomode>1) numVtxCandidates=1;
290 const StBTofHeader* btofHeader = (btofColl ? btofColl->tofHeader() : 0);
291 float vpd_zvertex = (btofHeader ? btofHeader->vpdVz() : -999);
292 for (
unsigned int vtxIdx = 0; vtxIdx < totVertices; vtxIdx++) {
293 pvtx =
event->primaryVertex(vtxIdx);
294 if (QAmode) cutshist->Fill(3);
295 if (! (IAttr(
"EastOff") || IAttr(
"WestOff"))) {
297 StVertexFinderId vtxFindID = pvtx->vertexFinderId();
298 float min_rank = -1e6;
300 case minuitVertexFinder : min_rank = -5;
break;
301 case ppvVertexFinder :
302 case ppvNoCtbVertexFinder : min_rank = 0;
break;
306 if (vtxFindID == minuitVertexFinder) totVertices = 1;
308 if (pvtx->ranking() < min_rank)
break;
310 if (QAmode) cutshist->Fill(4);
311 if (pvtx->numberOfDaughters() < vtxMinTrks)
continue;
312 if (QAmode) cutshist->Fill(5);
313 if (pvtx->numMatchesWithBEMC() < vtxEmcMatch)
continue;
314 if (QAmode) cutshist->Fill(6);
315 if (pvtx->numMatchesWithBTOF() < vtxTofMatch)
continue;
316 if (QAmode) cutshist->Fill(7);
317 if (pvtx->numPostXTracks() > vtxPCTs)
continue;
318 if (QAmode) cutshist->Fill(8);
319 if (vtxVpdAgree > 0 &&
320 TMath::Abs(pvtx->position().z() - vpd_zvertex) > vtxVpdAgree)
continue;
321 if (QAmode) cutshist->Fill(9);
322 vtxCandidates[numVtxCandidates] = vtxIdx;
324 if (numVtxCandidates == MAXVTXCANDIDATES)
break;
327 if (!numVtxCandidates)
return kStOk;
328 if (QAmode) cutshist->Fill(10);
330 StSPtrVecTrackNode& theNodes =
event->trackNodes();
331 unsigned int nnodes = theNodes.size();
332 if (!nnodes)
return kStOk;
333 if (QAmode) cutshist->Fill(11);
337 int thistime =
event->time();
339 timehist->SetBinContent(evt,thistime-lasttime);
341 runid =
event->runId();
344 if (evt>1) curhist = imodHN(curhist+1);
345 schists[curhist] ->Reset();
346 schistsE[curhist]->Reset();
347 schistsW[curhist]->Reset();
350 gapZhistpos->Reset();
351 gapZhistneg->Reset();
352 if (doSecGaps)
for (
int i=0; i<24; i++) {
354 gapZhistS[i]->Reset();
355 gapZhistposS[i]->Reset();
356 gapZhistnegS[i]->Reset();
361 if (doNtuple && !Calibmode) ntup->Reset();
365 times[curhist] = thistime;
370 SCcorrection =
new TNamed(
"SCcorrection",
371 (St_spaceChargeCorR2C::instance()->getSpaceChargeString()).Data());
372 SCEWRatio =
new TNamed(
"SCEWRatio",Form(
"%f",
373 St_spaceChargeCorR2C::instance()->getEWRatio()));
374 GLcorrection =
new TNamed(
"GLcorrection",Form(
"%f",
375 St_tpcGridLeakC::instance()->MiddlGLStrength()));
376 gMessMgr->Info() <<
"Using the following corrections:" << endm;
377 gMessMgr->Info() <<
"sc = " << SCcorrection->GetTitle() << endm;
378 gMessMgr->Info() <<
"E/W= " << SCEWRatio->GetTitle() << endm;
379 gMessMgr->Info() <<
"GL = " << GLcorrection->GetTitle() << endm;
383 if (thistime == lasttime) evtsnow++;
385 evtstbin[curhist] = evtsnow;
389 <<
"used (for this event) SpaceCharge = "
390 << lastsc <<
" (" << thistime <<
")" << endm;
392 <<
"zdc west+east = "
393 << runinfo->zdcWestRate()+runinfo->zdcEastRate() << endm;
395 <<
"zdc coincidence = "
396 << runinfo->zdcCoincidenceRate() << endm;
400 runinfo->setSpaceCharge(lastsc);
401 runinfo->setSpaceChargeCorrectionMode(m_ExB->GetSpaceChargeMode());
403 if (runinfo->runId() > 10000000) inGapRow = 13;
404 else if (runinfo->runId() > 0) inGapRow = 12;
409 unsigned int i,j,k,v;
413 Double_t emcRadius = 0;
416 if (reqEmcMatch || reqEmcOrTofMatch) {
417 bemcDet =
event->emcCollection()->detector(kBarrelEmcTowerId);
419 if (!emcGeom) emcGeom = StEmcGeom::instance(
"bemc");
420 emcRadius = emcGeom->Radius() + 30;
425 for (v=0; v<numVtxCandidates; v++) {
426 if (TrackInfomode<2) {
427 pvtx =
event->primaryVertex(vtxCandidates[v]);
428 if (! pvtx)
continue;
429 vtxPos = pvtx->position();
430 vtxPosErr = pvtx->positionError();
433 for (i=0; i<nnodes; i++) {
434 for (j=0; j<theNodes[i]->entries(global); j++) {
435 if (QAmode) cutshist->Fill(16);
436 StTrack* tri = theNodes[i]->track(global,j);
438 if (QAmode) cutshist->Fill(17);
442 if (! map.hasHitInDetector(kTpcId))
continue;
443 if (QAmode) cutshist->Fill(18);
447 if ((map.hasHitInDetector(kSvtId) ||
448 map.hasHitInDetector(kPxlId) ||
449 map.hasHitInDetector(kIstId)) && TrackInfomode < 1)
continue;
450 if (QAmode) cutshist->Fill(19);
451 if (map.numberOfHits(kTpcId) < minTpcHits)
continue;
452 if (QAmode) cutshist->Fill(20);
455 Bool_t tofMatch = kFALSE;
456 if (reqTofMatch || reqEmcOrTofMatch) {
457 const StPtrVecTrackPidTraits& theTofPidTraits = tri->pidTraits(kTofId);
458 if (theTofPidTraits.size()) {
459 if (QAmode) cutshist->Fill(21);
460 StTrackPidTraits* theSelectedTrait = theTofPidTraits[theTofPidTraits.size()-1];
461 if (theSelectedTrait) {
462 if (QAmode) cutshist->Fill(22);
465 if (QAmode) cutshist->Fill(23);
470 tofMatch = (Mflag > 0);
475 if (reqTofMatch && !tofMatch)
continue;
477 if (QAmode) cutshist->Fill(24);
480 Bool_t emcMatch = kFALSE;
481 if (reqEmcMatch || (reqEmcOrTofMatch&&(!tofMatch))) {
482 Double_t mEmcThresh = 0.15;
483 Double_t energyBEMC = -100.0;
484 UInt_t tower_eta,tower_mod = 0;
487 if ((emcPosition->
trackOnEmc(&emcTrkPosition,&emcTrkMomentum,
488 tri,runinfo->magneticField()/10.,emcRadius))) {
489 if (QAmode) cutshist->Fill(25);
490 Float_t emcEta = emcTrkPosition.pseudoRapidity();
491 Float_t emcPhi = emcTrkPosition.phi();
492 Int_t m = 0 ,e = 0,s = 0,
id = 0;
493 emcGeom->
getBin(emcPhi,emcEta,m,e,s);
494 if (emcGeom->getId(m,e,s,
id) == 0) {
499 if (tower_mod >= 1 && tower_mod <= 120) {
500 if (QAmode) cutshist->Fill(26);
501 if (event->emcCollection()) {
503 StSPtrVecEmcRawHit& emcHits = emcMod->hits();
504 for (UInt_t emcHit=0; emcHit<emcHits.size(); emcHit++) {
505 if ((emcHits[emcHit]) && (emcHits[emcHit]->eta() == tower_eta)
506 && (emcHits[emcHit]->sub() == tower_sub)) {
507 energyBEMC = emcHits[emcHit]->energy();
511 emcMatch = (energyBEMC >= mEmcThresh);
516 if (!emcMatch)
continue;
518 if (QAmode) cutshist->Fill(27);
523 if (!(xvec.x() || xvec.y() || xvec.z()))
continue;
524 if (QAmode) cutshist->Fill(28);
526 if (!(pvec.x() || pvec.y()))
continue;
527 if (QAmode) cutshist->Fill(29);
529 float oldPt = pvec.perp();
530 if (oldPt < 0.0001)
continue;
531 if (QAmode) cutshist->Fill(30);
534 if (pvec.z() * xvec.z() > 0) e_or_w = ( (xvec.z() > 0) ? 1 : -1 );
538 Float_t eta=pvec.pseudoRapidity();
540 Double_t pathlen = 0;
544 Double_t DCAerr = 0.;
548 DCA3 = dcahh.
distance(vtxPos,kFALSE);
549 DCA2 = dcahh.geometricSignedDistance(vtxPos.x(),vtxPos.y());
552 thelix.
Dca(vtxPos.x(),vtxPos.y(),&DCAerr);
553 phi = TMath::ATan2(dcahh.cy(pathlen),dcahh.
cx(pathlen));
554 if (TrackInfomode>1) {
555 vtxPos.setZ(dcahh.z(pathlen));
559 DCA2 = hh.geometricSignedDistance(vtxPos.x(),vtxPos.y());
560 pathlen = hh.
pathLength(vtxPos.x(),vtxPos.y());
561 phi = TMath::ATan2(hh.cy(pathlen),hh.
cx(pathlen));
562 if (TrackInfomode>1) {
563 vtxPos.setZ(hh.z(pathlen));
567 if (TrackInfomode>1) {
568 if (TMath::Abs(DCA2) > 2)
continue;
570 if (DCA3 > 4)
continue;
572 if (QAmode) cutshist->Fill(31);
573 Int_t ch = (int) triGeom->charge();
576 Int_t sec,sector = -1;
578 Int_t prowmask = 0x0;
580 Double_t rerrors[128];
581 Double_t rphierrors[128];
582 memset(rerrors,0,64*
sizeof(Float_t));
583 memset(rphierrors,0,64*
sizeof(Float_t));
584 StPtrVecHit& hits = tri->detectorInfo()->hits();
585 for (k=0;k<hits.size();k++) {
587 if (hit->detector() == kTpcId) {
590 if ((hit->position().z() > 1 && sec > 12) ||
591 (hit->position().z() <-1 && sec < 13)) PCT++;
592 int lastInner = pads->innerPadRows(sec);
593 if (prow >= lastInner-2 && prow <= lastInner+3) {
594 sector = ( sec == sector || sector < 0 ? sec : 0 );
598 int shifter = prow-(lastInner-1);
599 if (shifter<0) shifter += (inGapRow==12 ? 2 : 1);
600 else if (shifter>3) shifter--;
601 prowmask |= (0x1 << shifter);
604 rs[k] = hit->position().perp();
605 Float_t herr = hit->positionError().perp();
607 rphierrors[k] = herr;
609 if (PCT && TrackInfomode<2)
continue;
610 bool good4gap = (sector > 0) && (prowmask == 0xF);
611 if (QAmode) cutshist->Fill(32);
614 LOG_INFO << Form(
"GOODTRACK %d %d %6.2f %9.4f %8.3f %8.4f %8.4f %6.4f %6.4f %d",
615 runid,event->id(),vtxPos.z(),ch/oldPt,eta,phi,DCA2,DCAerr,
616 vtxPosErr.perp(),hits.size()) << endm;
620 Float_t space = 10000.;
621 Int_t predictFailed = m_ExB->PredictSpaceChargeDistortion(hits.size(),ch,oldPt,vtxPos.z(),
622 eta,phi,DCA2,rs,rerrors,rphierrors,space);
624 if (QAmode) cutshist->Fill(40+predictFailed);
627 if (QAmode) cutshist->Fill(33);
629 TH1F** aschists = (e_or_w > 0 ? schistsW :
630 (e_or_w < 0 ? schistsE : 0));
631 Bool_t doSecSCs = (doSecGaps && sector>0);
634 Double_t spaceErr = TMath::Abs(space*DCAerr/DCA2);
635 Float_t spaceEW = space + lastsc * (e_or_w < 0 ? lastEWRatio : 1.0);
639 ga1.SetParameters(SCX/spaceErr,space,spaceErr);
640 for (Int_t si=1;si<=SCN1;si++) {
641 Double_t sx = schists[curhist]->GetBinCenter(si);
642 if (TMath::Abs((sx-space)/spaceErr) < 4.5) {
644 schists[curhist]->Fill(sx,ga1.Eval(sx));
648 if (aschists || doSecSCs) {
649 ga1.SetParameters(SCX/spaceErr,spaceEW,spaceErr);
650 for (Int_t si=1;si<=SCN1;si++) {
651 Double_t sx = schists[curhist]->GetBinCenter(si);
652 if (TMath::Abs((sx-spaceEW)/spaceErr) < 4.5) {
654 if (aschists) aschists[curhist]->Fill(sx,ga1.Eval(sx));
655 if (doSecSCs) schistS [sector ]->Fill(sx,ga1.Eval(sx));
660 schists[curhist]->Fill(space);
661 if (aschists) aschists[curhist]->Fill(spaceEW);
662 if (doSecSCs) schistS [sector ]->Fill(spaceEW);
664 FillQAHists(DCA2,space,spaceEW,ch,hh,e_or_w);
667 if (doGaps && good4gap &&
668 (e_or_w!=0) && (TMath::Abs(ch)==1) && (oldPt>0.3))
669 FillGapHists(tri,hh,e_or_w,ch);
674 if (QAmode) cutshist->Fill(9);
677 ntrks[curhist] = schists[curhist] ->Integral();
678 ntrksE[curhist] = schistsE[curhist]->Integral();
679 ntrksW[curhist] = schistsW[curhist]->Integral();
680 if (doSecGaps)
for (i=0; i<24; i++) ntrksS[i] = schistS[i]->Integral();
683 int result = DecideSpaceCharge(thistime);
685 if (doGaps) DetermineGaps();
688 static float ntent = 0.0;
689 static float nttrk = 0.0;
691 if (ntent == 0.0) memset(X,0,51*
sizeof(
float));
693 float last_nttrk = nttrk;
694 nttrk = ntrks[curhist];
695 float s0 = ( nttrk ? last_nttrk / nttrk : 0 );
699 gMessMgr->Info() <<
"reset = " << doReset << endm;
700 gMessMgr->Info() <<
"nevts = " << ntent << endm;
701 gMessMgr->Info() <<
"ntrks = " << nttrk << endm;
702 if (doSecGaps)
for (i=0; i<24; i++) {
703 gMessMgr->Info() <<
"ntrks(" << i+1 <<
") = " << ntrksS[i] << endm;
708 int fbin = evt + 1 - ((int) ntent);
711 X[1] = FindPeak(dcehist->ProjectionY(
"_dy",fbin,evt),ee);
712 X[2] = s0*X[2] + s1*runinfo->zdcCoincidenceRate();
713 X[3] = s0*X[3] + s1*runinfo->zdcWestRate();
714 X[4] = s0*X[4] + s1*runinfo->zdcEastRate();
715 X[5] = s0*X[5] + s1*runinfo->bbcCoincidenceRate();
716 X[6] = s0*X[6] + s1*runinfo->bbcWestRate();
717 X[7] = s0*X[7] + s1*runinfo->bbcEastRate();
718 X[8] = s0*X[8] + s1*runinfo->bbcBlueBackgroundRate();
719 X[9] = s0*X[9] + s1*runinfo->bbcYellowBackgroundRate();
720 X[10] = s0*X[10] + s1*runinfo->initialBeamIntensity(blue);
721 X[11] = s0*X[11] + s1*runinfo->initialBeamIntensity(yellow);
722 X[12] = runinfo->beamFillNumber(blue);
723 X[13] = runinfo->magneticField();
724 X[14] =
event->runId();
726 if ((QAmode) && (evt <= EVN)) {
727 X[16] = FindPeak(dcahistN->ProjectionZ(
"_dnz",fbin,evt,1,PHN),ee);
728 X[17] = FindPeak(dcahistP->ProjectionZ(
"_dpz",fbin,evt,1,PHN),ee);
729 X[18] = FindPeak(dcahistE->ProjectionZ(
"_dez",fbin,evt,1,PHN),ee);
730 X[19] = FindPeak(dcahistW->ProjectionZ(
"_dwz",fbin,evt,1,PHN),ee);
732 X[20] = gapZfitslope;
733 X[21] = gapZfitintercept;
734 X[22] = gapZdivslope;
735 X[23] = gapZfitslopeneg;
736 X[24] = gapZfitinterceptneg;
737 X[25] = gapZdivslopeneg;
738 X[26] = gapZfitslopepos;
739 X[27] = gapZfitinterceptpos;
740 X[28] = gapZdivslopepos;
741 X[29] = gapZfitslopeeast;
742 X[30] = gapZfitintercepteast;
743 X[31] = gapZdivslopeeast;
744 X[32] = gapZfitslopewest;
745 X[33] = gapZfitinterceptwest;
746 X[34] = gapZdivslopewest;
747 X[35] = s0*X[35] + s1*runinfo->spaceCharge();
748 X[36] = s0*X[36] + s1*((float) (runinfo->spaceChargeCorrectionMode()));
749 X[37] = s0*X[37] + s1*St_tpcGridLeakC::instance()->MiddlGLStrength();
750 X[38] = s0*X[38] + s1*St_trigDetSumsC::Nc(runinfo->zdcCoincidenceRate(),
751 runinfo->zdcEastRate(),runinfo->zdcWestRate());
752 X[39] = s0*X[39] + s1*St_trigDetSumsC::Nc(runinfo->bbcCoincidenceRate(),
753 runinfo->bbcEastRate(),runinfo->bbcWestRate());
762 X[40] = s0*X[40] + s1*runinfo->backgroundRate();
763 X[41] = s0*X[41] + s1*St_trigDetSumsC::instance()->getPVPDWest();
764 X[42] = s0*X[42] + s1*St_trigDetSumsC::instance()->getPVPDEast();
770 X[43] = s0*X[43] + s1*St_trigDetSumsC::instance()->getCTBOrTOFp();
771 X[44] = s0*X[44] + s1*St_trigDetSumsC::instance()->getCTBWest();
772 X[45] = s0*X[45] + s1*St_trigDetSumsC::instance()->getCTBEast();
778 X[123] = s0*X[123] + s1*St_trigDetSumsC::instance()->getEPDX();
781 X[46] = s0*X[46] + s1*m_ExB->GetConst_0();
782 X[47] = s0*X[47] + s1*m_ExB->GetConst_1();
787 X[50] = s0*X[50] + s1*lastEWRatio*runinfo->spaceCharge();
791 X[52+3*i] = gapZfitslopeS[i];
792 X[53+3*i] = gapZfitinterceptS[i];
796 if (doReset || !Calibmode) ntup->Fill(X);
798 if (doReset) {ntent = 0.0; nttrk = 0.0; }
807 Int_t StSpaceChargeEbyEMaker::DecideSpaceCharge(
int time) {
814 Bool_t QAout = QAmode || PrePassmode;
815 Bool_t do_auto = kTRUE;
816 Bool_t few_stats = kTRUE;
817 Bool_t large_err = kTRUE;
818 Bool_t large_dif = kTRUE;
827 maxdiff = MAXDIFFA - (MAXDIFFA-MAXDIFFE)*oldness(imodHN(curhist-1));
830 int timedif = time-lasttime;
832 gMessMgr->Info() <<
"time since last event = "
834 gMessMgr->Info() <<
"curhist = "
840 Bool_t decideFromData = ((PrePassmode) || (Calibmode) || (lasttime==0) || (timedif < 30));
841 if (decideFromData) {
844 static int iscMax = 1;
845 if (!Calibmode && iscMax<SCHN) iscMax = curhist+1;
846 for (isc=0; isc<iscMax; isc++) {
847 int i = imodHN(curhist-isc);
848 ntrkstot += ntrks[i] * oldness(i);
849 ntrkstotE += ntrksE[i] * oldness(i);
850 ntrkstotW += ntrksW[i] * oldness(i);
852 if (!isc) gMessMgr->Info(
"Building with: i, ni, oi, nt:");
853 gMessMgr->Info() <<
"Building with: " << i <<
", "
854 << ntrks[i] <<
", " << oldness(i) <<
", " << ntrkstot << endm;
855 gMessMgr->Info() <<
"....east with: " << i <<
", "
856 << ntrksE[i] <<
", " << oldness(i) <<
", " << ntrkstotE << endm;
857 gMessMgr->Info() <<
"....west with: " << i <<
", "
858 << ntrksW[i] <<
", " << oldness(i) <<
", " << ntrkstotW << endm;
862 few_stats = (IAttr(
"EastOff") ?
863 (ntrkstotW < MINTRACKS) :
865 (ntrkstotE < MINTRACKS) :
867 (ntrkstotE < MINTRACKS || ntrkstotW < MINTRACKS) :
868 (ntrkstot < MINTRACKS) ) ) );
870 BuildHist(i,schist ,schists );
871 BuildHist(i,schistE,schistsE);
872 BuildHist(i,schistW,schistsW);
873 FindSpaceCharge(schist ,sc ,esc );
874 FindSpaceCharge(schistE,scE,escE);
875 FindSpaceCharge(schistW,scW,escW);
876 if (doSecGaps)
for (
int j=0;j<24;j++) FindSpaceCharge(schistS[j],scS[j],escS[j]);
878 gMessMgr->Info() <<
"sc = " << sc <<
" +/- " << esc << endm;
879 gMessMgr->Info() <<
"scE = " << scE <<
" +/- " << escE << endm;
880 gMessMgr->Info() <<
"scW = " << scW <<
" +/- " << escW << endm;
881 if (doSecGaps)
for (
int j=0;j<24;j++) {
882 gMessMgr->Info() <<
"sc" << Form(
"%2d",j+1) <<
" = " << scS[j] <<
" +/- " << escS[j] << endm;
885 large_err = (esc == 0) || (esc > SCALER_ERROR);
887 if (PrePassmode) { do_auto=kFALSE;
break; }
889 dif = TMath::Abs(sc-lastsc);
890 large_dif = dif > maxdiff;
891 if (!large_dif || Calibmode) {
903 if (QAout && (isc == SCHN)) gMessMgr->Info()
904 <<
"STORED DATA EXHAUSTED: "
905 << SCHN <<
" events" << endm;
915 if (QAout && decideFromData) {
916 if (few_stats) gMessMgr->Info()
917 <<
"(RECENT) STATS TOO FEW: "
918 << ntrkstot <<
" / " << ntrkstotE <<
" / " << ntrkstotW
919 <<
" (" << MINTRACKS <<
")" << endm;
920 else if (large_err) gMessMgr->Info()
921 <<
"FIT ERROR TOO LARGE: "
922 << esc <<
" (" << SCALER_ERROR <<
")" << endm;
923 else if (large_dif) gMessMgr->Info()
924 <<
"DIFFERENCE TOO LARGE: "
925 << dif <<
" (" << maxdiff <<
")" << endm;
927 gMessMgr->Info(
"using auto SpaceCharge");
928 if (Calibmode) doReset = kFALSE;
929 else m_ExB->AutoSpaceChargeR2();
931 gMessMgr->Info() <<
"using SpaceCharge = "
932 << sc <<
" +/- " << esc <<
" (" << time <<
")" << endm;
933 scehist->SetBinContent(evt,sc);
934 scehist->SetBinError(evt,esc);
943 else m_ExB->ManualSpaceChargeR2(sc,lastEWRatio);
948 void StSpaceChargeEbyEMaker::FindSpaceCharge(TH1F* aschist,
float& asc,
float& aesc) {
950 double res = FindPeak(aschist,aesc);
951 asc = (res > -500. ? res : 0.0);
954 double StSpaceChargeEbyEMaker::FindPeak(TH1* hist,
float& pkwidth) {
956 if (!hist)
return -996.;
958 if (hist->Integral() < 100.0)
return -997.;
959 double mn = hist->GetMean();
960 double rms = TMath::Abs(hist->GetRMS());
961 double range = hist->GetXaxis()->GetXmax() - hist->GetXaxis()->GetXmin();
962 mn *= 1.0 + (rms/range); rms *= 1.5;
965 double pmax = TMath::Max(hist->GetMaximum(),0.);
966 double lp = pmax*0.001;
967 double up = pmax*10.0;
968 double lw = rms*0.001;
969 double uw = rms*10.0;
970 ga1.SetParameters(pmax,mn,rms*0.5);
972 ga1.SetParLimits(0,lp,up);
973 ga1.SetParLimits(2,lw,uw);
975 int fitResult = hist->Fit(&ga1,
976 (gROOT->GetVersionInt() >= 53000 ?
"WLRB0Q" :
"LLRB0Q"));
978 ga1.ReleaseParameter(0);
979 ga1.ReleaseParameter(2);
980 if (fitResult != 0)
return -999.;
981 double rp = ga1.GetParameter(0);
982 if (rp == lp || rp == up)
return -998;
983 pkwidth = TMath::Abs(ga1.GetParError(1));
984 return ga1.GetParameter(1);
988 void StSpaceChargeEbyEMaker::InitQAHists() {
990 scehist =
new TH1F(
"SpcChgEvt",
"SpaceCharge fit vs. Event",
992 timehist =
new TH1F(
"EvtTime",
"Event Times",
994 dcehist =
new TH2F(
"DcaEve",
"psDCA vs. Event",
995 EVN,0.,EVN,DCN,DCL,DCH);
996 dcphist =
new TH3F(
"DcaPhi",
"psDCA vs. Phi",
997 PHN,0,PI2,DCN,DCL,DCH,(QAmode ? 3 : 1),-1.5,1.5);
1005 myhist =
new TH3F(
"SpcEvt",
"SpaceCharge vs. Phi vs. Event",
1006 EVN,0.,EVN,PHN,0,PI2,SCN2,SCL,SCH);
1007 dcahist =
new TH3F(
"DcaEvt",
"psDCA vs. Phi vs. Event",
1008 EVN,0.,EVN,PHN,0,PI2,DCN,DCL,DCH);
1009 dczhist =
new TH2F(
"DcaZ",
"psDCA vs. Z",
1011 ZN,ZL,ZH,DCN,DCL,DCH);
1012 myhistN =
new TH3F(
"SpcEvtN",
"SpaceCharge vs. Phi vs. Event Neg",
1013 EVN,0.,EVN,PHN,0,PI2,SCN2,SCL,SCH);
1014 myhistP =
new TH3F(
"SpcEvtP",
"SpaceCharge vs. Phi vs. Event Pos",
1015 EVN,0.,EVN,PHN,0,PI2,SCN2,SCL,SCH);
1016 myhistE =
new TH3F(
"SpcEvtE",
"SpaceCharge vs. Phi vs. Event East",
1017 EVN,0.,EVN,PHN,0,PI2,SCN2,SCL,SCH);
1018 myhistW =
new TH3F(
"SpcEvtW",
"SpaceCharge vs. Phi vs. Event West",
1019 EVN,0.,EVN,PHN,0,PI2,SCN2,SCL,SCH);
1020 dcahistN =
new TH3F(
"DcaEvtN",
"psDCA vs. Phi vs. Event Neg",
1021 EVN,0.,EVN,PHN,0,PI2,DCN,DCL,DCH);
1022 dcahistP =
new TH3F(
"DcaEvtP",
"psDCA vs. Phi vs. Event Pos",
1023 EVN,0.,EVN,PHN,0,PI2,DCN,DCL,DCH);
1024 dcahistE =
new TH3F(
"DcaEvtE",
"psDCA vs. Phi vs. Event East",
1025 EVN,0.,EVN,PHN,0,PI2,DCN,DCL,DCH);
1026 dcahistW =
new TH3F(
"DcaEvtW",
"psDCA vs. Phi vs. Event West",
1027 EVN,0.,EVN,PHN,0,PI2,DCN,DCL,DCH);
1028 cutshist =
new TH1I(
"CutsHist",
"Step at which tracks and events are cut",
1044 if (doNtuple) ntup =
new TNtuple(
"SC",
"Space Charge",
1045 "sc:dca:zdcx:zdcw:zdce:bbcx:bbcw:bbce:bbcbb:bbcyb:intb:inty:fill:mag:run:event:dcan:dcap:dcae:dcaw:gapf:gapi:gapd:gapfn:gapin:gapdn:gapfp:gapip:gapdp:gapfe:gapie:gapde:gapfw:gapiw:gapdw:usc:uscmode:ugl:zdcc:bbcc:vpdx:vpdw:vpde:zdcxnk:zdcwnk:zdcenk:const0:const1:sce:scw:usce:sc1:gapf1:gapi1:sc2:gapf2:gapi2:sc3:gapf3:gapi3:sc4:gapf4:gapi4:sc5:gapf5:gapi5:sc6:gapf6:gapi6:sc7:gapf7:gapi7:sc8:gapf8:gapi8:sc9:gapf9:gapi9:sc10:gapf10:gapi10:sc11:gapf11:gapi11:sc12:gapf12:gapi12:sc13:gapf13:gapi13:sc14:gapf14:gapi14:sc15:gapf15:gapi15:sc16:gapf16:gapi16:sc17:gapf17:gapi17:sc18:gapf18:gapi18:sc19:gapf19:gapi19:sc20:gapf20:gapi20:sc21:gapf21:gapi21:sc22:gapf22:gapi22:sc23:gapf23:gapi23:sc24:gapf24:gapi24:epdx");
1048 gapZhist =
new TH2F(
"Gaps",
"Gaps",GZN,GZL,GZH,GN,GL,GH);
1049 gapZhistneg =
new TH2F(
"Gapsneg",
"Gaps Neg",GZN,GZL,GZH,GN,GL,GH);
1050 gapZhistpos =
new TH2F(
"Gapspos",
"Gaps Pos",GZN,GZL,GZH,GN,GL,GH);
1051 if (doSecGaps)
for (
int i=0; i<24; i++) {
1053 schistS[i] =
new TH1F(Form(
"SpCh%02d",j),Form(
"Space Charge%02d",j),SCN1,SCL,SCH);
1054 gapZhistS[i] =
new TH2F(Form(
"Gaps%02d",j),Form(
"Gaps%02d",j),GZN,GZL,GZH,GN,GL,GH);
1055 gapZhistnegS[i] =
new TH2F(Form(
"Gapsneg%02d",j),Form(
"Gaps Neg%02d",j),GZN,GZL,GZH,GN,GL,GH);
1056 gapZhistposS[i] =
new TH2F(Form(
"Gapspos%02d",j),Form(
"Gaps Pos%02d",j),GZN,GZL,GZH,GN,GL,GH);
1062 void StSpaceChargeEbyEMaker::WriteQAHists() {
1065 if (!(QAmode || doNtuple || doGaps))
return;
1068 gMessMgr->Error(
"StSpaceChargeEbyEMaker: No runid => No output");
1073 runid -= 1000000*(runid/1000000);
1075 TString fname =
"./hists";
1076 if (PrePassmode) fname.Append(
"Pre");
1077 gSystem->cd(fname.Data());
1079 fname = Form(
"Hist%d.root",runid);
1080 f1 = gSystem->Which(
".",fname.Data());
1085 TFile ff(fname.Data(),
"RECREATE");
1106 gapZhistneg->Write();
1107 gapZhistpos->Write();
1108 if (doSecGaps)
for (
int i=0; i<24; i++) {
1109 schistS[i]->Write();
1110 gapZhistS[i]->Write();
1111 gapZhistnegS[i]->Write();
1112 gapZhistposS[i]->Write();
1115 if (doNtuple) ntup->Write();
1117 SCcorrection->Write();
1119 GLcorrection->Write();
1123 gMessMgr->Info() <<
"QA hists file: " << fname.Data() << endm;
1129 void StSpaceChargeEbyEMaker::FillQAHists(
float DCA,
float space,
float spaceEW,
1133 double pl = pls.first;
1134 if (TMath::Abs(pls.second) < TMath::Abs(pls.first)) pl = pls.second;
1136 float Phi = hh_at_pl.phi();
1137 while (Phi < 0) Phi += PI2;
1138 while (Phi >= TMath::TwoPi()) Phi -= PI2;
1143 float evtn = ((float) evt) - 0.5;
1144 dcehist->Fill(evtn,DCA);
1145 dcphist->Fill(Phi,DCA,(
float) e_or_w);
1148 myhist->Fill(evtn,Phi,space);
1149 dcahist->Fill(evtn,Phi,DCA);
1151 myhistP->Fill(evtn,Phi,space);
1152 dcahistP->Fill(evtn,Phi,DCA);
1154 myhistN->Fill(evtn,Phi,space);
1155 dcahistN->Fill(evtn,Phi,DCA);
1158 myhistW->Fill(evtn,Phi,spaceEW);
1159 dcahistW->Fill(evtn,Phi,DCA);
1160 }
else if (e_or_w < 0) {
1161 myhistE->Fill(evtn,Phi,spaceEW);
1162 dcahistE->Fill(evtn,Phi,DCA);
1164 if ((e_or_w != 0) && (TMath::Abs(hh.dipAngle()) < 0.05)) dczhist->Fill(hh_at_pl.z(),DCA);
1168 int StSpaceChargeEbyEMaker::imodHN(
int i) {
1170 return ( i >= SCHN ? imodHN(i-SCHN) : (i < 0 ? imodHN(i+SCHN) : i) );
1173 float StSpaceChargeEbyEMaker::oldness(
int i,
int j) {
1178 if (j<0) j = curhist;
1187 if (times[k] != times[i]) { k = imodHN(k-1);
break; }
1190 float time_factor = (times[j]-times[i]) + (1.-(evtstbin[i]/evtstbin[k]));
1192 float decay_const = -0.12;
1194 s = exp( decay_const * time_factor );
1199 void StSpaceChargeEbyEMaker::BuildHist(
int i, TH1F* aschist, TH1F** aschists) {
1203 aschist->Add(aschists[isc],1.0);
1205 isc = imodHN(isc-1);
1206 aschist->Add(aschists[isc],oldness(isc));
1210 void StSpaceChargeEbyEMaker::SetTableName() {
1216 ux.GetGTime(date,time);
1217 gMessMgr->Info() <<
"first event date = " << date << endm;
1218 gMessMgr->Info() <<
"first event time = " << time << endm;
1219 tabname = Form(
"./StarDb/Calibrations/rich/spaceChargeCorR2.%08d.%06d.C",date,time);
1223 if (TrackInfomode) {
1224 if (TrackInfomode<2)
return;
1226 if (TrackInfomode>2) setMinTpcHits(0);
1230 setReqEmcOrTofMatch(kFALSE);
1231 }
else if (date < 20071000) {
1235 setReqEmcOrTofMatch(kFALSE);
1238 }
else if (date < 20090000) {
1242 setReqEmcOrTofMatch(kFALSE);
1245 }
else if (date < 20100000) {
1250 void StSpaceChargeEbyEMaker::WriteTableToFile(){
1251 gMessMgr->Info() <<
"Writing new table to:\n "
1252 << tabname.Data() << endm;
1253 TString dirname = gSystem->DirName(tabname.Data());
1254 TString estr = dirname;
1255 estr.Prepend(
"mkdir -p ");
1256 gSystem->Exec(estr.Data());
1257 if (gSystem->OpenDirectory(dirname.Data())==0) {
1258 if (gSystem->mkdir(dirname.Data())) {
1259 gMessMgr->Warning() <<
"Directory creation failed for:\n " << dirname
1260 <<
"\n Putting table file in current directory" << endm;
1261 tabname.Remove(0,tabname.Last(
'/')).Prepend(
".");
1264 ofstream *out =
new ofstream(tabname.Data());
1265 SCTable()->SavePrimitive(*out,
"");
1269 St_spaceChargeCor* StSpaceChargeEbyEMaker::SCTable() {
1270 St_spaceChargeCor* table =
new St_spaceChargeCor(
"spaceChargeCorR2",1);
1271 spaceChargeCor_st* row = table->GetTable();
1272 row->fullFieldB = sc;
1273 row->halfFieldB = sc;
1274 row->zeroField = (float) evt;
1275 row->halfFieldA = sc;
1276 row->fullFieldA = sc;
1281 row->ewratio = m_ExB->CurrentSpaceChargeEWRatio();
1286 float StSpaceChargeEbyEMaker::FakeAutoSpaceCharge() {
1288 float zdcsum = runinfo->zdcWestRate()+runinfo->zdcEastRate();
1289 float sc = 6e-8 * zdcsum;
1295 int e_or_w,
int ch) {
1297 float fsign = (
event->runInfo()->magneticField() < 0 ? -1 : 1 );
1298 StPtrVecHit hts = tri->detectorInfo()->hits(kTpcId);
1299 float gap = 0.;
float zgap = 0.;
int ct=0;
1300 float GAPRADIUS = 121.8;
1302 for (UInt_t ht=0; ht<hts.size(); ht++) {
1304 Int_t prow = hit->padrow();
1305 Int_t sec = hit->sector();
1306 int lastInner = pads->innerPadRows(sec);
1307 if ((prow != lastInner) && (prow != lastInner+1))
continue;
1308 float gsign = ( prow > lastInner ? -1 : 1 );
1312 float hphi = hp.phi() + TMath::TwoPi();
1313 while (hphi > TMath::Pi()/12.) hphi -= TMath::Pi()/6.;
1314 if (TMath::Abs(hphi) > 0.75*TMath::Pi()/12.)
break;
1316 float distToOuterRow = pads->radialDistanceAtRow(sec,lastInner+1) - GAPRADIUS;
1317 float distToInnerRow = GAPRADIUS - pads->radialDistanceAtRow(sec,lastInner + inGapRow - 13);
1318 zgap += (hp.z() / (distToInnerRow+distToOuterRow)) *
1319 ( prow == lastInner ? distToOuterRow : distToInnerRow );
1323 Double_t residual = hh.geometricSignedDistance(hp.x(),hp.y());
1325 sector = ( sec == sector || sector < 0 ? sec : 0 );
1326 if (sector == 0)
return;
1327 Double_t sector_angle = (TMath::Pi()/6.) * (sec < 13 ? 3 - sec : sec - 21);
1328 Double_t pathlen = hh.
pathLength(hp.x(),hp.y());
1329 Double_t theta = TMath::ATan2(hh.cy(pathlen),hh.
cx(pathlen)) - sector_angle;
1330 Double_t phi = hp.phi() - sector_angle;
1332 Double_t Eff1 = TMath::Cos(theta);
1336 Float_t x1[3],x2[3];
1337 x1[0] = hp.perp()*TMath::Sin(phi);
1338 x1[1] = hp.perp()*TMath::Cos(phi);
1340 m_ExB->UndoGridLeakDistortion(x1,x2,sec);
1341 Double_t dX = x2[0]-x1[0];
1342 if (TMath::Abs(dX) > 1e-20) {
1345 Eff3 = gsign * ((x2[1]-x1[1])/dX) * TMath::Sin(theta);
1347 m_ExB->UndoGridLeakDistortion(x1,x2,sec);
1348 Eff2 = (x2[0]-x1[0])/dX;
1351 Double_t DistortionX = Eff2 * residual / (Eff1 + Eff3);
1353 gap += fsign * gsign * DistortionX;
1357 sector = (doSecGaps ? sector - 1 : -1);
1358 float abs_zgap = TMath::Abs(zgap);
1359 if ((ct==2) && (abs_zgap<200.0) && (abs_zgap>10.0)) {
1360 gapZhist->Fill(zgap,gap);
1361 if (ch==1) gapZhistpos->Fill(zgap,gap);
1362 else gapZhistneg->Fill(zgap,gap);
1364 gapZhistS[sector]->Fill(zgap,gap);
1365 if (ch==1) gapZhistposS[sector]->Fill(zgap,gap);
1366 else gapZhistnegS[sector]->Fill(zgap,gap);
1369 if (abs_zgap<150 && abs_zgap>25) {
1371 float gap_scaled = (gap * 100.0) / (ZGGRID - abs_zgap);
1373 float z_beyond = ZGGRID+1.0;
1374 gapZhist->Fill(z_beyond,gap_scaled);
1375 if (ch==1) gapZhistpos->Fill(z_beyond,gap_scaled);
1376 else gapZhistneg->Fill(z_beyond,gap_scaled);
1378 gapZhistS[sector]->Fill(z_beyond,gap_scaled);
1379 if (ch==1) gapZhistposS[sector]->Fill(z_beyond,gap_scaled);
1380 else gapZhistnegS[sector]->Fill(z_beyond,gap_scaled);
1386 void StSpaceChargeEbyEMaker::DetermineGaps() {
1387 TString GapStr =
"Gap measurements: fit slope & intercept, div slope";
1390 GapStr +=
"\nneg (by sector):";
1391 for (
int i=0; i<24; i++) {
1392 GapStr += Form(
"\n%2d : ",i+1);
1393 GapStr += DetermineGapHelper(gapZhistnegS[i],gapZfitslopenegS[i],gapZfitinterceptnegS[i],gapZdivslopenegS[i]);
1395 GapStr +=
"\npos (by sector):";
1396 for (
int i=0; i<24; i++) {
1397 GapStr += Form(
"\n%2d : ",i+1);
1398 GapStr += DetermineGapHelper(gapZhistposS[i],gapZfitslopeposS[i],gapZfitinterceptposS[i],gapZdivslopeposS[i]);
1400 GapStr +=
"\nall (by sector):";
1401 for (
int i=0; i<24; i++) {
1402 GapStr += Form(
"\n%2d : ",i+1);
1403 GapStr += DetermineGapHelper(gapZhistS[i],gapZfitslopeS[i],gapZfitinterceptS[i],gapZdivslopeS[i]);
1405 GapStr +=
"\nAll sectors:";
1408 GapStr +=
"\nneg: ";
1409 GapStr += DetermineGapHelper(gapZhistneg,gapZfitslopeneg,gapZfitinterceptneg,gapZdivslopeneg);
1410 GapStr +=
"\npos: ";
1411 GapStr += DetermineGapHelper(gapZhistpos,gapZfitslopepos,gapZfitinterceptpos,gapZdivslopepos);
1412 GapStr +=
"\nall: ";
1413 GapStr += DetermineGapHelper(gapZhist,gapZfitslope,gapZfitintercept,gapZdivslope);
1415 LOG_INFO << GapStr << endm;
1418 TString StSpaceChargeEbyEMaker::DetermineGapHelper(TH2F* gh,
1419 float& fitslope,
float& fitintercept,
float& divslope) {
1421 TString result =
"n/a";
1422 if (gh->GetEntries() < 10) {
1423 fitslope = 0; fitintercept = 0; divslope = 0;
1424 egapZfitslope = 0; egapZfitintercept = 0; egapZdivslope = 0;
1427 ga1.SetParameters(gh->GetEntries()/(16.*2.*10.),0.,0.1);
1428 ga1.SetParLimits(0,0.001,10.0*gh->GetEntries());
1429 gh->FitSlicesY(&ga1,1,0,20,
"LB0Q");
1430 ga1.ReleaseParameter(0);
1431 const char* hn = gh->GetName();
1432 TH1D* GapsChi2 = (TH1D*) gDirectory->Get(Form(
"%s_chi2",hn));
1433 TH1D* GapsAmp = (TH1D*) gDirectory->Get(Form(
"%s_0",hn));
1434 TH1D* GapsMean = (TH1D*) gDirectory->Get(Form(
"%s_1",hn));
1435 TH1D* GapsRMS = (TH1D*) gDirectory->Get(Form(
"%s_2",hn));
1437 divslope = GapsMean->GetBinContent(GZN);
1438 egapZdivslope = TMath::Abs(GapsMean->GetBinError(GZN));
1442 GapsMean->SetBinContent(8,0); GapsMean->SetBinError(8,0);
1443 GapsMean->SetBinContent(9,0); GapsMean->SetBinError(9,0);
1445 ln1.SetRange(-150.,150.);
1446 GapsMean->Fit(&ln1,
"R0Q");
1447 fitslope = ln1.GetParameter(1);
1448 fitintercept = ln1.GetParameter(0);
1452 egapZfitslope = TMath::Abs(ln1.GetParError(1));
1453 egapZfitintercept = TMath::Abs(ln1.GetParError(0));
1455 ln1.SetRange(-150.,0.);
1456 GapsMean->Fit(&ln1,
"R0Q");
1457 gapZfitslopeeast = ln1.GetParameter(1);
1458 gapZfitintercepteast = ln1.GetParameter(0);
1460 ln1.SetRange(0.,150.);
1461 GapsMean->Fit(&ln1,
"R0Q");
1462 gapZfitslopewest = ln1.GetParameter(1);
1463 gapZfitinterceptwest = ln1.GetParameter(0);
1470 result = Form(
"%7.4f+/-%7.4f , %7.4f+/-%7.4f , %7.4f+/-%7.4f",
1471 fitslope,egapZfitslope,fitintercept,egapZfitintercept,
1472 divslope,egapZdivslope);
1476 float StSpaceChargeEbyEMaker::EvalCalib(TDirectory* hdir) {
1479 dcehist =
static_cast<TH2F*
>(hdir->Get(
"DcaEve"));
1480 timehist =
static_cast<TH1F*
>(hdir->Get(
"EvtTime"));
1481 scehist =
static_cast<TH1F*
>(hdir->Get(
"SpcChgEvt"));
1482 if (!(dcehist && timehist && scehist)) {
1483 LOG_ERROR <<
"Problems finding SC histograms" << endm;
1489 float spc = (float) (scehist->GetEntries());
1490 float dcc = (float) (dcehist->GetEntries());
1491 float evc = (float) (timehist->GetEntries());
1493 float hm=0,hw=0,gm=0,gw=0,gm1=0,gw1=0,gme=0,gwe=0,pm=0,pw=0,epsec=0,frac=0,wid=9.99;
1497 TH1D* dcaproj = dcehist->ProjectionY();
1500 ga1.SetParameters(1.,0.,1.);
1501 dcaproj->Fit(&ga1,
"Q");
1502 hm = ga1.GetParameter(1);
1503 hw = TMath::Abs(ga1.GetParameter(2));
1505 ga1.SetRange(hm-hd,hm+hd);
1506 dcaproj->Fit(&ga1,
"RQ");
1507 gm = ga1.GetParameter(1);
1508 gw = TMath::Abs(ga1.GetParameter(2));
1513 ga1.SetRange(gm-0.9*gw,gm+0.9*gw);
1514 dcaproj->Fit(&ga1,
"RQ");
1515 gm = ga1.GetParameter(1);
1516 gw = TMath::Abs(ga1.GetParameter(2));
1517 ga1.SetRange(gm-0.8*gw,gm+0.8*gw);
1518 dcaproj->Fit(&ga1,
"RQ");
1519 gm = ga1.GetParameter(1);
1520 gw = TMath::Abs(ga1.GetParameter(2));
1521 ga1.SetRange(gm-0.7*gw,gm+0.7*gw);
1522 dcaproj->Fit(&ga1,
"RQ");
1523 gm = ga1.GetParameter(1);
1524 gw = TMath::Abs(ga1.GetParameter(2));
1525 gme = TMath::Abs(ga1.GetParError(1));
1526 gwe = TMath::Abs(ga1.GetParError(2));
1529 wid = gw1*gw1+gw*gw;
1530 if (wid>0) wid = TMath::Min(10.,TMath::Log10(wid));
1535 scehist->Fit(
"pol0",
"Q");
1536 pl0 = scehist->GetFunction(
"pol0");
1538 pm = pl0->GetParameter(0);
1539 pw = pl0->GetParError(0);
1544 timehist->GetXaxis()->SetRange(1,(
int) evc);
1545 timehist->Fit(
"pol0",
"LQ");
1546 pl0 = timehist->GetFunction(
"pol0");
1547 if (pl0) epsec = pl0->GetParameter(0);
1555 if (frac<0.2) code = 1. + frac;
1556 else if (wid>0) code = 2. + 0.1*wid;
1558 LOG_INFO << Form(
"SCeval: %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
1559 hm,hw,gm,gw,pm,pw,gm1,gw1,spc,dcc,evc,epsec,gme,gwe) << endm;
1562 LOG_ERROR <<
"CheckFail: Break of SpaceCharge performance! code = " << code << endm;
Bool_t trackOnEmc(StThreeVectorD *position, StThreeVectorD *momentum, const StTrack *const track, Double_t magField, Double_t emcRadius=225.405) const
Track projection utility.
double distance(const StThreeVector< double > &p, bool scanPeriods=true) const
minimal distance between point and helix
double cx(double s) const
pointing vector of helix at point s
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
unsigned char matchFlag() const
Matching information.
virtual const char * GetName() const
special overload
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
double Dca(const double point[3], double *dcaErr=0) const
DCA to given space point (with error matrix)