00001
00002
00003
00004
00005
00006
00007
00008 #include <map>
00009 #include <iostream>
00010 #include "TH1I.h"
00011 #include "TH2I.h"
00012 #include "TCanvas.h"
00013 #include "TFile.h"
00014 #include <TROOT.h>
00015 #include <TRint.h>
00016 #include <TKey.h>
00017 #include "TTree.h"
00018 #include <TApplication.h>
00019
00020 #include "root/MTRun.hh"
00021 #include "root/MTEvent.hh"
00022 #include "root/MTChannel.hh"
00023
00024
00025 using namespace std;
00026
00027
00028
00029 void add(map<unsigned int,map<unsigned int ,int> >&channels_map, unsigned int asu, unsigned int hit_time){
00030
00031 if ( channels_map.find(asu) == channels_map.end()) {
00032
00033 map<unsigned int, int> nbHitMap;
00034 nbHitMap[hit_time]=1;
00035 channels_map.insert(make_pair(asu,nbHitMap));
00036 }
00037 else{
00038
00039 map<unsigned int, int> &nbHitMap = channels_map.find(asu)->second;
00040 if (nbHitMap.find(hit_time) == nbHitMap.end()){
00041
00042 nbHitMap.insert(make_pair(hit_time,1));
00043 }
00044 else{
00045
00046 nbHitMap[hit_time] = nbHitMap[hit_time]++;
00047 }
00048 }
00049 }
00050
00051
00052
00053 int main(void){
00054
00055
00056
00057
00058
00059 bool plot = 1;
00060
00061
00062 Int_t blabla = 2;
00063
00064
00065 Int_t threshold = 1000;
00066
00067
00068 Int_t timecut = 50;
00069
00070
00071
00072
00073 string file = "05082011_2248_MGT.root";
00074
00075
00076
00077
00078 TApplication *theApp;
00079 theApp = new TRint("App", 0, NULL);
00080 TCanvas *c0 = new TCanvas("c0", "Prototype m2", 100, 50, 1000, 600);
00081 TH2I *hxy = new TH2I("hxy","Hit position distribution (No time cut);y (cm);x (cm)",96,0,96,96,0,96);
00082 TH2I *hxy2 = new TH2I("hxy2","Hit position distribution (within time cut);y (cm);x (cm)",96,0,96,96,0,96);
00083 TH2I *hxy3 = new TH2I("hxy3","Hit position distribution (at the time where it is square);y (cm);x (cm)",96,0,96,96,0,96);
00084
00085
00086
00087
00088
00089
00090 TFile *f = new TFile(file.c_str());
00091 if(blabla==1||blabla==2||blabla==3){
00092 cout<<endl;
00093 cout<<"reading File : "<<file<<endl;
00094 }
00095
00096
00097 TIter nextkey(f->GetListOfKeys());
00098 TKey *key;
00099 UInt_t counter = 0;
00100
00101 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00102
00103
00104
00105 while (key = (TKey*)nextkey()) {
00106
00107 counter++;
00108 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00109
00110 TTree *tree = (TTree*)key->ReadObj();
00111 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00112
00113 Int_t nEvent = tree->GetEntries();
00114 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl;
00115
00116 MTEvent *evt = new MTEvent();
00117
00118 TBranch *branch= tree->GetBranch("MTEvent");
00119 branch->SetAddress(&evt);
00120
00121
00122 bool IsSquare = 0;
00123 Int_t list_square_events[nEvent][4];
00124 Int_t list_square_events_timecut[nEvent][4];
00125 UInt_t list_event[nEvent];
00126 UInt_t list_event_timecut[nEvent];
00127 UInt_t nb_tot = 0;
00128 UInt_t nb_timecut = 0;
00129
00130
00131
00132 for (int i=0;i<nEvent-1;i++){
00133
00134 tree->GetEntry(i);
00135
00136 UInt_t nchannel = evt->GetNchannel();
00137
00138
00139
00140 map<unsigned int,map<unsigned int,int> > channels_map;
00141
00142
00143 Int_t tmin=0;
00144 Int_t tmax=0;
00145
00146
00147 IsSquare=0;
00148
00149
00150 UInt_t SquareTime=0;
00151
00152
00153 for (int j=0;j<nchannel;j++){
00154
00155
00156 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00157
00158
00159 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00160 UInt_t board_id = channel->GetBoardId();
00161
00162
00163
00164 if(j==0) {
00165 tmin=hit_time;
00166 tmax=hit_time;
00167 }
00168 if(hit_time<tmin) tmin=hit_time;
00169 if(hit_time>tmax) tmax=hit_time;
00170
00171
00172 add(channels_map, board_id, hit_time);
00173 }
00174
00175 unsigned int timeold=0;
00176
00177
00178 map<unsigned int, map<unsigned int,int> >::iterator iter1;
00179 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00180
00181 unsigned int azu=iter1->first;
00182 map<unsigned int,int> hits_per_time=iter1->second;
00183
00184 map<unsigned int,int>::iterator iter2;
00185 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00186
00187 unsigned int time = iter2->first;
00188 int nb_hits = iter2->second;
00189
00190
00191 if (nb_hits>=threshold) {
00192
00193
00194
00195 IsSquare=1;
00196
00197
00198 SquareTime=time;
00199
00200 if(blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at time "<<time<<" with n_hits = "<<nb_hits<<" DELTA T= "<<time-timeold<<endl;
00201 timeold=time;
00202
00203
00204 list_square_events[nb_tot][0] = i+1;
00205 list_square_events[nb_tot][1] = azu;
00206 list_square_events[nb_tot][2] = time;
00207 list_square_events[nb_tot][3] = nb_hits;
00208 if(time>tmax-timecut){
00209 list_square_events_timecut[nb_timecut][0] = i+1;
00210 list_square_events_timecut[nb_timecut][1] = azu;
00211 list_square_events_timecut[nb_timecut][2] = time;
00212 list_square_events_timecut[nb_timecut][3] = nb_hits;
00213 }
00214
00215
00216 nb_tot++;
00217 if(time>tmax-timecut) nb_timecut++;
00218
00219
00220 list_event[nb_tot-1] = i+1;
00221 if(time>tmax-timecut) list_event_timecut[nb_tot-1] = i+1;
00222 }
00223 }
00224 }
00225
00226
00227 if (IsSquare && plot){
00228
00229 TH1I *hdt = new TH1I("hdt","Hit time distribution (No time cut);N_hits;Time",tmax-tmin+3,-1,tmax-tmin+1);
00230 TH1I *hdt2 = new TH1I("hdt2","Hit time distribution (within time cut);N_hits;Time",timecut+3,tmax-timecut-1,tmax+1);
00231 TH1I *hdt3 = new TH1I("hdt3","Hit time distribution (around the time where it is square);N_hits;Time",23,SquareTime-tmin-11,SquareTime-tmin+11);
00232
00233
00234 for (int j=0;j<nchannel;j++){
00235
00236
00237 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00238
00239
00240 UInt_t board_id = channel->GetBoardId();
00241 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00242
00243
00244 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00245 if(hit_time>tmax-timecut) hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00246 if(hit_time==SquareTime) hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00247 hdt->Fill(hit_time-tmin);
00248 if(hit_time>tmax-timecut) hdt2->Fill(hit_time-tmin);
00249 if(hit_time>SquareTime-100 && hit_time<SquareTime+500) hdt3->Fill(hit_time-tmin);
00250 }
00251
00252
00253 c0->Divide(3,2);
00254 c0->cd(1);
00255 hxy->GetXaxis()->SetTitle("X (cm)");
00256 hxy->GetYaxis()->SetTitle("Y (cm)");
00257 hxy->Draw("zcol");
00258
00259 c0->cd(2);
00260 hxy2->GetXaxis()->SetTitle("X (cm)");
00261 hxy2->GetYaxis()->SetTitle("Y (cm)");
00262 hxy2->Draw("zcol");
00263
00264 c0->cd(3);
00265 hxy3->GetXaxis()->SetTitle("X (cm)");
00266 hxy3->GetYaxis()->SetTitle("Y (cm)");
00267 hxy3->Draw("zcol");
00268
00269 c0->cd(4);
00270
00271
00272
00273 hdt->GetXaxis()->SetTitle("time after trigger (BcId)");
00274 hdt->GetYaxis()->SetTitle("Nb hits");
00275 hdt->Draw();
00276
00277 c0->cd(5);
00278
00279
00280
00281 hdt2->GetXaxis()->SetTitle("time after trigger (BcId)");
00282 hdt2->GetYaxis()->SetTitle("Nb hits");
00283 hdt2->Draw();
00284
00285 c0->cd(6);
00286
00287
00288
00289 hdt3->GetXaxis()->SetTitle("time after trigger (BcId)");
00290 hdt3->GetYaxis()->SetTitle("Nb hits");
00291 hdt3->Draw();
00292
00293
00294 char plotname[20] = "plot_evt";
00295 char buf[10];
00296 sprintf(buf,"%d",i+1);
00297 strcat(plotname, buf);
00298 strcat(plotname,".gif");
00299 c0->SaveAs(plotname);
00300
00301
00302 c0->Clear();
00303
00304
00305 hxy->Reset();
00306 hxy2->Reset();
00307 hxy3->Reset();
00308
00309
00310
00311
00312
00313
00314 hdt->Delete();
00315 hdt2->Delete();
00316 hdt3->Delete();
00317 }
00318 }
00319
00320
00321 if(blabla==2||blabla==3) cout<<endl;
00322 if(blabla==1||blabla==2||blabla==3) {
00323
00324
00325 cout<<"In key "<<counter<<":"<<endl<<endl;;
00326 cout<<" Nb square evt= "<<nb_tot<<endl;
00327 cout<<" Nb square evt within the timecut (delta t < "<<timecut<<") = "<<nb_timecut<<endl<<endl;
00328
00329
00330 cout<<"List of square events: "<<endl;
00331 for(int it=0;it<nb_tot;it++) cout<<" "<<list_event[it];
00332 cout<<endl<<endl;
00333
00334
00335 cout<<"List of square events that are square within the timecut (delta t < "<<timecut<<")"<<endl;
00336 for(int it=0;it<nb_timecut;it++) cout<<" "<<list_event_timecut[it];
00337 cout<<endl<<endl;
00338 }
00339
00340 if(blabla==2||blabla==3) {
00341
00342
00343 cout<<"Hereafter I show the list of square events in each board/asu at each time and their number of hits:"<<endl;
00344 cout<<"Event, Board/asu, time, Nb_hits"<<endl;
00345 for(int it=0;it<nb_tot;it++) {
00346 for(int itt=0;itt<4;itt++) cout<<list_square_events[it][itt]<<"; ";
00347 cout<<endl;
00348 }
00349 cout<<endl;
00350 cout<<"Hereafter I show the list of square events that are square within the timecut (delta t < "<<timecut<<"):"<<endl;
00351 cout<<"Event, Board/asu, time, Nb_hits"<<endl;
00352 for(int it=0;it<nb_timecut;it++) {
00353 for(int itt=0;itt<4;itt++) cout<<list_square_events_timecut[it][itt]<<"; ";
00354 cout<<endl;
00355 }
00356 cout<<endl;
00357 }
00358 cout<<endl;
00359 }
00360 theApp->Run();
00361 delete theApp;
00362 return 0;
00363 }
00364