00001
00002
00003
00004
00005
00006 {
00007
00008 gROOT->Reset();
00009 gROOT->SetStyle("Bold");
00010 gStyle->SetPalette(1);
00011 gSystem->Load("~/Micromegas/Analyse/trunk/lib/libMicro.so");
00012
00013 gSystem->Load("~/Micromegas/Analyse/trunk/src/analyse/Damien/load.C");
00014
00015
00016
00017
00018
00019
00020
00021 bool plot = 1;
00022
00023
00024 Int_t blabla = 2;
00025
00026
00027 Int_t threshold = 500;
00028
00029
00030 string file = "05082011_1055_MGT.root";
00031
00032
00033
00034
00035 TFile *f = new TFile(file.c_str());
00036 if(blabla==1||blabla==2||blabla==3){
00037 cout<<endl;
00038 cout<<"reading File : "<<file<<endl;
00039 }
00040
00041
00042 TIter nextkey(f.GetListOfKeys());
00043 TKey *key;
00044 UInt_t counter = 0;
00045
00046
00047
00048
00049 TH2I *hxy = new TH2I("hxy","Hit position distribution;y (cm);x (cm)",96,0,96,96,0,96);
00050 TH1I *hdt = new TH1I("hdt","Hit time distribution;N_hits;delta_t (/200ns)",128,0,128);
00051 if(plot){
00052
00053 TCanvas *c0 = new TCanvas("c0", "Prototype m2", 100, 50, 1000, 500);
00054 c0->Divide(2,1);
00055 }
00056 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00057
00058
00059
00060 while (key = (TKey*)nextkey()) {
00061
00062 counter++;
00063 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00064
00065 TTree *tree = (TTree*)key->ReadObj();
00066 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00067
00068 Int_t nEvent = tree.GetEntries();
00069 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl;
00070
00071 MTEvent *evt = new MTEvent();
00072
00073 TBranch *branch= tree->GetBranch("MTEvent");
00074 branch->SetAddress(&evt);
00075
00076 UInt_t list_event[nEvent];
00077
00078
00079 std::map<unsigned int,std::map<unsigned int,int> > nb_square;
00080 UInt_t nb_tot;
00081
00082
00083
00084 for (int i=0;i<nEvent-1;i++){
00085
00086 tree.GetEntry(i);
00087
00088 UInt_t nchannel = evt->GetNchannel();
00089 if(blabla==3) cout<<"Event "<<i+1<<" / "<<nEvent<<"; nb of channels= "<<nchannel<<endl;
00090
00091
00092 std::map<unsigned int,std::map<unsigned int,int> > channels_map;
00093
00094
00095
00096 for (int j=0;j<nchannel;j++){
00097
00098
00099 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00100
00101
00102 UInt_t board_id = channel->GetBoardId();
00103 UInt_t abs_time = channel->GetBcId_Abs() - (channel->GetBcId_Dif() - channel->GetBcId_Hit() );
00104
00105
00106 if ( channels_map.find(board_id) == channels_map.end()) {
00107 std::map<unsigned int, int> nbHitMap;
00108 nbHitMap[abs_time]=1;
00109 channels_map.insert(make_pair(board_id,nbHitMap));
00110 }
00111 else{
00112 std::map<unsigned int, int> &nbHitMap = channels_map.find(board_id)->second;
00113 if (nbHitMap.find(abs_time) == nbHitMap.end()){
00114 nbHitMap.insert(make_pair(abs_time,1));
00115 }
00116 else{
00117 nbHitMap[abs_time] = nbHitMap[abs_time]++;
00118 }
00119 }
00120
00121 if(blabla==3) cout<<"Channel : "<<channel<<"; hit on asu "<<board_id<<"; at memory order "<<mem_order<<endl;
00122
00123
00124 if (plot){
00125 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00126 hdt->Fill(abs_time);
00127 }
00128 }
00129
00130
00131
00132 std::map<unsigned int, std::map<unsigned int,int> >::iterator iter1;
00133 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00134
00135 unsigned int azu=iter1->first;
00136 std::map<unsigned int,int> hits_per_abstime=iter1->second;
00137
00138 std::map<unsigned int,int>::iterator iter2;
00139 for(iter2=hits_per_abstime.begin();iter2!=hits_per_abstime.end();iter2++){
00140
00141 unsigned int abstime = iter2->first;
00142 int nb_hits = iter2->second;
00143
00144 if (nb_hits>= threshold) {
00145 if(blabla==2||blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at abs_time "<<abstime<<" with n_hits = "<<nb_hits<<endl;
00146
00147
00148 if ( nb_square.find(board_id) == nb_square.end()) {
00149 std::map<unsigned int, int> nbHitMap;
00150 nbHitMap[abs_time]=1;
00151 nb_square.insert(make_pair(board_id,nbHitMap));
00152 }
00153 else{
00154 std::map<unsigned int, int> &nbHitMap = nb_square.find(board_id)->second;
00155 if (nbHitMap.find(abs_time) == nbHitMap.end()){
00156 nbHitMap.insert(make_pair(abs_time,1));
00157 }
00158 else{
00159 nbHitMap[abs_time] = nbHitMap[abs_time]++;
00160 }
00161 }
00162
00163
00164 nb_tot++;
00165
00166
00167 list_event[nb_tot-1] = i+1;
00168 }
00169 }
00170 }
00171
00172
00173 if (plot){
00174 c0->cd(1);
00175 hxy->SetTitle("Hits position");
00176 hxy.GetXaxis()->SetTitle("X (cm)");
00177 hxy.GetYaxis()->SetTitle("Y (cm)");
00178 hxy.GetYaxis()->SetLogy();
00179 hxy.GetYaxis()->SetGridy();
00180 hxy->Draw("zcol");
00181
00182 c0->cd(2);
00183 hdt->SetTitle("Hits time");
00184 hdt.GetXaxis()->SetTitle("delta t (/ 200 ns)");
00185 hdt.GetYaxis()->SetTitle("Nb hits");
00186 hdt.GetYaxis()->SetLogy();
00187 hdt.GetYaxis()->SetGridy();
00188 hdt->Draw();
00189 }
00190 }
00191
00192
00193
00194 if(blabla==2||blabla==3) cout<<endl;
00195 if(blabla==1||blabla==2||blabla==3) {
00196
00197
00198 cout<<"In key "<<counter<<" Nb tot evt square = "<<nb_tot<<endl;
00199
00200
00201 cout<<"List of square events: "<<endl;
00202
00203 for(int it=0;it<nb_tot;it++) cout<<" "<<list_event[it];
00204 cout<<endl<<endl;
00205 }
00206
00207 if(blabla==2||blabla==3) {
00208
00209
00210 cout<<"Hereafter I show the nb of event square in each board/asu at each time:"<<endl<<endl<<"Board/asu i"<<endl<<"memory order:";
00211 for (int ti=0;ti<128;ti++) cout<<" "<<ti;
00212 cout<<endl;
00213
00214 std::map<unsigned int, std::map<unsigned int,int> >::iterator iter1;
00215 for(iter1=nb_square.begin();iter1!=nb_square.end();iter1++){
00216
00217 unsigned int azu=iter1->first;
00218 std::map<unsigned int,int> nb_square_per_abstime=iter1->second;
00219
00220 cout<<endl;
00221 cout<<"asu "<<azu<<endl;
00222
00223 std::map<unsigned int,int>::iterator iter2;
00224 for(iter2=nb_square_per_abstime.begin();iter2!=nb_square_per_abstime.end();iter2++){
00225
00226 unsigned int abstime = iter2->first;
00227 int nb_hits = iter2->second;
00228
00229 cout<<" "<<nb_hits;
00230 }
00231 cout<<endl;
00232 }
00233 cout<<endl;
00234 }
00235 cout<<endl;
00236 }
00237 return 0;
00238 }
00239