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 chip, unsigned int hit_time){
00030
00031 if ( channels_map.find(chip) == channels_map.end()) {
00032
00033 map<unsigned int, int> nbHitMap;
00034 nbHitMap[hit_time]=1;
00035 channels_map.insert(make_pair(chip,nbHitMap));
00036 }
00037 else{
00038
00039 map<unsigned int, int> &nbHitMap = channels_map.find(chip)->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 = 40;
00066
00067
00068 Int_t timecut = 50;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 string file = "06082011_0829_MGT.root";
00088
00089
00090
00091
00092 TApplication *theApp;
00093 theApp = new TRint("App", 0, NULL);
00094 TCanvas *c0 = new TCanvas("c0", "Prototype m2", 100, 50, 1000, 600);
00095 TH2I *hxy = new TH2I("hxy","Hit position distribution (No time cut);y (cm);x (cm)",96,0,96,96,0,96);
00096 TH2I *hxy2 = new TH2I("hxy2","Hit position distribution (within time cut);y (cm);x (cm)",96,0,96,96,0,96);
00097 TH2I *hxy3 = new TH2I("hxy3","Hit position distribution (at the time where it is chip);y (cm);x (cm)",96,0,96,96,0,96);
00098
00099
00100
00101
00102
00103
00104 TFile *f = new TFile(file.c_str());
00105 if(blabla==1||blabla==2||blabla==3){
00106 cout<<endl;
00107 cout<<"reading File : "<<file<<endl;
00108 }
00109
00110
00111 TIter nextkey(f->GetListOfKeys());
00112 TKey *key;
00113 UInt_t counter = 0;
00114
00115 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00116
00117
00118
00119 while (key = (TKey*)nextkey()) {
00120
00121 counter++;
00122 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00123
00124 TTree *tree = (TTree*)key->ReadObj();
00125 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00126
00127 Int_t nEvent = tree->GetEntries();
00128 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl;
00129
00130 MTEvent *evt = new MTEvent();
00131
00132 TBranch *branch= tree->GetBranch("MTEvent");
00133 branch->SetAddress(&evt);
00134
00135
00136 bool IsChip = 0;
00137 Int_t list_chip_events[nEvent][4];
00138 Int_t list_chip_events_timecut[nEvent][4];
00139 UInt_t list_event[nEvent];
00140 UInt_t list_event_timecut[nEvent];
00141 UInt_t nb_tot = 0;
00142 UInt_t nb_timecut = 0;
00143 UInt_t begin_t = 0;
00144 UInt_t end_t = 0;
00145
00146
00147
00148 for (int i=0;i<nEvent-1;i++){
00149
00150 tree->GetEntry(i);
00151
00152 UInt_t nchannel = evt->GetNchannel();
00153
00154
00155
00156 map<unsigned int,map<unsigned int,int> > channels_map;
00157
00158
00159 Int_t tmin=0;
00160 Int_t tmax=0;
00161
00162
00163 IsChip=0;
00164
00165
00166 UInt_t ChipTime=0;
00167
00168
00169 for (int j=0;j<nchannel;j++){
00170
00171
00172 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00173
00174
00175 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00176 UInt_t chip_id = channel->GetChipId();
00177
00178
00179
00180 if(j==0) {
00181 tmin=hit_time;
00182 tmax=hit_time;
00183 }
00184 if(hit_time<tmin) tmin=hit_time;
00185 if(hit_time>tmax) tmax=hit_time;
00186
00187
00188 if(i==0 && j==0) {
00189 begin_t=hit_time;
00190 end_t=hit_time;
00191 }
00192 if(hit_time<begin_t) begin_t=hit_time;
00193 if(hit_time>end_t) end_t=hit_time;
00194
00195
00196 add(channels_map, chip_id, hit_time);
00197 }
00198
00199 unsigned int timeold=0;
00200
00201
00202 map<unsigned int, map<unsigned int,int> >::iterator iter1;
00203 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00204
00205 unsigned int chiip=iter1->first;
00206 map<unsigned int,int> hits_per_time=iter1->second;
00207
00208 map<unsigned int,int>::iterator iter2;
00209 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00210
00211 unsigned int time = iter2->first;
00212 int nb_hits = iter2->second;
00213
00214
00215 if (nb_hits>=threshold) {
00216
00217
00218
00219 IsChip=1;
00220
00221
00222 ChipTime=time;
00223
00224 if(blabla==3) cout <<" -> event: "<<i+1<<" = chip in chip no "<<chiip<<" at time "<<time<<" with n_hits = "<<nb_hits<<" DELTA T= "<<time-timeold<<endl;
00225 timeold=time;
00226
00227
00228 list_chip_events[nb_tot][0] = i+1;
00229 list_chip_events[nb_tot][1] = chiip;
00230 list_chip_events[nb_tot][2] = time;
00231 list_chip_events[nb_tot][3] = nb_hits;
00232 if(time>tmax-timecut){
00233 list_chip_events_timecut[nb_timecut][0] = i+1;
00234 list_chip_events_timecut[nb_timecut][1] = chiip;
00235 list_chip_events_timecut[nb_timecut][2] = time;
00236 list_chip_events_timecut[nb_timecut][3] = nb_hits;
00237 }
00238
00239
00240 nb_tot++;
00241 if(time>tmax-timecut) nb_timecut++;
00242
00243
00244 list_event[nb_tot-1] = i+1;
00245 if(time>tmax-timecut) list_event_timecut[nb_tot-1] = i+1;
00246 }
00247 }
00248 }
00249
00250
00251 if (IsChip && plot){
00252
00253 TH1I *hdt = new TH1I("hdt","Hit time distribution (No time cut);N_hits;Time",tmax-tmin+3,-1,tmax-tmin+1);
00254 TH1I *hdt2 = new TH1I("hdt2","Hit time distribution (within time cut);N_hits;Time",timecut+3,tmax-timecut-1,tmax+1);
00255 TH1I *hdt3 = new TH1I("hdt3","Hit time distribution (around the time where it is chip);N_hits;Time",23,ChipTime-tmin-11,ChipTime-tmin+11);
00256
00257
00258 for (int j=0;j<nchannel;j++){
00259
00260
00261 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00262
00263
00264 UInt_t chip_id = channel->GetChipId();
00265 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00266
00267
00268 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00269 if(hit_time>tmax-timecut) hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00270 if(hit_time==ChipTime) hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00271 hdt->Fill(hit_time-tmin);
00272 if(hit_time>tmax-timecut) hdt2->Fill(hit_time-tmin);
00273 if(hit_time>ChipTime-100 && hit_time<ChipTime+500) hdt3->Fill(hit_time-tmin);
00274 }
00275
00276
00277 c0->Divide(3,2);
00278 c0->cd(1);
00279 hxy->GetXaxis()->SetTitle("X (cm)");
00280 hxy->GetYaxis()->SetTitle("Y (cm)");
00281 hxy->Draw("zcol");
00282
00283 c0->cd(2);
00284 hxy2->GetXaxis()->SetTitle("X (cm)");
00285 hxy2->GetYaxis()->SetTitle("Y (cm)");
00286 hxy2->Draw("zcol");
00287
00288 c0->cd(3);
00289 hxy3->GetXaxis()->SetTitle("X (cm)");
00290 hxy3->GetYaxis()->SetTitle("Y (cm)");
00291 hxy3->Draw("zcol");
00292
00293 c0->cd(4);
00294
00295
00296
00297 hdt->GetXaxis()->SetTitle("time after trigger (BcId)");
00298 hdt->GetYaxis()->SetTitle("Nb hits");
00299 hdt->Draw();
00300
00301 c0->cd(5);
00302
00303
00304
00305 hdt2->GetXaxis()->SetTitle("time after trigger (BcId)");
00306 hdt2->GetYaxis()->SetTitle("Nb hits");
00307 hdt2->Draw();
00308
00309 c0->cd(6);
00310
00311
00312
00313 hdt3->GetXaxis()->SetTitle("time after trigger (BcId)");
00314 hdt3->GetYaxis()->SetTitle("Nb hits");
00315 hdt3->Draw();
00316
00317
00318 char plotname[20] = "plot_evt";
00319 char buf[10];
00320 sprintf(buf,"%d",i+1);
00321 strcat(plotname, buf);
00322 strcat(plotname,".gif");
00323 c0->SaveAs(plotname);
00324
00325
00326 c0->Clear();
00327
00328
00329 hxy->Reset();
00330 hxy2->Reset();
00331 hxy3->Reset();
00332
00333
00334
00335
00336
00337
00338 hdt->Delete();
00339 hdt2->Delete();
00340 hdt3->Delete();
00341 }
00342 }
00343
00344
00345 if(blabla==2||blabla==3) cout<<endl;
00346 if(blabla==1||blabla==2||blabla==3) {
00347
00348
00349 cout<<"In key "<<counter<<":"<<endl<<endl;;
00350 cout<<" Nb chip evt = "<<nb_tot<<endl;
00351 cout<<" Nb chip evt / Nevent tot = "<<1.0*nb_tot/nEvent*100.<<" %"<<endl;
00352 cout<<" Nb chip evt within the timecut (delta t < "<<timecut<<") = "<<nb_timecut<<endl;
00353 float rate = float(nb_tot)/(end_t-begin_t)*1000000000/200*60;
00354 cout<<" Chip event rate = "<<rate<<" event/min"<<endl<<endl;
00355
00356
00357 cout<<"List of chip events: "<<endl;
00358 for(int it=0;it<nb_tot;it++) cout<<" "<<list_event[it];
00359 cout<<endl<<endl;
00360
00361
00362 cout<<"List of chip events that are chip within the timecut (delta t < "<<timecut<<")"<<endl;
00363 for(int it=0;it<nb_timecut;it++) cout<<" "<<list_event_timecut[it];
00364 cout<<endl<<endl;
00365 }
00366
00367 if(blabla==2||blabla==3) {
00368
00369
00370 cout<<"Hereafter I show the list of chip events in each chip/chip at each time and their number of hits:"<<endl;
00371 cout<<"Event, chip, time, Nb_hits"<<endl;
00372 for(int it=0;it<nb_tot;it++) {
00373 for(int itt=0;itt<4;itt++) cout<<list_chip_events[it][itt]<<"; ";
00374 cout<<endl;
00375 }
00376 cout<<endl;
00377 cout<<"Hereafter I show the list of chip events that are chip within the timecut (delta t < "<<timecut<<"):"<<endl;
00378 cout<<"Event, chip, time, Nb_hits"<<endl;
00379 for(int it=0;it<nb_timecut;it++) {
00380 for(int itt=0;itt<4;itt++) cout<<list_chip_events_timecut[it][itt]<<"; ";
00381 cout<<endl;
00382 }
00383 cout<<endl;
00384 }
00385 cout<<endl;
00386 }
00387 theApp->Run();
00388 delete theApp;
00389 return 0;
00390 }
00391