//////////////////////////////////////////// // StaLandAdapter interface // generic interface to Root/Trees // e.d.f revision 04/2012 // // Author: sebastian.kupny@uj.edu.pl //////////////////////////////////////////// #include "StaLandAdapter.h" using namespace sta; ClassImp(PaddleCalParam); ClassImp(StaAdapter); PaddleCalParam::PaddleCalParam():rDiff(0),rWidth(0),rLambda(0),rChannel2MeV(0),rTimeOffset(0), rQdc1Gain(0),rQdc2Gain(0),rQdc1Offset(0),rQdc2Offset(0),rQdcDiff(0) { }; PaddleCalParam::~PaddleCalParam() { }; void PaddleCalParam::print() { cout << "[Diff=" << rDiff; cout << ", Width=" << rWidth; cout << ", Lambda=" << rLambda; cout << ", Channel12MeV=" << rChannel2MeV; cout << ", TimeOffset=" << rTimeOffset; cout << ", rQdc1Gain=" << rQdc1Gain; cout << ", rQdc2Gain=" << rQdc2Gain; cout << ", rQdc1Offset=" << rQdc1Offset; cout << ", rQdc2Offset=" << rQdc2Offset; cout << ", rQdcDiff=" << rQdcDiff; cout << "]"; } StaAdapter::StaAdapter() { //rTempLandEvtStaIn = new TRootLANDEventStaInput(); rAreParameterConfigured = kFALSE; rVerboseLevel = 0; rGlobalTimeOffsetForAllPaddles = 0; ///Added 2012.07.03 }; StaAdapter::~StaAdapter() { //delete rTempLandEvtStaIn; }; void StaAdapter::configure ( string configFile1, string configFile2 ) { fStaPrepareParameters( configFile1, configFile2 ); rAreParameterConfigured = kTRUE; } //void StaAdapter::calculate ( TRootLANDEventStaOutput *A_landEvtOut, const TRootLANDEvent * A_rootLandEv, TRandom2 *A_randomNumberGeneratort) //{ // // fStaPrepareData( rTempLandEvtStaIn, A_rootLandEv , A_randomNumberGeneratort); // fStaCalculate(A_landEvtOut, rTempLandEvtStaIn); // // return; //} /// Function fStaPrepareData is just for get data from object TRootLANDEvent and present them as an input for STA algorithm. /// So in this case the function plays a role of adapter for the different kind of data presentation. ///If you add random number generator as a parameter that means you want to generate random events (test mode). void StaAdapter::fStaPrepareData(TRootLANDEventStaInput *A_landEvtStaIn, const TRootLANDEvent * A_rootLandEvt, TRandom2 *A_randomNumberGenerator) { /// TODO: Here Using information from A_rootLandEvt fill the A_landEvtStaIn. Int_t verboseLevel = rVerboseLevel; Double_t LandDistanceFromTarget = rLandDistanceFromTarget; ///[cm] Double_t DistanceBetweenVetoAndFirstPlane = rDistanceBetweenVetoAndFirstPlane; ///[cm] Double_t LandAngleFromBeamLine_thetaY = rLandAngleFromBeamLine_thetaY; ///[deg] if ( verboseLevel > 9 ) cout << "-I STA: Log: LandDistanceFromTarget = " << LandDistanceFromTarget << endl; if ( verboseLevel > 9 ) cout << "-I STA: Log: DistanceBetweenVetoAndFirstPlane = " << DistanceBetweenVetoAndFirstPlane << endl; if ( verboseLevel > 9 ) cout << "-I STA: Log: LandAngleFromBeamLine_thetaY = " << LandAngleFromBeamLine_thetaY << endl; Double_t L = 200; ///[cm] Paddle length ///Double_t c = 15.74; ///[ cm/ns] speed of light in paddle Double_t Pi = M_PI; /// 3.1415; Int_t Nhits = A_rootLandEvt->rawmulti; ///Given parameters from TRootLANDEvent Double_t t1 = 0; ///time from PT [ns] Double_t t2 = 0; ///time from PT [ns] Double_t e1 = 0; Double_t e2 = 0; Double_t qdc1 = 0; Double_t qdc2 = 0; ///Variables which are input for the algorithm (those are here calculated) Double_t x = 0.; Double_t y = 0.; Double_t z = 0.; Double_t t = 0.; Double_t e = 0.; Int_t p = 0; Double_t qdc1norm = 0.; Double_t qdc2norm = 0.; ///Additional parameters Double_t xLand = 0.; Double_t yLand = 0.; Double_t zLand = 0.; Int_t PlaneNo = 0; Int_t PaddleNoInPlane = 0; Int_t PlaneThickness = 10; ///[cm] ///TODO: Need to be set //(With space in between paddles should be about 10.1 cm) ///Recalculation of the angle Double_t thetaY_rad = LandAngleFromBeamLine_thetaY * TMath::DegToRad(); Double_t sin_angle = sin ( thetaY_rad); Double_t cos_angle = cos ( thetaY_rad ); Int_t acceptedHits = 0; for ( Int_t i = 0; i < Nhits; i++) { if ( (A_randomNumberGenerator == NULL) ) { if ( verboseLevel > 2 ) cout << "-I STA: " << "# New Hit in PadID[hitNo=" << i << "]=" << A_rootLandEvt->padID[i] << "\t"; ///Validation the input data if ( A_rootLandEvt->tcal1[i] <= 0 || A_rootLandEvt->tcal2[i] <= 0 ) { if ( verboseLevel > 2 ) cout << "-I STA: " << "- Hit not accepted." << endl; continue; } if ( verboseLevel > 2 ) cout << "-I STA: " << "- Hit accepted:" << endl; PlaneNo = Int_t ((A_rootLandEvt->padID[i]) / 100 ); PaddleNoInPlane = (A_rootLandEvt->padID[i]) % 100; t1 = A_rootLandEvt->tcal1[i] - rLandConfigParam[PlaneNo][PaddleNoInPlane].rDiff; t2 = A_rootLandEvt->tcal2[i] + rLandConfigParam[PlaneNo][PaddleNoInPlane].rDiff; qdc1 = A_rootLandEvt->qdc1[i]; qdc2 = A_rootLandEvt->qdc2[i]; if ( verboseLevel > 3 ) cout << "-I STA: " << " PaddleID = " << A_rootLandEvt->padID[i] << " (" << PlaneNo << ", "<< PaddleNoInPlane <<")" << endl; if ( PlaneNo % 2 == 0 && PlaneNo > 0 ) /// Horizontal plane. assuming that plane No. 0 is Veto { ///cout << "Horizontal plane" << endl; xLand = (t1-t2)*rLandConfigParam[PlaneNo][PaddleNoInPlane].rWidth; yLand = (PaddleNoInPlane - 9.5) * PlaneThickness; /// 9.5 => 10 paddles to left - 0.5 for centering hit in center of paddle } else /// Vertical plane { ///cout << "Vertical plane" << endl; xLand = (PaddleNoInPlane - 9.5) * PlaneThickness; yLand = (t1-t2)*rLandConfigParam[PlaneNo][PaddleNoInPlane].rWidth; if (PlaneNo == 0) ///For Veto there's reverses orientation { yLand = -yLand; } } zLand = (PlaneNo + 0.5) * PlaneThickness; ///Validation calculated localization if (( xLand > 110. || xLand < -110. ) || ( yLand > 110. || yLand < -110. ) ) { continue; } ///For debuging only: tempLandX = xLand; tempLandY = yLand; tempLandZ = zLand; ///Transformations to LAB coordinate system ///Transform. No 1 //xLand = - xLand; ///Transform. No 2 /* zLand += LandDistanceFromTarget; if ( PlaneNo == 0) ///+ correction for Veto position { zLand -= DistanceBetweenVetoAndFirstPlane; } */ ///Transform. No 3 /* x = zLand * sin_angle + xLand * cos_angle; y = yLand; z = zLand * cos_angle - xLand * sin_angle; */ x = xLand; y = yLand; z = zLand; ///TODO: Need to be corrected qdc1norm = ((qdc1- rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdc1Offset)* rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdc1Gain )/rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdcDiff; qdc2norm = ((qdc2- rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdc2Offset)* rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdc2Gain)*rLandConfigParam[PlaneNo][PaddleNoInPlane].rQdcDiff; e1 = qdc1norm; e2 = qdc2norm; t = 0.5*( t1 + t2 ) + rLandConfigParam[PlaneNo][PaddleNoInPlane].rTimeOffset ; ///TODO: Set the correct sign for time offset correction + or - t += rGlobalTimeOffsetForAllPaddles; ///To synchronize Land event with other detectors (with real lab time) p = PlaneNo; e = sqrt(e1*e2)*exp( L/(2.*rLandConfigParam[PlaneNo][PaddleNoInPlane].rLambda)); e *= rLandConfigParam[PlaneNo][PaddleNoInPlane].rChannel2MeV; /// rescale to proper energy scale ///For debuging only: tempLand2X = x; tempLand2Y = y; tempLand2Z = z; } else ///For testing this function and STA algorithm, when random generator is given as parameter. { x = 10*A_randomNumberGenerator->Rndm(); y = 10*A_randomNumberGenerator->Rndm(); z = 10*A_randomNumberGenerator->Rndm(); t = 10*A_randomNumberGenerator->Rndm(); e = 10*A_randomNumberGenerator->Rndm(); p = (Int_t)(10*A_randomNumberGenerator->Rndm()); //acceptedHits = i; } A_landEvtStaIn->fX[acceptedHits] = x; A_landEvtStaIn->fY[acceptedHits] = y; A_landEvtStaIn->fZ[acceptedHits] = z; A_landEvtStaIn->fTime[acceptedHits] = t; A_landEvtStaIn->fEnergy[acceptedHits] = e; A_landEvtStaIn->fPlane[acceptedHits] = p; A_landEvtStaIn->fPaddle[acceptedHits] = PaddleNoInPlane; //A_landEvtStaIn->fQdc1[acceptedHits] = qdc1; //A_landEvtStaIn->fQdc2[acceptedHits] = qdc2; //A_landEvtStaIn->fQdc1norm[acceptedHits] = qdc1norm; //A_landEvtStaIn->fQdc2norm[acceptedHits] = qdc2norm; if ( verboseLevel > 3 ) cout << "-I STA: " << " For this Paddle: Param[rDiff]=" << rLandConfigParam[PlaneNo][PaddleNoInPlane].rDiff; if ( verboseLevel > 3 ) cout << ",Param[rWidth]=" << rLandConfigParam[PlaneNo][PaddleNoInPlane].rWidth; if ( verboseLevel > 3 ) cout << ",Param[rLambda]=" << rLandConfigParam[PlaneNo][PaddleNoInPlane].rLambda; if ( verboseLevel > 3 ) cout << ",Param[rChannel2MeV]=" << rLandConfigParam[PlaneNo][PaddleNoInPlane].rChannel2MeV; if ( verboseLevel > 3 ) cout << ",Param[rTimeOffset]=" << rLandConfigParam[PlaneNo][PaddleNoInPlane].rTimeOffset << endl; if ( verboseLevel > 3 ) cout << "-I STA: " << " t1=" << t1 << ", t2=" << t2 << ", qdc1=" << qdc1 << ", qdc2=" << qdc2 << endl; if ( verboseLevel > 2 ) cout << "-I STA: " << " Calculated[hit No=" << i << " (x="<< x << ",y=" << y << ",z=" << z << "), e=" << e << ",t=" << t << ",p=" << p << "]" << endl; if ( verboseLevel > 2 ) cout << "-I STA: " << " InA_landEvtStaIn[" << "(fX="<< A_landEvtStaIn -> fX [ acceptedHits ] << ",fY=" << A_landEvtStaIn -> fY [ acceptedHits ] << ",fZ=" << A_landEvtStaIn -> fZ [ acceptedHits ] << ")"; //if ( verboseLevel > 2 ) cout << ", qdc1=" << A_landEvtStaIn -> fQdc1[ acceptedHits ] << ", qdc2="<< A_landEvtStaIn -> fQdc2 [ acceptedHits ] <<"]"; if ( verboseLevel > 2 ) cout << endl; acceptedHits++; } if ( verboseLevel > 4 ) cout << "-I STA: " << "## Accepted hits:" << acceptedHits << "/" << Nhits << endl; A_landEvtStaIn->fNHit = acceptedHits; }; /// This function reads data from TRootLANDEventStaInput object, calls sta algorithm and wirte the result to the TRootLANDEventStaOutput. void StaAdapter::fStaCalculate(TRootLANDEventStaOutput *A_landEvtOut, const TRootLANDEventStaInput *A_landEvtIn) { Int_t verboseLevel = 0; LandEvent evt; Int_t Nhits = A_landEvtIn->fNHit; Float_t x = 0.; Float_t y = 0.; Float_t z = 0.; Float_t t = 0.; Float_t e = 0.; Float_t p = 0.; /// 1. Initialize for(int i = 0; i < Nhits ; i++){ x = 0.; y = 0.; z = 0.; t = 0.; e = 0.; p = 0.; x = A_landEvtIn->fX[i]; y = A_landEvtIn->fY[i]; z = A_landEvtIn->fZ[i]; t = A_landEvtIn->fTime[i]; e = A_landEvtIn->fEnergy[i]; p = A_landEvtIn->fPlane[i]; evt.AddHit ( x, y, z, t, e, p ); if ( verboseLevel > 2 ) cout << "-I STA: " << "addHit[" << Nhits << " ("<< x << "," << y << "," << z << "), e=" << e << ",t=" << t << ",p=" << p << "]" << endl; } Int_t n = evt.GetNhit(); if ( verboseLevel > 2 ) cout << "-I STA: " << "Land Event stored hits = " << n << endl; /// 2. Launching algorithm STA::AVE(&evt); /// 3. Fill the output Int_t numberOfClusters = evt.GetMult(); for(Int_t i = 0; i < numberOfClusters; i++) { A_landEvtOut->fCharge[i] = evt.GetParticle(i)->GetCharge() ; A_landEvtOut->fEnergy[i] = evt.GetParticle(i)->GetEnergy(); A_landEvtOut->fRapidity[i] = evt.GetParticle(i)->GetRapidity(); A_landEvtOut->fTheta[i] = evt.GetParticle(i)->GetTheta(); A_landEvtOut->fPhi[i] = evt.GetParticle(i)->GetPhi(); //A_landEvtOut->fVX = evt->GetHit(i)->GetPosition().X; //A_landEvtOut->fVY = evt->GetHit(i)->GetPosition().Y; //A_landEvtOut->fVZ = evt->GetHit(i)->GetPosition().Z; } A_landEvtOut->fNClusters = numberOfClusters; /* Int_t clusterIndex = 0; for(Int_t i = 0; i < n; i++) { if( evt[i] -> IsPrimary() ){ A_landEvtOut->fCharge[clusterIndex] = evt[i]->GetCharge(); A_landEvtOut->fVX[clusterIndex] = evt[i]->GetPosition().X; A_landEvtOut->fVY[clusterIndex] = evt[i]->GetPosition().Y; A_landEvtOut->fVZ[clusterIndex] = evt[i]->GetPosition().Z; if ( verboseLevel > 0 ) cout << evt[i]->GetPosition().X << " " << evt[i]->GetPosition().Y << " " << evt[i]->GetPosition().Z << endl; if ( verboseLevel > 0 ) cout <<"Charge:=" << evt[i]->GetCharge()<< ", "; if ( verboseLevel > 0 ) cout << "wrt@[" << A_landEvtOut->fCharge[clusterIndex] << " ("<< A_landEvtOut->fVX[clusterIndex] << "," << A_landEvtOut->fVY[clusterIndex] << "," << A_landEvtOut->fVZ[clusterIndex] << ")]" << endl; clusterIndex++; } } A_landEvtOut->fNClusters = clusterIndex; */ }; /// Print configuration parameters stored in container rLandConfigParam. void StaAdapter::printConfigurationsParameters() { cout << "-I STA: " << "Container was initialized from config files: " << rAreParameterConfigured << " (1:yes, 0:no)" << endl; cout << "-I STA: " << "Global time offset for LAND: " << rGlobalTimeOffsetForAllPaddles << endl; for ( Int_t iplane = 0; iplane < rPlaneNo; iplane++ ) { for ( Int_t ipaddle = 0; ipaddle < rPaddlesInPlaneNo; ipaddle++ ) { cout << "Padde [" << iplane<<"][" << ipaddle<< "]:"; rLandConfigParam[iplane][ipaddle].print(); cout << endl; } } } void StaAdapter::fStaRadFromFile_DiffAndWidth(string configFileWithDiffAndWidth ) { /// Read from file 1 if ( configFileWithDiffAndWidth.length() > 0 ){ cout << "-I STA: " << "STA Land configuration procedure read Width and Diff from file " << configFileWithDiffAndWidth << "...\t\t"; string line; ifstream file ( configFileWithDiffAndWidth.c_str() ); int paddle = 0; int plane = 0; float width = 0; float diff = 0; int returnValue = 0; if (file.is_open()) { while ( file.good() ) { getline (file,line); returnValue = sscanf(line.c_str(), "%d %d %f %f", &plane, &paddle, &diff, &width); plane +=1; ///Because in config file fouttime_all.dat plane with No 0 is the first plane, and here we take 0-plane for veto. ///24.06.2012 TODO: Check that ! if ( returnValue == 4 ) { rLandConfigParam[plane][paddle].rDiff = diff; rLandConfigParam[plane][paddle].rWidth = width ; } if ( rVerboseLevel > 1 ) cout << "-I STA: " << line << ". LineParsingReturnValue = " << returnValue << endl; if ( rVerboseLevel > 1 ) cout << "-I STA: " << "plane= " << plane<< ", paddle= " << paddle<<", width= " << width<<", diff= " << diff<< endl; } file.close(); for(int iPaddle = 0; iPaddle < rPaddlesInPlaneNo; iPaddle++) ///For Veto (with plane index = 0) { rLandConfigParam[0][iPaddle].rDiff = 0.; rLandConfigParam[0][iPaddle].rWidth = 0.5 * 15.74 ;///half of the speed of light in paddle } cout << " DONE " << endl; } else{ cout << "-I STA: " << "FILED: Unable to open file"; } } return; } //______________________________________________________________________ void StaAdapter::fStaRadFromFile_QDiffAndGain(string configFileWithQDiffAndGain ) { /// Read from file 2 if ( configFileWithQDiffAndGain.length() > 0 ){ cout << "-I STA: " << "STA Land configuration procedure read gains from file " << configFileWithQDiffAndGain << "...\t\t"; string line; ifstream file ( configFileWithQDiffAndGain.c_str() ); int paddle = 0; int plane = 0; float param1 = 0; float param2 = 0; float param3 = 0; float param4 = 0; float param5 = 0; float param6 = 0; int returnValue = 0; if (file.is_open()) { while ( file.good() ) { getline (file,line); returnValue = sscanf(line.c_str(), "%d %d %f %f %f %f %f %f", &plane, &paddle, ¶m1, ¶m2, ¶m3, ¶m4, ¶m5, ¶m6 ); plane +=1; ///Because in config file fout_all.dat plane with No 0 is the first plane, and here we take 0-plane for veto. if ( returnValue == 8 ) { ///rLandConfigParam[plane][paddle].? = param?; TODO: Fulfil that rLandConfigParam[plane][paddle].rQdc1Gain = param1; rLandConfigParam[plane][paddle].rQdc1Offset = param2; rLandConfigParam[plane][paddle].rQdc2Gain = param3; rLandConfigParam[plane][paddle].rQdc2Offset = param4; rLandConfigParam[plane][paddle].rQdcDiff = param5; /// param6 not used } if ( rVerboseLevel > 1 ) cout << "-I STA: " << line << ". LineParsingReturnValue = " << returnValue << endl; if ( rVerboseLevel > 1 ) cout << "-I STA: " << "plane= " << plane<< ", paddle= " << paddle; if ( rVerboseLevel > 1 ) cout << ", param1=" << param1 << ", param2=" << param2 << ", param3=" << param3; if ( rVerboseLevel > 1 ) cout << ", param4=" << param4 << ", param5=" << param5 << ", param6=" << param6 << endl; } file.close(); for(int iPaddle = 0; iPaddle < rPaddlesInPlaneNo; iPaddle++) ///For Veto (with plane index = 0) { ///rLandConfigParam[0][iPaddle].? = 0.; TODO: Fulfil that } cout << " DONE " << endl; } else{ cout << "-I STA: " << "FILED: Unable to open file"; } } return; } //______________________________________________________________________ void StaAdapter::fStaRadFromFile_Offset( string configFileWithOffset ) { /// Read from file 2 if ( configFileWithOffset.length() > 0 ){ cout << "-I STA: " << "STA Land configuration procedure read offsets from file " << configFileWithOffset << "...\t\t"; string line; ifstream file ( configFileWithOffset.c_str() ); int paddle = 0; int plane = 0; float offset = 0; int returnValue = 0; if (file.is_open()) { while ( file.good() ) { getline (file,line); returnValue = sscanf(line.c_str(), "%d %d %f", &plane, &paddle, &offset); if ( returnValue == 3 ) { rLandConfigParam[plane][paddle].rTimeOffset = offset ; } if ( rVerboseLevel > 1 ) cout << "-I STA: " << line << ". LineParsingReturnValue = " << returnValue << endl; if ( rVerboseLevel > 1 ) cout << "-I STA: " << "plane= " << plane<< ", paddle= " << paddle<<", time offset= " << offset << endl; } file.close(); for(int iPaddle = 0; iPaddle < rPaddlesInPlaneNo; iPaddle++) ///TODO: Check what for veto { ///rLandConfigParam[0][iPaddle].rTimeOffset = 0.; } cout << " DONE " << endl; } else{ cout << "-I STA: " << "FILED: Unable to open file"; } } return; } //______________________________________________________________________ ///TODO: Need to be finished fStaPrepareParameters. void StaAdapter::fStaPrepareParameters( string configFileWithDiffAndWidth, string configFileWithQDiffAndGain, string configFileWithOffset ) { if ( rVerboseLevel > 0 ) cout << "-I STA: " << "noOfPlanes= " << rPlaneNo << endl; if ( rVerboseLevel > 0 ) cout << "-I STA: " << "noOfPaddlesInPlane= " << rPaddlesInPlaneNo << endl; ///Set default values for ( Int_t iplane = 0; iplane < rPlaneNo; iplane++ ) { for ( Int_t ipaddle = 0; ipaddle < rPaddlesInPlaneNo; ipaddle++ ) { ///cout << " Read for ["<< iplane << ", " << ipaddle << "]" << endl; rLandConfigParam[iplane][ipaddle].rDiff = 0; rLandConfigParam[iplane][ipaddle].rWidth = 0; rLandConfigParam[iplane][ipaddle].rLambda = 100; rLandConfigParam[iplane][ipaddle].rChannel2MeV = 1; rLandConfigParam[iplane][ipaddle].rTimeOffset = 0; rLandConfigParam[iplane][ipaddle].rQdc1Gain = 0; rLandConfigParam[iplane][ipaddle].rQdc2Gain = 0; rLandConfigParam[iplane][ipaddle].rQdc1Offset = 0; rLandConfigParam[iplane][ipaddle].rQdc2Offset = 0; rLandConfigParam[iplane][ipaddle].rQdcDiff = 0; } } fStaRadFromFile_DiffAndWidth( configFileWithDiffAndWidth ); fStaRadFromFile_QDiffAndGain( configFileWithQDiffAndGain ); fStaRadFromFile_Offset ( configFileWithOffset ); rAreParameterConfigured = kTRUE; } ///End of file