/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/root/beamProfile.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1566 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2012-03-08 14:00:10 +0100 (Thu, 08 Mar 2012) $ */
00002 /* 
00003  * File:   beamProfile.cpp
00004  * Author: jacquem
00005  *
00006  * Created on May 6, 2010, 10:03 AM
00007  */
00008 
00009 // System includes
00010 #include <iostream>
00011 #include <stdlib.h>
00012 #include <vector>
00013 
00014 // Root includes
00015 #include "TString.h"
00016 #include "TApplication.h"
00017 #include <TStyle.h>
00018 #include <TFile.h>
00019 #include <TTree.h>
00020 #include <TKey.h>
00021 
00022 // Framework inlcudes
00023 #include "BeamProfile.hh"
00024 #include "Run.hh"
00025 #include "Detector.hh"
00026 #include "XMLTool.hh"
00027 #include "Toolbox.hh"
00028 #include "MicroException.hh"
00029 #include "Log.hh"
00030 #include "Chamber.hh"
00031 
00032 #include "Board.hh"
00033 #include "Chip.hh"
00034 #include "Dif.hh"
00035 
00036 #include "root/MTRun.hh"
00037 #include "root/MTEvent.hh"
00038 //#include "Event.hh"
00039 
00040 using namespace std;
00041 
00042 
00043 
00044 int main(int argc, char** argv) {
00045 
00046 
00047 FILELog::ReportingLevel() = FILELog::FromString(INFO);
00048 string filename ;
00049 ui32 nbEvents = 0;
00050 ui32 nbChannels = 0;
00051 
00052 // Manage command options
00053 //if ( argc == 1)
00054 //{
00055     //cout << endl  << "usage: beamProfile   [root file Name]" << endl ;
00056     //cout << "help:  beamProfile -h " << endl;
00057     //exit(0);
00058 //}
00059 BeamProfile manager(argc,argv);
00060 
00061 filename = manager.getFileName();
00062 
00063 if ( filename.empty())
00064 {
00065     cout << "a root file name is mandatory. Please use -f option to set it. " << endl;
00066     exit(0);
00067 }
00068 
00069 // Build detector from XML file
00070         Detector detector;
00071         // Get detector information
00072         if ( ! manager.getXMLFileName().empty())
00073         {
00074             SteerDesc steerDesc;
00075             XMLTool xml;
00076             xml.parse(steerDesc, manager.getXMLFileName());
00077             detector.build(steerDesc);
00078             manager.SetDetector(&detector);
00079         }
00080 
00081 
00082 // Create ROOT Application
00083 TApplication theApp("App", 0, NULL);
00084 gStyle->SetPalette(1);
00085 
00086 // Open root file
00087 int nchannel = 0;
00088 
00089 TFile f(filename.c_str());
00090 cout<<"reading File : "<<filename<<endl;
00091 
00092 // Get TTree list form root file
00093 TIter nextkey(f.GetListOfKeys());
00094 TKey *key;
00095 
00096 // Loop over TTree ( one TTree by rawfile )
00097 while (key = (TKey*)nextkey())
00098 {
00099     TTree *tree = (TTree*)key->ReadObj();
00100     if ( tree == NULL) { exit(0);} ;
00101 
00102           if  (manager.getShowRunInfo())
00103                 {
00104                     //Get Run information ( name, date, dif and chip confiration )
00105         MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00106         if ( run != NULL) run->Info();
00107           }
00108                  FILE_LOG(logINFO  ) << endl << "TTree[" <<tree->GetName() << "]" << endl;
00109 
00110                 // Get number of event for current  TTree
00111     int nEvent = tree->GetEntries();
00112 
00113                 // Get TTree MTEvent branch
00114     MTEvent *evt = new MTEvent();
00115     TBranch *branch= tree->GetBranch("MTEvent");
00116     branch->SetAddress(&evt);
00117 
00118 
00119                 // Loop over events
00120     for (int i=0;i<nEvent;i++)
00121     {
00122         nbEvents++;
00123                          if ( nbEvents % 100 == 0) FILE_LOG(logINFO  ) << "Event " << i+1 <<" / " << nEvent << "\r" << flush;
00124                 // Print computate status
00125                 //if (i%10 == 0){cout<<(float)(i*100)/(float)(nEvent)<<" %"<<"\r"<<flush;}
00126 
00127                 // Get ith event
00128         tree->GetEntry(i);
00129                                 // Get number of MTChannel for this event
00130         nchannel = evt->GetNchannel();
00131                     manager.FillHotChamber(*evt);
00132 
00133                                 // loop over MTChannel
00134         for (int j=0;j<nchannel;j++)
00135         {
00136             nbChannels++;
00137             MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00138                                                 // Get x,y position
00139 
00140                              manager.FillXyDist(*channel);
00141 
00142                              manager.FillHitPerChipDist(*channel);
00143 
00144                        manager.FillHitPerChannel(*channel);
00145 
00146                              manager.FillDeltaT(*channel);
00147 
00148                             manager.FillHotChip(*channel);
00149 
00150             //manager.FillTimestamp(*channel);
00151 
00152         }
00153     } // End of event loop.
00154 } // end while over TTree
00155 
00156 manager.DrawXyDist();
00157 manager.DrawHitPerChipDist();
00158 manager.DrawHitPerChannelDist();
00159 manager.DrawDeltaT();
00160 manager.DrawHotChamber();
00161 
00162 
00163 manager.PrintHotChip();
00164 cout << endl <<endl << "----------- SUCCESS ---------------" << endl;
00165 cout << endl << "----------- " << nbEvents <<" events, " << nbChannels << " channels. ---------------" << endl;
00166 cout << " Close Root  ( or  press Ctrl^C ) to finish."<< endl;
00167 
00168 theApp.Run();
00169 return (EXIT_SUCCESS);
00170 }
00171 
00172 
00173 

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7