• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/cern-oct11/go4/RICH/TRICHProc.cxx (r4864/r3566)

Go to the documentation of this file.
00001 /* Generated by Together */
00002 
00003 #include "TRICHProc.h"
00004 #include "TCBMBeamtimeEvent.h"
00005 
00006 #include "TGo4Version.h"
00007 #if __GO4BUILDVERSION__ > 40502
00008 #include "go4iostream.h"
00009 #else
00010 #include "Riostream.h"
00011 #endif
00012 #include "TSystem.h"
00013 #include "TGo4UserException.h"
00014 #include "TGo4MbsEvent.h"
00015 #include "roc/Message.h"
00016 #include "roc/Board.h"
00017 
00018 #include "TGo4Analysis.h"
00019 
00020 #include "CbmRichRingFitterCOP.h"
00021 #include "CbmRichRingFitterEllipseTau.h"
00022 #include "CbmRichRingFinderHoughImpl.h"
00023 
00024 #include "TEllipse.h"
00025 #include "TLatex.h"
00026 #include <sstream>
00027 #include <fstream>
00028 
00029 TRICHProc::TRICHProc() :
00030    TCBMBeamtimeProc(),
00031    fRocInputEvent(0),
00032    fOutputEvent(0),
00033    fHodo1(0),
00034    fTriglogEvent(0),
00035    fBeamEvent(0),
00036    fEventNr(0),
00037    fNrSED(0)
00038 {
00039 }
00040 
00041 
00042 TRICHProc::TRICHProc(const char* name) :
00043    TCBMBeamtimeProc(name),
00044         fRocInputEvent(0),
00045         fOutputEvent(0),
00046     fHodo1(0),
00047     fTriglogEvent(0),
00048         fBeamEvent(0),
00049         fEventNr(0),
00050         fNrSED(0)
00051 {
00052    cout << "**** TRICHProc: Create instance " << name << endl;
00053    
00054    
00055    fPar = (TRICHParam*) MakeParameter("RICHPar", "TRICHParam");
00056    
00057    
00058    if (!ReadMapmtGeometry("mapmt-geometry.txt")) {
00059       printf("First step of reading MAPMT geometry failed \n");
00060       if (!ReadMapmtGeometry("RICH/mapmt-geometry.txt")) {
00061          printf("second step of reading MAPMT geometry failed \n");
00062       }
00063    }
00064    
00065    hEntries2dIntegral = MakeTH2('D', "MAPMT/Entries2dIntegral", "Integral of ADC values per MAPMT channels", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00066    hEntries2dMean = MakeTH2('D', "MAPMT/Entries2dMean", "Mean ADC values per MAPMT channels", 32, 10., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00067    
00068    hEntriesperPMT = MakeTH2('I', "MAPMT/EntriesperPMT", "Number of hits per MAPMT", 4, 0., 32., 4, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00069    
00070    hADCall = MakeTH1('I', "MAPMT/ADCall", "Distribution of corrected ADC values", 100, 0., 4096.);
00071    hHittime = MakeTH1('I', "MAPMT/Hittime", "Distribution of difference between AUX2 and MAPMT hit", 1024, -1500, 4096.);
00072 
00073    for (Int_t iPMT=1; iPMT<=16; iPMT++) {
00074       hHitMultperPMT[iPMT]=MakeTH1('I', Form("MAPMT/HitMultperPMT%i",iPMT), Form("Hit Multiplicity on PMT %i",iPMT),50,-0.5,49.5, "x (mm)", "y (mm)");
00075    }
00076    
00077 
00078 
00079    // window scan of the hodoscope   
00080    fNofHodWindowsX = 4;
00081    fNofHodWindowsY = 4;
00082    hHodXYscan=MakeTH2('F', "MAPMT/HodXYscan", "HodXYscan", 16*fNofHodWindowsX, 0., 16.*fNofHodWindowsX, 16.*fNofHodWindowsY, 0., 16.*fNofHodWindowsY, "x-pos (pixel)", "y-pos (pixel)");
00083       
00084    hNofHitsInHodo = MakeTH1('F', "MAPMT/hNofHitsInHodo", "Number of hits in hodoscope", 4, 0, 4, "Number of hits in hodoscope");
00085    hHodoADCvsNofHitInEv = MakeTH2('F', "MAPMT/hHodoADCvsNofHitInEv", "ADC value in hodoscope vs. number of hits in event", 6000, 0., 6000., 60, 0., 60., "ADC in hodoscope", "Number of hits in event");
00086    hNotAssignedHitsXY = MakeTH2('F', "MAPMT/hNotAssignedHitsXY", "Not assigned hits", 32, 0., 208., 32, 0., 208., "x-pos (mm)", "y-pos (mm)");
00087 
00088    // book additional 2d histograms for position plots with condition on fiber hod
00089    hMAPMT_hcor2d_s1 = MakeTH2('I', "MAPMT/mapmt_detector_h1", "Number of hits per MAPMT channels, hcut1", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00090    hMAPMT_hcor2d_s2 = MakeTH2('I', "MAPMT/mapmt_detector_h2", "Number of hits per MAPMT channels, hcut2", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00091    hMAPMT_hcor2d_s3 = MakeTH2('I', "MAPMT/mapmt_detector_h3", "Number of hits per MAPMT channels, hcut3", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00092    hMAPMT_hcor2d_s4 = MakeTH2('I', "MAPMT/mapmt_detector_h4", "Number of hits per MAPMT channels, hcut4", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00093    hMAPMT_hcor2d_s5 = MakeTH2('I', "MAPMT/mapmt_detector_h5", "Number of hits per MAPMT channels, hcut5", 32, 0., 32., 32, 0., 32., "x-pos (pixel)", "y-pos (pixel)");
00094    
00095    hNofFoundRings= MakeTH1('F', "MAPMT/hNofFoundRings", "Number of found rings", 3, 0.0, 3., "Number of found rings");
00096 
00097    hTimespread=MakeTH1('I',"MAPMT/Timespread","Timespread of hits",50,-25,25,"time (ns)","hits");
00098    
00099    //[0] is electron, [1] is pion, [2] is muon, [3] is all
00100    string p[] = {"e", "pi", "mu", "all"};
00101    for (Int_t i = 0; i < 4; i++){
00102       //book circle fitting histograms
00103       hCircleFitRadius[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/CircleFitRadius_")+p[i]).c_str(), "Radius of fitted rings", 501, -0.5, 100.5, "ring radius [mm]");
00104       hCircleFitCenter[i] = MakeTH2('F', (string("MAPMT/fitting/")+p[i]+string("/CircleFitCenter_")+p[i]).c_str(), "Center of fitted rings", 208, 0., 208., 208, 0., 208., "x-pos [mm]", "y-pos [mm]");
00105       hCircleFitChi2[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/CircleFitChi2_")+p[i]).c_str(), "Chi2 of fitted rings", 200, 0., 40., "chi2");
00106       hCircleFitDR[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/CircleFitDR_")+p[i]).c_str(), "dR of fitted rings", 200, -20., 20., "dR [mm]");
00107       
00108       //book ellipse fitting histograms
00109       hEllipseFitAaxis[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitAaxis_")+p[i]).c_str(), "A axis of fitted ellipse", 501, -0.5, 100.5, "A axis [mm]");
00110       hEllipseFitBaxis[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitBaxis_")+p[i]).c_str(), "B axis of fitted ellipse", 501, -0.5, 100.5, "B axis [mm]");
00111       hEllipseFitPhi[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitPhi_")+p[i]).c_str(), "Phi of fitted ellipses", 400, -2., 2., "Phi [rad]");
00112       hEllipseFitBoverA[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitBoverA_")+p[i]).c_str(), "B/A of fitted ellipses", 100, 0., 1., "B/A");
00113       hEllipseFitCenter[i] = MakeTH2('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitCenter_")+p[i]).c_str(), "Center of fitted ellipses", 208, 0., 208., 208, 0., 208., "x-pos [mm]", "y-pos [mm]");
00114       hEllipseFitChi2[i] = MakeTH1('F', (string("MAPMT/fitting/")+p[i]+string("/EllipseFitChi2_")+p[i]).c_str(), "Chi2 of fitted ellipses", 200, 0., 40., "chi2");
00115 
00116       //number of hits per event for all events, for events with good circle fit, for event with good ellipse fit
00117       hNofHitsEvAll[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvAll_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00118       hNofHitsEvRingFinder[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvRingFinder_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00119       hNofHitsEvCircleFit[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvCircleFit_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00120       hNofHitsEvEllipseFit[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvEllipseFit_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00121       hNofHitsEvRingFinderEff[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvRingFinderEff_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00122       hNofHitsEvCircleFitEff[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvCircleFitEff_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00123       hNofHitsEvEllipseFitEff[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsEvEllipseFitEff_")+p[i]).c_str(), "Nof hits in event", 60, 0, 60, "Nof hits in event");
00124 
00125       hNofHitsRingFinder[i] = MakeTH1('F', (string("MAPMT/efficiency/")+p[i]+string("/NofHitsRingFinder_")+p[i]).c_str(), "Nof hits in ring", 60, 0, 60, "Nof hits in ring");
00126 
00127       hEntries2d[i]=MakeTH2('I', (string("MAPMT/Entries2d_")+p[i]).c_str(), "Hits per Pixel", 32, 0., 32., 32, 0., 32., "x-pos [pixel]", "y-pos [pixel]");
00128    }
00129 
00130    SetParticleIdentificationConditions();
00131    
00132    hMAPMT_HitMultvsO2 = MakeTH2('I', "MAPMT/mapmt_hitmultvsO2","HitMultiplicity vs O2",100,0,400,50,-0.5,49.5,"O2 level","hitmult");
00133    
00134    // book conditions
00135    fMAPMT_cond = MakeWinCond("hADCall", 20., 2500., "hADCall"); //0., 1500.
00136    fMAPMT_cond->SetHistogram("hADCall");
00137    fMAPMT_tcond = MakeWinCond("hHittime", -200., -100., "hHittime"); //0., 900.
00138    fMAPMT_tcond->SetHistogram("hHittime");
00139 
00140    Int_t nofPics = 30;
00141    int maxNofRings = 2;
00142    fCirclePicture.resize(nofPics);
00143    fCircle.resize(nofPics);
00144    fCircleText.resize(nofPics);
00145    fEllipse.resize(nofPics);
00146    fEllipseText.resize(nofPics);
00147    hSED.resize(nofPics);
00148    fRingHits.resize(nofPics);
00149    fEventHits.resize(nofPics);
00150    for (Int_t i = 0; i < nofPics; i++){
00151 
00152       hSED[i] = MakeTH2('I', Form("MAPMT/SED/SED%i",i),Form("Single Event %i",i), 32, 0., 208., 32, 0., 208., "x-pos (mm)", "y-pos (mm)");
00153 
00154       fCirclePicture[i] = new TGo4Picture(Form("Event%i",i), "Circle picture");
00155 
00156       fCircle[i].resize(maxNofRings);
00157       fEllipse[i].resize(maxNofRings);
00158       for (int iR = 0; iR < maxNofRings; iR++){
00159                   fCircle[i][iR] = new TEllipse(16., 16., 10.);
00160                   fCircle[i][iR]->SetFillStyle(0);
00161                   fCircle[i][iR]->SetLineWidth(2);
00162 
00163                   fEllipse[i][iR] = new TEllipse(16., 16., 10.);
00164                   fEllipse[i][iR]->SetFillStyle(0);
00165                   fEllipse[i][iR]->SetLineWidth(2);
00166                   fEllipse[i][iR]->SetLineColor(kBlue);
00167 
00168               fCirclePicture[i]->AddSpecialObject(fCircle[i][iR]);
00169               fCirclePicture[i]->AddSpecialObject(fEllipse[i][iR]);
00170       }
00171 
00172       fCircleText[i] = new TLatex(5, 30, "(x,y,r)");
00173       fEllipseText[i] = new TLatex(5, 30, "(x,y,r)");
00174 
00175       fCirclePicture[i]->AddObject(hSED[i]);
00176       fCirclePicture[i]->AddSpecialObject(fCircleText[i]);
00177       //fCirclePicture[i]->AddSpecialObject(fCircle[i]);
00178       fCirclePicture[i]->AddSpecialObject(fEllipseText[i]);
00179       //fCirclePicture[i]->AddSpecialObject(fEllipse[i]);
00180 
00181       fRingHits[i].resize(fMaxNofHitsInEventDraw);
00182       fEventHits[i].resize(fMaxNofHitsInEventDraw);
00183       for (int iH = 0; iH < fMaxNofHitsInEventDraw; iH++){
00184           fEventHits[i][iH] = new TEllipse(16., 16., 10.);
00185           fEventHits[i][iH]->SetFillColor(kRed);
00186           fCirclePicture[i]->AddSpecialObject(fEventHits[i][iH]);
00187       }
00188       for (int iH = 0; iH < fMaxNofHitsInEventDraw; iH++){
00189           fRingHits[i][iH] = new TEllipse(16., 16., 10.);;
00190           fRingHits[i][iH]->SetFillColor(kYellow+2);
00191           fCirclePicture[i]->AddSpecialObject(fRingHits[i][iH]);
00192       }
00193 
00194       AddPicture(fCirclePicture[i], "CirclePicture");
00195    }
00196 
00197    printf("RICH Histograms created \n");
00198    fflush ( stdout);
00199    
00200    fRingFitter = new CbmRichRingFitterCOP();
00201    fEllipseFitter = new CbmRichRingFitterEllipseTau();
00202    fRingFinder = new CbmRichRingFinderHoughImpl();
00203    
00204    fEventTime=-1;
00205    fO2level=-1;
00206    fH2Olevel=-1;
00207 }
00208 
00209 TRICHProc::~TRICHProc()
00210 {
00211 }
00212 
00213 void TRICHProc::SetParticleIdentificationConditions()
00214 {
00215         //21_10_x
00216         //Double_t electronpntsc1c2[4][2] = { {500, 500}, {450, 1300}, {1200, 1620}, {1300, 500} };
00217         //30_10_00x
00218         Double_t electronpntsc1c2[4][2] = { {2150, 720}, {1900, 1800}, {1220, 1730}, {1200, 670} };
00219         //27_10_017
00220         //Double_t electronpntsc1c2[4][2] = { {2420, 550}, {2000, 2310}, {1020, 2150}, {940, 540} };
00221         //23_10_x
00222         //Double_t electronpntsc1c2[4][2] = { {1375, 500}, {1360, 1540}, {530, 1700}, {520, 500} };
00223         //29_10_x
00224         //Double_t electronpntsc1c2[4][2] = { {2180, 645}, {2145, 1920}, {1120, 1910}, {1140, 645} };
00225 
00226         fElectronCondc1c2 = MakePolyCond("RichElectronCondc1c2", 4, electronpntsc1c2);
00227         fElectronCondc1c2->SetHistogram("Ch1_Ch2");
00228 
00229         Double_t muonpntsc1c2[4][2] = { {500, 500}, {450, 1300}, {1200, 1620}, {1300, 500}  };
00230         fMuonCondc1c2 = MakePolyCond("RichMuonCondc1c2", 4, muonpntsc1c2);
00231         fMuonCondc1c2->SetHistogram("Ch1_Ch2");
00232 
00233         Double_t pionpntsc1c2[4][2] = { {500, 500}, {450, 1300}, {1200, 1620}, {1300, 500} };
00234         fPionCondc1c2 = MakePolyCond("RichPionCondc1c2", 4, pionpntsc1c2);
00235         fPionCondc1c2->SetHistogram("Ch1_Ch2");
00236 }
00237 
00238 
00239 bool TRICHProc::ReadMapmtGeometry(const char* fname)
00240 {
00241   for (int ncell=0; ncell<NUM_MAPMP_CELLS; ncell++) {
00242     fMAPMTCells[ncell].xbin = 0.;
00243     fMAPMTCells[ncell].ybin = 0.;
00244     fMAPMTCells[ncell].xcoord = 0.;
00245     fMAPMTCells[ncell].ycoord = 0.;
00246     fMAPMTCells[ncell].globalchannel = 0;
00247     fMAPMTCells[ncell].mapmt = 0;
00248     fMAPMTCells[ncell].pixel = 0;
00249     fMAPMTCells[ncell].roc = 0;
00250     fMAPMTCells[ncell].feb = 0;
00251     fMAPMTCells[ncell].febchannel = 0;
00252   }
00253   
00254   std::ifstream f(fname);
00255   if (!f)  {
00256     printf("MAPMT geometry file not found %s\n", fname);
00257     return false;
00258   }
00259   
00260   char sbuf[1024];
00261   
00262   // skip first two lines
00263   f.getline(sbuf, sizeof(sbuf));
00264   f.getline(sbuf, sizeof(sbuf));
00265   
00266   int nread = 0;
00267   
00268   while (!f.eof()) {
00269     f.getline(sbuf, sizeof(sbuf));
00270     if (strlen(sbuf)==0) break;
00271     
00272     int globalchannel(0), mapmt(0), pixel(0), roc(0), feb(0), febchannel(0);
00273     float xcoord(0.), ycoord(0.), xbin(0.), ybin(0.);
00274     
00275     if (sscanf(sbuf, "%d %d %d %d %d %d %f %f %f %f", &globalchannel, &roc, &feb, &febchannel, &mapmt, &pixel, &xcoord, &ycoord, &xbin, &ybin)!=10) {
00276       printf("MAPMT read line %d format error %s\n", nread, sbuf);
00277       return false;
00278     }
00279     
00280     int ncell = febchannel;//febchannel + (feb==2 ? 128 : 0);
00281     
00282     ncell = roc*256 + febchannel;
00283     if(feb==2) {
00284       ncell = ncell + 128;
00285     }
00286     
00287     
00288     if ((ncell<0) || (ncell>=NUM_MAPMP_CELLS)) {
00289       printf("MAPMT read wrong cell address %d in line %d\n", ncell, nread);
00290       return false;
00291     }
00292     
00293     // printf("ncell = %d xbin = %3.1f ybin = %3.1f\n", ncell, xbin, ybin);
00294     
00295     fMAPMTCells[ncell].xbin = xbin;
00296     fMAPMTCells[ncell].ybin = ybin;
00297     fMAPMTCells[ncell].xcoord = xcoord;
00298     fMAPMTCells[ncell].ycoord = ycoord;
00299     fMAPMTCells[ncell].globalchannel = globalchannel;
00300     fMAPMTCells[ncell].mapmt = mapmt;
00301     fMAPMTCells[ncell].pixel = pixel;
00302     fMAPMTCells[ncell].roc = roc;
00303     fMAPMTCells[ncell].feb = feb;
00304     fMAPMTCells[ncell].febchannel = febchannel;
00305     
00306     nread++;
00307   }
00308   
00309   if (nread!=1024) {
00310     printf("MAPMT geometry read %d lines, expected %d\n", nread, 1024);
00311     return false;
00312   }
00313   
00314   printf("Load MAPMT geometry from file %s done\n", fname);
00315   
00316   return true;
00317 }
00318 
00319 void TRICHProc::FinalizeEvent()
00320 {
00321   if(!fRocInputEvent->IsValid()) return; // skip incomplete roc events from first step
00322 
00323   // SL: do we need extra processing of pulser events here - probably not
00324   if (fMbsEvent && fMbsEvent->IsPulser()) return;
00325   
00326   ProcessRICH();
00327   fEventNr++;  
00328 }
00329 
00330 void TRICHProc::InitEvent(TGo4EventElement* outevnt)
00331 {
00332   // first assign input event:
00333   // since input event object is never discarded within processor lifetime,
00334   // we just search for subevent by name once to speed up processing  
00335    if(fRocInputEvent==0) {
00336       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00337       if(btevent)
00338       {
00339          fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00340          fTriglogEvent=dynamic_cast<TTriglogEvent*>(btevent->GetSubEvent("TRIGLOG"));
00341          fMbsEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00342          fEpicsEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00343       } 
00344       else
00345       {
00346          fRocInputEvent=dynamic_cast<TRocEvent*>(GetInputEvent());
00347 
00348       }
00349       if(fRocInputEvent==0) {
00350          GO4_STOP_ANALYSIS_MESSAGE("**** TRICHProc: Fatal error: input event is not a TRocEvent!!! STOP GO4");
00351       }
00352    }
00353 
00354    // then assign output event
00355    // since output event object is never discarded within processor lifetime,
00356    // we just search for subevent by name once to speed up processing
00357    if(fOutputEvent==0)
00358    {
00359       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00360       if(btevent)
00361       {
00362          fOutputEvent=dynamic_cast<TRICHEvent*>(btevent->GetSubEvent("RICH"));
00363          fHodo1 = dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo1"));
00364          fBeamEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00365       }
00366       else
00367       {
00368 
00369          fOutputEvent= dynamic_cast<TRICHEvent*>(outevnt);
00370       }
00371       if(fOutputEvent==0) {
00372          GO4_STOP_ANALYSIS_MESSAGE("**** TRICHProc: Fatal error: output event is not a TRICHEvent!!! STOP GO4");
00373       }
00374 
00375    }
00376 }
00377 
00378 void TRICHProc::ProcessRICH()
00379 {
00380    // Get Event time (in secs) from MBS event
00381    if (fTriglogEvent) {
00382       fEventTime = fTriglogEvent->fMbsTimeSecs;
00383    }
00384    
00385    // Get O2 and H2O concentration from Epics event, interpolate missing data
00386    if (fEpicsEvent && fEpicsEvent->IsValid()) {
00387       fO2level=fEpicsEvent->GetDouble("CBM:RICH:Gas:O2");
00388       fH2Olevel=fEpicsEvent->GetDouble("CBM:RICH:Gas:H2O");
00389 
00390    }
00391    if (fEventTime>1318648546 && fEventTime<1318720000) {
00392       fO2level=350;
00393       if (fEventTime>1318655338) fO2level=18844646*pow(0.9999834,(fEventTime-1318000000));
00394    }
00395 
00396   // SaveParameters();
00397       
00398    // Get Cherenkov 1/2 signal
00399    Double_t cherenkov1=fMbsEvent->fData1182[1][0]; //RICH1+2: Electron
00400    Double_t cherenkov2=fMbsEvent->fData1182[0][1]; //RICH2only: Muon
00401                                                    //none: Pion
00402    Double_t leadglass=fMbsEvent->fData1182[1][5];
00403    
00404    //perform particle identification
00405    //Bool_t isElectron = fBeamEvent->fIsElectron;
00406    //Bool_t isMuon = fBeamEvent->fIsMuon;
00407    //Bool_t isPion = fBeamEvent->fIsPion;
00408    bool isElectron = fElectronCondc1c2->Test(cherenkov1,cherenkov2);
00409    bool isMuon = fMuonCondc1c2->Test(cherenkov1,cherenkov2);
00410    bool isPion = fPionCondc1c2->Test(cherenkov1,cherenkov2);
00411 
00412    //access information from fiber hodoscope
00413    Double_t hodx=0;
00414    Double_t hody=0;
00415    if (fHodo1 && (fHodo1->NumHits()>0)) {
00416       hodx = fHodo1->Hit(0).X;
00417       hody = fHodo1->Hit(0).Y;
00418    }
00419    //cout << "hodo x,y " << hodx << " " << hody << endl;
00420    
00421    // needed for hodXYscan
00422    Double_t dx = 64. / fNofHodWindowsX;
00423    Double_t dy = 64. / fNofHodWindowsY;
00424    Int_t xNum = (Int_t)( (hodx + 32.) / dx);
00425    Int_t yNum = (Int_t)( (hody + 32.) / dy);
00426    
00427     //printf("\nEventtime in secs: %i \n",fEventTime);
00428     //printf("O2 content: %f \n",fO2level);
00429     //printf("H2O content: %f \n",fH2Olevel);
00430     //printf("Cherenkov 1/2: %f %f \n",cherenkov1,cherenkov2);
00431     //printf("Hodoscope position: %f / %f \n",hodx,hody);
00432 
00433    Int_t NrHitsperPMT[17];
00434    for (Int_t iPMT=0; iPMT<=16; iPMT++) NrHitsperPMT[iPMT]=0;
00435   
00436    vector<Double_t> timearray;
00437    //collect all hits from one event in vector
00438    vector<CbmRichHitLight> hits;
00439   
00440    for (UInt_t RICHROC=fPar->RICHFirstROC; RICHROC<=fPar->RICHLastROC; RICHROC++) {
00441      // cout << "  Processing ROC "<< RICHROC << endl;
00442       // Loop over all ROCs which deliver RICH data
00443       
00444       if (RICHROC>MAX_ROC) continue;
00445       
00446       TRocData* RocData=dynamic_cast<TRocData*>(fRocInputEvent->getEventElement(RICHROC));
00447       if (RocData==0) continue;  //no data from this ROC available;
00448       
00449       for (UInt_t MessageNr=0; MessageNr<RocData->fExtMessages.size(); MessageNr++) {
00450          //cout << "  Processing message " << MessageNr << "from ROC " << RICHROC << endl;
00451          //cout << "Msg.size() = " << RocData->fExtMessages.size() << endl;
00452          // Loop over all messages from particular RICH-ROC
00453          
00454          TRocMessageExtended msg=RocData->fExtMessages.at(MessageNr);
00455          if (msg.GetMessageType() != roc::MSG_HIT) continue;  // only interrested in HIT messages
00456          //cout << "roc::MSG_HIT" << endl;
00457 
00458          // extraxt message information
00459          UInt_t dataROC=msg.GetRocNumber();
00460          UInt_t dataFEBNr=msg.GetNxNumber();  // 0 or 2
00461          UInt_t dataFEBCh=msg.GetNxChNum();   // 0..127
00462          Double_t dataHitTime=msg.GetTriggerDeltaT();
00463          Int_t dataHitADCraw=msg.GetNxADC();
00464          Int_t dataHitADCcor=msg.GetCorrectedNxADC();
00465                   
00466          // calculate ncell from ROC and FEB number
00467          int ncell(0);
00468          // ncell = dataROC*(RICHROC-fPar->RICHFirstROC) + dataFEBCh;
00469          ncell=(dataROC- fPar->RICHFirstROC) * 256+dataFEBCh;
00470          if(dataFEBNr==2) {
00471                  ncell = ncell + 128;  
00472          }
00473 
00474          Float_t dist=msg.GetTriggerDeltaT(); // corrected trigger diff is already in input message!
00475          hHittime->Fill(dist);
00476          
00477          // calculate corrected (inverse) ADC value, mapmtPedestal can be changed in TRICHParams.cxx or parameter editor in the Go4 GUI
00478          int rADC = fPar->mapmtPedestal - msg.GetNxADC();
00479          
00480          // fill histogram with all MAPMT ADC values to have reference for condition
00481          hADCall->Fill(dataHitADCcor);
00482          
00483          // get mapping from geometry file
00484          double xbin = fMAPMTCells[ncell].xbin;
00485          double ybin = fMAPMTCells[ncell].ybin;
00486          double xcoord = fMAPMTCells[ncell].xcoord;
00487          double ycoord = fMAPMTCells[ncell].ycoord;
00488          Int_t mapmt = fMAPMTCells[ncell].mapmt;
00489          
00490          // store mapped info to ROOT tree
00491          fOutputEvent->fMAPM_X[ncell]=xbin;
00492          fOutputEvent->fMAPM_Y[ncell]=ybin;
00493          fOutputEvent->fMAPM_Xcoord[ncell]=xcoord;
00494          fOutputEvent->fMAPM_Ycoord[ncell]=ycoord;
00495          fOutputEvent->fMAPM_Integral[ncell]=dataHitADCcor;
00496          fOutputEvent->fMAPM_Integral_raw[ncell]=rADC;
00497          fOutputEvent->fMAPM_DeltaT[ncell]=dist;
00498          
00499          // printf("GET HIT ncell = %d xbin = %3.1f ybin = %3.1f\n", ncell, xbin, ybin);
00500          
00501          // if condition is ok, fill XY histogram.
00502          // Condition range can be modified in the condition editor in the Go4 GUI
00503          if (fMAPMT_cond->Test(dataHitADCcor) && fMAPMT_tcond->Test(dist)) {
00504                  timearray.push_back(dist);
00505 
00506                  // create hit and add it to the vector of hits
00507                  CbmRichHitLight hit(xcoord, ycoord);
00508                  hits.push_back(hit);
00509 
00510                  if (xbin < 16 && ybin < 16) hHodXYscan->Fill(xbin + 16. * xNum, ybin + 16. * yNum);
00511                  
00512                  if (isElectron) hEntries2d[0]->Fill(xbin, ybin);
00513                  if (isMuon) hEntries2d[2]->Fill(xbin, ybin);
00514                  if (isPion) hEntries2d[1]->Fill(xbin, ybin);
00515                  hEntries2d[3]->Fill(xbin, ybin);
00516 
00517                  Double_t c1=-0.050;
00518                  Double_t c2=-0.040;
00519                  Double_t c3=-0.030;
00520                  Double_t c4=-0.020;
00521                  Double_t c5=-0.010;
00522                  hMAPMT_hcor2d_s1->Fill(xbin+c1*hodx,ybin+0*hody);
00523                  hMAPMT_hcor2d_s2->Fill(xbin+c2*hodx,ybin+0*hody);
00524                  hMAPMT_hcor2d_s3->Fill(xbin+c3*hodx,ybin+0*hody);
00525                  hMAPMT_hcor2d_s4->Fill(xbin+c4*hodx,ybin+0*hody);
00526                  hMAPMT_hcor2d_s5->Fill(xbin+c5*hodx,ybin+0*hody);
00527 
00528                  hEntriesperPMT->Fill(xbin, ybin);
00529                  hEntries2dIntegral->Fill(xbin, ybin, dataHitADCcor);
00530                  
00531                  if (mapmt >=1 && mapmt <= 16) NrHitsperPMT[mapmt]++;
00532          }
00533          
00534          int nbin = hEntries2d[3]->GetBin(hEntries2d[3]->GetXaxis()->FindBin(xbin), hEntries2d[3]->GetYaxis()->FindBin(ybin));
00535          double entries = hEntries2d[3]->GetBinContent(nbin);
00536          double integral = hEntries2dIntegral->GetBinContent(nbin);
00537          hEntries2dMean->SetBinContent(nbin, (entries <= 0.) ? 0. : integral/entries);
00538       } //MessageNr
00539    } //RICHROC
00540 
00541    for (Int_t iPMT=1; iPMT<=16; iPMT++) {
00542       hHitMultperPMT[iPMT]->Fill(NrHitsperPMT[iPMT]);
00543    }
00544    
00545    // time deviation of individual hits from average, not very fast implementation...
00546    Double_t mean=0;
00547    for (Int_t ihit=0; ihit<timearray.size(); ihit++){
00548       // printf("time %i: %f \n",ihit,timearray[ihit]);
00549       mean=mean+timearray[ihit];
00550    }
00551    mean=mean/timearray.size();
00552    // printf("mean: %f \n",mean);
00553    for (Int_t ihit=0; ihit<timearray.size(); ihit++) {
00554       hTimespread->Fill(timearray[ihit]-mean);
00555    }
00556    // hit Multiplicity vs O2 level
00557    if (hits.size() > 5 && hits.size() < 40) hMAPMT_HitMultvsO2->Fill(fO2level, hits.size());
00558 
00559    if (fHodo1 != NULL && fHodo1->NumHits() >=1){
00560            hNofHitsInHodo->Fill(fHodo1->NumHits());
00561            hHodoADCvsNofHitInEv->Fill(fHodo1->Hit(0).ADC, hits.size());
00562    }
00563 
00564    DoAnalysis(hits, isElectron, isPion, isMuon);
00565 }
00566 
00567 void TRICHProc::SaveParameters()
00568 {
00569         ofstream outfile;
00570         outfile.open ("rich_parameters.txt", ios_base::app);
00571 
00572         double o2 = -1.0;
00573         double h2o = -1.0;
00574         double ptb = -1.0;
00575         double tt1 = -1.0;
00576         double pt4 = -1.0;
00577         double refrIndex = -1.0;
00578 
00579         if (fEpicsEvent && fEpicsEvent->IsValid()) {
00580         o2 = fEpicsEvent->GetDouble("CBM:RICH:Gas:O2");
00581                 h2o = fEpicsEvent->GetDouble("CBM:RICH:Gas:H2O");
00582         ptb = fEpicsEvent->GetDouble("CBM:RICH:Gas:PTB");
00583                 tt1 = fEpicsEvent->GetDouble("CBM:RICH:Gas:TT-1");
00584         pt4 = fEpicsEvent->GetDouble("CBM:RICH:Gas:PT-4");
00585         refrIndex = fEpicsEvent->GetDouble("CBM:RICH:Gas:RefrIndex");
00586         };
00587 
00588         if (o2 == -1. && h2o == -1. && ptb == -1. && tt1 == -1. && pt4 == -1. && refrIndex == -1.) return;
00589 
00590         TGo4AnalysisStep* firststep = TGo4Analysis::Instance()->GetAnalysisStepNum(0);
00591         if (dynamic_cast<TGo4MbsFileParameter*>(firststep->GetEventSource())) {
00592                 outfile << firststep->GetEventSourceName() << " " <<
00593                                 fEventTime << " " <<
00594                                 o2 << " " <<
00595                                 h2o << " " <<
00596                                 ptb << " " <<
00597                                 tt1 << " " <<
00598                                 pt4 << " " <<
00599                                 refrIndex << endl;
00600         }
00601         outfile.close();
00602         time_t rawtime = fEventTime;
00603         //time ( &rawtime );
00604         printf ( "The current local time is: %s", ctime (&rawtime) );
00605 }
00606 
00607 void TRICHProc::DoAnalysis(
00608                 const vector<CbmRichHitLight>& hits,
00609                 bool isElectron,
00610                 bool isPion,
00611                 bool isMuon)
00612 {
00613         //cout << "hits.size() = " << hits.size() << endl;
00614         if (hits.size() < 1) return;
00615 
00616     //[0] is electron, [1] is pion, [2] is muon, [3] is all
00617         Int_t hIndex = -1;
00618         if (isElectron) hIndex = 0;
00619         else if (isPion) hIndex = 1;
00620         else if (isMuon) hIndex = 2;
00621         if (hIndex < 0) hIndex = 2;
00622 
00623         hNofHitsEvAll[hIndex]->Fill(hits.size());
00624         hNofHitsEvAll[3]->Fill(hits.size());
00625 
00626         fRingFinder->DoFind(hits);
00627         vector<CbmRichRingLight*> rings = fRingFinder->GetFoundRings();
00628         hNofFoundRings->Fill(rings.size());
00629         if (rings.size() <= 0) return;
00630         CbmRichRingLight* ring = rings[0];
00631         //if (rings.size() == 2) cout << "2 rings were found" << endl;
00632 
00633         Int_t nofHits = ring->GetNofHits();
00634         for (Int_t iH = 0; iH < hits.size(); iH++){
00635                 Bool_t hitFound = false;
00636                 for (Int_t i = 0; i < nofHits; i++) {
00637                    if (ring != NULL && ring->GetHit(i).fX == hits[iH].fX && ring->GetHit(i).fY == hits[iH].fY){
00638                            hitFound = true;
00639                    }
00640                 }
00641                 if (hitFound == false) hNotAssignedHitsXY->Fill(hits[iH].fX, hits[iH].fY);
00642         }
00643 
00644         hNofHitsRingFinder[hIndex]->Fill(ring->GetNofHits());
00645         hNofHitsRingFinder[3]->Fill(ring->GetNofHits());
00646 
00647         hNofHitsEvRingFinder[hIndex]->Fill(hits.size());
00648         hNofHitsEvRingFinder[3]->Fill(hits.size());
00649         hNofHitsEvRingFinderEff[hIndex]->Divide(hNofHitsRingFinder[hIndex], hNofHitsEvAll[hIndex]);
00650         hNofHitsEvRingFinderEff[hIndex]->Divide(hNofHitsRingFinder[3], hNofHitsEvAll[3]);
00651         //cout << "Ring finder eff:" << 100.* (double)hNofHitsRingFinder[3]->GetEntries()/ hNofHitsAll[3]->GetEntries() << endl;
00652 
00653         //fit COP
00654         for (int iR = 0; iR < rings.size(); iR++){
00655                 fRingFitter->DoFit(rings[iR]);
00656         }
00657         FillCircleFitHistograms(hIndex, ring, hits.size());// fill histograms for a specific particle
00658         FillCircleFitHistograms(3, ring, hits.size());// fill histograms for all particle. [3] is all
00659         DrawEventHits(hits, fNrSED);
00660         DrawRingHits(ring, fNrSED);
00661         DrawCircles(rings, fNrSED);
00662 
00663         for (int iR = 0; iR < rings.size(); iR++){
00664                 fEllipseFitter->DoFit(rings[iR]);
00665         }
00666         if (hIndex>=0) FillEllipseFitHistograms(hIndex, ring, hits.size());// fill histograms for a specific particle
00667         FillEllipseFitHistograms(3, ring, hits.size());// fill histograms for a specific particle
00668         DrawEllipses(rings, fNrSED);
00669 
00670         // rotate single event printing to next histogram ONLY if last one had a non-empty event
00671         if ( rings.size() == 2 ){// && ring->GetBaxis()/ring->GetAaxis() < 0.7) {
00672                 fNrSED++;
00673                 if (fNrSED >= hSED.size()) fNrSED = 0;
00674         }
00675         //if (ring != NULL) delete ring;
00676 }
00677 
00678 void TRICHProc::FillCircleFitHistograms(
00679                 Int_t hIndex,
00680                 CbmRichRingLight* ring,
00681                 int nofEventHits)
00682 {
00683    if (hIndex != -1){
00684       if (ring->GetRadius() > 0. && ring->GetCenterX() > 0. && ring->GetCenterY() > 0.) {
00685          hCircleFitRadius[hIndex]->Fill(ring->GetRadius());
00686          hCircleFitCenter[hIndex]->Fill(ring->GetCenterX(), ring->GetCenterY());
00687          hCircleFitChi2[hIndex]->Fill(ring->GetChi2() / ring->GetNofHits());
00688          for (int iH = 0; iH < ring->GetNofHits(); iH++){
00689                  double xc = ring->GetCenterX();
00690                  double yc = ring->GetCenterY();
00691                  CbmRichHitLight h = ring->GetHit(iH);
00692                  double dr = sqrt((xc - h.fX)*(xc - h.fX) + (yc - h.fY)*(yc - h.fY)) - ring->GetRadius();
00693                  hCircleFitDR[hIndex]->Fill(dr);
00694          }
00695       }
00696       // good fitted ring
00697       if (ring->GetRadius() > 20 && ring->GetRadius() < 70) hNofHitsEvCircleFit[hIndex]->Fill(nofEventHits);
00698       hNofHitsEvCircleFitEff[hIndex]->Divide(hNofHitsEvCircleFit[hIndex], hNofHitsEvAll[hIndex]);
00699    }
00700 }
00701 
00702 void TRICHProc::FillEllipseFitHistograms(
00703                 Int_t hIndex,
00704                 CbmRichRingLight* ring,
00705                 int nofEventHits)
00706 {
00707    if (ring->GetAaxis() > 0. && ring->GetBaxis() > 0. && ring->GetPhi() != -1. && ring->GetCenterX() != -1. && ring->GetCenterY()!=-1.) {
00708       hEllipseFitAaxis[hIndex]->Fill(ring->GetAaxis());
00709       hEllipseFitBaxis[hIndex]->Fill(ring->GetBaxis()); 
00710       hEllipseFitBoverA[hIndex]->Fill(ring->GetBaxis()/ring->GetAaxis());  
00711       hEllipseFitPhi[hIndex]->Fill(ring->GetPhi());    
00712       hEllipseFitCenter[hIndex]->Fill(ring->GetCenterX(),ring->GetCenterY());
00713       hEllipseFitChi2[hIndex]->Fill(ring->GetChi2() / ring->GetNofHits());
00714    }
00715    //good fitted ring with ellipse fitter
00716    if (ring->GetAaxis() > 20 && ring->GetAaxis() < 80 && ring->GetBaxis() > 20
00717                    && ring->GetBaxis() < 80) hNofHitsEvEllipseFit[hIndex]->Fill(nofEventHits);
00718    hNofHitsEvEllipseFitEff[hIndex]->Divide(hNofHitsEvEllipseFit[hIndex], hNofHitsEvAll[hIndex]);
00719 }
00720 
00721 void TRICHProc::DrawRingHits(
00722                 CbmRichRingLight* ring,
00723                 Int_t sedNum)
00724 {
00725         if (ring->GetNofHits() > fMaxNofHitsInEventDraw) return;
00726 
00727    Int_t nofHits = ring->GetNofHits();
00728    for (Int_t i = 0; i < nofHits; i++) {
00729           fRingHits[sedNum][i]->SetX1(ring->GetHit(i).fX);
00730           fRingHits[sedNum][i]->SetY1(ring->GetHit(i).fY);
00731           fRingHits[sedNum][i]->SetR1(3);
00732           fRingHits[sedNum][i]->SetR2(3);
00733    }
00734    for (Int_t i = nofHits; i < fMaxNofHitsInEventDraw; i++){
00735            fRingHits[sedNum][i]->SetX1(-999999);
00736    }
00737 }
00738 
00739 void TRICHProc::DrawEventHits(
00740                 const vector<CbmRichHitLight>& hits,
00741                 Int_t sedNum)
00742 {
00743    if (hits.size() > fMaxNofHitsInEventDraw) return;
00744    Int_t nofHits = hits.size();
00745    for (Int_t i = 0; i < nofHits; i++) {
00746            fEventHits[sedNum][i]->SetX1(hits[i].fX);
00747            fEventHits[sedNum][i]->SetY1(hits[i].fY);
00748            fEventHits[sedNum][i]->SetR1(4);
00749            fEventHits[sedNum][i]->SetR2(4);
00750    }
00751    for (Int_t i = nofHits; i < fMaxNofHitsInEventDraw; i++){
00752            fEventHits[sedNum][i]->SetX1(-999999);
00753    }
00754 }
00755 
00756 void TRICHProc::DrawCircles(
00757                 const vector<CbmRichRingLight*>& rings,
00758                 Int_t sedNum)
00759 {
00760         if (rings.size() <= 0) return;
00761         for (int iR = 0; iR < rings.size(); iR++){
00762            fCircle[sedNum][iR]->SetX1(rings[iR]->GetCenterX());
00763            fCircle[sedNum][iR]->SetY1(rings[iR]->GetCenterY());
00764            fCircle[sedNum][iR]->SetR1(rings[iR]->GetRadius());
00765            fCircle[sedNum][iR]->SetR2(rings[iR]->GetRadius());
00766    }
00767    stringstream ss;
00768    ss.precision(3);
00769    ss << "(x,y,r,n):(" << rings[0]->GetCenterX() << ", " << rings[0]->GetCenterY() << ","
00770                    << rings[0]->GetRadius()<< ", " << rings[0]->GetNofHits() << ")";
00771    fCircleText[sedNum]->SetText(5, 200, ss.str().c_str());
00772 }
00773 
00774 
00775 void TRICHProc::DrawEllipses(
00776                 const vector<CbmRichRingLight*>& rings,
00777                 Int_t sedNum)
00778 {
00779         for (int iR = 0; iR < rings.size(); iR++){
00780            fEllipse[sedNum][iR]->SetX1(rings[iR]->GetCenterX());
00781            fEllipse[sedNum][iR]->SetY1(rings[iR]->GetCenterY());
00782            fEllipse[sedNum][iR]->SetR1(rings[iR]->GetAaxis());
00783            fEllipse[sedNum][iR]->SetR2(rings[iR]->GetBaxis());
00784            fEllipse[sedNum][iR]->SetTheta(rings[iR]->GetPhi() * 180. / 3.1415);
00785         }
00786    stringstream ss;
00787    ss.precision(3);
00788    ss << "(x,y,a,b,p,n):(" << rings[0]->GetCenterX() << ", " << rings[0]->GetCenterY() << ","
00789       << rings[0]->GetAaxis()<< ", "<< rings[0]->GetBaxis()<< ", " << rings[0]->GetPhi()<< ", "
00790       << rings[0]->GetNofHits() << ")";
00791    fEllipseText[sedNum]->SetText(5, 185, ss.str().c_str());
00792 }

Generated on Tue Dec 10 2013 04:52:17 for ROCsoft by  doxygen 1.7.1