/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/ahcalReco.cpp File Reference

#include "lcio.h"
#include "IO/LCWriter.h"
#include "EVENT/LCIO.h"
#include <EVENT/CalorimeterHit.h>
#include "EVENT/LCGenericObject.h"
#include "IMPL/LCCollectionVec.h"
#include "IMPL/CalorimeterHitImpl.h"
#include "TFile.h"
#include "TTree.h"
#include "TreeClass.hh"
#include <cstdlib>
#include <iostream>
#include <sstream>

Include dependency graph for ahcalReco.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file ahcalReco.cpp.

00027                                 {
00028 
00029 
00030   if (argc==3)
00031   {
00032 
00033     static string lcioFile = argv[1] ;
00034     TString rootfilename = argv[2];
00035 
00036     IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00037     lcReader->open( lcioFile ) ;
00038 
00039     bool display = 0;
00040     bool display_dif = 0;
00041 
00042     int i = 0;
00043     unsigned int n = i + 1e9 ;
00044 
00045     LCEvent* evt = NULL;
00046 
00047     int nthEvent = 0;//500;//23500;
00048     //lcReader->skipNEvents(nthEvent) ;
00049 
00050     TFile * tf = new TFile(rootfilename.Data(),"RECREATE");
00051 
00052     float energy = 0;
00053     float xpos = 0;
00054     float ypos = 0;
00055     float zpos = 0;
00056     int dif_trg = 0;
00057 
00058     TString collec_name;
00059     TString collec_type;
00060 
00061     cout<<endl;
00062     cout<<"Read file "<<lcioFile<<endl;
00063     cout<<endl;
00064 
00065     MTEvent *ahcalEvt =  new MTEvent();
00066     //TTree *mt = new TTree(lcioFile.c_str(),"AHCAL MT format");
00067     TTree *mt = new TTree("AHCAL" ,"AHCAL MT format");
00068     mt->SetMaxTreeSize(4000000000); // 4 Mb
00069     mt->Branch("MTEvent",&ahcalEvt,16000,2);// second argument is class of evt!!!
00070 
00071     unsigned int energyFill = 0;
00072     unsigned int difFill = 0;
00073 
00074     while( (evt = lcReader->readNextEvent()) != 0 )
00075     {
00076       bool energyFilled = false;
00077       bool difFilled = false;
00078         
00079       i++;
00080       // Fill MT Event
00081       ahcalEvt->SetGlobalTriggerCounter(i);
00082 
00083       if (i%100==0){cout<<"Read event "<<i<<" \r"<<flush;}
00084 
00085       //LCTOOLS::dumpEventDetailed( evt );
00086 
00087       const vector<string>* collNames = evt->getCollectionNames();
00088     
00089       vector<string>::const_iterator it;
00090     
00091       for ( it = collNames->begin(); it!=collNames->end(); ++it) 
00092       {
00093         LCCollection*  collec = evt->getCollection(*it);
00094         if (display){cout<<endl;cout << " collection "<<*it<<" of type " << collec->getTypeName() << endl;}
00095 
00096         collec_name = *it;
00097         collec_type = collec->getTypeName();
00098 
00099         //Calo Hits
00100         if (collec_type == "CalorimeterHit")
00101         {
00102           for ( int element = 0; element < collec->getNumberOfElements(); element++)
00103           {
00104             CalorimeterHit *hit = dynamic_cast<CalorimeterHit*>(collec->getElementAt(element));
00105             if (hit != NULL)
00106             {
00107               if(display)
00108               {
00109                 cout<<"Hit with energy "<<hit->getEnergy()<<" GeV at position "<<hit->getPosition()[0]<<" "<<hit->getPosition()[1]<<" "<<hit->getPosition()[2]<<endl; 
00110               }
00111               energy = hit->getEnergy();
00112               if  ( element == 0 ) { energyFill++; energyFilled =true; }
00113               xpos = hit->getPosition()[0];
00114               ypos = hit->getPosition()[1];
00115               zpos = hit->getPosition()[2];
00116               MTChannel mtHit;
00117               mtHit.SetX(xpos);
00118               mtHit.SetY(ypos);
00119               mtHit.SetZ(zpos);
00120               mtHit.SetEnergy( energy);
00121               ahcalEvt->AddChannel(&mtHit);
00122             }
00123           } 
00124         }
00125 
00126         //DIF trigger
00127         if (collec_name == "CALDAQ2_DifTrigger")
00128         {
00129           for ( int element = 0; element < collec->getNumberOfElements(); element++)
00130           {
00131             LCGenericObject *obj = dynamic_cast<LCGenericObject*>(collec->getElementAt(element));
00132             if (obj != NULL)
00133             {       
00134               dif_trg = obj->getIntVal(0);
00135               //if ( dif_trg < 0 ) { cout << "dif_trg[" << dif_trg << "] pour i[" << i+nthEvent << "]" << endl; dif_trg = 0;}
00136 
00137               // Fill MT Event dif synchro
00138               ahcalEvt->SetDifSynchro(dif_trg);
00139               difFill++;
00140               difFilled = true;
00141               ahcalEvt->SetEventId(i);
00142     
00143               if (display_dif){cout<<"  dif trigger number of evt["<<i+nthEvent<<"] = "<<dif_trg<<endl;}
00144             }
00145           }
00146         }
00147       }
00148       //if ( energyFilled && difFilled ) 
00149       if ( difFilled ) 
00150       {
00151          mt->Fill();
00152       }  
00153       ahcalEvt->SetNchannel(0); 
00154       if (i==n){break;}
00155     } // end while event
00156 
00157     mt->Fill();
00158     lcReader->close() ;
00159     tf->Write("", TObject::kOverwrite);
00160     tf->Close();
00161   
00162     delete lcReader ;
00163   }
00164   else
00165   {
00166     cout<<"argument 1 is the slcio file - arg 2 is the final rootfile with position, energy and trigger number"<<endl;
00167   }
00168 
00169 
00170   return 0;
00171 }


Generated on Mon Jan 7 13:16:55 2013 for MicromegasFramework by  doxygen 1.4.7