int fqAddNoiseE(float *aBlock, EFFECT *rEffect) { udword i; if (rEffect->fNoiseLev > 0.0) for(i = rmin(rEffect->nFiltMinFreq, nBSize); i < rmin(rEffect->nFiltMaxFreq, nBSize); i++) aBlock[i] += gaussian() * rEffect->fNoiseLev; return OK; }
static int fqIncEffect(float *aBlock, float *fVal, udword nDur, float *aBuf, sdword nSize, sdword *nPos, char aEffect) { udword s; sdword t; if (aBlock == 0) { if (nSize < FQ_SIZE) { return ERR; } else { memset(aBuf, 0, nSize << 2); *nPos = 0; return OK; } } if (nDur > 0) { if (*nPos >= nSize) *nPos = 0; s = (udword)floor((float)nSize / (float)FQ_SIZE * FQ_SLICE); t = *nPos - ((udword)floor((float)rmin(nDur, s) / FQ_SLICE) * FQ_SIZE); if (t < 0) t += nSize; fqAdd(aBlock, &aBuf[t]); memcpy(&aBuf[*nPos], aBlock, nBSize << 2); switch (aEffect) { case FQ_TIME_DELAY: fqScale(&aBuf[*nPos], *fVal); break; case FQ_TIME_ACMODEL: fqEqualize(&aBuf[*nPos], fVal); break; } *nPos += FQ_SIZE; } return OK; }
void CBaseAnimating::SetSequenceBox( void ) { Vector mins, maxs; // Get sequence bbox if( ExtractBbox( pev->sequence, mins, maxs ) ) { // expand box for rotation // find min / max for rotations float yaw = pev->angles.y * ( M_PI / 180.0 ); Vector xvector, yvector; xvector.x = cos( yaw ); xvector.y = sin( yaw ); yvector.x = -sin( yaw ); yvector.y = cos( yaw ); Vector bounds[ 2 ]; bounds[ 0 ] = mins; bounds[ 1 ] = maxs; Vector rmin( 9999, 9999, 9999 ); Vector rmax( -9999, -9999, -9999 ); Vector base, transformed; for( int i = 0; i <= 1; i++ ) { base.x = bounds[ i ].x; for( int j = 0; j <= 1; j++ ) { base.y = bounds[ j ].y; for( int k = 0; k <= 1; k++ ) { base.z = bounds[ k ].z; // transform the point transformed.x = xvector.x*base.x + yvector.x*base.y; transformed.y = xvector.y*base.x + yvector.y*base.y; transformed.z = base.z; if( transformed.x < rmin.x ) rmin.x = transformed.x; if( transformed.x > rmax.x ) rmax.x = transformed.x; if( transformed.y < rmin.y ) rmin.y = transformed.y; if( transformed.y > rmax.y ) rmax.y = transformed.y; if( transformed.z < rmin.z ) rmin.z = transformed.z; if( transformed.z > rmax.z ) rmax.z = transformed.z; } } } rmin.z = 0; rmax.z = rmin.z + 1; SetSize( rmin, rmax ); } }
void find(int i, int k){ if(k==1){ st[i][k]=stack[i]; return; } if(!st[i][k-1]) find(i,k-1); if(!st[i+(1<<(k-1))][k-1]) find(i+(1<<(k-1)),k-1); st[i][k]=rmin(st[i][k-1],st[i+(1<<(k-1))][k-1]); }
void PrintDetectorGeometry() { gSystem->Load("libITSUpgradeBase"); gSystem->Load("libITSUpgradeSim"); TArrayD rmin(0); TArrayD rmax(0); GetDetectorRadii(&rmin,&rmax); for (Int_t i=0; i<rmin.GetSize(); i++) { cout<<i<<": (rmin,rmax)=("<<rmin.At(i)<<","<<rmax.At(i)<<")cm"<<endl; } }
Geom::OptRect font_instance::BBox(int glyph_id) { int no = -1; if ( id_to_no.find(glyph_id) == id_to_no.end() ) { LoadGlyph(glyph_id); if ( id_to_no.find(glyph_id) == id_to_no.end() ) { // didn't load } else { no = id_to_no[glyph_id]; } } else { no = id_to_no[glyph_id]; } if ( no < 0 ) { return Geom::OptRect(); } else { Geom::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]); Geom::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]); return Geom::Rect(rmin, rmax); } }
int fqLimitE(float *aBlock, EFFECT *rEffect) { udword i; if (rEffect->fLimitLev != 1.0) { if (rEffect->fLimitLev == 0.0) { memset(&aBlock[rmin(rEffect->nFiltMinFreq, nBSize)], 0, (rmin(rEffect->nFiltMaxFreq, nBSize) - rmin(rEffect->nFiltMinFreq, nBSize)) << 2); } else { for (i = rmin(rEffect->nFiltMinFreq, nBSize); i < rmin(rEffect->nFiltMaxFreq, nBSize); i++) { if ((aBlock[i] > 0.0) && (aBlock[i] > rEffect->fLimitLev * 32767.0)) aBlock[i] = rEffect->fLimitLev * 32767.0; if ((aBlock[i] < 0.0) && (aBlock[i] < rEffect->fLimitLev * -32767.0)) aBlock[i] = rEffect->fLimitLev * -32767.0; } if (1.0 / rEffect->fLimitLev * 3.0 < 1.0) for (i = rmin(rEffect->nFiltMinFreq, nBSize); i < rmin(rEffect->nFiltMaxFreq, nBSize); i++) if (aBlock[i] != 0.0) aBlock[i] *= (1.0 / rEffect->fLimitLev * 3.0); } } return OK; }
int rmq(int l, int r){ int k=int(log((float)r-l+1)/log(2.0)); if(!st[l][k]) find(l,k); if(!st[r-(1<<k)+1][k]) find(r-(1<<k)+1,k); return rmin(st[l][k], st[r-(1<<k)+1][k]); }
int main(int argc, char * argv[]) { simplmat <double> data; simplmat <double> dout; SpectralAnalysis sa; // Do 199 Simulations and takes the 5 lowest and 5 highest values // to make the confidence envelopes. If the calculated value is // between these highest or lowest values it is significative at 5% level // int numSimul=199,numExtreme=5,windowPos=0,numExtremeT=5; char randz; double probConf=0.05; double probConfT=0.05; double probOrig=0.05; int bonfCorr=0,signif=0; // OJO Falta agregar en parametros int reaPer=0; string fType="BI"; if( argc <3 ) { cerr << "Usage: rnzSpectral inputFile.sed outFile fileType winPos{0,1,2,3} [R/A] [prob] [bonfCorr{0,1}] [numSimulations]" << endl; exit(1); } if( argc >= 4) { fType = argv[3]; windowPos = atoi(argv[4]); randz = toupper(argv[5][0]); // R=Randomizations, A=Asintotic chisqr. if( windowPos > 3 || windowPos <0 ) { cerr << "Out of range: 3 > windowPos > 0" << endl; exit(1); } } if( randz=='R' ) { if( argc == 9) { probOrig = atof(argv[6]); bonfCorr = atoi(argv[7]); numSimul = atoi(argv[8]); } else { cerr << "Invalid number of arguments" << endl; exit(1); } } else { if( argc == 8 ) { probOrig = atof(argv[6]); bonfCorr = atoi(argv[7]); } else { cerr << "Invalid number of arguments" << endl; exit(1); } } RWFile file; string fName = argv[1]; string outFName = argv[2]; if( fName.find(".sed")!=string::npos ) { if(!file.ReadSeed(fName.c_str(), data, fType.c_str() )) exit(1); } else if( fName.find(".img")!=string::npos ) { if(!file.ReadIdrisi(fName.c_str(), data)) exit(1); } else { cerr << "File type not supported: " << fName << endl; exit(1); } sa.Transpose(data); // Los datos leidos estan en formato (x,y) y las funciones // tienen (y,x) o sea (row,col) int rows=data.getRows(); int cols=data.getCols(); double var; int s,l; simplmat <double> origData(data); sa.SetPow2(data,origData,windowPos); int origRows = rows; int origCols = cols; rows=data.getRows(); cols=data.getCols(); var = sa.Spec2D(data,dout); // Calculates the periodogram usando FFT simplmat<double> rper; // Rearranged periodogram simplmat<double> polper; // Polar sa.Spekout(rows,cols,dout,rper); // Rearranges the periodogram ofstream fOut; if(reaPer) { string rperOut="r."+outFName; fOut.open(rperOut.c_str()); fOut << rper.getCols() << "\t" << rper.getRows() << endl; fOut << "Rearranged periodogram" << endl; for(l=0;l<rper.getRows();l++) { for(s=0;s<rper.getCols();s++) fOut.form("%10.6f",rper(l,s)) << "\t"; fOut << endl; } fOut.close(); } sa.Polar2D(rows,cols,rper,polper); // Calculates the Polar Spectrum // OJO modifica rper!!!!!!!!!!!! int d = int(0.5*sqrt(rows*rows + cols*cols)+1); // Outputs the rearranged periodogram // //string rperOut("rper."); //rperOut+=outFName; //if(!file.WriteSeed(rperOut.c_str(), rper)) // exit(1); fOut.open(outFName.c_str()); if( bonfCorr ) { probConf=probOrig/d; probConfT=probOrig/18; } else { probConf=probOrig; probConfT=probOrig; } numExtreme = 1+probConf*numSimul/2; if( numExtreme <=1 ) { cerr << "numExtreme <= 1" << endl; exit(1); } numExtremeT = 1+probConfT*numSimul/2; if( numExtremeT <=1 ) { cerr << "numExtremeT <= 1" << endl; exit(1); } Randomizations rz; simplmat<double> thetamin; simplmat<double> thetamax; simplmat<double> rmin; simplmat<double> rmax; simplmat<double> rpol; // Polar Spectrum for randomizations thetamin.resize(18,numExtremeT,1000.0); thetamax.resize(18,numExtremeT,0.0); rmin.resize(d,numExtreme,1000.0); rmax.resize(d,numExtreme,0.0); for(s=0; s<numSimul; s++) { rz.Randomize(origData); sa.SetPow2(data,origData); sa.Spec2D(data,dout); sa.Spekout(rows,cols,dout,rper); sa.Polar2D(rows,cols,rper,rpol); for(l=0;l<d;l++) { sa.spectMax(rpol(l,0),rmax,l,numExtreme); sa.spectMin(rpol(l,0),rmin,l,numExtreme); // cout << setw(2) << l+1 << "\t"; // cout.form("%8.5f", rpol(l,0)) << endl; } for(l=0;l<18;l++) { sa.spectMax(rpol(l,2),thetamax,l,numExtremeT); sa.spectMin(rpol(l,2),thetamin,l,numExtremeT); // cout << "\t\t" << setw(4) << l*10 << "\t"; // cout.form("%8.5f", rpol(l,2)) << endl; } } fOut << "R Spectrum " << "\t" << outFName << endl; fOut << "Randomizations: "<< "\t" << numSimul << "\t" << numExtreme << "\t" << probConf << endl; fOut << "Data dim:" << "\t" << origRows << "\t" << origCols << endl; fOut << "Window dim:" << "\t" << rows << "\t" << cols << "\tPosition:\t" << windowPos << endl; for(l=0;l<d;l++) { signif = 0; fOut << setw(2) << l+1 << "\t"; fOut.form("%8.5f", polper(l,0)) << "\t"; fOut.form("%8.5f", rmin(l,0)) << "\t"; fOut.form("%8.5f", rmax(l,0)) << "\t"; fOut.form("%8.5f", polper(l,1)) << "\t"; if( polper(l,0)<rmin(l,0) ) signif = -1; if( polper(l,0)>rmax(l,0) ) signif = 1; fOut << signif << endl; } fOut << "\nTheta Spectrum" << endl; fOut << "Randomizations: "<< "\t" << numSimul << "\t" << numExtremeT << "\t" << probConfT << endl; for(l=0;l<18;l++) { signif = 0; fOut << setw(4) << l*10 << "\t"; fOut.form("%8.5f", polper(l,2)) << "\t"; fOut.form("%8.5f", thetamin(l,0)) << "\t"; fOut.form("%8.5f", thetamax(l,0)) << "\t"; fOut.form("%8.5f", polper(l,3)) << "\t"; if( polper(l,2)<thetamin(l,0) ) signif = -1; if( polper(l,2)>thetamax(l,0) ) signif = 1; fOut << signif << endl; } return 0; }
void ViewSimple2D::redraw( bool paused ) { vec2f ctr; ctr = vec2f( 300, 300 ); // 2d part glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0, 800, 0, 600 ) ; glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Draw pumpkins in a ring int i, j, k; float t, sz=60; int x, y; Pumpkin p; // the "board" glDisable( GL_TEXTURE_2D ); glLineWidth( 3.0 ); vec4f fill = vec4f( 0.5f, 0.7f, 0.6f, 0.5f ), line = vec4f( 0.8f, 0.3f, 0.8f, 1.0f ), fill_dest = vec4f( 0.9f, 0.4f, 0.5f, 0.5f ), line_dest = vec4f( 0.2f, 1.0f, 0.2f, 1.0f ); // The center "storage ring" drawCircle( ctr, 50, SHAPE_LINE_AND_FILL, fill, line, 100 ); // The outer ring drawCircle( ctr, 250, SHAPE_LINE, fill, line, 100 ); gfEnableFont( m_fontId, 25 ); // a bunch of dots for the board vec2f freeze_pos, freeze_dir; vec2f queue_pos, queue_dir; vec2f station_pos; vec4f color, linecolor; char *label = NULL; for (i = 0; i < MACHINE_SLOTS; i++) { t = (2.0*M_PI)/MACHINE_SLOTS * i; x = ctr[0] + cos(t)*250.0; y = ctr[1] - sin(t)*250.0; label = NULL; if ((i >= DEST_SLOT_NDX) && (i < DEST_SLOT_NDX+5)) { color = fill_dest; linecolor = line_dest; if (i==DEST_SLOT_NDX+2) label = "Destination"; } else if (i==FREEZER_NDX) { color = vec4f( 0.0f, 1.0f, 1.0f, 0.6f ); linecolor = vec4f( 1.0f, 1.0f, 1.0f, 1.0f ); label = "Freeze"; // draw freezer slots freeze_dir = vec2f( cos(t), -sin(t) ); freeze_pos = vec2f( x, y ) - freeze_dir*sz; for (int j=0; j < FREEZER_CAPACITY; j++) { drawCircle( freeze_pos - (freeze_dir*30*j), 15, SHAPE_LINE_AND_FILL, vec4f( 1.0, 1.0, 1.0, 1.0 ), vec4f( 0.0, 1.0, 1.0, 1.0), 12 ); } } else if (i==PRODUCTION_NDX) { color = fill; linecolor = line; // draw production slots queue_dir = vec2f( cos(t), -sin(t) ); queue_pos = vec2f( x, y ) + queue_dir*sz*0.6f; queue_dir = vec2f( 0.0, 1.0 ); // vertical queue for (int j=0; j < PRODUCTION_CAPACITY; j++) { drawCircle( queue_pos + (queue_dir*30*j), 15, SHAPE_LINE_AND_FILL, vec4f( 1.0, 1.0, 1.0, 1.0 ), vec4f( 0.5, 0.5, 0.5, 1.0), 12 ); } } else if (i==TORCHY_NDX) { color = vec4f( 1.0f, 0.0f, 0.0f, 0.6f ); linecolor = vec4f( 1.0f, 1.0f, 0.0f, 1.0f ); label = "Torchy"; } else { color = fill; linecolor = line; } // draw swap lines if ((i==SWAP_NDX1)||(i==SWAP_NDX2)||(i==SWAP_NDX3)) { glColor4f( linecolor[0], linecolor[1], linecolor[2], linecolor[3] ); glBegin( GL_LINES ); glVertex3f( ctr[0], ctr[1], 0 ); glVertex3f( x, y, 0 ); glEnd(); label = "Swap"; } // draw circle drawCircle( vec2f( x, y ), 25, SHAPE_LINE_AND_FILL, color, linecolor, 8 ); // draw current station if (m_station==i) { station_pos = vec2f(x, y ); } // draw label if (label) { glColor4f( linecolor[0], linecolor[1], linecolor[2], linecolor[3] ); gfBeginText(); float lx = x - (gfGetStringWidth( label )/2.0); glTranslated( (lx<5.0)?5.0:lx, y, 0.0 ); gfDrawString( label ); gfEndText(); glDisable( GL_TEXTURE_2D ); } } // draw combos color = fill; linecolor = line; vec2f rmin(610,545), rmax(795, 595); for (i=0; i < m_game->getNumCombos(); i++) { Combo c = m_game->getCombo( i ); glDisable( GL_TEXTURE_2D ); drawRect( rmin, rmax, SHAPE_LINE_AND_FILL, color, vec4f( 0.0, 0.9, 0.9, 1.0) ); gfEnableFont( m_fontId, 15 ); gfBeginText(); glTranslated( (rmin[0] + (rmax[0]-rmin[0])/2.0) - gfGetStringWidth( c.m_name.c_str() )/2.0 , rmax[1]-12, 0.0 ); gfDrawString( c.m_name.c_str() ); gfEndText(); // draw combo Value gfEnableFont( m_fontId, 25 ); gfBeginText(); glTranslated( rmax[0]-30 , rmax[1]-35, 0.0 ); gfDrawStringFmt( "%d", c.m_value ); gfEndText(); // draw combo pumpkins glBindTexture( GL_TEXTURE_2D, m_texPumpkinIcons ); vec2f px(rmin[0]+5, rmin[1]+5); for (j=0; j < c.m_groups.size(); j++) { p = Pumpkin(); p.m_type = c.m_groups[j].m_item; if ( (p.m_type == ANY_PUMPKIN) || (p.m_type == ANY_ITEM) ) { glColor3f( m_groupColor[j][0], m_groupColor[j][1], m_groupColor[j][2] ); } else { glColor3f( 1.0, 1.0, 1.0 ); } for (k=0; k < c.m_groups[j].m_count; k++ ) { drawPumpkin( px, p, sz*0.5, false ); px[0] = px[0] + sz*0.5; } } rmin[1] = rmin[1] - 55; rmax[1] = rmax[1] - 55; } gfEnableFont( m_fontId, 25 ); if (!paused) { // Draw pumpkins in the machine glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texPumpkinIcons ); glColor3f( 1.0, 1.0, 1.0 ); vec2f v; for (i = 0; i < MACHINE_SLOTS; i++) { p = m_game->getPumpkin( i ); if (p.m_type == EMPTY) continue; v = calcPosFromNdx( i ); x = v[0] - (sz/2); y = v[1] - (sz/2); drawPumpkin( vec2f( x, y ), p, sz ); } // draw frozen pumpkins for ( j=0; j < m_game->getFreezerUsage(); j++) { p = m_game->getFrozenFood( j ); // shouldn't be empty, but... if (p.m_type != EMPTY) { drawPumpkin( (freeze_pos+ - (freeze_dir*30*j)) - vec2f(sz*0.25,sz*0.25), p, sz*0.5 ); } } // draw queued pumpkins for ( j=0; j < m_game->getProdQueueSize(); j++) { p = m_game->getQueuedPumpkin( j ); // shouldn't be empty, but... if (p.m_type != EMPTY) { drawPumpkin( (queue_pos+ (queue_dir*30*j)) - vec2f(sz*0.25,sz*0.25), p, sz*0.5 ); } } // draw center pumpkin p = m_game->getCenterPumpkin(); if (p.m_type != EMPTY) { drawPumpkin( vec2f( ctr[0]-(sz*1.5/2), ctr[1]-(sz*1.5/2)), p, sz*1.5 ); } } // Draw last combo acheived if (m_lastComboAge < COMBO_DISPLAY_TIME) { char buff[200]; t = 1.0 - (m_lastComboAge/COMBO_DISPLAY_TIME); gfEnableFont( m_fontId, 25 ); gfBeginText(); sprintf( buff, "%d - %s - %d", m_lastCombo.m_value, m_lastCombo.m_name.c_str(), m_lastCombo.m_value ); glColor3f( 1.0, t, t ); glTranslated( ctr[0] - gfGetStringWidth( buff )/2, ctr[1]+50-(50.0*t)+j*5, 0.0 ); gfDrawString( buff ); gfEndText(); } glDisable( GL_TEXTURE_2D ); // draw cursor drawCircle( station_pos, 30, SHAPE_LINE, color, vec4f( 0.0, 1.0, 1.0, 1.0), 8 ); drawCircle( station_pos, 35, SHAPE_LINE, color, vec4f( 0.0f, 0.8f, 0.8f, 1.0f), 8 ); // Draw animated pumpkins if (!paused) { glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texPumpkinIcons ); PumpkinAnim pa; for (i = 0; i < m_panim.size(); i++) { pa = m_panim[i]; glPushMatrix(); glTranslated( pa.m_pos[0] - sz/2, pa.m_pos[1]-sz/2, 0.0 ); drawPumpkin( vec2f( 0.0, 0.0 ), pa, sz ); glPopMatrix(); } } // draw particles drawParts(); }
void UnplacedTorus::Print(std::ostream &os) const { os << "UnplacedTorus {" << rmin() << ", " << rmax() << ", " << rtor() << ", " << sphi() << ", " << dphi(); }
void CountTrackableMCs(TH1F *hAllMC, Bool_t onlyPrims,Bool_t onlyPion) { gSystem->Load("libITSUpgradeBase"); gSystem->Load("libITSUpgradeSim"); // open run loader and load gAlice, kinematics and header AliRunLoader* runLoader = AliRunLoader::Open("galice.root"); if (!runLoader) { Error("Check kine", "getting run loader from file %s failed", "galice.root"); return; } runLoader->LoadHeader(); runLoader->LoadKinematics(); runLoader->LoadTrackRefs(); AliLoader *dl = runLoader->GetDetectorLoader("ITS"); //Trackf TTree *trackRefTree = 0x0; TClonesArray *trackRef = new TClonesArray("AliTrackReference",1000); // TH1F *hRef = new TH1F("","",100,0,100); TH1F *hR = new TH1F("","",100,0,100); if (hAllMC==0) hAllMC = new TH1F("","",100,0.1,2); Float_t ptmin = hAllMC->GetBinCenter(1)-hAllMC->GetBinWidth(1)/2; Float_t ptmax = hAllMC->GetBinCenter(hAllMC->GetNbinsX())+hAllMC->GetBinWidth(hAllMC->GetNbinsX())/2; // Int_t nAllMC = 0; // Detector geometry TArrayD rmin(0); TArrayD rmax(0); GetDetectorRadii(&rmin,&rmax); TArrayI nLaySigs(rmin.GetSize()); printf("Counting trackable MC tracks ...\n"); for(Int_t iEv =0; iEv<runLoader->GetNumberOfEvents(); iEv++){ Int_t nTrackableTracks = 0; runLoader->GetEvent(iEv); AliStack* stack = runLoader->Stack(); printf("+++ event %i (of %d) +++++++++++++++++++++++ # total MCtracks: %d \n",iEv,runLoader->GetNumberOfEvents()-1,stack->GetNtrack()); trackRefTree=runLoader->TreeTR(); TBranch *br = trackRefTree->GetBranch("TrackReferences"); if(!br) { printf("no TR branch available , exiting \n"); return; } br->SetAddress(&trackRef); // init the trackRef tree trackRefTree=runLoader->TreeTR(); trackRefTree->SetBranchAddress("TrackReferences",&trackRef); // Count trackable MC tracks for (Int_t iMC=0; iMC<stack->GetNtrack(); iMC++) { TParticle* particle = stack->Particle(iMC); if (TMath::Abs(particle->Eta())>etaCut) continue; if (onlyPrims && !stack->IsPhysicalPrimary(iMC)) continue; if (onlyPion && TMath::Abs(particle->GetPdgCode())!=211) continue; Bool_t isTrackable = 0; nLaySigs.Reset(0); trackRefTree->GetEntry(stack->TreeKEntry(iMC)); Int_t nref=trackRef->GetEntriesFast(); for(Int_t iref =0; iref<nref; iref++){ AliTrackReference *trR = (AliTrackReference*)trackRef->At(iref); if(!trR) continue; if(trR->DetectorId()!=AliTrackReference::kITS) continue; Float_t radPos = trR->R(); hR->Fill(radPos); for (Int_t il=0; il<rmin.GetSize();il++) { if (radPos>=rmin.At(il)-0.1 && radPos<=rmax.At(il)+0.1) { // cout<<" in Layer "<<il<<" "<<radPos; nLaySigs.AddAt(1.,il); // cout<<" "<<nLaySigs.At(il)<<endl; } } } if (nLaySigs.GetSum()>=3) { isTrackable =1; // cout<<nLaySigs.GetSum()<<endl; } if (isTrackable) { Double_t ptMC = particle->Pt(); // Double_t etaMC = particle->Eta(); // if (ptMC>ptmin&&ptMC<ptmax) {nTrackableTracks++;hAllMC->Fill(ptMC);} if (ptMC>ptmin) {nTrackableTracks++;hAllMC->Fill(ptMC);} } } // entries tracks MC printf(" -> trackable MC tracks: %d (%d)\n",nTrackableTracks,hAllMC->GetEntries()); }//entries Events hR->DrawCopy(); hAllMC->DrawCopy(); runLoader->UnloadHeader(); runLoader->UnloadKinematics(); delete runLoader; }
main (int argc, char *argv[]) { int i, j, **seqs, **nall, ord=1, ns, **pij, lkf=0, npt=0, pnew=0, anc=0; int tcat=1, rcat=0, verb=1, miss=0, *flocs; int sw_flag=0, moment_flag=0, rmin_flag=0, sim_flag=0, test_flag=0; char fname[MAXNAME+1], **seqnames; long seed=-setseed(); extern int sizeofpset; double *locs; double **lkmat, *lkres; FILE *ifp=NULL, *ifp2=NULL, *ifp3=NULL, *tfp; struct site_type **pset; struct data_sum *data; int ask_questions = 1; char *in_str; print_help(argc, argv); idum = &seed; data = malloc((size_t) sizeof(struct data_sum)); data->exact = 0; strcpy(data->prefix, ""); for(i = 0; i < argc; i++) { if(*argv[i] == '-') { in_str = argv[i]; ask_questions = 0; if(strcmp(in_str, "-seq") == 0) ifp = fopen(argv[i+1], "r"); if(strcmp(in_str, "-loc") == 0) ifp2 = fopen(argv[i+1], "r"); if(strcmp(in_str, "-lk") == 0) { lkf = 1; ifp3 = fopen(argv[i+1], "r"); } if(strcmp(in_str, "-exact") == 0) data->exact = 1; if(strcmp(in_str, "-concise") == 0) verb=0; if(strcmp(in_str, "-window") == 0) sw_flag=1; if(strcmp(in_str, "-moment") == 0) moment_flag=1; if(strcmp(in_str, "-simulate") == 0) sim_flag=1; if(strcmp(in_str, "-rmin_flag") == 0) rmin_flag=2; if(strcmp(in_str, "-test") == 0) test_flag=1; if(strcmp(in_str, "-prefix") == 0) strcpy(data->prefix, argv[i+1]); } } if (ifp == NULL) { printf("\nCould not find seqs file in command line.\n"); printf("\nInput filename for seqs:\n"); scanf("%s", &fname); ifp = fopen(fname, "r"); } if (ifp == NULL) nrerror("Error in opening sequence file"); fscanf(ifp,"%i%i%i", &data->nseq, &data->lseq, &data->hd); if ((data->nseq < 2) || (data->lseq < 2)) {printf("\n\nInsufficient data for analysis (n > 1, L > 1) \n\n"); exit(1);} if (data->nseq > SEQ_MAX) {printf("\n\nMore than max no. sequences: Using first %i for analysis\n\n", SEQ_MAX); data->nseq=SEQ_MAX;} printf("\nAnalysing %i (n=%i) sequences of length %i seg sites\n", data->nseq, data->hd, data->lseq); seqs = imatrix(1, data->nseq, 1, data->lseq); seqnames = cmatrix(1, data->nseq+11, 1, MAXNAME+11); if (read_fasta(seqs, ifp, data->nseq, data->lseq, seqnames)) printf("\nSequences read succesfully\n"); fclose(ifp); nall = imatrix(1, data->lseq, 1, 6); allele_count(seqs, data->nseq, data->lseq, nall,1, data->hd, data->prefix); /*Store lnfac values in array for speed of computation*/ lnfac_array = (double *) malloc((size_t) ((int) (data->nseq+2)*(data->hd))*sizeof(double)); lnfac_array[0]=lnfac_array[1]=0; for (j=2;j<=((int) data->nseq*(data->hd));j++) lnfac_array[j]=(double) lnfac_array[j-1]+log(j); /*Open file with location of seg sites and read in data*/ if (ifp2 == NULL) { printf("\nCould not find locs file in command line.\n"); printf("\nInput name of file containing location of seg sites\n\n"); scanf("%s", &fname); ifp2 = fopen(fname, "r"); } if (ifp2 == NULL) nrerror("Cannot open loc file"); fscanf(ifp2, "%i %lf %c", &ns, &data->tlseq, &data->lc); if (ns != data->lseq) nrerror("Lseq and Locs disagree"); if ((data->lc != 'C')&&(data->lc != 'L')) nrerror("Must input linear(L)/conversion(C)"); if (data->lc == 'C') { data->avc=0; while (data->avc <= 0) { printf("\n\nInput average tract length for conversion model: ");scanf("%lf", &(data->avc)); } } locs = dvector(1, data->lseq); flocs = ivector(1, data->lseq); /*Array to use when simulating data*/ for (i=1; i<=data->lseq; i++) { fscanf(ifp2, "%lf", &locs[i]); if ((locs[i]==0)||(locs[i]>data->tlseq)) {printf("\n\nError in Loc file\n\n%lf\n", data->tlseq); exit(1);} if (i>1 && locs[i]<=locs[i-1]) nrerror("Error in locs file: SNPs must be montonically increasing"); } printf("\nLocation of seg sites\n\n"); for (i=1; i<=data->lseq; i++) printf("%3i %4.2lf\n", i, locs[i]); fclose(ifp2); /*Read in likelihood file where needed*/ if (ask_questions) { printf("\n\nUse existing likelihood file? (yes=1, no=0):"); scanf("%i", &lkf); /*lkf is a flag: 1 means use existing likelihood file as starting point*/ if (lkf) { printf("\n\nInput name of likelihood file: "); scanf("%s", &fname); ifp3 = fopen(fname, "r"); } else data->exact=0; if (lkf == 1) { printf("\n\nIs likelihood file an exact match to data?(no=0/yes=1): "); scanf("%i", &data->exact); } } if (lkf && !ifp3) nrerror("Cannot open likelihood file"); if (!lkf && data->hd==2) nrerror("For diploid data need complete lookup table for sequences"); /*Store pair-types in pij matrix - classify in pair_spectrum routine*/ data->w = data->lseq; /*Note for this program use all data - pair_int restricts to a smaller window*/ pij = imatrix((int) 1,(int) data->lseq,(int) 1,(int) data->w); for (i=1;i<=data->lseq;i++) for (j=1;j<=data->w;j++) pij[i][j]=0; pset = init_pset(pset, lkf, ifp3, &npt, data); /*Reads in type configurations from likelihood file*/ printf("\n\n*** Calculating distribution of pair types ***\n\n"); pset = pair_spectrum(seqs, data, nall, pset, &npt, &pnew, &miss, anc, pij); printf("\n\n *** Completed classification of pair types ***\n\n"); if (data->exact && (pnew || miss)) nrerror("Lookup table is not exact for sequences\n(possibly generated by interval)"); printf("\n\nOld = %i: New = %i: Missing = %i\n\n", npt,pnew,miss); data->ptt = (int) npt+pnew+miss; /*npt is number from likelihood file, pnew is number new with no missing data, miss is # new with missing data*/ if (verb) { strcpy(fname, data->prefix); tfp = fopen(strcat(fname, "type_table.txt"), "w"); if (!tfp) nrerror("Cannot open type file"); type_print(pij, data->lseq, data->w,tfp); fclose(tfp); } if (verb) print_pairs(stdout, pset, npt+pnew, data->hd, data->nseq); /*Need a complete set for missing data or diploid data - check this*/ if (!data->exact && (data->hd ==2 || miss)) { printf("\n\nMissing data or diploid: checking that likelihood table is exhaustive\n\n"); check_exhaustive(pset,npt,(data->nseq)*((int) data->hd)); } /*Read parameters and likelihoods from likelihood file - where appropriate*/ if (lkf) { read_pars(ifp3, &tcat, &data->th, &data->rcat, &data->rmax); lkmat = dmatrix(1,npt+pnew+miss,1,data->rcat); if (lkf) read_lk(ifp3, lkmat, npt, tcat, data->rcat); } /*If haploid, but novel types, need to calculate new likelihoods and input parameter values*/ if (data->hd ==1 && pnew) { /*Note can have pnew for diploid data, but this has been checked for already*/ if (!lkf) { data->th=data->rmax=-1.0; data->rcat=0; printf("\n\nInput theta per site (suggest Watterson estimate of %.5lf):",(double) data->lseq/(watterson(data->nseq*data->hd)*data->tlseq)); while (data->th<0.0) scanf("%lf", &data->th); printf("\n\nMax 4Ner for grid (suggest 100):"); while(data->rmax<0.0) scanf("%lf", &data->rmax); printf("\n\nNumber of points on grid (suggest 101, min=2):"); while(data->rcat<2) scanf("%i", &data->rcat); lkmat = dmatrix(1,npt+pnew+miss,1,data->rcat); } lk_est(pset,npt,pnew,lkmat,data->th,data->rcat,data->rmax); data->exact=1; } /*Sum over missing data or resolve genotypes and sum over missing data+configurations*/ else if (miss && data->hd==1) { printf("\n\n*** Calculating likelihoods for missing data ***\n\n"); for (i=1;i<=miss;i++) { lk_miss(pset[npt+i],lkmat[npt+i],lkmat,data); printf("\rType %i", i); } printf(" ...Done!\n\n"); } /*Sum over resolutions for diploid data*/ else if (data->hd==2 && !data->exact) { printf("\n\n*** Resolving diploid data: %i ***\n\n",pnew+miss); lkres = dvector(1,data->rcat); for (i=1;i<=pnew+miss;i++) { lk_resolve(lkres,pset[npt+i],lkmat[npt+i],lkmat,data); printf("\rType %i", i); } free_dvector(lkres,1,data->rcat); printf(" ...Done!\n\n"); } /*If new likelihood generated can output likelihood file for future analyses*/ if (verb) print_lks(pset, data, npt+pnew+miss, lkmat); /*Basic analysis - estimation of 4Ner asuming constant rate*/ data->rme=data->rmax; data->rce=data->rcat; if (1) { printf("\n\nDo you wish to change grid over which to estimate likelihoods for (default = %i points, 4Ner 0 - %.1lf) (1/0) :",data->rcat,data->rmax); scanf("%i", &lkf); if (lkf) { data->rme=-10; data->rce=0; printf("\n\nMax 4Ner for estimation : "); while (data->rme < 0.0) scanf("%lf", &data->rme); printf("\n\nNumber of classes to estimate for: "); while (data->rce < 1) scanf("%i", &data->rce); } } data->lksurf = dmatrix(1,data->rce,1,2); lk_surf(pset, pij, data, lkmat, data->th, locs, 1); /*Print marginal likelihood ratio test statistics for each pair of sites*/ printf("\n\nCalculating fits\n\n"); fit_pwlk(data,pij,locs,lkmat,verb); /*Sliding windows version*/ if (1) { printf("\n\nDo you wish to carry out a sliding windows analysis? (yes=1/no=0):"); scanf("%i", &sw_flag); } if (sw_flag) lk_win(pset,pij,data,lkmat,locs,nall); /*Nonparametric estimation of recombination rate*/ if (1) { printf("\n\nPrint out table of Rmin values?\n(0=No, 1=Total only, 2=Full table):"); scanf("%i", &rmin_flag); } if (rmin_flag) { rmin(data, pset, pij, locs, lkf-1); printf("\n\nLower bound on Rmin = %i\n\n",data->rmin); } /*Estimate 4Ner by Wakeley 1997 method*/ if (1) { printf("\n\nEstimate 4Ner by moment method? (yes=1, no=0)"); scanf("%i", &moment_flag); } if (moment_flag) wakeley_est(data, seqs, locs); /*Recombination tests - only available for haploid data!*/ if (data->hd==1) { if (1) { printf("\n\nDo you wish to test for recombination? (yes=1, no=0): "); scanf("%i", &test_flag); } if (test_flag) { rec_test(data, pij, locs, lkmat, pset, npt+pnew+miss); } } /*Conditional simulation - only available for haploid data with a complete lk file*/ if (data->hd==1 && !(data->exact)) { if (1) { printf("\n\nDo you wish to test constant-rate model and estimate sampling distribution by simulation? (yes=1/no=0): "); scanf("%i", &test_flag); } if (test_flag) { freq_min(locs, flocs, nall, data); printf("\n\nHow many simulations? "); scanf("%i", &lkf); snp_sim(locs, flocs, pset, lkmat, lkf, data); } } free_imatrix(pij,1,data->lseq,1,data->w); free_imatrix(seqs,1,data->nseq,1,data->lseq); free_imatrix(nall,1,data->lseq,1,5); for (i=1;i<sizeofpset;i++) free(pset[i]); free(pset); free(data); free_dvector(locs, 1, data->lseq); free_ivector(flocs, 1, data->lseq); /* system("PAUSE"); */ }
/************************************************************************* * This function is the entry point of the initial partitioning algorithm. * This algorithm assembles the graph to all the processors and preceed * serially. **************************************************************************/ idx_t Mc_Diffusion(ctrl_t *ctrl, graph_t *graph, idx_t *vtxdist, idx_t *where, idx_t *home, idx_t npasses) { idx_t h, i, j; idx_t nvtxs, nedges, ncon, pass, iter, domain, processor; idx_t nparts, mype, npes, nlinks, me, you, wsize; idx_t nvisited, nswaps = -1, tnswaps, done, alldone = -1; idx_t *rowptr, *colind, *diff_where, *sr_where, *ehome, *map, *rmap; idx_t *pack, *unpack, *match, *proc2sub, *sub2proc; idx_t *visited, *gvisited; real_t *transfer, *npwgts, maxdiff, minflow, maxflow; real_t lbavg, oldlbavg, ubavg, *lbvec; real_t *diff_flows, *sr_flows; real_t diff_lbavg, sr_lbavg, diff_cost, sr_cost; idx_t *rbuffer, *sbuffer; idx_t *rcount, *rdispl; real_t *solution, *load, *workspace; matrix_t matrix; graph_t *egraph; if (graph->ncon > 3) return 0; WCOREPUSH; nvtxs = graph->nvtxs; nedges = graph->nedges; ncon = graph->ncon; nparts = ctrl->nparts; mype = ctrl->mype; npes = ctrl->npes; ubavg = ravg(ncon, ctrl->ubvec); /* initialize variables and allocate memory */ lbvec = rwspacemalloc(ctrl, ncon); diff_flows = rwspacemalloc(ctrl, ncon); sr_flows = rwspacemalloc(ctrl, ncon); load = rwspacemalloc(ctrl, nparts); solution = rwspacemalloc(ctrl, nparts); npwgts = graph->gnpwgts = rwspacemalloc(ctrl, ncon*nparts); matrix.values = rwspacemalloc(ctrl, nedges); transfer = matrix.transfer = rwspacemalloc(ctrl, ncon*nedges); proc2sub = iwspacemalloc(ctrl, gk_max(nparts, npes*2)); sub2proc = iwspacemalloc(ctrl, nparts); match = iwspacemalloc(ctrl, nparts); rowptr = matrix.rowptr = iwspacemalloc(ctrl, nparts+1); colind = matrix.colind = iwspacemalloc(ctrl, nedges); rcount = iwspacemalloc(ctrl, npes); rdispl = iwspacemalloc(ctrl, npes+1); pack = iwspacemalloc(ctrl, nvtxs); unpack = iwspacemalloc(ctrl, nvtxs); rbuffer = iwspacemalloc(ctrl, nvtxs); sbuffer = iwspacemalloc(ctrl, nvtxs); map = iwspacemalloc(ctrl, nvtxs); rmap = iwspacemalloc(ctrl, nvtxs); diff_where = iwspacemalloc(ctrl, nvtxs); ehome = iwspacemalloc(ctrl, nvtxs); wsize = gk_max(sizeof(real_t)*nparts*6, sizeof(idx_t)*(nvtxs+nparts*2+1)); workspace = (real_t *)gk_malloc(wsize, "Mc_Diffusion: workspace"); graph->ckrinfo = (ckrinfo_t *)gk_malloc(nvtxs*sizeof(ckrinfo_t), "Mc_Diffusion: rinfo"); /* construct subdomain connectivity graph */ matrix.nrows = nparts; SetUpConnectGraph(graph, &matrix, (idx_t *)workspace); nlinks = (matrix.nnzs-nparts) / 2; visited = iwspacemalloc(ctrl, matrix.nnzs); gvisited = iwspacemalloc(ctrl, matrix.nnzs); for (pass=0; pass<npasses; pass++) { rset(matrix.nnzs*ncon, 0.0, transfer); iset(matrix.nnzs, 0, gvisited); iset(matrix.nnzs, 0, visited); iter = nvisited = 0; /* compute ncon flow solutions */ for (h=0; h<ncon; h++) { rset(nparts, 0.0, solution); ComputeLoad(graph, nparts, load, ctrl->tpwgts, h); lbvec[h] = (rmax(nparts, load)+1.0/nparts) * (real_t)nparts; ConjGrad2(&matrix, load, solution, 0.001, workspace); ComputeTransferVector(ncon, &matrix, solution, transfer, h); } oldlbavg = ravg(ncon, lbvec); tnswaps = 0; maxdiff = 0.0; for (i=0; i<nparts; i++) { for (j=rowptr[i]; j<rowptr[i+1]; j++) { maxflow = rmax(ncon, transfer+j*ncon); minflow = rmin(ncon, transfer+j*ncon); maxdiff = (maxflow - minflow > maxdiff) ? maxflow - minflow : maxdiff; } } while (nvisited < nlinks) { /* compute independent sets of subdomains */ iset(gk_max(nparts, npes*2), UNMATCHED, proc2sub); CSR_Match_SHEM(&matrix, match, proc2sub, gvisited, ncon); /* set up the packing arrays */ iset(nparts, UNMATCHED, sub2proc); for (i=0; i<npes*2; i++) { if (proc2sub[i] == UNMATCHED) break; sub2proc[proc2sub[i]] = i/2; } iset(npes, 0, rcount); for (i=0; i<nvtxs; i++) { domain = where[i]; processor = sub2proc[domain]; if (processor != UNMATCHED) rcount[processor]++; } rdispl[0] = 0; for (i=1; i<npes+1; i++) rdispl[i] = rdispl[i-1] + rcount[i-1]; iset(nvtxs, UNMATCHED, unpack); for (i=0; i<nvtxs; i++) { domain = where[i]; processor = sub2proc[domain]; if (processor != UNMATCHED) unpack[rdispl[processor]++] = i; } SHIFTCSR(i, npes, rdispl); iset(nvtxs, UNMATCHED, pack); for (i=0; i<rdispl[npes]; i++) { ASSERT(unpack[i] != UNMATCHED); domain = where[unpack[i]]; processor = sub2proc[domain]; if (processor != UNMATCHED) pack[unpack[i]] = i; } /* Compute the flows */ if (proc2sub[mype*2] != UNMATCHED) { me = proc2sub[2*mype]; you = proc2sub[2*mype+1]; ASSERT(me != you); for (j=rowptr[me]; j<rowptr[me+1]; j++) { if (colind[j] == you) { visited[j] = 1; rcopy(ncon, transfer+j*ncon, diff_flows); break; } } for (j=rowptr[you]; j<rowptr[you+1]; j++) { if (colind[j] == me) { visited[j] = 1; for (h=0; h<ncon; h++) { if (transfer[j*ncon+h] > 0.0) diff_flows[h] = -1.0 * transfer[j*ncon+h]; } break; } } nswaps = 1; rcopy(ncon, diff_flows, sr_flows); iset(nvtxs, 0, sbuffer); for (i=0; i<nvtxs; i++) { if (where[i] == me || where[i] == you) sbuffer[i] = 1; } egraph = ExtractGraph(ctrl, graph, sbuffer, map, rmap); if (egraph != NULL) { icopy(egraph->nvtxs, egraph->where, diff_where); for (j=0; j<egraph->nvtxs; j++) ehome[j] = home[map[j]]; RedoMyLink(ctrl, egraph, ehome, me, you, sr_flows, &sr_cost, &sr_lbavg); if (ncon <= 4) { sr_where = egraph->where; egraph->where = diff_where; nswaps = BalanceMyLink(ctrl, egraph, ehome, me, you, diff_flows, maxdiff, &diff_cost, &diff_lbavg, 1.0/(real_t)nvtxs); if ((sr_lbavg < diff_lbavg && (diff_lbavg >= ubavg-1.0 || sr_cost == diff_cost)) || (sr_lbavg < ubavg-1.0 && sr_cost < diff_cost)) { for (i=0; i<egraph->nvtxs; i++) where[map[i]] = sr_where[i]; } else { for (i=0; i<egraph->nvtxs; i++) where[map[i]] = diff_where[i]; } } else { for (i=0; i<egraph->nvtxs; i++) where[map[i]] = egraph->where[i]; } gk_free((void **)&egraph->xadj, &egraph->nvwgt, &egraph->adjncy, &egraph, LTERM); } /* Pack the flow data */ iset(nvtxs, UNMATCHED, sbuffer); for (i=0; i<nvtxs; i++) { domain = where[i]; if (domain == you || domain == me) sbuffer[pack[i]] = where[i]; } } /* Broadcast the flow data */ gkMPI_Allgatherv((void *)&sbuffer[rdispl[mype]], rcount[mype], IDX_T, (void *)rbuffer, rcount, rdispl, IDX_T, ctrl->comm); /* Unpack the flow data */ for (i=0; i<rdispl[npes]; i++) { if (rbuffer[i] != UNMATCHED) where[unpack[i]] = rbuffer[i]; } /* Do other stuff */ gkMPI_Allreduce((void *)visited, (void *)gvisited, matrix.nnzs, IDX_T, MPI_MAX, ctrl->comm); nvisited = isum(matrix.nnzs, gvisited, 1)/2; tnswaps += GlobalSESum(ctrl, nswaps); if (iter++ == NGD_PASSES) break; } /* perform serial refinement */ Mc_ComputeSerialPartitionParams(ctrl, graph, nparts); Mc_SerialKWayAdaptRefine(ctrl, graph, nparts, home, ctrl->ubvec, 10); /* check for early breakout */ for (h=0; h<ncon; h++) { lbvec[h] = (real_t)(nparts) * npwgts[rargmax_strd(nparts,npwgts+h,ncon)*ncon+h]; } lbavg = ravg(ncon, lbvec); done = 0; if (tnswaps == 0 || lbavg >= oldlbavg || lbavg <= ubavg + 0.035) done = 1; alldone = GlobalSEMax(ctrl, done); if (alldone == 1) break; } /* ensure that all subdomains have at least one vertex */ /* iset(nparts, 0, match); for (i=0; i<nvtxs; i++) match[where[i]]++; done = 0; while (done == 0) { done = 1; me = iargmin(nparts, match); if (match[me] == 0) { if (ctrl->mype == PE) printf("WARNING: empty subdomain %"PRIDX" in Mc_Diffusion\n", me); you = iargmax(nparts, match); for (i=0; i<nvtxs; i++) { if (where[i] == you) { where[i] = me; match[you]--; match[me]++; done = 0; break; } } } } */ /* now free memory and return */ gk_free((void **)&workspace, (void **)&graph->ckrinfo, LTERM); graph->gnpwgts = NULL; graph->ckrinfo = NULL; WCOREPOP; return 0; }
void UnplacedTorus::Print() const { printf("UnplacedTorus {%.2f, %.2f, %.2f, %.2f, %.2f}", rmin(), rmax(), rtor(), sphi(), dphi() ); }
int main ( int argc , char** argv ) { int mtrx [ RW ][ CL ] , i , j , m , i1 , j1 , s , c ; int rslt [ CL ] ; int* rsli , * rslj , rsi , rsj ; rsi = rsj = 0 ; // copy matrix for ( i = 0 ; i < RW ; i++ ) for ( j = 0 ; j < CL ; j++ ) mtrx [ i ][ j ] = matrix [ i ][ j ] ; // print init matrix printf ( "Init\n" ) ; pmtr ( mtrx , RW , CL ) ; printf ( "\n\n" ) ; // Step 1. Find minimal elem in row and // vichitaem from all elements of this row l5: s = 1 ; for ( i = 0 ; i < RW ; i++ ) { m = rmin ( mtrx , i , CL ) ; for ( j = 0 ; j < CL ; j++ ) mtrx [ i ][ j ] -= m ; } #if ( DBG == 1 ) // print matrix printf ( "Step 1\n" ) ; pmtr ( mtrx , RW , CL ) ; printf ( "\n\n" ) ; #endif l0: for ( j = 0 ; j < CL ; j++ ) rslt [ j ] = -1 ; // build result array for ( j = 0 ; j < CL ; j++ ) { for ( i = 0 ; i < RW ; i++ ) { if ( ( mtrx [ i ][ j ] == 0 ) && ( rslt [ j ] == -1 ) && ( inar ( rslt , i , CL ) == -1 ) ) { j1 = inrw ( mtrx , i , 0 , j , CL ) ; if ( j1 == -1 ) { rslt [ j ] = i ; break ; } if ( incl ( mtrx , j , 0 , i , RW ) == -1 ) { rslt [ j ] = i ; break; } l1: if ( incl ( mtrx , j1 , 0 , i , RW ) == -1 ) { rslt [ j1 ] = i ; break; } j1 = inrw ( mtrx , i , 0 , j1 , CL ) ; if ( j1 == -1 ) { rslt [ j ] = i ; break; } goto l1 ; } } } // check if task solved j1 = inar ( rslt , -1 , CL ) ; if ( j1 == -1 ) goto l99 ; else if ( s == 2 ) goto l2 ; // Step 2. Use step for columns. s++ ; for ( j = j1 ; j < CL ; j++ ) { if ( rslt [ j ] != -1 ) continue ; m = cmin ( mtrx , j , RW ) ; for ( i = 0 ; i < RW ; i++ ) mtrx [ i ][ j ] -= m ; } #if ( DBG == 1 ) printf ( "Step 2\n" ) ; pmtr ( mtrx , RW , CL ) ; printf ( "\n\n" ) ; #endif goto l0; l2: // Step 3. Find unused rows c = 0 ; for ( i = 0 ; i < RW ; i++ ) if ( inar ( rslt , i , CL ) == -1 ) { rsi++ ; c++ ; if ( ( rsi - 1 ) == 0 ) { rsli = ( int* ) malloc ( rsi * sizeof ( *rsli ) ) ; *rsli = i ; } else { rsli = realloc ( rsli , rsi * sizeof ( *rsli ) ) ; *( rsli + ( rsi - 1 ) ) = i ; } } if ( c == 0 ) goto l4 ; l3: // in all unused rows find columns' numbers with zero c = 0 ; for ( i = 0 ; i < rsi ; i++ ) { j1 = inrw ( mtrx , *( rsli + i ) , 0 , -1 , CL ) ; while ( j1 != -1 ) { if ( !inpn ( rslj , j1 , rsj ) ) { rsj++ ; c++ ; if ( ( rsj - 1 ) == 0 ) { rslj = ( int* ) malloc ( rsj * sizeof ( *rslj ) ) ; *rslj = j1 ; } else { rslj = realloc ( rslj , rsj * sizeof ( *rslj ) ) ; *( rslj + ( rsj - 1 ) ) = j1 ; } } j1 = inrw ( mtrx , *( rsli + i ) , 0 , j1 , CL ) ; } } if ( c == 0 ) goto l4 ; // in all unused columns find rows' numbers with zero c = 0 ; for ( j = 0 ; j < rsj ; j++ ) { i1 = incl ( mtrx , *( rslj + j ) , 0 , -1 , RW ) ; while ( i1 != -1 ) { if ( !inpn ( rsli , i1 , rsi ) ) { rsi++ ; c++ ; rsli = realloc ( rsli , rsi * sizeof ( *rsli ) ) ; *( rsli + ( rsi - 1 ) ) = i1 ; } i1 = incl ( mtrx , *( rslj + j ) , 0 , i1 , RW ) ; } } if ( c ) goto l3 ; l4: // Step 4. Vicherkivaem otmechennie stolbci // i neotmechennie stroki // for i == rsli , j != rslj m = -1 ; for ( i = 0 ; i < RW ; i++ ) { if ( !inpn ( rsli , i , rsi ) ) continue ; for ( j = 0 ; j < CL ; j++ ) { if ( inpn ( rslj , j , rsj ) ) continue ; m = ( mtrx [ i ][ j ] < m || m < 0 ) ? mtrx [ i ][ j ] : m ; } } for ( i = 0 ; i < RW ; i++ ) { for ( j = 0 ; j < CL ; j++ ) { if ( inpn ( rsli , i , rsi ) && !inpn ( rslj , j , rsj ) ) mtrx [ i ][ j ] -= m ; if ( !inpn ( rsli , i , rsi ) && inpn ( rslj , j , rsj ) ) mtrx [ i ][ j ] += m ; } } free ( rsli ) ; free ( rslj ) ; rsi = rsj = 0 ; #if ( DBG == 1 ) printf ( "Step 4\n" ) ; pmtr ( mtrx , RW , CL ) ; printf ( "\n\n" ) ; #endif goto l5 ; l99: for ( j = 0 ; j < CL ; j++ ) printf ( "For task: %d use worker:%d\n" , j , rslt [ j ] ) ; printf ( "\n" ) ; return 0 ; }
int fqFilterE(float *aBlock, EFFECT *rEffect) { memset(aBlock, 0, rmin(rEffect->nFiltMinFreq, nBSize) << 2); memset(&aBlock[rmin(rEffect->nFiltMaxFreq, nBSize) << 2], 0, (nBSize - rmin(rEffect->nFiltMaxFreq, nBSize)) << 2); return OK; }
void srcPositionStudy(Int_t binWidth, TString source, TString geometry) { int numFiles = 200; TString simLocation; TChain *chain = new TChain("anaTree"); if (geometry==TString("2011-2012")) simLocation = TString(getenv("SIM_2011_2012")); else if (geometry==TString("2012-2013")) simLocation = TString(getenv("SIM_2012_2013")); else if (geometry==TString("2012-2013_ISOBUTANE")) simLocation = TString(getenv("SIM_2012_2013_ISOBUTANE")); else { std::cout << "BAD GEOMETRY\n"; exit(0); } for (int i=0; i<numFiles; i++) { chain->AddFile(TString::Format("%s/%s/analyzed_%i.root",simLocation.Data(),source.Data(),i)); } Double_t maxEn = 1500.; Double_t minEn = 0.; Double_t fidMax = 55.; Int_t nHists = (int)(fidMax/binWidth); std::vector <TH1D*> histsE(nHists, 0); std::vector <TH1D*> histsW(nHists, 0); std::vector <Double_t> rmin(nHists,0); std::vector <Double_t> rmax(nHists,0); std::vector <Double_t> rmid(nHists,0); //final means and errors std::vector < Double_t > EastMeans(nHists,0.); std::vector < Double_t > WestMeans(nHists,0.); std::vector < Double_t > EastMeanErrors(nHists,0.); std::vector < Double_t > WestMeanErrors(nHists,0.); for (Int_t i=0; i<nHists; i++) { rmin[i] = i*binWidth; rmax[i] = (i+1)*binWidth; rmid[i] = (double)rmin[i] + (double)binWidth/2.; histsE[i] = new TH1D(TString::Format("his%iE",i), TString::Format("%s %i mm radius bins East", source.Data(),binWidth), 550, 0., 1100.); histsW[i] = new TH1D(TString::Format("his%iW",i), TString::Format("%s %i mm radius bins West", source.Data(),binWidth), 550, 0., 1100.); histsE[i]->SetLineColor(i+1); histsW[i]->SetLineColor(i+1); } Double_t primPos[4]; // Set the addresses of the information read in from the simulation file chain->SetBranchAddress("MWPCEnergy",&mwpcE); chain->SetBranchAddress("time",&Time); chain->SetBranchAddress("Edep",&edep); chain->SetBranchAddress("EdepQ",&edepQ); chain->SetBranchAddress("MWPCPos",&mwpc_pos); chain->SetBranchAddress("ScintPos",&scint_pos); chain->SetBranchAddress("primKE",&primKE); chain->SetBranchAddress("primTheta",&primTheta); chain->SetBranchAddress("primPos",&primPos); //Get total number of events in TChain UInt_t nevents = chain->GetEntries(); cout << "events = " << nevents << endl; for (Int_t i=0; i<nevents; i++) { chain->GetEvent(i); Int_t nBin = primPos[3]*1000./binWidth; if (edepQ.EdepQE>0. && primKE<maxEn && primKE>minEn && mwpcE.MWPCEnergyE>0.1 && primTheta>TMath::Pi()/2.) histsE[nBin]->Fill(edepQ.EdepQE); if (edepQ.EdepQW>0. && primKE<maxEn && primKE>minEn && mwpcE.MWPCEnergyW>0.1 && primTheta<TMath::Pi()/2.) histsW[nBin]->Fill(edepQ.EdepQW); if (i%100000==0) std::cout << "*"; } std::cout << std::endl; TCanvas *c1 = new TCanvas("c1","c1",1600,1200); c1->Divide(2,2); //TCanvas *c2 = new TCanvas("c2"); //histsE[1]->Draw("SAME"); Double_t refMeanE = 0., refMeanW = 0.; //This will hold the mean of the center pixel std::cout << nHists << endl; for (Int_t i=0; i<nHists; i++) { c1->cd(1); histsE[i]->Draw("SAME"); EastMeans[i] = histsE[i]->GetMean(); EastMeanErrors[i] = EastMeans[i]>0. ? EastMeans[i]/sqrt(histsE[i]->GetEntries()) : 0.; //cout << EastMeans[i][0] << " " << EastMeans[i][1] << endl; c1->cd(2); histsW[i]->Draw("SAME"); WestMeans[i] = histsW[i]->GetMean(); WestMeanErrors[i] = WestMeans[i]>0. ? WestMeans[i]/sqrt(histsW[i]->GetEntries()) : 0.; if (i==0) { refMeanE = EastMeans[i], refMeanW = WestMeans[i]; } } //TCanvas *c3 = new TCanvas("c3"); c1->cd(3); std::vector <Double_t> xerr(nHists,0.); TGraphErrors *gEast = new TGraphErrors(11, &rmax[0],&EastMeans[0],&xerr[0],&EastMeanErrors[0]); gEast->SetMarkerStyle(21); gEast->SetTitle(TString::Format("East %s Mean EQ vs. position",source.Data())); gEast->GetXaxis()->SetTitle("Position Bin Edge (mm)"); gEast->GetYaxis()->SetTitle("Energy (keV)"); gEast->Draw("AP"); TLine *eastLine = new TLine(gEast->GetXaxis()->GetXmin(),refMeanE,gEast->GetXaxis()->GetXmax(),refMeanE); eastLine->SetLineStyle(2); eastLine->Draw(); //TCanvas *c4 = new TCanvas("c4"); c1->cd(4); TGraphErrors *gWest = new TGraphErrors(11, &rmax[0],&WestMeans[0],&xerr[0],&WestMeanErrors[0]); gWest->SetMarkerStyle(21); gWest->SetTitle(TString::Format("West %s Mean EQ vs. position",source.Data())); gWest->GetXaxis()->SetTitle("Position Bin Edge (mm)"); gWest->GetYaxis()->SetTitle("Energy (keV)"); gWest->Draw("AP"); TLine *westLine = new TLine(gWest->GetXaxis()->GetXmin(),refMeanW,gWest->GetXaxis()->GetXmax(),refMeanW); westLine->SetLineStyle(2); westLine->Draw(); }