00001
00002
00003
00004
00005
00006
00007
00008 #include <map>
00009 #include <iostream>
00010 #include "TFile.h"
00011 #include <TROOT.h>
00012 #include <TRint.h>
00013 #include <TKey.h>
00014 #include "TTree.h"
00015
00016 #include "root/MTRun.hh"
00017 #include "root/MTEvent.hh"
00018 #include "root/MTChannel.hh"
00019
00020 using namespace std;
00021
00022 int main(void){
00023
00024
00025
00026
00027
00028 Int_t blabla = 3;
00029
00030
00031 Int_t threshold = 1000;
00032
00033
00034 string file = "05082011_1055_MGT.root";
00035
00036
00037
00038
00039 TFile *f = new TFile(file.c_str());
00040 if(blabla==1||blabla==2||blabla==3){
00041 cout<<endl;
00042 cout<<"reading File : "<<file<<endl;
00043 }
00044
00045
00046 TIter nextkey(f->GetListOfKeys());
00047 TKey *key;
00048 UInt_t counter = 0;
00049
00050 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00051
00052
00053
00054 while (key = (TKey*)nextkey()) {
00055
00056 counter++;
00057 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00058
00059 TTree *tree = (TTree*)key->ReadObj();
00060 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00061
00062 Int_t nEvent = tree->GetEntries();
00063 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl<<endl;
00064
00065 MTEvent *evt = new MTEvent();
00066
00067 TBranch *branch= tree->GetBranch("MTEvent");
00068 branch->SetAddress(&evt);
00069
00070
00071 bool IsSquare;
00072 Int_t Asu;
00073 Int_t AbsTime;
00074
00075
00076
00077 for (int i=0;i<nEvent-1;i++){
00078
00079 tree->GetEntry(i);
00080
00081 UInt_t nchannel = evt->GetNchannel();
00082 if(blabla==3) cout<<"Event "<<i+1<<" / "<<nEvent<<"; nb of channels= "<<nchannel<<endl;
00083
00084
00085 map<unsigned int,map<unsigned int,int> > channels_map;
00086
00087
00088 IsSquare=0;
00089 Asu = -1;
00090 AbsTime = -1;
00091
00092
00093 for (int j=0;j<nchannel;j++){
00094
00095
00096 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00097
00098
00099 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00100 UInt_t board_id = channel->GetBoardId();
00101
00102
00103
00104 if ( channels_map.find(board_id) == channels_map.end()) {
00105
00106 map<unsigned int, int> nbHitMap;
00107 nbHitMap[hit_time]=1;
00108 channels_map.insert(make_pair(board_id,nbHitMap));
00109 }
00110 else{
00111
00112 map<unsigned int, int> &nbHitMap = channels_map.find(board_id)->second;
00113 if (nbHitMap.find(hit_time) == nbHitMap.end()){
00114
00115 nbHitMap.insert(make_pair(hit_time,1));
00116 }
00117 else{
00118
00119 nbHitMap[hit_time] = nbHitMap[hit_time]++;
00120 }
00121 }
00122 }
00123
00124
00125 map<unsigned int, map<unsigned int,int> >::iterator iter1;
00126 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00127
00128 unsigned int azu=iter1->first;
00129 map<unsigned int,int> hits_per_time=iter1->second;
00130
00131 map<unsigned int,int>::iterator iter2;
00132 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00133
00134 unsigned int time = iter2->first;
00135 int nb_hits = iter2->second;
00136
00137
00138 if (nb_hits>=threshold) {
00139
00140
00141 IsSquare = 1;
00142 Asu = azu;
00143 AbsTime = time;
00144
00145 if(blabla==2) cout<<"*";
00146 if(blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at abstime "<<time<<" with n_hits = "<<nb_hits<<endl;
00147 }
00148 }
00149 }
00150 }
00151 if(blabla==2||blabla==3) cout<<endl;
00152 }
00153 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00154 return 0;
00155 }
00156