/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/TB2011/Lapp_test/Telescope/Pedestals.C

Go to the documentation of this file.
00001 {gROOT->Reset();
00002   
00003   gSystem->Load("/LC/Detecteurs/MicroMegas/users/chefdevi/micromegasFrameWork/trunk/lib/libMicro.so");
00004   
00005 
00006 
00007 //  bool cut = 1;
00008   TString sigma_cut = "2";
00009 
00010   int pedestal = 20;
00011 
00012 
00013 
00014   TString file = "p1107g42.root";
00015   TString dir = "/lapp_data/LC/Detecteurs/MicroMegas/data/TB2011/Preparatifs/Telescope/";
00016   TString filename = dir + file;
00017 
00018 
00019   bool display = 0;
00020 
00021 
00022   TH1I * hc_adc = new TH1I("hc_adc","",672,0,672);
00023 
00024   TH1I * hchamber_0[96];
00025   TH1I * hchamber_1[96];
00026   TH1I * hchamber_2[96];
00027   TH1I * hchamber_3[96*4];
00028 
00029   TString name,title;
00030 
00031   for (int i=0;i<96;i++){
00032 
00033     name = Form("hchamber_0_channel_%i",i);
00034     title = Form("ADC of chamber_0_channel_%i",i);
00035     hchamber_0[i] = new TH1I(name,title,1024,0,1024);
00036 
00037     name = Form("hchamber_1_channel_%i",i);
00038     title = Form("ADC of chamber_1_channel_%i",i);
00039     hchamber_1[i] = new TH1I(name,title,1024,0,1024);
00040 
00041     name = Form("hchamber_2_channel_%i",i);
00042     title = Form("ADC of chamber_2_channel_%i",i);
00043     hchamber_2[i] = new TH1I(name,title,1024,0,1024);}
00044 
00045   for (int i=0;i<96*4;i++){
00046 
00047     name = Form("hchamber_3_channel_%i",i);
00048     title = Form("ADC of chamber_3_channel_%i",i);
00049     hchamber_3[i] = new TH1I(name,title,1024,0,1024);}
00050 
00051 
00052   cout << "open rootfile"<<endl;
00053 
00054   TFile *f = new TFile(filename);
00055 
00056   TIter nextkey(f.GetListOfKeys());
00057   TKey *key;
00058 
00059   while (key = (TKey*)nextkey()) {
00060     
00061     TTree *tree = (TTree*)key->ReadObj();                
00062     MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00063     //run->Info();
00064 
00065   int nEvent = tree.GetEntries();
00066   cout <<"nEvent="<<nEvent<<endl;
00067 
00068 
00069   MTEvent *evt = new MTEvent();
00070 
00071   TBranch *branch= tree->GetBranch("MTEvent");
00072   branch->SetAddress(&evt);
00073 
00074   int nchannel = 0;
00075   float zpos = 0;
00076   float adc = 0;
00077   int hardid = 0;
00078 
00079 
00080   cout<<endl;
00081   cout<<"Reading"<<endl;
00082   
00083   tree.GetEntry(i);
00084   nchannel = evt->GetNchannel();
00085 
00086   cout<<"event number = "<<i<<"  Number of hits = "<<nchannel<<endl;
00087 
00088   for (int j=0;j<nchannel;j++){
00089     MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00090     zpos = channel->GetZ();
00091     adc = channel->GetAnalogValue();
00092     hc_adc->SetBinContent(j+1,adc);
00093     cout<<j<<" "<<zpos<<" "<<adc<<endl;}
00094   break;}}}
00095 
00096 
00097 
00098     for (int j=0;j<96;j++){
00099       MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00100       zpos = channel->GetZ();
00101       hardid = channel->GetHardId();
00102       adc = channel->GetAnalogValue();
00103       hchamber_0[hardid]->Fill(adc);}
00104 
00105     for (int j=96;j<96*2;j++){
00106       MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00107       zpos = channel->GetZ();
00108       hardid = channel->GetHardId();
00109       adc = channel->GetAnalogValue();
00110       hchamber_1[hardid]->Fill(adc);}
00111 
00112     for (int j=96*2;j<96*3;j++){
00113       MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00114       zpos = channel->GetZ();
00115       hardid = channel->GetHardId();
00116       adc = channel->GetAnalogValue();
00117       hchamber_2[hardid]->Fill(adc);}
00118 
00119     for (int j=96*3;j<96*7;j++){
00120       MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00121       zpos = channel->GetZ();
00122       hardid = channel->GetHardId();
00123       adc = channel->GetAnalogValue();
00124       hchamber_3[hardid]->Fill(adc);}}}
00125 
00126 
00127 
00128 
00129 }
00130 
00131 
00132 
00133   /*Fit*/
00134 
00135 
00136   cout<<endl;
00137   cout<<"Fitting"<<endl;
00138 
00139 
00140   TF1 * ff = new TF1("ff","gaus",0,1024);
00141   
00142   float param_chamber_0[96][3];
00143   float param_chamber_1[96][3];
00144   float param_chamber_2[96][3];
00145   float param_chamber_3[96*4][3];
00146 
00147 
00148   for (int i=0;i<96;i++){
00149 
00150     ff->SetParameters(hchamber_0[i]->GetMaximumBin(),hchamber_0[i]->GetMean(),hchamber_0[i]->GetRMS());
00151     hchamber_0[i]->Fit(ff,"q");
00152     param_chamber_0[i][0] = floor(0.5+ff->GetParameter(0));
00153     param_chamber_0[i][1] = floor(0.5+ff->GetParameter(1));
00154     param_chamber_0[i][2] = floor(0.5+ff->GetParameter(2));
00155 
00156     ff->SetParameters(hchamber_1[i]->GetMaximumBin(),hchamber_1[i]->GetMean(),hchamber_1[i]->GetRMS());
00157     hchamber_1[i]->Fit(ff,"q");
00158     param_chamber_1[i][0] = floor(0.5+ff->GetParameter(0));
00159     param_chamber_1[i][1] = floor(0.5+ff->GetParameter(1));
00160     param_chamber_1[i][2] = floor(0.5+ff->GetParameter(2));
00161 
00162     ff->SetParameters(hchamber_2[i]->GetMaximumBin(),hchamber_2[i]->GetMean(),hchamber_2[i]->GetRMS());
00163     hchamber_2[i]->Fit(ff,"q");
00164     param_chamber_2[i][0] = floor(0.5+ff->GetParameter(0));
00165     param_chamber_2[i][1] = floor(0.5+ff->GetParameter(1));
00166     param_chamber_2[i][2] = floor(0.5+ff->GetParameter(2));
00167 
00168     ff->SetParameters(hchamber_2[i]->GetMaximumBin(),hchamber_2[i]->GetMean(),hchamber_2[i]->GetRMS());
00169     hchamber_2[i]->Fit(ff,"q");
00170     param_chamber_2[i][0] = floor(0.5+ff->GetParameter(0));
00171     param_chamber_2[i][1] = floor(0.5+ff->GetParameter(1));
00172     param_chamber_2[i][2] = floor(0.5+ff->GetParameter(2));}
00173 
00174   for (int i=0;i<96*4;i++){
00175 
00176     ff->SetParameters(hchamber_3[i]->GetMaximumBin(),hchamber_3[i]->GetMean(),hchamber_3[i]->GetRMS());
00177     hchamber_3[i]->Fit(ff,"q");
00178     param_chamber_3[i][0] = floor(0.5+ff->GetParameter(0));
00179     param_chamber_3[i][1] = floor(0.5+ff->GetParameter(1));
00180     param_chamber_3[i][2] = floor(0.5+ff->GetParameter(2));}
00181 
00182 
00183 
00184 
00185   /*Writing*/
00186   cout<<endl;
00187   cout<<"Writing"<<endl;
00188   cout<<endl;
00189 
00190 //if (cut)
00191 //{ 
00192  ofstream out0(output_path+"PedestalADC1_cut.ini");
00193   ofstream out1(output_path+"PedestalADC2_cut.ini");
00194   ofstream out2(output_path+"PedestalADC3_cut.ini");
00195   ofstream out3(output_path+"PedestalADC4_cut.ini");
00196 
00197   out0<<"BLOCK0"<<endl;
00198   for (int i=0;i<96;i++){out0<<i<<","<<param_chamber_0[i][1]-pedestal<<","<<param_chamber_0[i][1]+param_chamber_0[i][2]*sigma_cut.Atoi()<<endl;}
00199   out0<<"-1"<<endl;
00200   out0<<"BLOCK1"<<endl;
00201   for (int i=0;i<96;i++){out0<<i<<","<<param_chamber_1[i][1]-pedestal<<","<<param_chamber_1[i][1]+param_chamber_1[i][2]*sigma_cut.Atoi()<<endl;}
00202   out0<<"-1"<<endl;
00203 
00204   out1<<"BLOCK0"<<endl;
00205   for (int i=0;i<96;i++){out1<<i<<","<<param_chamber_2[i][1]-pedestal<<","<<param_chamber_2[i][1]+param_chamber_2[i][2]*sigma_cut.Atoi()<<endl;}
00206   out1<<"-1"<<endl;
00207   out1<<"BLOCK1"<<endl;
00208   for (int i=0;i<96;i++){out1<<i<<","<<param_chamber_3[i][1]-pedestal<<","<<param_chamber_3[i][1]+param_chamber_3[i][2]*sigma_cut.Atoi()<<endl;}
00209   out1<<"-1"<<endl;
00210 
00211   out2<<"BLOCK0"<<endl;
00212   for (int i=0;i<96;i++){out2<<i<<","<<param_chamber_3[i+96][1]-pedestal<<","<<param_chamber_3[i][1]+param_chamber_3[i][2]*sigma_cut.Atoi()<<endl;}
00213   out2<<"-1"<<endl;
00214   out2<<"BLOCK1"<<endl;
00215   for (int i=0;i<96;i++){out2<<i<<","<<param_chamber_3[i+96*2][1]-pedestal<<","<<param_chamber_3[i][1]+param_chamber_3[i][2]*sigma_cut.Atoi()<<endl;}
00216   out2<<"-1"<<endl;
00217 
00218   out3<<"BLOCK0"<<endl;
00219   for (int i=0;i<96;i++){out3<<i<<","<<param_chamber_3[i+96*3][1]-pedestal<<","<<param_chamber_3[i][1]+param_chamber_3[i][2]*sigma_cut.Atoi()<<endl;}
00220   out3<<"-1"<<endl;
00221 //}
00222 //else
00223 //{
00224   ofstream out0(output_path+"PedestalADC1.ini");
00225   ofstream out1(output_path+"PedestalADC2.ini");
00226   ofstream out2(output_path+"PedestalADC3.ini");
00227   ofstream out3(output_path+"PedestalADC4.ini");
00228 
00229   out0<<"BLOCK0"<<endl;
00230   for (int i=0;i<96;i++){out0<<i<<","<<param_chamber_0[i][1]-pedestal<<","<<0<<endl;}
00231   out0<<"-1"<<endl;
00232   out0<<"BLOCK1"<<endl;
00233   for (int i=0;i<96;i++){out0<<i<<","<<param_chamber_1[i][1]-pedestal<<","<<0<<endl;}
00234   out0<<"-1"<<endl;
00235 
00236   out1<<"BLOCK0"<<endl;
00237   for (int i=0;i<96;i++){out1<<i<<","<<param_chamber_2[i][1]-pedestal<<","<<0<<endl;}
00238   out1<<"-1"<<endl;
00239   out1<<"BLOCK1"<<endl;
00240   for (int i=0;i<96;i++){out1<<i<<","<<param_chamber_3[i][1]-pedestal<<","<<0<<endl;}
00241   out1<<"-1"<<endl;
00242 
00243   out2<<"BLOCK0"<<endl;
00244   for (int i=0;i<96;i++){out2<<i<<","<<param_chamber_3[i+96][1]-pedestal<<","<<0<<endl;}
00245   out2<<"-1"<<endl;
00246   out2<<"BLOCK1"<<endl;
00247   for (int i=0;i<96;i++){out2<<i<<","<<param_chamber_3[i+96*2][1]-pedestal<<","<<0<<endl;}
00248   out2<<"-1"<<endl;
00249 
00250   out3<<"BLOCK0"<<endl;
00251   for (int i=0;i<96;i++){out3<<i<<","<<param_chamber_3[i+96*3][1]-pedestal<<","<<0<<endl;}
00252   out3<<"-1"<<endl;
00253 
00254 //}
00255   cout<<"Done."<<endl;
00256  
00257 }
00258 

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7