69 #include "Stl3RawReaderMaker.h"
70 #include "St_DataSetIter.h"
71 #include "StMessMgr.h"
72 #include "StDAQMaker/StDAQReader.h"
73 #include "StDaqLib/L3/L3_Reader.hh"
74 #include "tables/St_l3RunSummary_Table.h"
75 #include "tables/St_l3AlgorithmInfo_Table.h"
76 #include "StEventTypes.h"
81 #include "St_l3_Coordinate_Transformer.h"
82 #include "St_l3_Coordinates.h"
86 extern "C" {
void gufld(Float_t *, Float_t *);}
97 Stl3RawReaderMaker::~Stl3RawReaderMaker(){
102 Int_t Stl3RawReaderMaker::Init(){
112 mNumberOfGl3Nodes = 0;
113 mNumberOfAlgorithms = 0;
117 for (
int i=0; i<MaxNumberOfGl3Nodes; i++) {
118 mGlobalCounter[i].nProcessed = 0;
119 mGlobalCounter[i].nReconstructed = 0;
120 for (
int j=0; j<MaxNumberOfAlgorithms; j++) {
121 mAlgorithmCounter[i][j].algId = 0;
122 mAlgorithmCounter[i][j].nProcessed = 0;
123 mAlgorithmCounter[i][j].nAccept = 0;
124 mAlgorithmCounter[i][j].nBuild = 0;
129 return StMaker::Init();
141 gMessMgr->Info(
"Stl3RawReaderMaker: Now we start l3RawReader Maker.");
146 DAQReaderSet = GetDataSet(
"StDAQReader");
148 gMessMgr->Error() <<
"Stl3RawReaderMaker::Make(): no DaqReader found!" << endm;
154 ml3reader = daqReader->getL3Reader();
164 if (ml3reader->getGlobalTrackReader())
165 gMessMgr->Info() << ml3reader->getGlobalTrackReader()->getNumberOfTracks()
166 <<
" global tracks found." << endm;
167 if (ml3reader->getSl3ClusterReader(sec))
168 gMessMgr->Info() << ml3reader->getSl3ClusterReader(sec)->getNumberOfClusters()
169 <<
" sl3 clusters found in sec " << sec << endm;
170 if (ml3reader->getSl3TrackReader(sec))
171 gMessMgr->Info() << ml3reader->getSl3TrackReader(sec)->getNumberOfTracks()
172 <<
" sl3 tracks found in sec " << sec << endm;
173 if (ml3reader->getI960ClusterReader(sec))
174 gMessMgr->Info() << ml3reader->getI960ClusterReader(sec)->getNumberOfClusters()
175 <<
" i960 clusters found in sec " << sec << endm;
181 gMessMgr->Info(
"Stl3RawReaderMaker: Fill StEvent.");
182 if (fillStEvent() != 0) {
183 gMessMgr->Error(
"Stl3RawReaderMaker: problems filling l3 into StEvent.");
190 gMessMgr->Info(
"Stl3RawReaderMaker: Embedding Mode, check L3 bias.");
191 return checkL3Bias();
195 gMessMgr->Error(
"Stl3RawReaderMaker: Unknown mode, return kStWarn");
207 gMessMgr->Warning(
"Stl3RawReaderMaker: L3 is ON, but no l3 data found in this event. Either DAQ has not send us this event or we crashed during online analysis.");
214 gMessMgr->Warning(
"Stl3RawReaderMaker: no l3 data found.");
230 Int_t Stl3RawReaderMaker::checkL3Bias()
236 gMessMgr->Error(
"Stl3RawReaderMaker: L3 is ON, but L3 summary data is missing!");
237 gMessMgr->Error(
"Stl3RawReaderMaker: ==> This event is bad, skip it!");
244 if (ml3reader->getL3_Summary()->on == 0) {
245 gMessMgr->Warning(
"Stl3RawReaderMaker: L3 crashed online on this event, no usefull information.");
246 gMessMgr->Warning(
"Stl3RawReaderMaker: ==> This event is WEIRD, but definitely unbiased!");
251 mNumberOfAlgorithms = gl3Reader->getNumberofAlgorithms();
266 for (
int i=0; i<mNumberOfAlgorithms; i++) {
267 if ( (algData[i].algId==10 || algData[i].algId==1)
268 && ml3reader->getL3_P()->trg_word>0x0fff
269 && ml3reader->getL3_P()->trg_word<0x2000
270 && algData[i].build==1 ) {
273 printf(
"L0 trigger word: %x\n", ml3reader->getL3_P()->trg_word);
274 printf(
"pass-thru algorithm Id: %i\n", algData[i].algId);
286 Int_t Stl3RawReaderMaker::fillStEvent()
290 mStEvent = (
StEvent *) GetInputDS(
"StEvent");
292 gMessMgr->Error(
"Stl3RawReaderMaker: No StEvent");
298 if (!myStL3Trigger) {
299 gMessMgr->Error(
"Stl3RawReaderMaker: No Stl3Trigger.");
302 mStEvent->setL3Trigger(myStL3Trigger);
306 if (!ml3reader->getL3_SUMD()) {
307 gMessMgr->Warning(
"Stl3RawReaderMaker: No L3_SUMD bank.");
308 myStL3Trigger->setL3EventSummary(NULL);
312 if (!ml3reader->getL3_Summary()) {
313 gMessMgr->Warning(
"Stl3RawReaderMaker: No l3 summary.");
314 myStL3Trigger->setL3EventSummary(NULL);
320 if (ml3reader->getL3_Summary()->on == 0) {
321 gMessMgr->Warning(
"Stl3RawReaderMaker: L3 crashed online on this event, no usefull information.");
322 myStL3Trigger->setL3EventSummary(NULL);
328 if (!myEventSummary) {
329 gMessMgr->Error(
"Stl3RawReaderMaker: No Stl3EventSummary.");
334 myStL3Trigger->setL3EventSummary(myEventSummary);
340 gMessMgr->Error(
"Stl3RawReaderMaker: L3 is ON, but L3 summary data is missing!");
345 mDbSet = GetDataBase(
"RunLog/l3");
351 if (l3runSummaryTable) {
352 l3RunSummary_st*
data = (l3RunSummary_st* )l3runSummaryTable->GetArray();
353 mNumberOfGl3Nodes = data->nGl3Nodes;
355 gMessMgr->Info() <<
"database: runNumber = " << data->runNumber << endm;
356 gMessMgr->Info() <<
"database: nGl3Nodes = " << data->nGl3Nodes << endm;
359 if (mNumberOfGl3Nodes>MaxNumberOfGl3Nodes) {
360 gMessMgr->Error() <<
"Stl3RawReaderMaker: number of gl3 nodes too high: db -> " << mNumberOfGl3Nodes
361 <<
" max -> " << MaxNumberOfGl3Nodes << endm;
366 mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
367 gMessMgr->Warning(
"Stl3RawReaderMaker: no table entry for this run in 'l3RunSummary' found!");
368 gMessMgr->Warning(
"Stl3RawReaderMaker: using default values.");
372 mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
373 gMessMgr->Warning(
"Stl3RawReaderMaker: no database 'Runlog/l3' found!");
374 gMessMgr->Warning(
"Stl3RawReaderMaker: using default values.");
378 int gl3Id = ml3reader->getGl3Id();
381 mNumberOfAlgorithms = gl3Reader->getNumberofAlgorithms();
384 if (mNumberOfAlgorithms >= MaxNumberOfAlgorithms) {
385 gMessMgr->Error() <<
"Stl3RawReaderMaker: number of algorithms exceeds limit: found "
386 << mNumberOfAlgorithms <<
", limit " << MaxNumberOfAlgorithms
390 if (gl3Id<=0 || gl3Id>= MaxNumberOfGl3Nodes) {
391 gMessMgr->Error() <<
"Stl3RawReaderMaker: gl3 id exceeds limit: found "
392 << gl3Id <<
", limit " << MaxNumberOfGl3Nodes
405 mGlobalCounter[gl3Id-1].nProcessed = gl3Reader->getNumberOfProcessedEvents();
406 mGlobalCounter[gl3Id-1].nReconstructed = gl3Reader->getNumberOfReconstructedEvents();
409 for (
int i=0; i<mNumberOfAlgorithms; i++) {
410 mAlgorithmCounter[gl3Id-1][i].algId = algData[i].algId;
411 mAlgorithmCounter[gl3Id-1][i].nProcessed = algData[i].nProcessed;
412 mAlgorithmCounter[gl3Id-1][i].nAccept = algData[i].nAccept;
413 mAlgorithmCounter[gl3Id-1][i].nBuild = algData[i].nBuild;
419 const int maxAlg = mNumberOfAlgorithms;
424 totalCounter.nProcessed = 0;
425 totalCounter.nReconstructed = 0;
426 for (
int i=0; i<mNumberOfAlgorithms; i++) {
427 totalAlgCounter[i].algId = 0;
428 totalAlgCounter[i].nProcessed = 0;
429 totalAlgCounter[i].nAccept = 0;
430 totalAlgCounter[i].nBuild = 0;
433 for (
int i=0; i<mNumberOfGl3Nodes; i++) {
436 if (mGlobalCounter[i].nProcessed==0 && mEventCounter<(2*mNumberOfGl3Nodes)) {
437 totalCounter.nProcessed = -1;
438 totalCounter.nReconstructed = -1;
439 for (
int j=0; j<mNumberOfAlgorithms; j++) {
440 totalAlgCounter[j].algId = mAlgorithmCounter[gl3Id-1][j].algId;
441 totalAlgCounter[j].nProcessed = -1;
442 totalAlgCounter[j].nAccept = -1;
443 totalAlgCounter[j].nBuild = -1;
449 totalCounter.nProcessed += mGlobalCounter[i].nProcessed;
450 totalCounter.nReconstructed += mGlobalCounter[i].nReconstructed;
451 for (
int k=0; k<mNumberOfAlgorithms; k++) {
452 totalAlgCounter[k].algId = mAlgorithmCounter[gl3Id-1][k].algId;
453 totalAlgCounter[k].nProcessed += mAlgorithmCounter[i][k].nProcessed;
454 totalAlgCounter[k].nAccept += mAlgorithmCounter[i][k].nAccept;
455 totalAlgCounter[k].nBuild += mAlgorithmCounter[i][k].nBuild;
464 myEventSummary->setCounters(totalCounter.nProcessed, totalCounter.nReconstructed);
465 myEventSummary->setNumberOfTracks(ml3reader->getL3_Summary()->nTracks);
466 myEventSummary->setL0TriggerWord(ml3reader->getL3_P()->trg_word);
472 l3AlgorithmInfo_st* dbAlgInfo = 0;
475 if (l3algorithmInfoTable) {
476 dbAlgInfo = (l3AlgorithmInfo_st* )l3algorithmInfoTable->GetArray();
478 for (
int i=0; i<l3algorithmInfoTable->
GetNRows(); i++) {
479 cout <<
" run \tidxAlg\talgId\tpreScale\tpostScale" << endl;
480 cout << dbAlgInfo[i].runNumber
481 <<
"\t" << dbAlgInfo[i].idxAlg
482 <<
"\t" << dbAlgInfo[i].algId
483 <<
"\t" << dbAlgInfo[i].preScale
484 <<
"\t" << dbAlgInfo[i].postScale << endl;
485 cout <<
" GI: " << dbAlgInfo[i].GI1 <<
" " << dbAlgInfo[i].GI2 <<
" " << dbAlgInfo[i].GI3
486 <<
" " << dbAlgInfo[i].GI4 <<
" " << dbAlgInfo[i].GI5 << endl;
487 cout <<
" GF: " << dbAlgInfo[i].GF1 <<
" " << dbAlgInfo[i].GF2 <<
" " << dbAlgInfo[i].GF3
488 <<
" " << dbAlgInfo[i].GF4 <<
" " << dbAlgInfo[i].GF5 << endl;
489 cout <<
"------------" << endl;
493 if (l3algorithmInfoTable->
GetNRows()!=mNumberOfAlgorithms) {
494 gMessMgr->Warning() <<
"Stl3RawReaderMaker: Warning: database entries don't match raw data!" << endm;
495 gMessMgr->Warning() <<
"Stl3RawReaderMaker: db nAlgorithms: " << l3algorithmInfoTable->
GetNRows()
496 <<
", raw data: " << mNumberOfAlgorithms
498 gMessMgr->Warning() <<
"Stl3RawReaderMaker: Skip database info for this event." << endm;
503 gMessMgr->Warning(
"Stl3RawReaderMaker: No entry for this run found in table 'l3algorithmInfo'.");
507 for (
int i=0; i<mNumberOfAlgorithms; i++) {
509 if (!myL3AlgorithmInfo) {
510 gMessMgr->Error(
"Stl3RawReaderMaker: No StL3AlgorithmInfo.");
513 myL3AlgorithmInfo->setCounters(totalAlgCounter[i].nProcessed,
514 totalAlgCounter[i].nAccept,
515 totalAlgCounter[i].nBuild);
524 if ( (algData[i].algId==10 || algData[i].algId==1)
525 && ml3reader->getL3_P()->trg_word>0x0fff
526 && ml3reader->getL3_P()->trg_word<0x2000
527 && algData[i].build==1 ) {
529 passThruId = algData[i].algId;
531 cout <<
"pass-thru algorithm Id: " << passThruId << endl;
535 myEventSummary->setUnbiasedTrigger();
540 if (dbAlgInfo && dbAlgInfo[i].algId==totalAlgCounter[i].algId) {
541 myL3AlgorithmInfo->setPreScale(dbAlgInfo[i].preScale);
542 myL3AlgorithmInfo->setPostScale(dbAlgInfo[i].postScale);
543 int intPara[IntParameterSize] = {dbAlgInfo[i].GI1, dbAlgInfo[i].GI2,
544 dbAlgInfo[i].GI3, dbAlgInfo[i].GI4,
546 float floatPara[FloatParameterSize] = {dbAlgInfo[i].GF1, dbAlgInfo[i].GF2,
547 dbAlgInfo[i].GF3, dbAlgInfo[i].GF4,
549 myL3AlgorithmInfo->setParameters(intPara, floatPara);
551 if (dbAlgInfo[i].algId==passThruId)
552 myEventSummary->setUnbiasedTriggerPreScale(dbAlgInfo[i].preScale);
555 myEventSummary->addAlgorithm(myL3AlgorithmInfo);
560 delete [] totalAlgCounter;
565 if (ml3reader->getGlobalTrackReader()) {
569 vertex vert = ml3reader->getGlobalTrackReader()->getVertex();
571 myL3Vertex->setPosition(*pos);
572 myStL3Trigger->addPrimaryVertex(myL3Vertex);
574 if (fillStEventWithL3GlobalTracks()!=0)
return 1;
589 Int_t Stl3RawReaderMaker::fillStEventWithL3GlobalTracks()
592 StSPtrVecTrackNode& myTrackNodeVector = myStL3Trigger->trackNodes();
593 StSPtrVecTrackDetectorInfo& myTrackDetectorInfoVector = myStL3Trigger->trackDetectorInfo();
596 int numberOfTracks = ml3reader->getGlobalTrackReader()->getNumberOfTracks();
597 gMessMgr->Info() <<
"Stl3RawReaderMaker: Try to fill " << numberOfTracks <<
" tracks into StEvent." << endm;
600 globalTrack* globalL3Tracks = ml3reader->getGlobalTrackReader()->getTrackList();
603 Float_t xval[3] = {0.,0.,0.};
606 int signOfField = bval[2] < 0 ? -1 : 1;
608 for (
int trackindex=0; trackindex<numberOfTracks; trackindex++) {
610 detectorInfo->setNumberOfPoints(globalL3Tracks[trackindex].nHits,kTpcId);
611 myTrackDetectorInfoVector.push_back(detectorInfo);
615 globalL3Tracks[trackindex].r0 * TMath::Sin(globalL3Tracks[trackindex].phi0),
616 globalL3Tracks[trackindex].z0);
618 globalL3Tracks[trackindex].pt * TMath::Sin(globalL3Tracks[trackindex].psi),
619 globalL3Tracks[trackindex].pt * globalL3Tracks[trackindex].tanl );
621 globalL3Tracks[trackindex].psi,
623 atan(globalL3Tracks[trackindex].tanl),
628 globalTrack->setFlag(globalL3Tracks[trackindex].flag);
629 globalTrack->setLength(globalL3Tracks[trackindex].length);
630 globalTrack->setDetectorInfo(detectorInfo);
631 globalTrack->setGeometry(helixModel);
633 int l3word = kL3FitId + (1<<l3Standard);
635 globalTrack->setEncodedMethod(l3word);
638 short h = globalTrack->geometry()->charge()*signOfField > 0 ? -1 : 1;
639 globalTrack->geometry()->setHelicity(h);
642 double curv = fabs(0.0003 * bval[2] / globalL3Tracks[trackindex].pt);
643 globalTrack->geometry()->setCurvature(curv);
646 if (globalL3Tracks[trackindex].dedx > 0) {
648 globalL3Tracks[trackindex].ndedx,
649 globalL3Tracks[trackindex].dedx*1e6, 0);
650 globalTrack->addPidTraits(myStDedxPidTraits);
655 trackNode->addTrack(globalTrack);
656 myTrackNodeVector.push_back(trackNode);
678 Int_t Stl3RawReaderMaker::fillStEventWithi960Hits()
682 myStL3Trigger->setTpcHitCollection(mHitCollection);
686 transformer.Print_parameters() ;
691 Int_t totalcluster = 0 ;
692 for ( Int_t secindex=1 ; secindex<=24 ; secindex+=2 )
694 if ( ml3reader->getI960ClusterReader(secindex)->getClusterList() )
696 gMessMgr->Info() <<
"Stl3RawReaderMaker: Found some i960 clusters in sector:" << secindex <<endm ;
697 L3_Cluster* myl3cluster = ml3reader->getI960ClusterReader(secindex)->getClusterList() ;
698 Int_t numOfClusters = ml3reader->getI960ClusterReader(secindex)->getNumberOfClusters() ;
700 for (Int_t clindex=0 ; clindex < numOfClusters ; clindex++)
704 Double_t pad = ((Double_t)(myl3cluster[clindex].pad)) / 64 ;
705 Double_t time = ((Double_t)(myl3cluster[clindex].time)) / 64 ;
706 Int_t row = myl3cluster[clindex].padrow ;
707 Int_t q = myl3cluster[clindex].charge ;
708 Char_t flag = myl3cluster[clindex].flags ;
711 Int_t RBMZ = myl3cluster[clindex].RB_MZ ;
712 Int_t
rb = RBMZ >> 4 ;
713 Int_t mz = RBMZ & 15 ;
717 if (rb<=6) { sector = secindex; }
else { sector = secindex+1; }
720 PTRS.Setptrs((Double_t) pad, (Double_t) time,(Double_t) row, (Double_t) sector) ;
721 transformer.raw_to_global(PTRS,XYZ) ;
726 cout << XYZ.Getx() <<
"\t" << XYZ.Gety() <<
"\t" << XYZ.Getz() <<
"\t";
727 cout << row <<
"\t" << sector <<
"\t" << rb <<
"\t" << mz <<
"\t" << q <<
"\t";
728 cout << ((Double_t)(myl3cluster[clindex].pad)) / 64 <<
"\t" ;
729 cout << ((Double_t)(myl3cluster[clindex].time)) / 64 <<
"\t" ;
730 cout << (Int_t)(myl3cluster[clindex].padrow) <<
"\n" ;
741 if ( row >=1 && row <=45 ) { hrow = row << 9 ; }
else { hrow=0 ; }
742 if ( sector >=1 && sector <=24 ) { hsec = sector << 4 ; }
else { hsec=0 ; }
749 tpcHit->setFlag(flag) ;
751 if (tpcHit) { mHitCollection->addHit(tpcHit) ;}
else {
delete tpcHit;
return 1;}
755 cout <<
"total found clusters " << totalcluster << endl;
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual TDataSet * Find(const char *path) const