149 #include "StSvtHitMaker.h"
151 #include "TDataSetIter.h"
152 #include "TObjectSet.h"
153 #include "StMessMgr.h"
154 #include "StMCTruth.h"
160 #include "StDbUtilities/StSvtCoordinateTransform.hh"
161 #include "StDbUtilities/StCoordinates.hh"
163 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
164 #include "StSvtClassLibrary/StSvtData.hh"
165 #include "StSvtClassLibrary/StSvtGeometry.hh"
166 #include "StSvtClassLibrary/StSvtWaferGeometry.hh"
167 #include "StSvtClassLibrary/StSvtT0.hh"
168 #include "StSvtAnalysedHybridClusters.hh"
169 #include "StSvtSimulationMaker/StSvtGeantHits.hh"
171 #include "StEventTypes.h"
172 #include "StDbUtilities/St_svtCorrectionC.h"
173 #include "StDbUtilities/St_svtHybridDriftVelocityC.h"
179 int n = (
char*)&filenameC - (
char*)&iWrite +
sizeof(filenameC);
194 delete mTimeHitResolution;
195 delete mAnodeHitResolution;
196 delete mXHitResolution;
197 delete mYHitResolution;
198 delete mZHitResolution;
199 delete mHitResolution;
204 Int_t StSvtHitMaker::Init()
207 if (Debug()) gMessMgr->Debug() <<
"In StSvtHitMaker::Init() ..." << endm;
209 return StMaker::Init();
214 Int_t StSvtHitMaker::InitRun(
int runumber)
217 if (Debug()) gMessMgr->Debug() <<
"In StSvtHitMaker::InitRun() ..." << endm;
220 if( GetSvtRawData()){
221 gMessMgr->Warning() <<
" No SVT raw data "<< endm;
226 mSvtGeantHitColl = 0;
227 St_DataSet *dataSet2 = GetDataSet(
"StSvtGeantHits");
259 m_x_vs_y =
new TH2F(
"si_x_vs_y",
"X vs Y of Si space points",
260 300,-30,30,300,-30,30);
262 m_x_vs_y->SetYTitle(
"y cm");
263 m_x_vs_y->SetXTitle(
"x cm");
265 mNwaf_no = 2*mSvtData->getNumberOfBarrels();
274 for(
int idbarrel=1; idbarrel<=mSvtData->getNumberOfBarrels();
275 idbarrel++, barrel++){
278 float n_ladders = float(mSvtData->getNumberOfLadders(idbarrel))+0.5;
280 sprintf(title1,
"SvtLayer");
281 sprintf(title2,
"%d", barrel+1);
282 title3 = strcat(title1,title2);
285 m_waf_no[barrel] =
new TH2F(title3,
" Si z vs ladder no.",
286 100,-25.,25.,100,0.5,n_ladders);
287 m_waf_no[barrel]->SetYTitle(
"ladder no");
288 m_waf_no[barrel]->SetXTitle(
"Z cm");
291 sprintf(title1,
"SvtLayer");
292 sprintf(title2,
"%d", barrel+1);
293 title3 = strcat(title1,title2);
294 m_waf_no[barrel] =
new TH2F(title3,
" Si z vs ladder no.",
295 100,-25.,25.,100,0.5,n_ladders);
296 m_waf_no[barrel]->SetYTitle(
"ladder no");
297 m_waf_no[barrel]->SetXTitle(
"Z cm");
301 m_hfile =
new TFile(filenameN,
"RECREATE",
"Clusters");
303 m_ClusTuple =
new TNtuple(
"Clusters",
"Clusters",
"flag:xl:yl:x:y:z:charge:mom2x:mom2y:numAnodes:numPixels:peak:hybrid:evt");
310 if (mSvtGeantHitColl){
312 mTimeHitResolution =
new TH1F(
"hitTRes",
"Delta X for Hits",1000,-2.0,2.0);
313 mAnodeHitResolution =
new TH1F(
"hitARes",
"Delta Z for Hits",1000,-2.0,2.0);
314 mXHitResolution =
new TH1F(
"hitXRes",
"Delta X for Hits",1000,-0.1,0.1);
315 mYHitResolution =
new TH1F(
"hitYRes",
"Delta Y for Hits",1000,-0.1,0.1);
316 mZHitResolution =
new TH1F(
"hitZRes",
"Delta Z for Hits",1000,-0.1,0.1);
317 mHitResolution =
new TH2F(
"hitRes",
"Delta Z Vs Delta X for Hits",1000,-2.0,2.0,1000,-2.0,2.0);
319 mTimeHitResolution->SetXTitle(
"delta X (timebucket)");
320 mAnodeHitResolution->SetXTitle(
"delta Z (anode)");
321 mXHitResolution->SetXTitle(
"delta X (cm)");
322 mYHitResolution->SetXTitle(
"delta Y (cm)");
323 mZHitResolution->SetXTitle(
"delta Z (cm)");
324 mHitResolution->SetXTitle(
"delta X (timebucket)");
325 mHitResolution->SetYTitle(
"delta Z (anode)");
330 TObject *objLast,*objHist;
332 objLast = gDirectory->GetList()->Last();
333 TIter nextHist(gDirectory->GetList());
334 int ready = !objLast;
335 while((objHist=nextHist())) {
336 if (!ready && objHist!=objLast)
continue;
338 if (objHist==objLast)
continue;
339 if (!objHist->InheritsFrom(
"TH1"))
continue;
342 ((TH1*)objHist)->SetDirectory(0);
343 AddHist((TH1*)objHist);
352 Int_t StSvtHitMaker::GetSvtRawData()
356 St_DataSet *dataSet2 = GetDataSet(
"StSvtData");
364 Int_t StSvtHitMaker::GetSvtClusterData()
368 St_DataSet *dataSet2 = GetDataSet(
"StSvtAnalResults");
372 if( !mSvtCluColl)
return kStWarn;
377 Int_t StSvtHitMaker::GetSvtGeometry()
381 dataSet = GetDataSet(
"StSvtGeometry");
383 gMessMgr->Error(
"Failure to get SVT geometry - THINGS HAVE GONE SERIOUSLY WRONG!!!!! \n");
394 Int_t StSvtHitMaker::GetSvtDriftVelocity()
398 dataSet = GetDataSet(
"StSvtDriftVelocity");
400 gMessMgr->Error(
"Failure to get SVT drift velocity - THINGS HAVE GONE SERIOUSLY WRONG!!!!! \n");
411 Int_t StSvtHitMaker::GetSvtDriftCurve()
418 Int_t StSvtHitMaker::GetSvtT0()
422 dataSet = GetDataSet(
"StSvtT0");
424 gMessMgr->Error(
"Failure to get SVT t0 - THINGS HAVE GONE SERIOUSLY WRONG!!!!! \n");
437 if (Debug()) gMessMgr->Debug() <<
"In StSvtHitMaker::Make() ..." << endm;
440 if( GetSvtRawData()){
441 gMessMgr->Warning() <<
" No SVT raw data" << endm;
445 if( GetSvtClusterData()){
446 gMessMgr->Warning() <<
" No SVT Cluster data" << endm;
451 gMessMgr->Warning() <<
" Things are wrong with the SVT database!!!!!!!!!" << endm;
454 TransformIntoSpacePoint();
465 void StSvtHitMaker::TransformIntoSpacePoint(){
467 int index, TotHits=0, GoodHit=0;
474 if(m_geom) SvtGeomTrans.setParamPointers(m_geom, mSvtData->getSvtConfig(), m_driftVeloc, m_driftCurve, m_t0,driftVelocityCor );
485 for(
int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
487 for (
int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
489 for (
int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
491 for (
int hybrid = 1;hybrid <=mSvtData->getNumberOfHybrids();hybrid++){
494 index = mSvtData->getHybridIndex(barrel,ladder,wafer,hybrid);
495 if(index < 0)
continue;
496 if (! driftVel->p(barrel,ladder,wafer,hybrid))
continue;
498 if( !mSvtBigHit)
continue;
500 for(
int clu=0; clu<mSvtBigHit->numOfHits(); clu++){
501 if (! driftVel->IsValidDriftRegion(barrel,ladder,wafer,hybrid, mSvtBigHit->WaferPosition()[clu].x()))
continue;
503 mSvtBigHit->svtHitData()[clu].id = TotHits;
504 waferCoord.setTimeBucket(mSvtBigHit->WaferPosition()[clu].x());
505 waferCoord.setAnode(mSvtBigHit->WaferPosition()[clu].y());
506 waferCoord.setLayer(mSvtBigHit->getLayerID());
507 waferCoord.setLadder(ladder);
508 waferCoord.setWafer(wafer);
509 waferCoord.setHybrid(hybrid);
512 SvtGeomTrans(waferCoord,localCoord);
513 SvtGeomTrans(localCoord,globalCoord);
520 mPos.setX(globalCoord.position().x());
521 mPos.setY(globalCoord.position().y());
522 mPos.setZ(globalCoord.position().z());
523 mSvtBigHit->svtHit()[clu].setPosition(mPos);
524 mSvtBigHit->svtHitData()[clu].uv[0] = localCoord.position().x();
525 mSvtBigHit->svtHitData()[clu].uv[1] = localCoord.position().y();
526 mSvtBigHit->svtHitData()[clu].anode = waferCoord.anode();
527 mSvtBigHit->svtHitData()[clu].timeb = waferCoord.timebucket();
533 Int_t hw_position, svtx, svty;
538 pEvent->setSvtHitCollection(svtHitColl);
546 hw_position += (1L<<4)*(index2);
547 svtx = int(waf->x()*4);
548 hw_position += (1L<<13)*(svtx);
549 svty = int(waf->y()*4);
550 hw_position += (1L<<22)*svty;
551 svtHit->setHardwarePosition(hw_position);
552 svtHit->setIdTruth(hit->idTruth(),hit->qaTruth());
554 svtHit->setPeak(dat->peakAdc);
555 svtHit->setCharge(hit->charge());
556 svtHit->setFlag(hit->flag());
557 if (driftVelocityCor) {
558 if (! driftVelocityCor->pCorrection(svtHit->layer(), svtHit->ladder(), svtHit->wafer(), svtHit->hybrid()))
559 svtHit->setFlag(hit->flag()+100);
561 svtHit->setFitFlag(0);
562 svtHit->setPosition(mSvtBigHit->svtHit()[clu].position());
563 svtHit->setId(dat->id);
564 svtHit->setLocalPosition(dat->uv[0],dat->uv[1]);
565 svtHit->setAnode(dat->anode);
566 svtHit->setTimebucket(dat->timeb);
567 svtHit->setNumberOfAnodes(dat->numOfAnodesInClu);
568 svtHit->setNumberOfPixels(dat->numOfPixelsInClu);
570 svtHitColl->addHit(svtHit);
573 if(mSvtBigHit->svtHit()[clu].flag() < 4) GoodHit++;
576 SaveIntoNtuple(mSvtBigHit->numOfHits(),index);
585 SafeDelete(driftVelocityCor);
586 gMessMgr->Info() <<
"Found " << GoodHit <<
" good hits " << endm;
590 Int_t StSvtHitMaker::FillHistograms(){
595 for(
int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
597 for (
int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
599 for (
int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
601 for (
int hybrid = 1;hybrid <=mSvtData->getNumberOfHybrids();hybrid++){
604 index = mSvtData->getHybridIndex(barrel,ladder,wafer,hybrid);
605 if(index < 0)
continue;
608 if( !mSvtBigHit)
continue;
610 for(
int clu=0; clu<mSvtBigHit->numOfHits(); clu++){
612 if( mSvtBigHit->svtHit()[clu].flag() < 4){
613 int layer = mSvtBigHit->getLayerID()-1;
614 int ladder = (int)(mSvtBigHit->svtHit()[clu].ladder());
616 m_x_vs_y->Fill(mSvtBigHit->svtHit()[clu].position().x(),mSvtBigHit->svtHit()[clu].position().y());
617 m_waf_no[layer]->Fill(mSvtBigHit->svtHit()[clu].position().z(),ladder,1);
629 void StSvtHitMaker::SaveIntoNtuple(
int numOfClusters,
int index)
632 for(
int i=0; i<numOfClusters; i++){
633 if( mSvtBigHit->svtHit()[i].flag() < 255)
635 mSvtBigHit->WaferPosition()[i].x(),
636 mSvtBigHit->WaferPosition()[i].y(),
637 mSvtBigHit->svtHit()[i].position().x(),
638 mSvtBigHit->svtHit()[i].position().y(),
639 mSvtBigHit->svtHit()[i].position().z(),
640 mSvtBigHit->svtHit()[i].charge(),
641 mSvtBigHit->svtHitData()[i].mom2[0],
642 mSvtBigHit->svtHitData()[i].mom2[1],
643 mSvtBigHit->svtHitData()[i].numOfAnodesInClu,
644 mSvtBigHit->svtHitData()[i].numOfPixelsInClu,
645 mSvtBigHit->svtHitData()[i].peakAdc,
647 mSvtData->getEventNumber());
669 Int_t StSvtHitMaker::Eval()
671 for(
int barrel = 1;barrel <= mSvtData->getNumberOfBarrels();barrel++) {
672 for (
int ladder = 1;ladder <= mSvtData->getNumberOfLadders(barrel);ladder++) {
673 for (
int wafer = 1;wafer <= mSvtData->getNumberOfWafers(barrel);wafer++) {
674 for (
int hybrid = 1;hybrid <=mSvtData->getNumberOfHybrids();hybrid++){
676 int index = mSvtData->getHybridIndex(barrel,ladder,wafer,hybrid);
677 if(index < 0)
continue;
680 if( !mSvtBigHit)
continue;
683 if( !mSvtGeantHit)
continue;
685 for(
int clu=0; clu<mSvtBigHit->numOfHits(); clu++){
687 float tim = mSvtBigHit->WaferPosition()[clu].x();
688 float anod = mSvtBigHit->WaferPosition()[clu].y();
690 float diffTime = 0,diffAnode = 0, diffX = 0, diffY = 0, diffZ = 0;
692 for(
int gHit = 0; gHit < mSvtGeantHit->numberOfHits(); gHit++){
695 diffTime = tim - mSvtGeantHit->waferCoordinate()[gHit].timebucket();
696 diffAnode = anod - mSvtGeantHit->waferCoordinate()[gHit].anode();
697 diffX = mSvtBigHit->svtHit()[clu].position().x() - mSvtGeantHit->globalCoordinate()[gHit].position().x();
698 diffY = mSvtBigHit->svtHit()[clu].position().y() - mSvtGeantHit->globalCoordinate()[gHit].position().y();
699 diffZ = mSvtBigHit->svtHit()[clu].position().z() - mSvtGeantHit->globalCoordinate()[gHit].position().z();
701 if ((fabs(tim - mSvtGeantHit->waferCoordinate()[gHit].timebucket()) < fabs(diffTime)) &&
702 (fabs(anod - mSvtGeantHit->waferCoordinate()[gHit].anode()) < fabs(diffAnode))) {
704 diffTime = tim - mSvtGeantHit->waferCoordinate()[gHit].timebucket();
705 diffAnode = anod - mSvtGeantHit->waferCoordinate()[gHit].anode();
706 diffX = mSvtBigHit->svtHit()[clu].position().x() - mSvtGeantHit->globalCoordinate()[gHit].position().x();
707 diffY = mSvtBigHit->svtHit()[clu].position().y() - mSvtGeantHit->globalCoordinate()[gHit].position().y();
708 diffZ = mSvtBigHit->svtHit()[clu].position().z() - mSvtGeantHit->globalCoordinate()[gHit].position().z();
713 mTimeHitResolution->Fill(diffTime);
714 mAnodeHitResolution->Fill(diffAnode);
715 mXHitResolution->Fill(diffX);
716 mYHitResolution->Fill(diffY);
717 mZHitResolution->Fill(diffZ);
718 mHitResolution->Fill(diffTime,diffAnode);
731 if (Debug()) gMessMgr->Debug() <<
"In StSvtHitMaker::Finish() ..."
738 delete m_hfile; m_hfile=0;
745 void StSvtHitMaker::SetFileNames(
const char* filen,
const char* filec){
751 double StSvtHitMaker::LaserTemperatureCorrection() {
757 double driftVelocityChange;
758 int barrel,ladder,wafer,hybrid;
764 driftVelocityChange=1.0;
770 index= mSvtData->getHybridIndex(barrel,ladder,wafer,hybrid);
774 return driftVelocityChange;
779 for(
int clu=0; clu<mSvtBigHit->numOfHits(); clu++){
784 tbin=mSvtBigHit->WaferPosition()[clu].x();
785 anode=mSvtBigHit->WaferPosition()[clu].y();
786 if((tbin>123)&&(tbin<125)&&(anode>195)&&( anode<197)) tbin1=tbin;
787 if((tbin>95)&&(tbin<98)&&(anode>198)&&(anode<201)) tbin2=tbin;
790 if((tbin1>0)&&(tbin2>0)&&(tbin1!=tbin2)) driftVelocityChange=27.03/(tbin1-tbin2);
794 cout <<
"Missing laser spot(s):" << endl;
795 cout <<
"spot 1 status " << tbin1 << endl;
796 cout <<
"spot 2 status " << tbin2 << endl;
797 return driftVelocityChange;
800 return driftVelocityChange;
TNtuple * m_ClusTuple
ladder no vs z of Si hit
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual const char * GetName() const
special overload
int mNwaf_no
x vs y of Si points
TH2F ** m_waf_no
size of following array