Changeset 312 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/softwareGenerator.cc
- Timestamp:
- Feb 5, 2013, 2:23:23 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/softwareGenerator.cc
r305 r312 1 1 #include "softwareGenerator.h" 2 2 #include "abstractElement.h" 3 #include "parmelaParticle.h" 3 #include "generatorParticle.h" 4 #include "mathematicalConstants.h" 5 #include "PhysicalConstants.h" 4 6 #include "dataManager.h" 5 7 … … 21 23 bool softwareGenerator::createInputFile(string inputFileName, particleBeam* beamBefore, unsigned int numeroDeb, unsigned int numeroFin, string workingDir) 22 24 { 23 24 25 if ( numeroDeb != numeroFin ) return false; 25 26 26 27 abstractElement* elPtr; 27 elPtr = dataManager_->getElementPointerFrom Index(numeroDeb);28 elPtr = dataManager_->getElementPointerFromNumero(numeroDeb); 28 29 29 30 if ( elPtr->getNomdElement().getElementType() != RFgun ) { … … 31 32 return false; 32 33 } 33 34 34 ofstream outfile; 35 35 string name = workingDir + inputFileName; … … 39 39 return false; 40 40 } 41 42 41 outfile << "&INPUT" << endl; 43 42 string fichier = "'" + workingDir + "faisceau.ini" + "'"; … … 50 49 return true; 51 50 } 51 52 53 bool softwareGenerator::execute(string inputFileName, unsigned int numeroDeb,unsigned int numeroFin,string workingDir,string& resul) { 54 ostringstream sortie; 55 bool ExecuteStatus = true; 56 resul.clear(); 57 sortie << " EXECUTION DE GENERATOR DE l'ELEMENT " << numeroDeb << " A L'ELEMENT " << numeroFin << endl; 58 59 char buf[132]; 60 string generatorJob = workingDir + "generator"; 61 generatorJob += string(" "); 62 generatorJob += workingDir + inputFileName; 63 64 65 ofstream outfile; 66 string nameOut = workingDir + "generator.output"; 67 string resultOfRun; 68 bool success = launchJob(generatorJob, resultOfRun); 69 sortie << resultOfRun << endl; 70 if ( !success) { 71 sortie << " launching of generator failed " << endl; 72 ExecuteStatus = false; 73 } 74 else { 75 cout << " execution generator MARCHE " << endl; 76 sortie << resultOfRun; 77 outfile.open(nameOut.c_str(), ios::out); 78 if (!outfile) 79 { 80 sortie << " error first opening transport output stream " << nameOut << endl; 81 ExecuteStatus = false; 82 } 83 else { 84 // on copie la sortie dans un fichier 'generator.out' 85 outfile << resultOfRun << endl; 86 outfile.close(); 87 } 88 } 89 resul = sortie.str(); 90 return ExecuteStatus; 91 } 92 93 bool softwareGenerator::buildBeamAfterElements(unsigned int numeroDeb,unsigned int numeroFin, vector<particleBeam>& beams, string workingDir) { 94 95 bool result = true; 96 if ( numeroDeb != numeroFin ) return false; 97 98 beams.push_back(particleBeam()); 99 vector<double> centroid; 100 bareParticle refPart; 101 vector<bareParticle> particles; 102 vector<bareParticle> particlesPassives; // on ne fait rien de ces particules pour l'instant 103 if (beamFromGenerator(string("faisceau.ini"),workingDir, centroid, refPart,particles, particlesPassives )) { 104 beams.back().setWithParticles(centroid, refPart,particles); 105 } else { 106 result = false; 107 } 108 return result; 109 } 110 111 bool softwareGenerator::beamFromGenerator(string beamFileName, string workingDir, vector<double>& centroid, bareParticle& refPart,vector<bareParticle>& particles, vector<bareParticle>& passiveParticles ) { 112 unsigned k; 113 FILE* filefais; 114 string nomfilefais = workingDir + beamFileName; 115 cout << " nom fichier sortie generator : " << nomfilefais << endl; 116 filefais = fopen(nomfilefais.c_str(), "r"); 117 if ( filefais == (FILE*)0 ) { 118 cerr << " beamFromGenerator() erreur a l'ouverture du fichier" << nomfilefais << endl;; 119 return false; 120 } 121 else cout << " beamFromGenerator() : ouverture du fichier " << nomfilefais << endl; 122 123 generatorParticle partic; 124 std::vector<generatorParticle> faisceau; 125 int nbProbPart =0; 126 double timeRef = 0.0; 127 double betagammaZRef = 0.0; 128 // lecture part. de reference 129 if ( partic.readFromGeneratorFile(filefais) > 0 ) 130 { 131 if ( partic.index != 1 ) { 132 cout << " ERROR softwareGenerator::beamFromGenerator : particles are not electrons, we have to reconsider this method " << endl; 133 return false; 134 } 135 136 if ( partic.flag != -1 ) { 137 cout << " ATTENTION softwareGenerator::beamFromGenerator : flag different de -1 " << endl; 138 } 139 if (fabs(partic.xx) > EPSILON || fabs(partic.yy) > EPSILON || fabs(partic.px) > EPSILON || fabs(partic.py) > EPSILON) { 140 printf(" ATTENTION softwareGenerator::beamFromGenerator : part. reference douteuse \n"); 141 partic.imprim(); 142 } 143 timeRef = partic.clock; 144 TRIDVECTOR posRef(100.*partic.xx,100.*partic.yy,100.*partic.zz); // en cm 145 betagammaZRef = partic.pz/ERESTeV; 146 // l'impulsion donnee par generator est en eV/c 147 TRIDVECTOR betagammaRef(partic.px/ERESTeV , partic.py/ERESTeV, betagammaZRef); 148 refPart = bareParticle(posRef, betagammaRef); 149 150 // seule la part. de reference a un pz absolu (les autres pat. on un pz relatif a la ref) 151 // je mets ici a zero, pour homogeneiser 152 partic.pz = 0.0; 153 faisceau.push_back(partic); 154 } 155 156 while( partic.readFromGeneratorFile(filefais) > 0 ) { 157 faisceau.push_back(partic); 158 if ( partic.flag != -1 ) nbProbPart++; 159 } 160 161 if ( faisceau.size() == 0) 162 { 163 cerr << " softwareGenerator::beamFromGenerator echec lecture " << endl; 164 return false; 165 } 166 // pour l'instant on choisit un centroid nul; 167 centroid.clear(); 168 centroid = vector<double>(6,0.0); 169 170 particles.clear(); 171 passiveParticles.clear(); 172 // particles.resize(faisceau.size() - nbProbPart, bareParticle()); 173 // passiveParticles.resize(nbProbPart, bareParticle()); 174 double x,y; 175 double deltaz; 176 double deltat; 177 TRIDVECTOR pos; 178 TRIDVECTOR betagamma; 179 double pxPart; 180 double pyPart; 181 double pzPartRel; 182 double deltaPzPart; 183 184 for ( k=0; k < faisceau.size(); k++) { 185 186 pxPart = faisceau.at(k).px; 187 pyPart = faisceau.at(k).py; 188 pzPartRel = faisceau.at(k).pz; 189 deltaPzPart = faisceau.at(k).pz; 190 x=faisceau.at(k).xx; 191 y=faisceau.at(k).yy; 192 193 // tout ce qui suit sera a clarifier 194 double betaGammax = pxPart/ERESTeV; 195 double betaGammay = pyPart/ERESTeV; 196 double betaGammaz = betagammaZRef + pzPartRel/ERESTeV; 197 betagamma.setComponents(betaGammax, betaGammay, betaGammaz); 198 double gamma = sqrt(1.0 + betagamma.norm2()); 199 200 // decalage temporel par rapport a la reference 201 deltat = faisceau.at(k).clock - timeRef; // nanoseondes 202 double ds = CLIGHT_m_per_ns * deltat /gamma; 203 x += betaGammax * ds; // en metres 204 y += betaGammay * ds; 205 206 // ici on neglige la difference entre gamma de la part. et gamma de la ref. 207 deltaz = (pzPartRel/ERESTeV) * CLIGHT_m_per_ns * deltat; // en metres 208 209 pos.setComponents(100.*x,100.*y,100.*deltaz); // en cm 210 if ( faisceau.at(k).flag == -1 ) { 211 particles.push_back(bareParticle(pos,betagamma)); 212 } else { 213 passiveParticles.push_back(bareParticle(pos,betagamma)); 214 } 215 } 216 217 218 return true; 219 }
Note: See TracChangeset
for help on using the changeset viewer.