Fork me on GitHub

Changeset 467 in svn for trunk/Resolutions_ATLAS.cpp


Ignore:
Timestamp:
Jul 10, 2009, 5:57:55 PM (15 years ago)
Author:
Xavier Rouby
Message:

cleaning, comments, progressbar, cout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Resolutions_ATLAS.cpp

    r458 r467  
    3838#include "TApplication.h"
    3939#include "TFile.h"
     40#include "TStopwatch.h"
    4041
    4142#include "ExRootTreeReader.h"
    4243#include "ExRootTreeWriter.h"
    4344#include "ExRootTreeBranch.h"
     45#include "ExRootProgressBar.h"
    4446#include "TreeClasses.h"
    4547
     
    189191{
    190192  int appargc = 2;
    191   char *appName = "Resolution";
    192   char *appargv[] = {appName, "-b"};
     193  char *appName= new char[20];
     194  char *appOpt= new char[20];
     195  sprintf(appName,"Resolution_ATLAS");
     196  sprintf(appOpt,"-b");
     197  char *appargv[] = {appName,appOpt};
    193198  TApplication app(appName, &appargc, appargv);
    194  
     199  delete [] appName;
     200  delete [] appOpt;
     201
    195202  if(argc != 3) {
    196203      cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl;
     
    200207  }
    201208
    202   srand (time (NULL));         /* Initialisation du générateur */
     209
     210  // 1. ********** initialisation ***********
     211
     212  srand (time (NULL));         
     213  TStopwatch globalwatch;
     214  globalwatch.Start();
    203215 
    204   //read the input TROOT file
    205216  string inputfilename(argv[1]), outputfilename(argv[2]);
    206217
     218  // 1.1 checks the input file
     219  if(inputfilename.find(".root") > inputfilename.length()   ) {
     220    cout << "input_file should be a .root file from Delphes!\n";
     221    return -1;
     222  }
     223  TFile f(inputfilename.c_str());
     224  if (!f.FindKey("GEN") || !f.FindKey("Analysis")           ) {
     225    cout << "input_file should be a .root file from Delphes!\n";
     226    cout << "it should contain both \"GEN\" and \"Analysis\" trees at least.\n";
     227    return -1;
     228  }
     229  f.Close();
     230
     231  // 1.2 checks the output file
    207232  if(outputfilename.find(".root") > outputfilename.length() ) {
    208233    cout << "output_file should be a .root file!\n";
    209234    return -1;
    210235  }
    211 
    212 
    213 
    214236  TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE");// Creates the file, but should be closed just after
    215237  outputFile->Close();
    216  
     238 
     239  // 1.3 Reads the trees in  input file
    217240  TChain chainGEN("GEN");
    218241  chainGEN.Add(inputfilename.c_str());
     
    228251  const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle");
    229252  TIter itGen((TCollection*)branchGen);
    230  
    231   //write the output root file
     253 
     254 
     255  // 1.4 Prepares the output root file
    232256  ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
    233257  ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
     
    236260  ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
    237261  ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
    238  
     262 
     263  // 1.5 other initialisations
    239264  TRootGenParticle *particle;
    240  
    241265  RESOLELEC * elementElec;
    242266  RESOLMUON *elementMuon;
     
    245269  ETMIS *elementEtmis;
    246270 
    247   int numTau=0;
    248   int numTauRec=0;
     271  int numTau=0, numTauRec=0;
    249272 
    250273  RESOLution *DET = new RESOLution();
     
    259282  DET->ReadDataCard(detectorcard);
    260283
    261 
    262   //Jet information
    263284  JetsUtil *JETRUN = new JetsUtil(detectorcard);
    264285
    265   TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information
    266   TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing generator level information
     286  TLorentzVector genMomentum(0,0,0,0); // generator level information
     287  TLorentzVector recoMomentum(0,0,0,0);// reconstruction level information
    267288  LorentzVector jetMomentum;
    268289 
     
    272293  vector<TLorentzVector> towers;
    273294 
    274   // Loop over all events
     295  // 2. Loop over all events
    275296  Long64_t entry, allEntries = treeReader->GetEntries();
    276   cout << "** Chain contains " << allEntries << " events" << endl;
     297  cout << endl << endl;
     298  cout <<"*********************************************************************"<< endl;
     299  cout <<"**                                                                 **"<< endl;
     300  cout <<"**                                                                 **"<< endl;
     301  cout <<"**                                                                 **"<< endl;
     302  cout <<"**        ####### Start resolution processing    ########          **"<< endl;
     303  cout << left  << setw(52) <<"**              Total number of events to run: "<<""
     304       << left  << setw(15) << allEntries <<""
     305       << right << setw(2) <<"**"<<endl;
     306
     307  ExRootProgressBar *Progress = new ExRootProgressBar(allEntries);
     308
    277309  for(entry = 0; entry < allEntries; ++entry)
    278310    {
     311      Progress->Update(entry);
    279312      TLorentzVector PTmisReco(0,0,0,0);
    280313      TLorentzVector PTmisGEN(0,0,0,0);
     
    282315      treeReaderGEN->ReadEntry(entry);
    283316      treeWriter->Clear();
    284       if((entry % 100) == 0 && entry > 0 )  cout << "** Processing element # " << entry << endl;
    285317     
    286318      TSimpleArray<TRootGenParticle> bGen;
     
    372404        TLorentzVector JETgen(0,0,0,0);
    373405        JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
    374         PairingJet(JETreco,JETgen,branchJet);
     406        PairingJet(JETreco,JETgen,branchJet,dR_jetpairing);
    375407        if(JETreco.Pt()>jet_pt_cut)
    376408          {
     
    383415          }
    384416      }
    385       numTau = numTau+TausHadr.GetEntries();
     417      numTau += TausHadr.GetEntries();
    386418
    387419      TIter itJet((TCollection*)branchJet);
     
    413445    } // Loop over all events
    414446  treeWriter->Write();
    415 
    416   cout << detectorcard << " has been used.\n";
    417   cout << "** Exiting..." << endl;
     447  globalwatch.Stop();
     448
     449
     450  // Screen output
     451  cout <<"**                                                                 **"<< endl;
     452  cout <<"**                                                                 **"<< endl;
     453  cout <<"**        ################## Time report #################         **"<< endl;
     454  cout << left  << setw(32) <<"**              Time report for "<<""
     455       << left  << setw(15) << allEntries <<""
     456       << right << setw(22) <<"events         **"<<endl;
     457  cout <<"**                                                                 **"<< endl;
     458  cout << left  << setw(10) <<"**"<<""
     459       << left  << setw(15) <<"Time (s):"<<""
     460       << right << setw(15) <<"CPU"<<""
     461       << right << setw(15) <<"Real"<<""
     462       << right << setw(14)  <<"**"<<endl;
     463  cout << left  << setw(10) <<"**"<<""
     464       << left  << setw(15) <<" +  Global:"<<""
     465       << right << setw(15) <<globalwatch.CpuTime()<<""
     466       << right << setw(15) <<globalwatch.RealTime()<<""
     467       << right << setw(14)  <<"**"<<endl;
     468
     469
     470  string tempstring = detectorcard + " has been used.";
     471  cout <<"**        ################## Configuration ###############         **"<< endl;
     472  cout << left << setw(16) << "**        " << ""
     473       << left << setw(51) <<  tempstring << "**" << endl;
     474
     475  tempstring =  outputfilename + " has been created.";
     476  cout << left << setw(16) << "**        " << ""
     477       << left << setw(51) <<  tempstring << "**" << endl;
     478
     479  cout << left << setw(16) << "**        " << ""
     480       << left << setw(51) <<  get_time_date() << "**" << endl;
     481
     482  cout <<"**                                                                 **"<< endl;
     483  cout <<"**                        Exiting ...                              **"<< endl;
     484  cout <<"**                                                                 **"<< endl;
     485  cout <<"**                                                                 **"<< endl;
     486  cout <<"*********************************************************************"<< endl;
     487
    418488 
    419489  delete treeWriter;
     
    422492}
    423493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
Note: See TracChangeset for help on using the changeset viewer.