20 #include "StGlobals.hh"
21 #include "StMatrix.hh"
22 #include "Randomize.h"
27 #include "StCoordinates.hh"
28 #include "StTpcCoordinateTransform.hh"
32 #include "StTpcSimpleGeometry.hh"
33 #include "StTpcSimpleSlowControl.hh"
34 #include "StTpcSimpleElectronics.hh"
35 #include "StSimpleMagneticField.hh"
36 #include "StTrsDeDx.hh"
39 #include "StTrsFastChargeTransporter.hh"
40 #include "StTrsSlowAnalogSignalGenerator.hh"
41 #include "StTrsFastDigitalSignalGenerator.hh"
44 #include "StTrsChargeSegment.hh"
45 #include "StTrsMiniChargeSegment.hh"
46 #include "StTrsAnalogSignal.hh"
47 #include "StTrsWireBinEntry.hh"
48 #include "StTrsWireHistogram.hh"
50 #include "StTrsSector.hh"
51 #include "StTrsDigitalSector.hh"
54 #include "StTrsRawDataEvent.hh"
55 #include "StTrsUnpacker.hh"
56 #include "StSequence.hh"
59 #include "g2t_tpc_hit.hh"
63 void whichSector(
int volId,
int* isDet,
int* sector,
int* padrow){
67 *isDet = (volId/100000);
69 volId -= (*isDet)*100000;
72 volId -= (*sector)*100;
80 cout <<
"Histogram" << endl;
85 string fname =
"hbook";
86 StHbookFile *hbookFile =
87 new StHbookFile(fname.c_str());
91 const int tupleSize1 = 5;
92 float tuple[tupleSize1];
93 StHbookTuple *theTuple =
94 new StHbookTuple(
"data", tupleSize1);
95 *theTuple <<
"sec" <<
"row" <<
"pad" <<
"amp" <<
"t" << book;
98 const int tupleSize2 = 5;
99 float tuple2[tupleSize2];
100 StHbookTuple *secTuple =
101 new StHbookTuple(
"dedx", tupleSize2);
103 *secTuple <<
"sec" <<
"row" <<
"x" <<
"y" <<
"z" << book;
110 cout <<
"*********************************************" << endl;
111 cout <<
"Try Initialize" << endl;
112 string geoFile(
"../run/TPCgeo.conf");
113 if (access(geoFile.c_str(),R_OK)) {
114 cerr <<
"ERROR:\n" << geoFile.c_str() <<
" cannot be opened" << endl;
116 cerr <<
"Exitting..." << endl;
120 string scFile =
"../run/sc.conf";
121 if (access(scFile.c_str(),R_OK)) {
122 cerr <<
"ERROR:\n" << scFile.c_str() <<
" cannot be opened" << endl;
123 cerr <<
"Exitting..." << endl;
127 string electronicsFile =
"../run/electronics.conf";
128 if (access(electronicsFile.c_str(),R_OK)) {
129 cerr <<
"ERROR:\n" << electronicsFile.c_str() <<
" cannot be opened" << endl;
130 cerr <<
"Exitting..." << endl;
134 string magFile =
"../run/example.conf";
135 if (access(magFile.c_str(),R_OK)) {
136 cerr <<
"ERROR:\n" << magFile.c_str() <<
" cannot be opened" << endl;
137 cerr <<
"Exitting..." << endl;
145 StTpcSimpleGeometry::instance(geoFile.c_str());
149 StTpcSimpleSlowControl::instance(scFile.c_str());
152 StSimpleMagneticField::instance(magFile.c_str());
155 StTpcSimpleElectronics::instance(electronicsFile.c_str());
168 StTrsWireHistogram::instance(mGeometryDb, mSlowControlDb);
171 mWireHistogram->setGasGainInnerSector(2000);
172 mWireHistogram->setGasGainOuterSector(1000);
173 mWireHistogram->setDoTimeDelay(
false);
182 StTrsUnpacker *mUnPacker =
new StTrsUnpacker;
190 StTrsFastChargeTransporter::instance(mGeometryDb, mSlowControlDb, mGasDb, mMagneticFieldDb);
192 mChargeTransporter->setChargeAttachment(
true);
193 mChargeTransporter->setGatingGridTransparency(
false);
196 mChargeTransporter->setExB(
false);
200 StTrsSlowAnalogSignalGenerator::instance(mGeometryDb, mSlowControlDb, mElectronicsDb, mSector);
205 setChargeDistribution(StTrsSlowAnalogSignalGenerator::endo);
212 setElectronicSampler(StTrsSlowAnalogSignalGenerator::symmetricGaussianApproximation);
217 mAnalogSignalGenerator->setDeltaRow(0);
218 mAnalogSignalGenerator->setDeltaPad(2);
219 mAnalogSignalGenerator->setSignalThreshold(1.*(.001*volt));
220 mAnalogSignalGenerator->setSuppressEmptyTimeBins(
true);
221 mAnalogSignalGenerator->addNoise(
false);
222 mAnalogSignalGenerator->generateNoiseUnderSignalOnly(
false);
223 mAnalogSignalGenerator->setNoiseRMS(900.);
226 StTrsFastDigitalSignalGenerator::instance(mElectronicsDb, mSector);
233 cout <<
"Processing" << endl;
235 int bisdet, bsectorOfHit, bpadrow;
245 ifstream ifs(
"/data/stix/event_14.txt",ios::in);
251 int firstSectorToProcess = 1;
252 int lastSectorToProcess = 1;
253 PR(firstSectorToProcess);
254 PR(lastSectorToProcess);
260 int currentSectorProcessed = firstSectorToProcess;
261 int lastSectorProcessed = currentSectorProcessed;
265 int numberOfPointsInWirePlane = 0;
267 int no_tpc_hits = 400000;
274 cout <<
"--> tpc_hit: " << i << endl;
275 ifs >> tpc_hit.volume_id
280 if(ifs.eof() || ifs.bad())
break;
282 whichSector(tpc_hit.volume_id, &bisdet, &bsectorOfHit, &bpadrow);
287 if(bsectorOfHit >= firstSectorToProcess)
292 if(bsectorOfHit <= lastSectorToProcess)
300 if(i != no_tpc_hits)
continue;
307 (bsectorOfHit == currentSectorProcessed)) {
317 double GEANTDriftLength = 208.55119*centimeter;
318 double GEANTOffSet = mGeometryDb->frischGrid() - GEANTDriftLength;
325 double zPosition = tpc_hit.x[2]*centimeter;
330 tpc_hit.x[1]*centimeter,
331 tpc_hit.x[2]*centimeter);
348 double beta = (bsectorOfHit>12) ?
349 -bsectorOfHit*M_PI/6 :
350 bsectorOfHit*M_PI/6 ;
352 double xp = hitPosition.x()*cos(beta) - hitPosition.y()*sin(beta);
353 double yp = hitPosition.x()*sin(beta) + hitPosition.y()*cos(beta);
356 sector12Coordinate(xp*centimeter,
368 (fabs(tpc_hit.de*GeV)),
369 tpc_hit.ds*centimeter,
373 tuple2[0] =
static_cast<float>(bsectorOfHit);
374 tuple2[1] =
static_cast<float>(bpadrow);
375 tuple2[2] =
static_cast<float>(sector12Coordinate.x());
376 tuple2[3] =
static_cast<float>(sector12Coordinate.y());
377 tuple2[4] =
static_cast<float>(sector12Coordinate.z());
378 secTuple->fill(tuple2);
384 #ifndef ST_NO_TEMPLATE_DEF_ARGS
387 vector<int,allocator<int> > all[3];
390 #ifndef ST_NO_TEMPLATE_DEF_ARGS
391 list<StTrsMiniChargeSegment> comp;
392 list<StTrsMiniChargeSegment>::iterator iter;
394 list<StTrsMiniChargeSegment,allocator<StTrsMiniChargeSegment> > comp;
395 list<StTrsMiniChargeSegment,allocator<StTrsMiniChargeSegment> >::iterator iter;
401 aSegment.split(mGasDb, mMagneticFieldDb, breakNumber, &comp);
404 #ifndef ST_NO_TEMPLATE_DEF_ARGS
412 for(iter = comp.begin();
419 mChargeTransporter->transportToWire(*iter);
426 #ifndef __sun // Bug in the sun iterators. Must Explicitly dereference!
432 mWireHistogram->addEntry(anEntry);
445 numberOfPointsInWirePlane++;
450 if(numberOfPointsInWirePlane) {
451 cout <<
"Processing Sector: " << currentSectorProcessed << endl;
456 cout <<
"--->inducedChargeOnPad()..." << endl;
457 mAnalogSignalGenerator->inducedChargeOnPad(mWireHistogram);
459 cout <<
"--->sampleAnalogSignal()..." << endl;
460 mAnalogSignalGenerator->sampleAnalogSignal();
470 mDigitalSignalGenerator->fillSector(aDigitalSector);
474 cout <<
"--->digitizeSignal()..." << endl;
475 mDigitalSignalGenerator->digitizeSignal();
484 mAllTheData->mSectors[(currentSectorProcessed-1)] = aDigitalSector;
489 mWireHistogram->clear();
491 numberOfPointsInWirePlane = 0;
494 PR(currentSectorProcessed);
495 currentSectorProcessed = bsectorOfHit;
497 PR(currentSectorProcessed);
517 cout <<
"Try Access the data!" << endl;
520 PR(mAllTheData->mSectors.size());
521 for(
int isector=1; isector<=24; isector++) {
522 int getSectorStatus =
523 mUnPacker->getSector(isector,
524 static_cast<StTpcRawDataEvent*>(mAllTheData));
528 if(getSectorStatus)
continue;
531 unsigned char* padList;
532 for(
int irow=1; irow<=45; irow++) {
536 int numberOfPads = mUnPacker->getPadList(irow, &padList);
542 for(
int ipad = 0; ipad<numberOfPads; ipad++) {
545 PR(static_cast<int>(padList[ipad]));
551 int getSequencesStatus =
552 mUnPacker->getSequences(irow, padList[ipad], &nseq, &listOfSequences);
554 PR(getSequencesStatus);
558 for(
int kk=0; kk<nseq; kk++) {
560 PR(listOfSequences[kk].length);
561 PR(listOfSequences[kk].startTimeBin);
563 for(
int zz=0; zz<listOfSequences[kk].length; zz++) {
564 cout <<
" " << kk <<
" " << zz <<
'\t'
565 <<
'\t' <<
static_cast<int>(*(listOfSequences[kk].firstAdc)) << endl;
566 tuple[0] =
static_cast<float>(isector);
567 tuple[1] =
static_cast<float>(irow);
568 tuple[2] =
static_cast<float>(padList[ipad]);
569 tuple[3] =
static_cast<float>(
static_cast<int>(*(listOfSequences[kk].firstAdc)));
570 tuple[4] =
static_cast<float>(listOfSequences[kk].startTimeBin+zz);
571 theTuple->fill(tuple);
573 listOfSequences[kk].firstAdc++;
589 cout <<
"Got to the end of the maker" << endl;
592 cout <<
"Save and close " << endl;
593 hbookFile->saveAndClose();