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 using namespace std;
00025
00026
00027 void add(map<unsigned int,map<unsigned long ,unsigned int> >&channels_map, unsigned int asu, unsigned long hit_time){
00028
00029 if ( channels_map.find(asu) == channels_map.end()) {
00030
00031 map<unsigned long, unsigned int> nbHitMap;
00032 nbHitMap[hit_time]=1;
00033 channels_map.insert(make_pair(asu,nbHitMap));
00034 }
00035 else{
00036
00037 map<unsigned long, unsigned int> &nbHitMap = channels_map.find(asu)->second;
00038 if (nbHitMap.find(hit_time) == nbHitMap.end()){
00039
00040 nbHitMap.insert(make_pair(hit_time,1));
00041 }
00042 else{
00043
00044 nbHitMap[hit_time] = nbHitMap[hit_time]++;
00045 }
00046 }
00047 }
00048
00049
00050
00051 int main(void){
00052
00053
00054
00055
00056
00057 Int_t blabla = 1;
00058
00059
00060 Int_t plot = 1;
00061
00062
00063 Int_t threshold = 50;
00064
00065
00066 Int_t timecut = 50;
00067
00068
00069 UInt_t chb = 1;
00070
00071
00072 string file = "05082011_1055_MGT.root";
00073
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 border);y (cm);x (cm)",96,0,96,96,0,96);
00084
00085
00086
00087 TFile *f = new TFile(file.c_str());
00088 if(blabla==1||blabla==2||blabla==3){
00089 cout<<endl;
00090 cout<<"reading File : "<<file<<endl;
00091 }
00092
00093
00094 TIter nextkey(f->GetListOfKeys());
00095 TKey *key;
00096 UInt_t counter = 0;
00097
00098 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00099
00100
00101
00102 while (key = (TKey*)nextkey()) {
00103
00104 counter++;
00105 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00106
00107 TTree *tree = (TTree*)key->ReadObj();
00108 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00109
00110 Int_t nEvent = tree->GetEntries();
00111 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl<<endl;
00112
00113 MTEvent *evt = new MTEvent();
00114
00115 TBranch *branch= tree->GetBranch("MTEvent");
00116 branch->SetAddress(&evt);
00117
00118
00119 bool IsBorder;
00120 Int_t Asu;
00121 ULong_t BorderTime;
00122 UInt_t nb_tot = 0;
00123 UInt_t nb_timecut = 0;
00124 ULong_t begin_t = 0;
00125 ULong_t end_t = 0;
00126
00127
00128
00129 for (int i=0;i<nEvent-1;i++){
00130
00131 tree->GetEntry(i);
00132
00133
00134 UInt_t A;
00135 UInt_t T;
00136 if(evt->IsSquare(300,A,T,chb)) {
00137 if(blabla==2||blabla==3) cout<<"evt "<<i+1<<" square"<<endl;
00138 continue;
00139 }
00140
00141 UInt_t nchannel = evt->GetNchannel();
00142 if(blabla==2||blabla==3) cout<<"Event "<<i+1<<" / "<<nEvent<<"; nb of channels= "<<nchannel<<endl;
00143
00144
00145 map<unsigned int,map<unsigned long,unsigned int> > channels_map;
00146
00147
00148 ULong_t tmin=2;
00149 ULong_t tmax=2;
00150
00151
00152 IsBorder=0;
00153 Asu = -1;
00154 BorderTime = -1;
00155
00156
00157 for (unsigned int j=0;j<nchannel;j++){
00158
00159
00160 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00161
00162
00163 ULong_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00164
00165
00166 if(j==0) {
00167 tmin=hit_time;
00168 tmax=hit_time;
00169 }
00170 if(hit_time<tmin) tmin=hit_time;
00171 if(hit_time>tmax) tmax=hit_time;
00172
00173
00174 if(i==0 && j==0) {
00175 begin_t=hit_time;
00176 end_t=hit_time;
00177 }
00178 if(hit_time<begin_t) begin_t=hit_time;
00179 if(hit_time>end_t) end_t=hit_time;
00180
00181
00182 if(blabla==3) cout <<"X= "<<channel->GetX()<<"; Y= "<<channel->GetY()<<endl;
00183 if (channel->GetX() != 0000 && channel->GetX() != 310000 && channel->GetX() != 320000 && channel->GetX() != 640000 && channel->GetX() != 650000 && channel->GetX() != 960000 && channel->GetY() != 000000 && channel->GetY() != 470000 && channel->GetY() != 480000 && channel->GetY() != 960000) continue;
00184
00185
00186 UInt_t board_id = channel->GetBoardId();
00187 if(blabla==3) cout<<"Channel : "<<j<<"; hit on asu "<<board_id<<"; at time "<<hit_time<<endl;
00188
00189
00190 add(channels_map, board_id, hit_time);
00191 }
00192
00193 unsigned int timeold=0;
00194
00195
00196 map<unsigned int, map<unsigned long,unsigned int> >::iterator iter1;
00197 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00198
00199 unsigned int azu=iter1->first;
00200 map<unsigned long,unsigned int> hits_per_time=iter1->second;
00201
00202 map<unsigned long,unsigned int>::iterator iter2;
00203 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00204
00205 unsigned long time = iter2->first;
00206 unsigned int nb_hits = iter2->second;
00207
00208
00209 if (nb_hits>=threshold) {
00210
00211
00212 IsBorder = 1;
00213 Asu = azu;
00214 BorderTime = time;
00215
00216 if(blabla==1||blabla==2||blabla==3) cout <<" -> event: "<<i+1<<" = border in asu no "<<azu<<" at abstime "<<time<<" with n_hits = "<<nb_hits<<endl;
00217 }
00218 }
00219 }
00220
00221 if (IsBorder && plot){
00222
00223 TH1I *hdt = new TH1I("hdt","Hit time distribution (No time cut);N_hits;Time",tmax-tmin+3,-1,tmax-tmin+1);
00224 TH1I *hdt2 = new TH1I("hdt2","Hit time distribution (within time cut);N_hits;Time",timecut+3,tmax-timecut-1,tmax+1);
00225 TH1I *hdt3 = new TH1I("hdt3","Hit time distribution (around the time where it is border);N_hits;Time",23,BorderTime-tmin-11,BorderTime-tmin+11);
00226
00227
00228 for (unsigned int j=0;j<nchannel;j++){
00229
00230
00231 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00232
00233
00234 UInt_t board_id = channel->GetBoardId();
00235 ULong_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00236
00237
00238 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00239 if(hit_time>tmax-timecut) hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00240 if(hit_time==BorderTime) hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00241 hdt->Fill(hit_time-tmin);
00242 if(hit_time>tmax-timecut) hdt2->Fill(hit_time-tmin);
00243 if(hit_time>BorderTime-100 && hit_time<BorderTime+500) hdt3->Fill(hit_time-tmin);
00244 }
00245
00246
00247 c0->Divide(3,2);
00248 c0->cd(1);
00249 hxy->GetXaxis()->SetTitle("X (cm)");
00250 hxy->GetYaxis()->SetTitle("Y (cm)");
00251 hxy->Draw("zcol");
00252
00253 c0->cd(2);
00254 hxy2->GetXaxis()->SetTitle("X (cm)");
00255 hxy2->GetYaxis()->SetTitle("Y (cm)");
00256 hxy2->Draw("zcol");
00257
00258 c0->cd(3);
00259 hxy3->GetXaxis()->SetTitle("X (cm)");
00260 hxy3->GetYaxis()->SetTitle("Y (cm)");
00261 hxy3->Draw("zcol");
00262
00263 c0->cd(4);
00264
00265
00266
00267 hdt->GetXaxis()->SetTitle("time after trigger (BcId)");
00268 hdt->GetYaxis()->SetTitle("Nb hits");
00269 hdt->Draw();
00270
00271 c0->cd(5);
00272
00273
00274
00275 hdt2->GetXaxis()->SetTitle("time after trigger (BcId)");
00276 hdt2->GetYaxis()->SetTitle("Nb hits");
00277 hdt2->Draw();
00278
00279 c0->cd(6);
00280
00281
00282
00283 hdt3->GetXaxis()->SetTitle("time after trigger (BcId)");
00284 hdt3->GetYaxis()->SetTitle("Nb hits");
00285 hdt3->Draw();
00286
00287
00288
00289 char plotname[100] = "plot_evt";
00290 char buf[10];
00291 sprintf(buf,"%d",i+1);
00292 strcat(plotname, buf);
00293 strcat(plotname,".gif");
00294
00295
00296
00297 c0->SaveAs(plotname);
00298
00299
00300 c0->Clear();
00301
00302
00303 hxy->Reset();
00304 hxy2->Reset();
00305 hxy3->Reset();
00306 hdt->Delete();
00307 hdt2->Delete();
00308 hdt3->Delete();
00309 }
00310 }
00311 if(blabla==2||blabla==3) cout<<endl;
00312 }
00313 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00314 theApp->Run();
00315 delete theApp;
00316 return 0;
00317 }
00318