/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/lcio/max_lcio.cc

Go to the documentation of this file.
00001 #include "lcio.h"
00002 
00003 #include "IO/LCWriter.h"
00004 #include "EVENT/LCIO.h"
00005 #include <EVENT/CalorimeterHit.h>
00006 #include "EVENT/LCGenericObject.h"
00007 #include "IMPL/LCCollectionVec.h"
00008 #include "IMPL/CalorimeterHitImpl.h"
00009 
00010 #include "TNtuple.h"
00011 #include "TH1F.h"
00012 #include "TFile.h"
00013 #include "TGraph.h"
00014 
00015 
00016 #include <cstdlib>
00017 #include <iostream>
00018 #include <sstream>
00019 
00020 
00021 using namespace std ;
00022 using namespace lcio ;
00023 
00024 
00025 
00026 int main(int argc, char** argv ){
00027 
00028 
00029   if (argc==3){
00030 
00031   static string lcioFile = argv[1] ;
00032   TString rootfilename = argv[2];
00033 
00034   IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00035   lcReader->open( lcioFile ) ;
00036 
00037   bool display = 0;
00038 
00039   int n = 1e9;
00040   int i = 0;
00041 
00042   LCEvent* evt = NULL;
00043 
00044   int nthEvent = 500;
00045   lcReader->skipNEvents(nthEvent) ;
00046 
00047   TFile * tf = new TFile(rootfilename.Data(),"RECREATE");
00048 
00049   TNtuple * nthit = new TNtuple("nthit","AHCAL Calo Hits","x:y:z:e");
00050   TNtuple * ntdif = new TNtuple("ntdif","AHCAL synchro DIF trigger number","trg");
00051 
00052   TGraph * tg_dif_trg_nevent = new TGraph();
00053   tg_dif_trg_nevent->SetName("tg_dif_trg_nevent");
00054   tg_dif_trg_nevent->SetTitle("Synchro DIF AHCAL trigger number");
00055   tg_dif_trg_nevent->GetXaxis()->SetTitle("AHCAL event number");
00056   tg_dif_trg_nevent->GetYaxis()->SetTitle("DIF trigger number");
00057 
00058   TH1F * hen = new TH1F("hen","Calo Hit energy;energy (GeV)",500,0,5);
00059   TH1F * hx = new TH1F("hx","Calo Hit position X;x (mm)",400,-600,600);
00060   TH1F * hy = new TH1F("hy","Calo Hit position Y;y (mm)",400,-600,600);
00061   TH1F * hz = new TH1F("hz","Calo Hit position Z;z (mm)",1200,0,1200);
00062 
00063 
00064   float energy = 0;
00065   float xpos = 0;
00066   float ypos = 0;
00067   float zpos = 0;
00068   int dif_trg = 0;
00069 
00070   TString collec_name;
00071   TString collec_type;
00072 
00073   cout<<endl;
00074   cout<<"Read file "<<lcioFile<<endl;
00075   cout<<endl;
00076 
00077 
00078  
00079   MTEvent *ahcalEvt =  new MTEvent();
00080   TTree mt(lcioFile,"AHCAL MT format");
00081   mt.SetMaxTreeSize(4000000000); // 4 Mb
00082   mt.Branch("MTEvent",&ahaclEvt,16000,2);// second argument is class of evt!!!
00083 
00084 
00085 
00086 
00087 
00088 
00089   while( (evt = lcReader->readNextEvent()) != 0 ){
00090       
00091     i++;
00092     // Fill MT Event
00093     ahcalEvt->SetGlobalTriggerCounter(i);
00094 
00095     if (i%100==0){cout<<"Read event "<<i<<" \r"<<flush;}
00096 
00097     //LCTOOLS::dumpEventDetailed( evt );
00098 
00099     const vector<string>* collNames = evt->getCollectionNames();
00100         
00101     vector<string>::const_iterator it;
00102         
00103     for ( it = collNames->begin(); it!=collNames->end(); ++it) {
00104 
00105       LCCollection*  collec = evt->getCollection(*it);
00106       if (display){cout<<endl;cout << " collection "<<*it<<" of type " << collec->getTypeName() << endl;}
00107 
00108       collec_name = *it;
00109       collec_type = collec->getTypeName();
00110 
00111 
00112       /*Calo Hits*/
00113 
00114       if (collec_type == "CalorimeterHit"){
00115 
00116               for ( int element = 0; element < collec->getNumberOfElements(); element++){
00117 
00118                 CalorimeterHit *hit = dynamic_cast<CalorimeterHit*>(collec->getElementAt(element));
00119 
00120           if (hit != NULL){
00121 
00122                   if(display){cout<<"Hit with energy "<<hit->getEnergy()<<" GeV at position "<<hit->getPosition()[0]<<" "<<hit->getPosition()[1]<<" "<<hit->getPosition()[2]<<endl;}
00123 
00124                   energy = hit->getEnergy();
00125                   xpos = hit->getPosition()[0];
00126                   ypos = hit->getPosition()[1];
00127                   zpos = hit->getPosition()[2];
00128        
00129                   nthit->Fill(xpos,ypos,zpos,energy);
00130        
00131        
00132                   hen->Fill(energy);
00133                   hx->Fill(xpos);
00134                   hy->Fill(ypos);
00135                   hz->Fill(zpos);}
00136 
00137             // Fill MT Event Hits
00138             MTChannel mtHit();
00139             mtHit.SetX(xpos);
00140             mtHit.SetY(ypos);
00141             mtHit.SetZ(zpos);
00142             mtHit.SetAnalogValue( int(energy));
00143             ahcalEvt->AddChannel(mtHit);
00144             
00145       }
00146    } 
00147 
00148 
00149       /*DIF trigger*/
00150 
00151       if (collec_name == "CALDAQ2_DifTrigger"){
00152 
00153         for ( int element = 0; element < collec->getNumberOfElements(); element++){
00154 
00155           LCGenericObject *obj = dynamic_cast<LCGenericObject*>(collec->getElementAt(element));
00156 
00157           if (obj != NULL){     
00158 
00159             dif_trg = obj->getIntVal(0);
00160 
00161             ntdif->Fill(dif_trg);
00162             tg_dif_trg_nevent->SetPoint(tg_dif_trg_nevent->GetN(),i,dif_trg);
00163 
00164       // Fill MT Event dif synchro
00165       ahcalEvt->SetDifSynchro(dif_trg);
00166 
00167             if (display){cout<<"  dif trigger number = "<<dif_trg<<endl;}}}}}
00168 
00169 
00170     
00171 
00172     if (i==n){break;}
00173     
00174     mt->Fill();  
00175     ahcalEvt->SetNchannel(0); 
00176   } // end while event
00177 
00178 
00179 
00180   lcReader->close() ;
00181   delete lcReader ;
00182 
00183 
00184 
00185   tg_dif_trg_nevent->Write();
00186 
00187 
00188   tf->Write();
00189   tf->Close();}
00190 
00191 
00192   else{cout<<"argument 1 is the slcio file - arg 2 is the final rootfile with position, energy and trigger number"<<endl;}
00193 
00194 
00195   return 0;}
00196 

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