void mergeFiles(QString XMLFile){ QString outname; QMap<int,O3DPFile*> o3dpfileMap; QVector<fileWithLocation> files; QVector<long> outGridSize(3,0); QVector<float> voxDims(3,0); QVector<double> outBBox(6,0); quint32 nmat = 0; /// Parse XML into /// - fileWithLocations /// - a fixed gridsize /// - bbox /// - outfilename QFile f(XMLFile); f.open(QIODevice::ReadOnly); QXmlStreamReader xml(&f); while(!xml.atEnd() && !xml.hasError()){ QXmlStreamReader::TokenType token = xml.readNext(); if(token == QXmlStreamReader::StartDocument){ //we don’t want any of this data, it isn’t any element //we need. continue; } if(token == QXmlStreamReader::StartElement) { if(xml.name() == "files"){ continue; } if(xml.name() == "filename"){ outname = xml.readElementText(); qDebug()<<"outname: "<<outname; } if(xml.name() == "inputfile"){ int id = xml.attributes().value("id").toInt(); QString filename = xml.readElementText(); O3DPFile* input = new O3DPFile(filename); o3dpfileMap[id] = input; } if (xml.name() == "insertfile"){ int id = xml.attributes().value("id").toInt(); QVector<int> indecies(3,0.0); indecies[0] = xml.attributes().value("x").toFloat(); indecies[1] = xml.attributes().value("y").toFloat(); indecies[2] = xml.attributes().value("z").toFloat(); fileWithLocation loc; loc.o3dp = o3dpfileMap[id]; loc.indices = indecies; nmat = std::max(nmat,loc.o3dp->num_mat); files.append(loc); } if(xml.name() == "gridsize"){ outGridSize[0] = xml.attributes().value("x").toLong(); outGridSize[1] = xml.attributes().value("y").toLong(); outGridSize[2] = xml.attributes().value("z").toLong(); } if(xml.name() == "voxeldims"){ voxDims[0] = xml.attributes().value("x").toFloat(); voxDims[1] = xml.attributes().value("y").toFloat(); voxDims[2] = xml.attributes().value("z").toFloat(); } } } if (xml.hasError()){qDebug()<<"Error:"<<xml.error();} for(int i=0;i<3;i++){ outBBox[3+i] = outGridSize[i]*voxDims[i]; } O3DPFile OutFile(outname,outGridSize,outBBox); OutFile.num_mat=nmat; OutFile.writeHeader(); for( int z=0; z<outGridSize[2]; z++){ QByteArray layer( outGridSize[1]*outGridSize[0],0); for(int f=0; f<files.length();f++){ int file_layer_number = z-files.at(f).indices[2]; // if the file is in this layer then add the values if( (file_layer_number > -1) && (file_layer_number < files.at(f).o3dp->gridSize[2]) ){ // get the layer QByteArray fileLayer = files.at(f).o3dp->layer(file_layer_number); // for each row write out for (int y=0;y<files.at(f).o3dp->gridSize[1];y++){ /// *--------> /// | | /// |---x /// \|/ int indexInLayer = (y+files.at(f).indices[1])*outGridSize[0]+ files.at(f).indices[0]; int len = files.at(f).o3dp->gridSize[0]; QByteArray col = fileLayer.mid(y*len,len); layer.replace(indexInLayer,len,col); } } } //OutFile.grid[z] = layer; qDebug()<<"layer:"<<z<<" : "<<OutFile.writeLayer(layer); } //qDebug()<<"generated"; //OutFile.writeAll(outname); qDebug()<<"done writing"; }
Int_t EtaAnalysis::ReduceNtuple(Bool_t RunInTestMode){ cout<<"Going to reduce the ntuple"<<endl; if(_fChain==NULL){ cout<<"No chain."<<endl; return 0; } ///link the branches in the input chain SetEtaBranches(); //the file must be created here so the 'new' histos and Tree is created in hard drive //OutFile=new TFile OutFile(_OutputDir+"/Reduced_New.root","recreate",_OutputDir+"/Reduced_New.root",1);//1=minimal compression if(OutFile.IsZombie()){cout<<"Failed to create file"<<endl;return 0;} //create new reduced ntuple TTree Ntuple("Ntuple","Ntuple",0); Long64_t maxsize=10000000000;//10Gb cout<<" file size "<<maxsize<<endl; Ntuple.SetMaxTreeSize(maxsize);//split files //disable autosaving Long64_t fautosave=20000000000;//50Gb !! cout<<" autosave "<<fautosave<<endl; Ntuple.SetAutoSave(fautosave); //Start the event loop; Long_t MaxNumberEvents=1000000000; if(RunInTestMode)MaxNumberEvents=10000; //create the branches in the Ntuple MakeEtaReducedNtupleBranches(&Ntuple); cout<<"Total Entries in Chain="<<_fChain->GetEntries()<<endl; cout<<"Going to start the event loop"<<endl; eventid=0; while(_fChain->GetEntry(eventid,0)>0&&eventid<MaxNumberEvents){ eventid++; if(eventid%50000==0)cout<<eventid<<" Events done."<<endl; ///Event vars FillEventVars(); //now do real loop for(EtaIdx=0;EtaIdx<nEta;EtaIdx++){ //should not fill any vars outside this method otherwise not saved into EtaPi FillEtaVars(); //save Ntuple.Fill(); }//Eta loop } //print summary cout<<"--------Summary-------"<<endl; cout<<"Total events = "<<eventid<<endl; ////Save the Ntuple and histograms cout<<"Going to save the ntuple and histograms"<<endl; if(Ntuple.AutoSave("Overwrite")){ cout<<"Ntuple written."<<endl;} else{ cout<<"Failed to write ntuple"<<endl;return 0;} cout<<"Objects in the current file"<<endl; Ntuple.GetCurrentFile()->ls(); OutFile.Close(); //this will delete all objects created inside the file if they were not written cout<<OutFile.GetName()<<" has been closed."<<endl; return 1; }
int main(int argc, char* argv[]) { Env = TEnv(argc, argv, TNotify::StdNotify); Env.PrepArgs(TStr::Fmt("Flow. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm())); double NetPRTimeSum = 0; double NetEKTimeSum = 0; int NumWins = 0; Try const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../tmp/capacity.txt", "Input file"); const int Iters = Env.GetIfArgPrefixInt("-n:", 10, "Number of runs per thread"); const int Threads = Env.GetIfArgPrefixInt("-t:", 4, "Number of threads"); printf("Integer Flow Test\n"); printf("Filename: %s\n", InFNm.CStr()); printf("Building Network...\n"); TFIn InFile(InFNm); // uncomment the following lines for the binary input file // If the input file is a binary, use the following line to load the network // PNEANet Net = TNEANet::Load(InFile); // uncomment the following lines for the text input file // If the input file is a text file, use the following to load the network and save as binary PNEANet Net; int MaxEdgeCap = BuildCapacityNetwork(InFNm, Net); const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "../tmp/flow.txt", "Output file"); TFOut OutFile(OutFNm); Net->Save(OutFile); // --- calculate flows printf("PNEANet Nodes: %d, Edges: %d\n\n", Net->GetNodes(), Net->GetEdges()); #pragma omp parallel for reduction(+:NetEKTimeSum,NetPRTimeSum,NumWins) schedule(static, 1) for (int t = 0; t < Threads; t++) { TRnd Random(t); for (int i = 0; i < Iters; i++) { int SrcNId = Net->GetRndNId(Random); int SnkNId = Net->GetRndNId(Random); double PRBeginTime = getcputime(); int NetMaxFlowPR = TSnap::GetMaxFlowIntPR(Net, SrcNId, SnkNId); double PREndTime = getcputime(); double NetPRFlowRunTime = PREndTime - PRBeginTime; double EKBeginTime = getcputime(); int NetMaxFlowEK = TSnap::GetMaxFlowIntEK(Net, SrcNId, SnkNId); double EKEndTime = getcputime(); double NetEKFlowRunTime = EKEndTime - EKBeginTime; IAssert(NetMaxFlowPR == NetMaxFlowEK); if (NetPRFlowRunTime < NetEKFlowRunTime) { NumWins++; } NetPRTimeSum += NetPRFlowRunTime; NetEKTimeSum += NetEKFlowRunTime; #pragma omp critical { #ifndef NOMP //printf("Thread: %d\n", omp_get_thread_num()); #endif printf("Source: %d, Sink %d\n", SrcNId, SnkNId); printf("Max Flow: %d\n", NetMaxFlowEK); printf("PR CPU Time: %f\n", NetPRFlowRunTime); printf("EK CPU Time: %f\n", NetEKFlowRunTime); printf("\n"); } } } int TotalRuns = Iters*Threads; printf ("Avg PR PNEANet Time: %f\n", NetPRTimeSum/TotalRuns); printf ("Avg EK PNEANet Time: %f\n", NetEKTimeSum/TotalRuns); printf ("%d out of %d PR was faster\n", NumWins, TotalRuns); Catch return 0; }
void MainWindow::interpol(){ QString ReRe; QString ResFile; QString OurDir="/qt/mynew/out_"; QString OurDate = (QDateTime::currentDateTime().toString("dd-MM-yyyy-hh-mm-ss")); QString format=".dpt"; ReRe=ResFile; ResFile.append(OurDir); ResFile.append(OurDate); ResFile.append(format); QFile OutFile(ResFile); OutFile.open(QIODevice::ReadWrite); QTextStream out(&OutFile); QString myfile = fileName; QString qString1 = myfile; QByteArray byteArray =qString1.toUtf8(); const char* cString =byteArray.constData(); int size=0; double x[MAX], y[MAX], xi, yi, yii, old_yi, next_yi, yi_min, xi_min; FILE *f; if((f=fopen(cString, "r"))==NULL){ printf("file is not found!\n"); exit(1); } while((fscanf(f,"%lf,%lf",&x[size],&y[size]))!=EOF && size < MAX){ size++; } gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_akima, size); gsl_spline_init (spline, x, y, size); xi_min = x[0]; yi_min = gsl_spline_eval(spline, xi_min, acc); for (xi = x[0]; xi <= x[size - 1]; xi += 0.1){ if(xi == x[0]){ yi = gsl_spline_eval(spline, xi, acc); } else{ yi = next_yi; } if (yi < yi_min){ yi_min = yi; xi_min = xi; } //Нахождение второй производной if(xi != x[0] && xi + 0.1 <= x[size - 2]){ next_yi = gsl_spline_eval(spline, xi += 0.1, acc); yii = (next_yi - 2 * yi + old_yi) / 0.01; out << "xi:\t" << xi << "yi:\t" << yi << "\n"; } old_yi = yi; } out << "yi_min:\t" << yi_min; gsl_spline_free(spline); gsl_interp_accel_free(acc); OutFile.close(); QFile File(ResFile); File.open(QIODevice::ReadOnly); QTextStream in(&File); QString line = in.readAll(); File.close(); }
int main( int argc, char *argv[] ) { bool bHelp = false; bool bError = false; bool bDouble = false; std::string RefName, OutName; File *RefFile = 0; FileList files; uint64_t n; //double dValue; //! Parse command line arguments (flags). for (;;) { int c, option_index=0; static struct option long_options[] = { { "help", 0, 0, OPT_HELP }, { "reference", 1, 0, OPT_REFERENCE }, { "output", 1, 0, OPT_OUTPUT }, { "double", 0, 0, OPT_DOUBLE }, { 0, 0, 0, 0 } }; c = getopt_long( argc, argv, "hr:o:d", long_options, &option_index ); if ( c == -1 ) break; switch (c) { case OPT_HELP: bHelp = true; break; case OPT_REFERENCE: assert(optarg !=NULL); RefName = optarg; break; case OPT_OUTPUT: assert(optarg !=NULL); OutName = optarg; break; case OPT_DOUBLE: bDouble = true; break; default: bError = true; } } if ( bError ) return 1; if ( !RefName.empty() ) { std::cout << "Opening " << RefName << std::endl; RefFile = new File( RefName, H5F_ACC_RDONLY ); RefFile->readClasses(); } // Open all MDL I/O files files.reserve( argc-optind ); while ( optind < argc ) { std::cout << "Opening " << argv[optind] << std::endl; files.push_back( new File(argv[optind++], RefName.empty() ? H5F_ACC_RDONLY : H5F_ACC_RDWR)); } // Put the files in iOrder order. std::for_each(files.begin(), files.end(), File::doReadClasses()); std::sort(files.begin(),files.end(), File::compStart()); // Check that there are no gaps and determine the totals std::for_each(files.begin(), files.end(), File::doAddStart(n)); std::cout << "We have a total of " << n << " dark particles" << std::endl; // Now fix the tables if we have a reference file if ( RefFile ) { std::for_each(files.begin(), files.end(), File::doFixClasses(RefFile)); std::for_each(files.begin(), files.end(), File::doWriteClasses()); } if ( !OutName.empty() ) { std::cout << "Creating " << OutName << std::endl; File OutFile( OutName, H5F_ACC_TRUNC ); OutFile.create(n,false); OutFile.copyAttributes(files.front()); std::for_each(files.begin(), files.end(), File::doMergeClasses(OutFile)); OutFile.writeClasses(); std::for_each(files.begin(), files.end(), File::doCopyData(OutFile)); } }
bool VYVReader::write ( const QString& fileName, bool inXML ) const { QFile OutFile(fileName); QString Message; int i; int j; if ( ! OutFile.open(QIODevice::WriteOnly) ) return false; if ( inXML ) { QTextStream stream( &OutFile ); QDomDocument doc; QDomNode xmlInstr = doc.createProcessingInstruction( "xml", QString("version=\"1.0\" encoding=\"UTF-8\"") ); doc.insertBefore( xmlInstr, doc.firstChild() ); doc.appendChild( toXML(doc) ); doc.save( stream, 4 ); return true; } Message = "Чтение из файла : " + fileName + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "Ферменная конструкция состоит из : " + QString::number(Data.nodesNum) + " Узлов и " + QString::number(Data.pivotsNum) + " Стержней\n\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "Количество случаев нагружения : " + QString::number(Data.loadsNum) + "\n\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "Допускаемое Напряжение \n" + QString::number(Data.stressLimit,'e',3) + "\n\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "Топология стержней : \n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i=0;i<Data.pivotsNum;i++) { Message = QString::number(i+1) + " Стержень : " + QString::number(Data.pivotsFirstNodes[i]) + " " + QString::number(Data.pivotsLastNodes[i]) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); } Message = "\nКоординаты Узлов : \n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.nodesNum; i++) { Message = QString::number(i+1) + " Узел : [" + QString::number(Data.x[i],'e',3) + "," + QString::number(Data.y[i],'e',3) + "] \n"; OutFile.write(Message.toAscii().data(), Message.length()); } Message = "\nПеремещения узлов :\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.loadsNum; i++) { Message = "Случай нагружения " + QString::number(i+1) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (j = 0; j < Data.nodesNum; j++) { Message = QString::number( j+1) + "Узел : [" + QString::number(Data.xTrans[Data.nodesNum*i+j],'e',3) + " , " + QString::number(Data.yTrans[Data.nodesNum*i+j],'e',3) + "] \n"; OutFile.write(Message.toAscii().data(), Message.length()); } } Message = "\nНапряжения в стержнях \n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.loadsNum; i++) { Message = "Случай нагружения " + QString::number(i+1) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (j = 0; j < Data.pivotsNum; j++) { Message = QString::number( j+1) + " Стержень : " + QString::number(Data.stress[Data.pivotsNum*i+j],'e',3) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); } } Message = "\nЗапас прочности \n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.loadsNum; i++) { Message = "Случай нагружения " + QString::number(i+1) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (j = 0; j < Data.pivotsNum; j++) { Message = QString::number( j+1) + " Стержень : " + QString::number( Data.safetyFactor[Data.pivotsNum*i+j],'e',3) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); } } Message = "\nНачальные площади\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.pivotsNum; i++) { Message = QString::number(i+1) + "Стержень : " + QString::number(Data.pivotSquare[i],'e',3) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); } Message = "\nОбъём = " + QString::number(Data.v) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "\nСиловой вес конструкции = " + QString::number(Data.forceWeight) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); Message = "\nДлины Стержней : \n\n"; OutFile.write(Message.toAscii().data(), Message.length()); for (i = 0; i < Data.pivotsNum; i++) { Message = QString::number(i+1) + "Стержень : " + QString::number(Data.pivotLength[i],'e',3) + "\n"; OutFile.write(Message.toAscii().data(), Message.length()); } return true; }
//=============================================================================================== // PROCEDURE: Write // PURPOSE: Copies the complete synch array to another file, packing out the file-offset entry. // BOOL CSynch::Write( HANDLE hDataFile, UINT uAcquiredSamples, UINT *puSynchCount, UINT uSampleSize ) { MEMBERASSERT(); ASSERT( hDataFile != INVALID_HANDLE_VALUE ); WPTRASSERT(puSynchCount); // Flush any cached Synch entries to the temp file. This should not fail as the reserve file // will have been released just prior to calling this function. If it does fail, we will // still be able to work with the Synch entries that were saved ok. if (m_uCacheCount) _Flush(); // Set the return value for the number of synch entries. If none exist, return. *puSynchCount = 0; if (m_uSynchCount == 0) return TRUE; // Seek to the end of the passed file. This will only fail for invalid file handles. CFileIO_NoClose OutFile(hDataFile); LONGLONG llCurrentPos = 0; if (!OutFile.Seek(0, FILE_END, &llCurrentPos)) return FALSE; // Seek to the start of the temporary file. SetFilePointer(m_hfSynchFile, 0L, NULL, FILE_BEGIN); // Read the Synch data in a buffer at a time and write it out to the passed file. UINT uEntries = m_uSynchCount; UINT uWritten = 0; UINT uCount = 0; while ( uEntries > 0 ) { uCount = min(uEntries, SYNCH_BUFFER_SIZE); // Read in a buffer from the temp file. VERIFY(Read( m_SynchBuffer, uWritten, uCount)); // Pack the buffer, removing the dwFileOffset members and checking for invalid synch entries. // If an invalid entry is found, the count is truncated at the last valid entry. if (!_PackBuffer(uAcquiredSamples, uCount, uSampleSize)) uEntries = uCount; // Write the packed buffer out to the temp file. if ( !OutFile.Write( m_SynchBuffer, uCount * 2 * sizeof(DWORD) )) { // If an error occurs, go back to the start of the block and truncate the file // ready for the next attempt after the user has freed up some disk space. VERIFY(OutFile.Seek(llCurrentPos, FILE_BEGIN)); VERIFY(OutFile.SetEndOfFile()); return FALSE; } uEntries -= uCount; uWritten += uCount; } // Seek back to end of the temporary file. SetFilePointer(m_hfSynchFile, 0L, NULL, FILE_END); //TRACE1( "CSynch::Write current file pointer is %d after seek to end.\n", // SetFilePointer(m_hfSynchFile, 0, NULL, FILE_CURRENT) ); *puSynchCount = uWritten; return TRUE; }
// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased... void plot_HE(TString inputfile="simevent_HE.root", TString outputfile="HE_histo.root", Int_t drawmode = 2, TString reffile="../data/HE_ref.root"){ // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif. //int doDraw = 0; int doDraw = drawmode; char * treename = "Events"; //The Title of Tree. delete gROOT->GetListOfFiles()->FindObject(inputfile); TFile * myf = new TFile(inputfile); TTree * tree = dynamic_cast<TTree*>(myf->Get("Events")); assert(tree != 0); TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj"); assert(branchLayer != 0); TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj"); assert(branchNxN != 0); TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj"); assert(branchJets != 0); // Just number of entries (same for all branches) int nent = branchLayer->GetEntries(); cout << "Entries branchLayer : " << nent << endl; nent = branchJets->GetEntries(); cout << "Entries branchJets : " << nent << endl; nent = branchNxN->GetEntries(); cout << "Entries branchNxN : " << nent << endl; // Variables from branches PHcalValidInfoJets infoJets; branchJets->SetAddress( &infoJets); PHcalValidInfoLayer infoLayer; branchLayer->SetAddress( &infoLayer); PHcalValidInfoNxN infoNxN; branchNxN->SetAddress( &infoNxN); //*************************************************************************** // Histo titles-labels const int Nhist1 = 47, Nhist2 = 1; // N simple and N combined histos const int Nhist1spec = 7; // N special out of Nsimple total const int nLayersMAX = 20; const int nDepthsMAX = 5; TH1F *h; // just a pointer TH1F *h1[Nhist1]; TH1F *h1l[nLayersMAX]; // + all scint. layers separately TH1F *h1d[nDepthsMAX]; // + all depths TH2F *h2[Nhist2]; TH2F *h2g[5]; // + eta-phi grid -related for all depthes char *label1[Nhist1], *label2[Nhist2], *label1l[nLayersMAX ]; char *label1d[nDepthsMAX], *label2g[5]; // simple histos label1[0] = &"rJetHits.gif"; label1[1] = &"tJetHits.gif"; label1[2] = &"eJetHits.gif"; label1[3] = &"ecalJet.gif"; label1[4] = &"hcalJet.gif"; label1[5] = &"hoJet.gif"; label1[6] = &"etotJet.gif"; label1[7] = &"detaJet.gif"; label1[8] = &"dphiJet.gif"; label1[9] = &"drJet.gif"; label1[10] = &"jetE.gif"; label1[11] = &"jetEta.gif"; label1[12] = &"jetPhi.gif"; label1[13] = &"dijetM.gif"; label1[14] = &"ecalNxNr.gif"; label1[15] = &"hcalNxNr.gif"; label1[16] = &"hoNxNr.gif"; label1[17] = &"etotNxNr.gif"; label1[18] = &"ecalNxN.gif"; label1[19] = &"hcalNxN.gif"; label1[20] = &"hoNxN.gif"; label1[21] = &"etotNxN.gif"; label1[22] = &"layerHits.gif"; label1[23] = &"etaHits.gif"; label1[24] = &"phiHits.gif"; label1[25] = &"eHits.gif"; label1[26] = &"tHits.gif"; label1[27] = &"idHits.gif"; label1[28] = &"jitterHits.gif"; label1[29] = &"eIxI.gif"; label1[30] = &"tIxI.gif"; label1[31] = &"eLayer.gif"; label1[32] = &"eDepth.gif"; label1[33] = &"eHO.gif"; label1[34] = &"eHBHE.gif"; label1[35] = &"elongHF.gif"; label1[36] = &"eshortHF.gif"; label1[37] = &"eEcalHF.gif"; label1[38] = &"eHcalHF.gif"; // special label1[39] = &"NxN_trans_fraction.gif"; label1[40] = &"tHist_50ns.gif"; label1[41] = &"tHist_eweighted.gif"; label1[42] = &"nHits_ECAL.gif"; label1[43] = &"nHits_HCAL.gif"; label1[44] = &"nHits.gif"; label1[45] = &"longProf_eweighted.gif"; label1[46] = &"E_hcal.gif"; label1l[0] = &"layer_0.gif"; label1l[1] = &"layer_1.gif"; label1l[2] = &"layer_2.gif"; label1l[3] = &"layer_3.gif"; label1l[4] = &"layer_4.gif"; label1l[5] = &"layer_5.gif"; label1l[6] = &"layer_6.gif"; label1l[7] = &"layer_7.gif"; label1l[8] = &"layer_8.gif"; label1l[9] = &"layer_9.gif"; label1l[10] = &"layer_10.gif"; label1l[11] = &"layer_11.gif"; label1l[12] = &"layer_12.gif"; label1l[13] = &"layer_13.gif"; label1l[14] = &"layer_14.gif"; label1l[15] = &"layer_15.gif"; label1l[16] = &"layer_16.gif"; label1l[17] = &"layer_17.gif"; label1l[18] = &"layer_18.gif"; label1l[19] = &"layer_19.gif"; label1d[0] = &"depth_0.gif"; label1d[1] = &"depth_1.gif"; label1d[2] = &"depth_2.gif"; label1d[3] = &"depth_3.gif"; label1d[4] = &"depth_4.gif"; // more complicated histos and profiles label2[0] = &"JetHCALvsECAL.gif"; label2g[0] = &"Eta-phi_grid_depth_0.gif"; label2g[1] = &"Eta-phi_grid_depth_1.gif"; label2g[2] = &"Eta-phi_grid_depth_2.gif"; label2g[3] = &"Eta-phi_grid_depth_3.gif"; label2g[4] = &"Eta-phi_grid_all_depths.gif"; // Some constants const float fact = 117.0; // sampling factor which corresponds to those // for layer = 0,1 in SimG4HcalValidation.cc //*************************************************************************** //...Book histograms for (Int_t i = 0; i < Nhist1-Nhist1spec; i++) { char hname[3]; sprintf(hname,"h%d",i); if(i == 4 || i == 7 || i == 8 || i == 11 || i == 12 || i == 6) { if(i == 11) h1[i] = new TH1F(hname,label1[i],100,-5.,5.); if(i == 12) h1[i] = new TH1F(hname,label1[i],72,-3.1415926,3.1415926); if(i == 7 || i == 8) h1[i] = new TH1F(hname,label1[i],100,-0.1,0.1); if( i == 4) h1[i] = new TH1F(hname,label1[i],50,0.,100.); if( i == 6) h1[i] = new TH1F(hname,label1[i],50,0.,100.); } else { h1[i] = new TH1F(hname,label1[i],100,1.,0.); } } // Special : global timing < 50 ns h1[40] = new TH1F("h40",label1[40],50,0.,50.); // Special : timing in the cluster (7x7) enery-weighted h1[41] = new TH1F("h41",label1[41],30,0.,30.); // Special : number of ECAL&HCAL hits h1[42] = new TH1F("h42",label1[42],300,0.,3000.); h1[43] = new TH1F("h43",label1[43],300,0.,3000.); h1[44] = new TH1F("h44",label1[44],300,0.,3000.); // Special : Longitudinal profile h1[45] = new TH1F("h45",label1[45],20,0.,20.); // Etot HCAL TH1F *h1[46] = new TH1F("h46",label1[46],50,0.,1.0); for (int i = 0; i < Nhist1; i++) { if(i != 39) h1[i]->Sumw2(); } for (int i = 0; i < Nhist2; i++) { char hname[3]; sprintf(hname,"D%d",i); h2[i] = new TH2F(hname,label2[i],100,0.,100.,100,0.,100.); } // h[i]->Sumw2(); // to get errors properly calculated // scint. layers for (int i = 0; i < nLayersMAX; i++) { char hname[4]; sprintf(hname,"hl%d",i); h1l[i] = new TH1F(hname,label1l[i],40,0.,0.4); } // depths Float_t max[5] = {30000, 500, 500, 200, 200.}; for (int i = 0; i < nDepthsMAX; i++) { char hname[3]; sprintf(hname,"hd%d",i); h1d[i] = new TH1F(hname,label1d[i],100,0.,max[i]); } // eta-phi grid (for muon samples) for (int i = 0; i < 5; i++) { char hname[3]; sprintf(hname,"Dg%d",i); h2g[i] = new TH2F(hname,label2g[i],1000,-5.,5.,576,-3.1415927,3.1415927); } //*************************************************************************** //*************************************************************************** //...Fetch the data and fill the histogram // branches separately - for (int i = 0; i<nent; i++) { // cout << "Ev. " << i << endl; // -- get entries branchLayer ->GetEntry(i); branchNxN ->GetEntry(i); branchJets ->GetEntry(i); // -- Leading Jet int nJetHits = infoJets.njethit(); //cout << "nJetHits = " << nJetHits << endl; std::vector<float> rJetHits(nJetHits); rJetHits = infoJets.jethitr(); std::vector<float> tJetHits(nJetHits); tJetHits = infoJets.jethitt(); std::vector<float> eJetHits(nJetHits); eJetHits = infoJets.jethite(); float ecalJet = infoJets.ecaljet(); float hcalJet = infoJets.hcaljet(); float hoJet = infoJets.hojet(); float etotJet = infoJets.etotjet(); float detaJet = infoJets.detajet(); float dphiJet = infoJets.dphijet(); float drJet = infoJets.drjet(); float dijetM = infoJets.dijetm(); for (int j = 0; j < nJetHits; j++) { h1[0]->Fill(rJetHits[j]); h1[1]->Fill(tJetHits[j]); h1[2]->Fill(eJetHits[j]); } h1[3]->Fill(ecalJet); // h1[4]->Fill(hcalJet); // h1[5]->Fill(hoJet); h1[6]->Fill(etotJet); h2[0]->Fill(ecalJet,hcalJet); // h1[7]->Fill(detaJet); h1[8]->Fill(dphiJet); h1[9]->Fill(drJet); h1[13]->Fill(dijetM); // All Jets int nJets = infoJets.njet(); std::vector<float> jetE (nJets); jetE = infoJets.jete(); std::vector<float> jetEta(nJets); jetEta = infoJets.jeteta(); std::vector<float> jetPhi(nJets); jetPhi = infoJets.jetphi(); for (int j = 0; j < nJets; j++) { h1[10]->Fill(jetE[j]); h1[11]->Fill(jetEta[j]); h1[12]->Fill(jetPhi[j]); } // NxN quantities float ecalNxNr = infoNxN.ecalnxnr(); float hcalNxNr = infoNxN.hcalnxnr(); float hoNxNr = infoNxN.honxnr(); float etotNxNr = infoNxN.etotnxnr(); float ecalNxN = infoNxN.ecalnxn(); float hcalNxN = infoNxN.hcalnxn(); float hoNxN = infoNxN.honxn(); float etotNxN = infoNxN.etotnxn(); h1[14]->Fill(ecalNxNr); h1[15]->Fill(hcalNxNr); h1[16]->Fill(hoNxNr); h1[17]->Fill(etotNxNr); h1[18]->Fill(ecalNxN); h1[19]->Fill(hcalNxN); h1[20]->Fill(hoNxN); h1[21]->Fill(etotNxN); // CaloHits from PHcalValidInfoLayer int nHits = infoLayer.nHit(); std::vector<float> idHits(nHits); idHits = infoLayer.idHit(); std::vector<float> phiHits(nHits); phiHits = infoLayer.phiHit(); std::vector<float> etaHits(nHits); etaHits = infoLayer.etaHit(); std::vector<float> layerHits(nHits); layerHits = infoLayer.layerHit(); std::vector<float> eHits(nHits); eHits = infoLayer.eHit(); std::vector<float> tHits(nHits); tHits = infoLayer.tHit(); int ne = 0, nh = 0; for (int j = 0; j < nHits; j++) { int layer = layerHits[j]-1; int id = (int)idHits[j]; if(id >= 10) {ne++;} else {if (id < 5) nh++;} // cout << "Hit subdet = " << id << " lay = " << layer << endl; h1[22]->Fill(Float_t(layer)); h1[23]->Fill(etaHits[j]); h1[24]->Fill(phiHits[j]); h1[25]->Fill(eHits[j]); h1[26]->Fill(tHits[j]); h1[27]->Fill(idHits[j]); // h1[28]->Fill(jitterHits[j]); // no jitter anymore h1[40]->Fill(tHits[j]); h1[41]->Fill(tHits[j],eHits[j]); if(id < 6) { // HCAL only. Depth is needed, not layer !!! //if(layer == 0) h2g[0]->Fill(etaHits[j],phiHits[j]); //if(layer == 1) h2g[1]->Fill(etaHits[j],phiHits[j]); //if(layer == 2) h2g[2]->Fill(etaHits[j],phiHits[j]); //if(layer == 3) h2g[3]->Fill(etaHits[j],phiHits[j]); h2g[4]->Fill(etaHits[j],phiHits[j]); } } h1[42]->Fill(Float_t(ne)); h1[43]->Fill(Float_t(nh)); h1[44]->Fill(Float_t(nHits)); // NxN PHcalValidInfoNxN // cout << " nIxI = " << nIxI << endl; int nIxI = infoNxN.nnxn(); std::vector<float> idIxI(nIxI); idIxI = infoNxN.idnxn(); std::vector<float> eIxI(nIxI); eIxI = infoNxN.enxn(); std::vector<float> tIxI(nIxI); tIxI = infoNxN.tnxn(); for (int j = 0; j < nIxI ; j++) { // NB !!! j < nIxI h1[29]->Fill(eIxI[j]); h1[30]->Fill(tIxI[j]); h1[39]->Fill(idIxI[j],eIxI[j]); // transverse profile } // Layers and depths PHcalValidInfoLayer std::vector<float> eLayer(nLayersMAX); eLayer = infoLayer.elayer(); std::vector<float> eDepth(nDepthsMAX); eDepth = infoLayer.edepth(); float eTot = 0.; for (int j = 0; j < nLayersMAX ; j++) { h1[31]->Fill(eLayer[j]); h1l[j]->Fill(eLayer[j]); h1[45]->Fill((Float_t)(j),eLayer[j]); // HCAL SimHits only eTot += eLayer[j]; } for (int j = 0; j < nDepthsMAX; j++) { h1[32]->Fill(eDepth[j]); h1d[j]->Fill(eDepth[j]); } h1[46]->Fill(eTot); // The rest PHcalValidInfoLayer float eHO = infoLayer.eho(); float eHBHE = infoLayer.ehbhe(); float elongHF = infoLayer.elonghf(); float eshortHF = infoLayer.eshorthf(); float eEcalHF = infoLayer.eecalhf(); float eHcalHF = infoLayer.ehcalhf(); h1[33]->Fill(eHO); h1[34]->Fill(eHBHE); h1[35]->Fill(elongHF); h1[36]->Fill(eshortHF); h1[37]->Fill(eEcalHF); h1[38]->Fill(eHcalHF); } // cout << "After event cycle " << i << endl; //...Prepare the main canva TCanvas *myc = new TCanvas("myc","",800,600); gStyle->SetOptStat(1111); // set stat :0 - nothing // Cycle for 1D distributions for (int ihist = 0; ihist < Nhist1 ; ihist++) { if(h1[ihist]->Integral() > 1.e-30 && h1[ihist]->Integral() < 1.e30 ) { h1[ihist]->SetLineColor(45); h1[ihist]->SetLineWidth(2); if(doDraw == 1) { h1[ihist]->Draw("h"); myc->SaveAs(label1[ihist]); } } } // Cycle for energy in all layers for (int ihist = 0; ihist < nLayersMAX; ihist++) { if(h1l[ihist]->Integral() > 1.e-30 && h1l[ihist]->Integral() < 1.e30 ) { h1l[ihist]->SetLineColor(45); h1l[ihist]->SetLineWidth(2); if(doDraw == 1) { h1l[ihist]->Draw("h"); myc->SaveAs(label1l[ihist]); } } } // Cycle for 2D distributions // for (int ihist = 0; ihist < 1 ; ihist++) { for (int ihist = 0; ihist < Nhist2 ; ihist++) { if(h2[ihist]->Integral() > 1.e-30 && h2[ihist]->Integral() < 1.e30 ) { h2[ihist]->SetMarkerColor(45); h2[ihist]->SetMarkerStyle(20); h2[ihist]->SetMarkerSize(0.7); // marker size ! h2[ihist]->SetLineColor(45); h2[ihist]->SetLineWidth(2); if(doDraw == 1) { h2[ihist]->Draw(); myc->SaveAs(label2[ihist]); } } } // Cycle for eta-phi grids // for (int ihist = 0; ihist < 5 ; ihist++) { for (int ihist = 4; ihist < 5 ; ihist++) { if(h2g[ihist]->Integral() > 1.e-30 && h2g[ihist]->Integral() < 1.e30 ) { h2g[ihist]->SetMarkerColor(41); h2g[ihist]->SetMarkerStyle(20); h2g[ihist]->SetMarkerSize(0.2); h2g[ihist]->SetLineColor(41); h2g[ihist]->SetLineWidth(2); if(doDraw == 1) { h2g[ihist]->Draw(); myc->SaveAs(label2g[ihist]); } } } // added by Julia Yarba //----------------------- // this is a temporary stuff that I've made // to create a reference ROOT histogram file if (doDraw == 2) { TFile OutFile(outputfile,"RECREATE") ; int ih = 0 ; for ( ih=0; ih<nLayersMAX; ih++ ) { h1l[ih]->Write() ; } for ( ih=0; ih<Nhist1; ih++ ) { h1[ih]->Write() ; } OutFile.Write() ; OutFile.Close() ; cout << outputfile << " histogram file created" << endl ; return ; } /* return; */ // now perform Chi2 test for histograms that hold // energy deposition in the Hcal layers 1-10, using // "reference" and "current" histograms // open up ref. ROOT file // TFile RefFile(reffile) ; // service variables // TH1F* ref_hist = 0 ; int ih = 0 ; // loop over layers 1-10 // for ( ih=1; ih<11; ih++ ) { // service - name of the ref histo // char ref_hname[4] ; sprintf( ref_hname, "hl%d", ih ) ; // retrive ref.histos one by one // ref_hist = (TH1F*)RefFile.Get( ref_hname ) ; // check if valid (no-NULL) // if ( ref_hist == NULL ) { // print warning in case of trouble // cout << "No such ref. histogram" << *ref_hname << endl ; } else { // everything OK - perform Chi2 test // Double_t *res; Double_t pval = h1l[ih]->Chi2Test( ref_hist, "UU", res ) ; // output Chi2 comparison results // cout << "[OVAL] : Edep in Layer " << ih << ", p-value= " << pval << endl ; } } // loop over specials : timing, nhits(ECAL and HCAL) // for ( ih=40; ih<47; ih++ ) { // service - name of the ref histo // char ref_hname[4] ; sprintf( ref_hname, "h%d", ih ) ; // retrive ref.histos one by one // ref_hist = (TH1F*)RefFile.Get( ref_hname ) ; // check if valid (no-NULL) // if ( ref_hist == NULL ) { // print warning in case of trouble // cout << "No such ref. histogram" << *ref_hname << endl ; } else { // everything OK - perform Chi2 test // Double_t *res; Double_t pval = h1[ih]->Chi2Test( ref_hist, "UU", res) ; // output Chi2 comparison results // cout << "[OVAL] : histo " << ih << ", p-value= " << pval << endl ; } } // close ref. ROOT file // RefFile.Close() ; // at the end, close "current" ROOT tree file // myf->Close(); return ; }
/// @brief This is the entry point for the unit test executable. /// @details This will contruct an AllUnitTestGroups with the listing of unit tests /// available from autodetect.h. It will then interpret any command line arguments /// and direct the created AllUnitTestGroups about which tests to run and how to run /// them. In addition to sending the results to the standard output a copy of the /// test results will be written to TestResults.txt, if not configure not to. /// @n @n /// If no arguments are passed this will add all the tests to the AllUnitTestGroups /// and execute all tests that are not interactive. Print out a default report of them. /// @return This will return EXIT_SUCCESS if the tests ran, even if some or all failed, /// even if a child process segfaulted, but will return other statuses only if the main /// process fails. If the main process cannot create child processes it will return EXIT_FAILURE. /// @param argc Is interpretted as the amount of passed arguments /// @param argv Is interpretted as the arguments passed in from the launching shell. int main (int argc, char** argv) { ArgC = argc; ArgV = argv; GlobalCoreTestGroup TestGroups; bool WriteFile = true; if( !system( NULL ) ) // If this is not being run from a shell somehow, then using system() to run this task in a new process is not really possible. { std::cerr << "system() call not supported, missing command processor." << std::endl; return EXIT_FAILURE; } // Display everything, or just a Summary or neither? Should this process do the work, or should we spawn a new process. bool FullDisplay = true, SummaryDisplay = true; if (argc > 0) //Not really sure how this would happen, but I would rather test for it than have it fail { CommandName=argv[0]; } else { return Usage("UnitTestGroups", TestGroups); } AllUnitTestGroups Runner(TestGroups); for (int c=1; c<argc; ++c) // Check Command line for keywords and get all the test names { String ThisArg(AllLower(argv[c])); if(ThisArg=="help") { return Usage(CommandName, TestGroups); } else if(ThisArg==MemSpaceArg) // Check to see if we do the work now or later { Runner.ExecuteInThisMemorySpace = true; } else if(ThisArg=="testlist") { return PrintList(TestGroups); } else if(ThisArg=="interactive") { Runner.RunInteractiveTests=true; Runner.RunAll=false; } else if(ThisArg=="automatic") { Runner.RunAutomaticTests=true; Runner.RunAll=false; } else if(ThisArg=="all") { Runner.RunAll=true; } else if(ThisArg=="summary") { FullDisplay = false, SummaryDisplay = true; } else if(ThisArg=="skipfile") { WriteFile = false; } else // Wasn't a command so it is either gibberish or a test group { try { TestGroups.at(ThisArg.c_str()); Runner.RunAll=false; Runner.TestGroupsToRun.push_back(AllLower(argv[c])); } catch ( const std::out_of_range&) { std::cerr << ThisArg << " is not a valid testgroup or parameter." << std::endl; Usage(CommandName, TestGroups); return ExitInvalidArguments; } } } Runner.RunTests(); if(WriteFile) { String FileName("TestResults.txt"); std::ofstream OutFile(FileName.c_str()); Runner.DisplayResults(OutFile, OutFile, SummaryDisplay, FullDisplay); OutFile.close(); } Runner.DisplayResults(cout, cerr, SummaryDisplay, FullDisplay); for(AllUnitTestGroups::iterator Iter = Runner.begin(); Iter!=Runner.end(); Iter++) { if(Iter->Results>Skipped) { return ExitFailure; } } return ExitSuccess; }
int main(int nArgCount, char** ppArgs) { if (!TdGuard::Aegis::GetSingleton().Init() || !TdGuard::Aegis::GetSingleton().DoWork()) { return 1; } //get the command line parameters CCommandLineParser Parser; //initialize the parser, skipping over the program name Parser.Init(nArgCount - 1, &(ppArgs[1]), OPTION_DELIMITER); //trim off extra parameters from all the options // /out <filename> Parser.SetNumParameters("out", 1); // /verbose Parser.SetNumParameters("verbose", 0); // /help Parser.SetNumParameters("help", 0); // /view Parser.SetNumParameters("view", 0); //see if the user wants help if(Parser.IsOptionSet("help")) { PrintHelp(); return 0; } //-------------------------- // Option verification //scan for unexpected options for(uint32 nCurrOption = 0; nCurrOption < Parser.GetNumOptions(); nCurrOption++) { const char* pszOptName = Parser.GetOptionName(nCurrOption); if( stricmp(pszOptName, "out") && stricmp(pszOptName, "verbose") && stricmp(pszOptName, "help") && stricmp(pszOptName, "view")) { PrintHelp(); #if _MSC_VER >= 1300 std::cout << "Unknown option: " << pszOptName << std::endl; #else cout << "Unknown option: " << pszOptName << endl; #endif return 1; } } //make sure that we have a filename if(Parser.GetNumGlobalParameters() == 0) { PrintHelp(); #if _MSC_VER >= 1300 std::cout << "A file to modify must be specified" << std::endl; #else cout << "A file to modify must be specified" << endl; #endif return 1; } //make sure that if they are outputting, that they have a file if(Parser.IsOptionSet("out") && (Parser.GetNumParameters("out") < 1)) { PrintHelp(); #if _MSC_VER >= 1300 std::cout << "A file name must be specified with -out" << std::endl; #else cout << "A file name must be specified with -out" << endl; #endif return 1; } //make sure that they aren't trying to view, and output if(Parser.IsOptionSet("view") && Parser.IsOptionSet("out")) { PrintHelp(); #if _MSC_VER >= 1300 std::cout << "-view and -out cannot be set. Please select only one." << std::endl; #else cout << "-view and -out cannot be set. Please select only one." << endl; #endif return 1; } //determine if we want verbose mode bool bVerbose = Parser.IsOptionSet("verbose"); //see if they want to view the file bool bView = Parser.IsOptionSet("view"); //get the filename const char* pszFilename = Parser.GetGlobalParameter(0); //determine if the input file is compressed bool bInFileCompressed = CLTAUtil::IsFileCompressed(pszFilename); //see if we can even open up the file CLTAFile InFile; InFile.Open(pszFilename, true, bInFileCompressed); //make sure we opened it okay if(InFile.IsValid() == false) { #if _MSC_VER >= 1300 std::cout << "Error: Unable to open the file " << pszFilename << std::endl; #else cout << "Error: Unable to open the file " << pszFilename << endl; #endif return 1; } //now we need to see if we are printing it out, or are writing it out to a file if(bView) { uint8 nVal; //print out the entire file while(InFile.ReadByte(nVal)) { #if _MSC_VER >= 1300 std::cout << (char)nVal; #else cout << (char)nVal; #endif } //close it out InFile.Close(); return 0; } //they don't want to view, they want to compress, lets figure out the file name char pszOutFile[_MAX_PATH]; if(Parser.IsOptionSet("out")) { strcpy(pszOutFile, Parser.GetParameter("out", 0)); } else { //strip out the extension int32 nStrLen = strlen(pszFilename); for(int32 nCurrChar = nStrLen - 1; nCurrChar >= 0; nCurrChar--) { if(pszFilename[nCurrChar] == '.') { break; } } //make sure we have a valid extension if((nCurrChar < 0) || ( stricmp(&pszFilename[nCurrChar], ".LTA") && stricmp(&pszFilename[nCurrChar], ".LTC"))) { #if _MSC_VER >= 1300 std::cout << "Error: The input file does not have a proper extension." << std::endl; std::cout << "Either specify an output filename or correct the extension." << std::endl; #else cout << "Error: The input file does not have a proper extension." << endl; cout << "Either specify an output filename or correct the extension." << endl; #endif return 1; } //now compose the final string strcpy(pszOutFile, pszFilename); strcpy(&(pszOutFile[nCurrChar]), bInFileCompressed ? ".lta" : ".ltc"); } //now we open up the output stream and convert the file CLTAFile OutFile(pszOutFile, false, bInFileCompressed ? false : true); //make sure it succeeded if(OutFile.IsValid() == false) { #if _MSC_VER >= 1300 std::cout << "Error: Unable to open file " << pszOutFile << " for writing." << std::endl; #else cout << "Error: Unable to open file " << pszOutFile << " for writing." << endl; #endif return 1; } //now we read in bytes until we must stop, then write out the bytes uint8 nVal; //convert the file while(InFile.ReadByte(nVal)) { if(OutFile.WriteByte(nVal) == false) { #if _MSC_VER >= 1300 std::cout << "Error: Unable to write to " << pszOutFile << std::endl; std::cout << "Disk may be full." << std::endl; #else cout << "Error: Unable to write to " << pszOutFile << endl; cout << "Disk may be full." << endl; #endif return 1; } } //close it out OutFile.Close(); InFile.Close(); return 0; }