00001
00002 #include "lcio.h"
00003
00004 #include "IO/LCWriter.h"
00005 #include "EVENT/LCIO.h"
00006 #include <EVENT/CalorimeterHit.h>
00007 #include "EVENT/LCGenericObject.h"
00008 #include "IMPL/LCCollectionVec.h"
00009 #include "IMPL/CalorimeterHitImpl.h"
00010
00011 #include "TFile.h"
00012 #include "TTree.h"
00013
00014 #include "TreeClass.hh"
00015
00016
00017 #include <cstdlib>
00018 #include <iostream>
00019 #include <sstream>
00020
00021
00022 using namespace std ;
00023 using namespace lcio ;
00024
00025
00026
00027 int main(int argc, char** argv ){
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;
00048
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
00067 TTree *mt = new TTree("AHCAL" ,"AHCAL MT format");
00068 mt->SetMaxTreeSize(4000000000);
00069 mt->Branch("MTEvent",&ahcalEvt,16000,2);
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
00081 ahcalEvt->SetGlobalTriggerCounter(i);
00082
00083 if (i%100==0){cout<<"Read event "<<i<<" \r"<<flush;}
00084
00085
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
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
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
00136
00137
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
00149 if ( difFilled )
00150 {
00151 mt->Fill();
00152 }
00153 ahcalEvt->SetNchannel(0);
00154 if (i==n){break;}
00155 }
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 }
00172