int FriendFull() { Float_t Q2,Q5,Q8, T0, T2, T4, T6, T10, dummy, Q2shift, Q5shift; Float_t Q2_pic_511, Q2_pic_127, Q5_pic_511, Q5_pic_127, A2, B2, A5, B5; Int_t i, j, event_counter, ID=0, status, nbentries; Int_t estim_511_Q2=0, estim_127_Q2=0, estim_511_Q5=0, estim_127_Q5=0; Int_t file_index, fileindex_start, fileindex_stop; FILE * fpjoin; char buffer[MAXBUFSIZE], basename[255], filename_in[255], filename_out[255]; cout << "Basename: "; cin >> basename; cout << "Du fichier # : "; cin >> fileindex_start; cout << "Au fichier # : "; cin >> fileindex_stop; printf("Q2, estimation pic 511: "); scanf("%d", &estim_511_Q2); printf("Q2, estimation pic 1.27: "); scanf("%d", &estim_127_Q2); printf("Q5, estimation pic 511: "); scanf("%d", &estim_511_Q5); printf("Q5, estimation pic 1.27: "); scanf("%d", &estim_127_Q5); TH1F *hT0_T6 = new TH1F("hT0_T6", "histogramme T0-T6", 4096, 0, 4096); TH1F *hT6_T0 = new TH1F("hT6_T0", "histogramme T6-T0", 4096, 0, 4096); for (int i=fileindex_start; i<=fileindex_stop; i++) { cout << basename << " " << i << endl; sprintf(filename_out,"%s_%03d.root",basename, i); TFile *fout = new TFile(filename_out,"RECREATE"); TTree *tRawData = new TTree("tRawData","Donnees brutes, temps recalibres"); tRawData->Branch("ID",&ID,"ID/I"); tRawData->Branch("event_counter",&event_counter,"event_counter/I"); tRawData->Branch("Q2",&Q2,"Q2/F"); tRawData->Branch("Q5",&Q5,"Q5/F"); tRawData->Branch("T0",&T0,"T0/F"); tRawData->Branch("T2",&T2,"T2/F"); tRawData->Branch("T6",&T6,"T6/F"); tRawData->Branch("T10",&T10,"T10/F"); TTree *tCorrectedData = new TTree("tCorrectedData","Energies recentrees sur les pics 511 et 1.27"); tCorrectedData->Branch("Q2shift",&Q2shift,"Q2shift/F"); tCorrectedData->Branch("Q5shift",&Q5shift,"Q5shift/F"); // Initialisation du random-generator sur l'horloge machine gRandom->SetSeed(0); sprintf(filename_in,"%s_%03d.join",basename, i); if ( (fpjoin = fopen(filename_in,"r")) == NULL) { printf("Erreur d'ouverture de fichier sur %s \n",filename_in); break; } fgets(buffer, MAXBUFSIZE, fpjoin); // je skippe la première ligne while(1) { status = fscanf(fpjoin, "%d %f %f %f %f %f %f %f %f\n", &event_counter, &Q2, &T0, &T10, &Q5, &T6, &T2, &Q8, &T4); T0 = (T0 + gRandom->Rndm() - 0.5) * cor0; T2 = (T2 + gRandom->Rndm() - 0.5) * cor2; T6 = (T6 + gRandom->Rndm() - 0.5) * cor6; T10 = (T10 + gRandom->Rndm() - 0.5) * cor10; Q2 = Q2 + gRandom->Rndm() - 0.5; Q5 = Q5 + gRandom->Rndm() - 0.5; ID++; if (status == EOF) break; tRawData->Fill(); } fclose(fpjoin); TH1F *htmp = new TH1F("htmp", "histogramme temporaire", 4096, 0, 4096); htmp->SetLineColor(4); tRawData->Draw("Q2>>htmp","","goff"); htmp->Fit("gaus","Q","",estim_511_Q2-100, estim_511_Q2+100); TF1 *fit1 = htmp->GetFunction("gaus"); Q2_pic_511 = fit1->GetParameter(1); htmp->Fit("gaus","Q","",estim_127_Q2-150, estim_127_Q2+150); TF1 *fit2 = htmp->GetFunction("gaus"); Q2_pic_127 = fit2->GetParameter(1); tRawData->Draw("Q5>>htmp","","goff"); htmp->Fit("gaus","Q","",estim_511_Q5-100, estim_511_Q5+100); TF1 *fit1 = htmp->GetFunction("gaus"); Q5_pic_511 = fit1->GetParameter(1); htmp->Fit("gaus","Q","",estim_127_Q5-150, estim_127_Q5+150); TF1 *fit2 = htmp->GetFunction("gaus"); Q5_pic_127 = fit2->GetParameter(1); A2 = (1270-511.0)/(Q2_pic_127 - Q2_pic_511); B2 = 1270 - Q2_pic_127 * A2; A5 = (1270-511.0)/(Q5_pic_127 - Q5_pic_511); B5 = 1270 - Q5_pic_127 * A5; nbentries = (Int_t)tRawData->GetEntries(); for (j=0; j< nbentries; j++) { tRawData->GetEntry(j); Q2shift = A2*Q2 + B2; Q5shift = A5*Q5 + B5; tCorrectedData->Fill(); } tRawData->AddFriend("tCorrectedData"); tRawData->Draw("T0-T6+500 >>+ hT0_T6","Q2shift>400 && Q2shift<600 && Q5shift>1200 && Q5shift<1500", "goff"); tRawData->Draw("T6-T0+500 >>+ hT6_T0","Q5shift>400 && Q5shift<600 && Q2shift>1200 && Q2shift<1500","goff"); tRawData->Write(); tCorrectedData->Write(); fout->Close(); } TH1F *htmp = new TH1F("htmp", "histogramme temporaire", 4096, 0, 4096); htmp->SetLineColor(4); return(0); }