00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include "TH1.h"
00011 #include "TH1F.h"
00012 #include "TH2F.h"
00013 #include "TH3F.h"
00014
00015
00016
00017
00018 #include "TF1.h"
00019 #include "TNtuple.h"
00020 #include "TFile.h"
00021 #include "TGraph.h"
00022 #include "TGraphErrors.h"
00023 #include "TSystem.h"
00024 #include "TStyle.h"
00025 #include "TMath.h"
00026 #include "TProfile.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035 int getDVInRun(int nInRun, int *runMacro, unsigned int *runTime, double *runDVE){
00036
00037 const double maxRMS = 0.001;
00038 const int minFilesInRun=5;
00039
00040
00041
00042 int nToUseInRun = nInRun-1;
00043 int iFirstToUseInRun=0;
00044 int *runDVEOrderI = new int[nToUseInRun];
00045 double *runDVEOrderV = new double[nToUseInRun];
00046
00047 for(int iInRun=0; iInRun<nToUseInRun; iInRun++){
00048 runDVEOrderV[iInRun]=runDVE[iInRun];
00049 runDVEOrderI[iInRun]=iInRun;
00050 }
00051
00052
00053 bool bOrder = kFALSE;
00054 while(!bOrder){
00055 bOrder = kTRUE;
00056 for(int iInRun=0; iInRun<nToUseInRun-1; iInRun++){
00057 if(runDVEOrderV[iInRun]>runDVEOrderV[iInRun+1]){
00058 int tempMinI = runDVEOrderI[iInRun+1];
00059 double tempMinV = runDVEOrderV[iInRun+1];
00060 runDVEOrderI[iInRun+1]=runDVEOrderI[iInRun];
00061 runDVEOrderI[iInRun]=tempMinI;
00062 runDVEOrderV[iInRun+1]=runDVEOrderV[iInRun];
00063 runDVEOrderV[iInRun]=tempMinV;
00064 bOrder=kFALSE;
00065 }
00066 }
00067 }
00068
00069 for(int iInRun=0; iInRun<nInRun; iInRun++){
00070 cout << "In run: " << iInRun << "/" << nInRun
00071 << " " << runMacro[iInRun]
00072 << " " << runTime[iInRun]
00073 << " " << runDVE[iInRun] << endl;
00074 }
00075
00076 for(int iInRun=0; iInRun<nToUseInRun; iInRun++){
00077 cout << "Order: " << iInRun << "/" << nToUseInRun
00078 << " " << runDVEOrderV[iInRun]
00079 << " " << runDVEOrderI[iInRun] << endl;
00080 }
00081
00082 int nInOrderU = 0;
00083 int nInOrderD = 0;
00084 for(int iInRun=0; iInRun<nToUseInRun; iInRun++){
00085 if(runDVEOrderI[iInRun]==iInRun){
00086 nInOrderU++;
00087 }
00088 if(runDVEOrderI[iInRun]==nToUseInRun-iInRun-1){
00089 nInOrderD++;
00090 }
00091 }
00092
00093 if(nToUseInRun>=minFilesInRun-1){
00094 if(nInOrderU==nToUseInRun || nInOrderD==nToUseInRun){
00095 double *meanDiff = new double[nToUseInRun-2];
00096 if(nInOrderU==nToUseInRun){
00097 cout << "Drift Velocities East are ordered (U) in time. Check convergence ..." << endl;
00098 for(int i=0; i<nToUseInRun-2; i++){
00099 meanDiff[i]=0.;
00100 for(int j=i; j<nToUseInRun-1; j++){
00101 meanDiff[i]+=(runDVEOrderV[j+1]-runDVEOrderV[j]);
00102 }
00103 meanDiff[i]/=(nToUseInRun-i-1);
00104 }
00105 }
00106 if(nInOrderD==nToUseInRun){
00107 cout << "Drift Velocities East are ordered (D) in time. Check convergence ..." << endl;
00108 for(int i=0; i<nToUseInRun-2; i++){
00109 meanDiff[i]=0.;
00110 for(int j=nToUseInRun-i-1; j>0; j--){
00111 meanDiff[i]+=runDVEOrderV[j-1]-runDVEOrderV[j];
00112 }
00113 meanDiff[i]/=(nToUseInRun-i-1);
00114 }
00115 }
00116 int nDiffInOrder = 0;
00117 for(int i=0; i<nToUseInRun-3; i++){
00118 if(meanDiff[i]>meanDiff[i+1]){
00119 nDiffInOrder++;
00120 }
00121 }
00122 if(nDiffInOrder>=nToUseInRun-3-1){
00123 if(nInOrderU==nToUseInRun) iFirstToUseInRun++;
00124 if(nInOrderD==nToUseInRun) nToUseInRun--;
00125 cout << "Convergence found! Will remove earliest entry and continue." << endl;
00126 }
00127 else {
00128 cout << "No convergence found! This run should be checked. No macro will be kept!" << endl;
00129 return -1;
00130 }
00131 }
00132 }
00133
00134 int tryThreeRMS = 0;
00135 int iNotValidRMS1 = -1;
00136 int iNotValidRMS2 = -1;
00137
00138 if(nToUseInRun==minFilesInRun-2){
00139 tryThreeRMS=2;
00140 }
00141
00142 while(tryThreeRMS<3){
00143 double runMean = 0.;
00144 double runRMS = 0.;
00145 int nRMS = 0;
00146
00147 for(int iInRun=iFirstToUseInRun; iInRun<nToUseInRun; iInRun++){
00148 if(iInRun!=iNotValidRMS1 && iInRun!=iNotValidRMS2){
00149 runMean+=runDVEOrderV[iInRun];
00150 runRMS+=runDVEOrderV[iInRun]*runDVEOrderV[iInRun];
00151 nRMS++;
00152 }
00153 }
00154 runMean/=nRMS;
00155 runRMS/=nRMS;
00156 runRMS-=runMean*runMean;
00157 runRMS=TMath::Sqrt(runRMS);
00158
00159 cout << "This run RMS = " << runRMS << endl;
00160
00161 int tryTwiceLow = 0;
00162 int iNotValidLow = -1;
00163
00164 if(runRMS<maxRMS){
00165 tryTwiceLow = 0;
00166 iNotValidLow = -1;
00167 while(tryTwiceLow<2){
00168 int iMeanOrder = 0;
00169 double diffToMean = 100.;
00170 for(int iInRun=iFirstToUseInRun; iInRun<nToUseInRun; iInRun++){
00171 double lDiffToMean = TMath::Abs(runDVEOrderV[iInRun]-runMean);
00172 if(lDiffToMean<diffToMean && iInRun!=iNotValidLow &&
00173 iInRun!=iNotValidRMS1 && iInRun!=iNotValidRMS2){
00174 diffToMean=lDiffToMean;
00175 iMeanOrder=iInRun;
00176 }
00177 }
00178 int lowThird = nInRun/3;
00179 if(runDVEOrderI[iMeanOrder]/lowThird!=0 || (tryTwiceLow==1 && tryThreeRMS==2)){
00180 int iKeepMacro = runMacro[runDVEOrderI[iMeanOrder]];
00181 cout << "Keep Macro: " << iKeepMacro << " " << runTime[runDVEOrderI[iMeanOrder]]
00182 << " " << runDVE[runDVEOrderI[iMeanOrder]] << endl;
00183 cout << runDVEOrderI[iMeanOrder] << "/" << nInRun << " " << iMeanOrder << endl;
00184
00185 return iKeepMacro;
00186 }
00187
00188 tryTwiceLow++;
00189 iNotValidLow=iMeanOrder;
00190 cout << "Drift Velocity East value closer to mean was found in the first third of the run, is safer to try next closest value." << endl;
00191 cout << "tryTwiceLow= " << tryTwiceLow << " iNotValidLow= " << iNotValidLow << endl;
00192 }
00193 }
00194
00195 int iFarOrder = 0;
00196 double diffToMean = 0.;
00197 for(int iInRun=iFirstToUseInRun; iInRun<nToUseInRun; iInRun++){
00198 double lDiffToMean = TMath::Abs(runDVEOrderV[iInRun]-runMean);
00199 if(lDiffToMean>diffToMean && iInRun!=iNotValidRMS1 && iInRun!=iNotValidRMS2){
00200 diffToMean=lDiffToMean;
00201 iFarOrder=iInRun;
00202 }
00203 }
00204 tryThreeRMS++;
00205 if (tryThreeRMS<2){
00206 iNotValidRMS1=iFarOrder;
00207 if (tryTwiceLow==2)
00208 cout << "Will remove Further most value and try again." << endl;
00209 else
00210 cout << "RMS of Drift Velocity East is too large! Will remove Further most value." << endl;
00211 cout << "RMS " << runRMS << " > " << maxRMS << endl;
00212 cout << "tryThreeRMS= " << tryThreeRMS << " iNotValidRMS1= " << iNotValidRMS1 << endl;
00213 }
00214 else{
00215 iNotValidRMS2=iFarOrder;
00216 if (tryTwiceLow==2)
00217 cout << "Will remove Further most value and try again." << endl;
00218 else
00219 cout << "RMS of Drift Velocity East is too large! Will remove Further most value." << endl;
00220 cout << "RMS " << runRMS << " > " << maxRMS << endl;
00221 cout << "tryThreeRMS= " << tryThreeRMS << " iNotValidRMS2= " << iNotValidRMS2 << endl;
00222 }
00223 }
00224
00225 cout << "Couldn't find a good macro to be kept for this run! Run should be checked!" << endl;
00226 return -1;
00227
00228 }
00229
00230 int getDriftVelocityDB(unsigned int funixTime, unsigned int& uitimedb, double& ldvedb ){
00231
00232 char *fDbName = "Calibrations_tpc";
00233 char *fTableName = "tpcDriftVelocity";
00234 char *fFlavorName = "laserDV";
00235 char *fTimestamp = "2004-10-31 00:00:00";
00236
00237
00238 StDbManager* mgr = StDbManager::Instance();
00239
00240 StDbConfigNode* configNode = mgr->initConfig(fDbName);
00241
00242 StDbTable* dbtable;
00243 dbtable = configNode->addDbTable(fTableName);
00244
00245
00246 if (dbtable == 0){
00247 cout << " No Table : " << fTableName << endl;
00248 return 0;
00249 }
00250
00251 if (fFlavorName != 0){
00252 dbtable -> setFlavor(fFlavorName);
00253 cout << "Flavor is set as " << fFlavorName << " by StDbTable::setFlavor." << endl;
00254 }else{
00255 cout << "Flavor is NOT assigned. Default value is set as 'ofl'. " << endl;
00256 dbtable -> setFlavor("ofl");
00257 }
00258
00259 if(funixTime) {
00260 mgr->setRequestTime(funixTime);
00261 } else {
00262 mgr->setRequestTime(fTimestamp);
00263 }
00264
00265 mgr->fetchDbTable(dbtable);
00266 void* cstruct = dbtable->GetTableCpy();
00267 Int_t nrows = dbtable->GetNRows();
00268
00269 St_tpcDriftVelocity * tpcDV =
00270 (St_tpcDriftVelocity*)TTable::New(fTableName,fTableName,cstruct,nrows);
00271
00272 if(!(tpcDV && tpcDV->HasData())) {
00273 cout << "No TTable returned!" << endl;
00274 return 0;
00275 }
00276 tpcDriftVelocity_st *ltpcDVs = (tpcDriftVelocity_st*)tpcDV->At(0);
00277
00278 uitimedb = dbtable->getBeginTime();
00279 ldvedb = ltpcDVs->laserDriftVelocityEast;
00280
00281 return 1;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 void LoadLaserDriftVelocityToDb(const char* dirName, const char* listOfMacros, const char* baseName, int mode=0){
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 const int nMacrosMax = 800;
00303 int nMacros = 0;
00304
00305 TString fullListName(dirName);
00306 fullListName +="/";
00307 fullListName +=listOfMacros;
00308
00309 const char* tmpLines = "/tmp/nLines.txt";
00310 TString myCount("/usr/bin/wc -l ");
00311 myCount += fullListName;
00312 myCount += " > ";
00313 myCount += tmpLines;
00314
00315
00316
00317
00318
00319 cout << "Executing: " << myCount.Data() << endl;
00320
00321 gSystem->Exec(myCount.Data());
00322 ifstream dvc(tmpLines);
00323 dvc >> nMacros;
00324 TString myRm("/bin/rm ");
00325 myRm += tmpLines;
00326 gSystem->Exec(myRm.Data());
00327
00328 cout << "Number of macros in list: " << nMacros << endl;
00329 nMacros = TMath::Min(nMacros,nMacrosMax);
00330 cout << "Number of macros to read: " << nMacros << endl;
00331
00332 const double maxdDVdt = 3*0.000002;
00333
00334
00335
00336
00337
00338 gSystem->Load("St_base");
00339 gSystem->Load("StUtilities");
00340 gSystem->Load("StarClassLibrary");
00341 gSystem->Load("St_Tables");
00342 gSystem->Load("StDbLib");
00343
00344
00345 double *xLaserDVE = new double[nMacros];
00346 double *yLaserDVE = new double[nMacros];
00347
00348 double *xLaserDVW = new double[nMacros];
00349 double *yLaserDVW = new double[nMacros];
00350
00351 int *macroStatus = new int[nMacros];
00352
00353 char nameMacro[100];
00354 TString fullNameMacro;
00355 unsigned int uidatetime;
00356
00357 St_tpcDriftVelocity *tpcDV;
00358 tpcDriftVelocity_st *tpcDVs;
00359
00360 FILE *theList;
00361 theList = fopen(fullListName.Data(),"r");
00362
00363
00364 StDbManager* mgr=StDbManager::Instance();
00365
00366
00367 const int maxDeltaT=120;
00368 const int maxFilesInRun=30;
00369 const int minFilesInRun=5;
00370
00371 int nInRun=0;
00372 int nMacroToKeep=0;
00373 int nTryToKeep=0;
00374 unsigned int lastTime=0;
00375 int *macroToKeep = new int[nMacros];
00376 int *runMacro = new int[maxFilesInRun];
00377 unsigned int *runTime = new unsigned int[maxFilesInRun];
00378 double *runDVE = new double[maxFilesInRun];
00379
00380
00381 for(int iMacro=0; iMacro<nMacros; iMacro++){
00382 if (!feof(theList)){
00383 cout << "\n" << "iMacro = " << iMacro << endl;
00384 macroStatus[iMacro]=6;
00385 fscanf(theList,"%s",&nameMacro);
00386 if(strstr(nameMacro,baseName)){
00387 fullNameMacro = TString(dirName);
00388 fullNameMacro+="/";
00389 fullNameMacro+=nameMacro;
00390 printf("Reading macro: %s\n",fullNameMacro.Data());
00391
00392 char* sdatetime=strstr(nameMacro,"."); sdatetime++;
00393 TString tsdatetime(sdatetime);
00394 tsdatetime = tsdatetime.ReplaceAll(".C","");
00395 tsdatetime = tsdatetime.ReplaceAll("."," ");
00396 tsdatetime = tsdatetime.Insert(4,"-");
00397 tsdatetime = tsdatetime.Insert(7,"-");
00398 tsdatetime = tsdatetime.Insert(13,":");
00399 tsdatetime = tsdatetime.Insert(16,":");
00400 sdatetime = tsdatetime.Data();
00401
00402 mgr->setRequestTime(sdatetime);
00403 uidatetime = mgr->getUnixRequestTime();
00404 cout << " " << sdatetime << " " << uidatetime << endl;
00405 if (uidatetime == 0){
00406 cout << " Macro error " << endl;
00407 return;
00408 }
00409
00410
00411 gROOT->LoadMacro(fullNameMacro.Data());
00412 tpcDV = (St_tpcDriftVelocity*)CreateTable();
00413 if(tpcDV && tpcDV->HasData()) {
00414 cout << " Macro succesfully loaded" << endl;
00415
00416 tpcDVs = (tpcDriftVelocity_st*)tpcDV->At(0);
00417
00418 xLaserDVE[iMacro]=uidatetime;
00419 yLaserDVE[iMacro]=tpcDVs->laserDriftVelocityEast;
00420
00421 xLaserDVW[iMacro]=uidatetime;
00422 yLaserDVW[iMacro]=tpcDVs->laserDriftVelocityWest;
00423
00424 cout << " Laser Drift Velocity East: " <<tpcDVs->laserDriftVelocityEast << endl;
00425
00426
00427
00428
00429
00430 if (mode == 1) {
00431
00432 macroToKeep[nMacroToKeep++] = iMacro;
00433 macroStatus[iMacro] = iMacro;
00434 continue;
00435 }
00436
00437
00438
00439 if (nInRun==0){ lastTime = uidatetime;}
00440
00441 if ((uidatetime-lastTime)<maxDeltaT && nInRun<maxFilesInRun ){
00442
00443 cout << " Delta time passed & not enough count "
00444 << nInRun << " <=> " << maxFilesInRun << " yet" << endl;
00445 runMacro[nInRun]=iMacro;
00446 runTime[nInRun]=uidatetime;
00447 runDVE[nInRun]=tpcDVs->laserDriftVelocityEast;
00448
00449 nInRun++;
00450 lastTime = uidatetime;
00451
00452 } else if (nInRun>=minFilesInRun-1){
00453
00454 nTryToKeep++;
00455 int keepIt = getDVInRun(nInRun,runMacro,runTime,runDVE);
00456 if (keepIt!=-1) {
00457 macroToKeep[nMacroToKeep++] = keepIt;
00458 for (int iInRun=0; iInRun<nInRun; iInRun++){
00459 macroStatus[runMacro[iInRun]]=keepIt;
00460 }
00461 }
00462 else {
00463 for (int iInRun=0; iInRun<nInRun; iInRun++){
00464 macroStatus[runMacro[iInRun]]=2;
00465 }
00466 }
00467
00468 nInRun=0;
00469
00470 runMacro[nInRun]=iMacro;
00471 runTime[nInRun]=uidatetime;
00472 runDVE[nInRun]=tpcDVs->laserDriftVelocityEast;
00473 nInRun++;
00474 lastTime = uidatetime;
00475
00476 } else {
00477
00478 cout << " Not Enough macros!" << nInRun << " " << minFilesInRun << endl;
00479 for (int iInRun=0; iInRun<nInRun; iInRun++){
00480 macroStatus[runMacro[iInRun]]=1;
00481 runMacro[nInRun]=0;
00482 runTime[nInRun]=0;
00483 runDVE[nInRun]=0;
00484 }
00485
00486 nInRun=0;
00487
00488 runMacro[nInRun]=iMacro;
00489 runTime[nInRun]=uidatetime;
00490 runDVE[nInRun]=tpcDVs->laserDriftVelocityEast;
00491 nInRun++;
00492 lastTime = uidatetime;
00493 }
00494 }
00495 }
00496 }
00497 }
00498
00499
00500 cout << "\n" << "Processing information" << endl;
00501 if (mode==0) {
00502 if (nInRun>=minFilesInRun-1 || mode==1){
00503 nTryToKeep++;
00504 int keepIt = mode || getDVInRun(nInRun,runMacro,runTime,runDVE);
00505 if (keepIt!=-1) {
00506 macroToKeep[nMacroToKeep++] = keepIt;
00507 for (int iInRun=0; iInRun<nInRun; iInRun++){
00508 macroStatus[runMacro[iInRun]]=keepIt;
00509 }
00510 }
00511 else {
00512 for (int iInRun=0; iInRun<nInRun; iInRun++){
00513 macroStatus[runMacro[iInRun]]=2;
00514 }
00515 }
00516
00517 } else {
00518 cout << "We concluded we do not have Enough macros at this stage" << endl;
00519 for (int iInRun=0; iInRun<nInRun; iInRun++){
00520 macroStatus[runMacro[iInRun]]=1;
00521 }
00522 }
00523
00524 cout << "Selected " << nMacroToKeep << " out of " << nTryToKeep
00525 << " runs with enough macros." << endl;
00526
00527 }
00528
00529 TString LoadDone(dirName); LoadDone +="/Load/Done/";
00530 TString LoadFailed(dirName); LoadFailed +="/Load/Failed/";
00531 TString LoadOthers(dirName); LoadOthers +="/Load/Others/";
00532 TString CheckBadRun(dirName); CheckBadRun+="/Check/BadRun/";
00533 TString CheckVarSel(dirName); CheckVarSel+="/Check/VarSel/";
00534 TString CheckVarOth(dirName); CheckVarOth+="/Check/VarOth/";
00535
00536
00537
00538
00539
00540
00541 unsigned int uidatetimedb =0;
00542 double laseredvdb =0.;
00543
00544 double dDVdt = 0.;
00545 double dDV =0.;
00546 double dt =0.;
00547 int iMacroToKeep = 0;
00548
00549 int nMacroKept=0;
00550 int *macroKept = new int[nMacros];
00551
00552 int nSuccess = 0;
00553 int nFailed = 0;
00554
00555 if (nMacroToKeep>0){
00556 rewind(theList);
00557 for(int iMacro=0; iMacro<nMacros; iMacro++){
00558 cout << "iMacro = " << iMacro << endl;
00559 if (!feof(theList)){
00560 fscanf(theList,"%s",&nameMacro);
00561 cout << "macroToKeep[" << iMacroToKeep << "]=" << macroToKeep[iMacroToKeep] << endl;
00562 if (iMacro==macroToKeep[iMacroToKeep]){
00563 if(strstr(nameMacro,baseName)){
00564 fullNameMacro = TString(dirName);
00565 fullNameMacro+="/";
00566 fullNameMacro+=nameMacro;
00567 printf("Reading macro: %s\n",fullNameMacro.Data());
00568
00569 char* sdatetime=strstr(nameMacro,"."); sdatetime++;
00570 TString tsdatetime(sdatetime);
00571 tsdatetime = tsdatetime.ReplaceAll(".C","");
00572 tsdatetime = tsdatetime.ReplaceAll("."," ");
00573 tsdatetime = tsdatetime.Insert(4,"-");
00574 tsdatetime = tsdatetime.Insert(7,"-");
00575 tsdatetime = tsdatetime.Insert(13,":");
00576 tsdatetime = tsdatetime.Insert(16,":");
00577 sdatetime = tsdatetime.Data();
00578 mgr->setRequestTime(sdatetime);
00579 uidatetime = mgr->getUnixRequestTime();
00580 cout << "sdatetime=" << sdatetime << " uidatetime=" << uidatetime << endl;
00581
00582 if(iMacroToKeep==0){
00583
00584 getDriftVelocityDB(uidatetime,uidatetimedb,laseredvdb);
00585
00586 dt = -(double) uidatetimedb;
00587 dDV = -laseredvdb;
00588 }
00589
00590
00591 gROOT->LoadMacro(fullNameMacro.Data());
00592 tpcDV = (St_tpcDriftVelocity*)CreateTable();
00593 if(!(tpcDV && tpcDV->HasData())) {
00594 cout << "No TTable returned!" << endl;
00595 continue;
00596 }
00597 tpcDVs = (tpcDriftVelocity_st*)tpcDV->At(0);
00598
00599
00600 cout << "dt=" << dt << " uidatetime=" << uidatetime << " -> " << (double) uidatetime << endl;
00601 dt += (double) uidatetime;
00602 cout << "Now dt=" << dt << endl;
00603
00604
00605 dDV += tpcDVs->laserDriftVelocityEast;
00606
00607
00608 if (dt==0){
00609 if(dDV==0) dDVdt = 0;
00610 else dDVdt = maxdDVdt+1;
00611 } else {
00612 dDVdt = TMath::Abs(dDV/dt);
00613 }
00614
00615 cout << "dDV/dt=" << dDV << "/" << dt << "=" << dDVdt << endl;
00616
00617 if(dDVdt<maxdDVdt){
00618 macroKept[nMacroKept++] = iMacro;
00619 int jMacro=iMacro;
00620 while(macroStatus[++jMacro]==iMacro){
00621 macroStatus[jMacro]=3;
00622 }
00623 jMacro=iMacro;
00624 while(macroStatus[--jMacro]==iMacro){
00625 macroStatus[jMacro]=3;
00626 }
00627 macroStatus[iMacro]=0;
00628
00629 dt=-(double)uidatetime;
00630 dDV=-tpcDVs->laserDriftVelocityEast;
00631 }
00632 else{
00633 int jMacro=iMacro;
00634 while(macroStatus[++jMacro]==iMacro){
00635 macroStatus[jMacro]=4;
00636 }
00637 jMacro=iMacro;
00638 while(macroStatus[--jMacro]==iMacro){
00639 macroStatus[jMacro]=4;
00640 }
00641 macroStatus[iMacro]=5;
00642
00643 dt-=(double)uidatetime;
00644 dDV-=tpcDVs->laserDriftVelocityEast;
00645 }
00646
00647 gInterpreter->ResetGlobals();
00648 iMacroToKeep++;
00649 }
00650 }
00651 }
00652 }
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667 StDbModifier *dm = new StDbModifier();
00668 dm->SetDbName("Calibrations_tpc");
00669 dm->SetFlavor("laserDV");
00670 dm->SetTableName("tpcDriftVelocity");
00671
00672
00673
00674 rewind(theList);
00675 for(int iMacro=0; iMacro<nMacros; iMacro++){
00676 cout << "iMacro = " << iMacro << endl;
00677 if (!feof(theList)){
00678 fscanf(theList,"%s",&nameMacro);
00679 cout << "macroStatus[" << iMacro << "]=" << macroStatus[iMacro] << endl;
00680 if(strstr(nameMacro,baseName)){
00681 fullNameMacro = TString(dirName);
00682 fullNameMacro+="/";
00683 fullNameMacro+=nameMacro;
00684 TString newFile;
00685 switch (macroStatus[iMacro]) {
00686 case 0:
00687 dm->SetInputFileName(fullNameMacro.Data());
00688 char* sdatetime=strstr(nameMacro,"."); sdatetime++;
00689 TString tsdatetime(sdatetime);
00690 tsdatetime = tsdatetime.ReplaceAll(".C","");
00691 tsdatetime = tsdatetime.ReplaceAll("."," ");
00692 tsdatetime = tsdatetime.Insert(4,"-");
00693 tsdatetime = tsdatetime.Insert(7,"-");
00694 tsdatetime = tsdatetime.Insert(13,":");
00695 tsdatetime = tsdatetime.Insert(16,":");
00696 sdatetime = tsdatetime.Data();
00697 dm->SetDateTime(sdatetime);
00698 cout << "Loading " << fullNameMacro.Data() << " ... ";
00699 if(dm->WriteDataToDB()==1){
00700 cout << " Succeeded!" << endl;
00701 newFile+=LoadDone;
00702 nSuccess++;
00703 }
00704 else {
00705 cout << " Failed!" << endl;
00706 newFile+=LoadFailed;
00707 nFailed++;
00708 }
00709 newFile+=nameMacro;
00710 break;
00711 case 1:
00712 newFile = TString(dirName);
00713 newFile+="/";
00714 newFile+=nameMacro;
00715 break;
00716 case 2:
00717 newFile+=CheckBadRun;
00718 newFile+=nameMacro;
00719 break;
00720 case 3:
00721 newFile+=LoadOthers;
00722 newFile+=nameMacro;
00723 break;
00724 case 4:
00725 newFile+=CheckVarOth;
00726 newFile+=nameMacro;
00727 break;
00728 case 5:
00729 newFile+=CheckVarSel;
00730 newFile+=nameMacro;
00731 break;
00732 default:
00733 newFile = TString(dirName);
00734 newFile+="/";
00735 newFile+=nameMacro;
00736 }
00737
00738
00739 cout << newFile.Data() << endl;
00740 if(rename(fullNameMacro.Data(),newFile.Data()))
00741 cout << "Error moving file to " << newFile.Data() << endl;
00742 FILE *FI;
00743 if( (FI = fopen(fullNameMacro.Data(),"r")) != NULL){
00744 cout << "File " << fullNameMacro.Data() << " remained at its original place " << endl;
00745 fclose(FI);
00746 }
00747 }
00748 }
00749 }
00750 }
00751
00752 double *xLaserDVEk = new double[nMacroKept];
00753 double *yLaserDVEk = new double[nMacroKept];
00754
00755 double *xLaserDVWk = new double[nMacroKept];
00756 double *yLaserDVWk = new double[nMacroKept];
00757
00758 for(int iMacro=0; iMacro<nMacroKept; iMacro++){
00759 xLaserDVEk[iMacro] = xLaserDVE[macroKept[iMacro]];
00760 yLaserDVEk[iMacro] = yLaserDVE[macroKept[iMacro]];
00761 xLaserDVWk[iMacro] = xLaserDVW[macroKept[iMacro]];
00762 yLaserDVWk[iMacro] = yLaserDVW[macroKept[iMacro]];
00763 }
00764
00765 TGraph *tpcLaserDriftVelocityEast = new TGraph(nMacros,xLaserDVE,yLaserDVE);
00766 TGraph *tpcLaserDriftVelocityWest = new TGraph(nMacros,xLaserDVW,yLaserDVW);
00767
00768 TGraph *tpcLaserDriftVelocityEastK = new TGraph(nMacroKept,xLaserDVEk,yLaserDVEk);
00769 TGraph *tpcLaserDriftVelocityWestK = new TGraph(nMacroKept,xLaserDVWk,yLaserDVWk);
00770
00771 TString Load(dirName); Load+="/Load/";
00772 Load+="tpcLaserDV_Auto.root";
00773 TFile *hFile = new TFile(Load.Data(),"RECREATE");
00774
00775 tpcLaserDriftVelocityEast->Write("tpcLaserDriftVelocityEast");
00776 tpcLaserDriftVelocityWest->Write("tpcLaserDriftVelocityWest");
00777 tpcLaserDriftVelocityEastK->Write("tpcLaserDriftVelocityEastK");
00778 tpcLaserDriftVelocityWestK->Write("tpcLaserDriftVelocityWestK");
00779
00780 hFile->Close();
00781
00782 TCanvas cvn1;
00783 cvn1.cd();
00784
00785 TH1F *oneDHisto = new TH1F("oneDHisto","oneDHisto",100,xLaserDVE[0]-100,xLaserDVE[nMacros-1]+100);
00786
00787 oneDHisto->SetMaximum(5.6);
00788 oneDHisto->SetMinimum(5.4);
00789 oneDHisto->SetTitle("TPC Laser Drift Velocity");
00790 oneDHisto->SetXTitle("Time (unix)");
00791 oneDHisto->SetYTitle("dv (cm/#mus)");
00792 oneDHisto->Draw();
00793
00794 tpcLaserDriftVelocityWest->SetMarkerStyle(23);
00795 tpcLaserDriftVelocityWest->SetMarkerColor(2);
00796
00797
00798 tpcLaserDriftVelocityEast->SetMarkerStyle(22);
00799 tpcLaserDriftVelocityEast->SetMarkerColor(4);
00800 tpcLaserDriftVelocityEast->Draw("PL");
00801
00802 tpcLaserDriftVelocityEastK->SetMarkerStyle(22);
00803 tpcLaserDriftVelocityEastK->Draw("PL");
00804
00805
00806 cvn1.Update();
00807 Load.ReplaceAll(".root",".eps");
00808 cvn1.SaveAs(Load.Data());
00809
00810 cout << endl << endl << " ******************************************** " << endl;
00811 cout << " Number of Macros attempted = " << nMacros << endl;
00812 cout << nSuccess << " loaded to DB and " << nFailed << " failed to be load!" << endl;
00813
00814 }
00815