#include "hrichN0cal.h"
#include "hmatrixcatiter.h"
#include "hades.h"
#include "hcategory.h"
#include "hevent.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hrichdetector.h"
#include "richdef.h"
#include "hrichlocalmaxheader.h"
#include "hrichlocal.h"
ClassImp(HRichN0Cal);
HRichN0Cal::HRichN0Cal(const Text_t *name,const Text_t *title,const Text_t *outName,const Char_t *typ):
HReconstructor(name, title) {
    outFile = new TFile(outName,"RECREATE");
    for(Int_t i =0;i<6;i++){
	
	    countEvt[i]=0;
    }
    Char_t hname3[40];
    Char_t hname4[40];
    Char_t hname1[40];
    histo = new TH1F**[6];
    for (Int_t i =0; i< 6 ; i++){
        histo[i] = new TH1F*[2];
	secFlag[i] = 0;
    }
    for (Int_t i =0; i< 6 ; i++){
	
	sprintf(hname3,"N0SiO2Sec%d",i);
	strcat(hname3,typ);
	sprintf(hname4,"N0MgF2Sec%d",i);
	
	strcat(hname4,typ);
	histo[i][0]=new TH1F(hname3,hname3,50,120,250);
	histo[i][1]=new TH1F(hname4,hname4,50,120,250);
    }
    thetaH = new TH1F*[6];
    
    for (Int_t i =0; i< 6 ; i++){
	sprintf(hname1,"ThetaSec%d",i);
	thetaH[i]  =new TH1F(hname1,hname1,100,0.5,100.5);
    }
    slopeBG[0] = 1.5;
    offSetBG[0] = -10.8;
    slopeBG[1]= 1.4;
    offSetBG[1]= -5.5;
    slopeBG[2]= 1.26;
    offSetBG[2]= -6.38;
    slopeBG[5] = 1.8;
    offSetBG[5]= -16.;
     cutSecD[0] = 45;
    cutSecD[1] = 44;
    cutSecD[2] = 48;
    cutSecD[5]  =60;
    
    
    
    cutSecD[3] = 0;
    cutSecD[4] = 0;
    
    
    
    
    
    
   
    
    
    
    
          cutSecU[0] = 300;
       cutSecU[1] = 300;
       cutSecU[2] = 300;
       cutSecU[3] = 300; 
       cutSecU[4] = 300; 
       cutSecU[5] = 300;
   
       
       
       ring1ThMin = 32;
       ring1ThMax = 52;
       ring2ThMin = 52;
       
       ring2ThMax = 90;
    secOk = 0;
}
HRichN0Cal::~HRichN0Cal(){
    delete outFile;
    delete thetaH;
    for(Int_t i =0; i< 6 ; i++){
	delete histo[i][0];
	delete histo[i][1];
    }
    for(Int_t i =0; i< 6 ; i++) delete histo[i];
    delete histo; 
}
Bool_t HRichN0Cal::init(){
 printf("initialization of rich photon\n");
    HRichDetector *pRichDet = (HRichDetector*) gHades -> getSetup()
	-> getDetector("Rich");
    fLocalCatHr=gHades->getCurrentEvent()->getCategory(catRichLocalMaxHeader);
    if (!fLocalCatHr) {
      fLocalCatHr=pRichDet->buildCategory(catRichLocalMaxHeader);
      if (!fLocalCatHr) return kFALSE;
      else gHades->getCurrentEvent()
                        ->addCategory(catRichLocalMaxHeader,fLocalCatHr, "Rich");
    }
    fIter2 = (HIterator*) getLocalHrCat() -> MakeIterator();
   
    fLocalCat = gHades -> getCurrentEvent() -> getCategory(catRichLocal);
    if (!fLocalCat) {
	fLocalCat = pRichDet -> buildCategory(catRichLocal);
	if (!fLocalCat) return kFALSE;
	else gHades -> getCurrentEvent() -> addCategory(catRichLocal, 
							fLocalCat, "Rich");
    }
    fIter1 = (HIterator*) getLocalCat() -> MakeIterator();
    return 0;
}
Int_t HRichN0Cal::execute(){
    HRichLocalMaxHeader *localHr = NULL;
    Float_t multSec[6];
    for (Int_t i =0; i< 6 ; i++){
	secFlag[i] = 0;
	multSec[i]=0;
    }
    fIter2 -> Reset();
    while ((localHr=(HRichLocalMaxHeader*)fIter2 -> Next())) {
	localHr->getSecMult(multSec);
	
    }
    
    secOk = 0;
    for(Int_t i = 0;i<6;i++){
	secOk +=filterSector(i,multSec[i]);
	
    }
    if(secOk==6&&(fLocalCat->getEntries())!=0){
	for(Int_t i = 0;i<6;i++){
	    countEvt[i]++;
	}
    }
    else return kSkipEvent;
    
    HRichLocal *local = NULL;
    fIter1 -> Reset();
    while ((local=(HRichLocal*)fIter1 -> Next())) {
	
	if (secOk==6){
	    Int_t sec =local->getSector();
	    Float_t theta =local->getLocalTheta();	
	    Float_t energy =  local->getLocalEnergy();
	    Int_t t = (Int_t)theta;
			
		thetaH[sec]->Fill(t);
		
		
		if(energy){ 
		    Float_t lambda = 1239/energy;  
		    
		    if(theta>ring1ThMin&&theta<ring1ThMax) {
			
			histo[local->getSector()][1]->Fill(lambda);
			
			
		    }
		    else if(theta>ring2ThMin&&theta<ring2ThMax) {
			
			histo[local->getSector()][0]->Fill(lambda);
			
			
		    }
		}
	
	}
	
    }
    return 0;
}
Int_t HRichN0Cal::filterSector(Int_t sec,Float_t multSec){
    
    if(multSec>cutSecD[sec]&&multSec< cutSecU[sec]) {
	secFlag[sec]=1;
	
	return 1;
    }
    else {
	secFlag[sec] =0;
	return 0;
    }
}
Bool_t HRichN0Cal::finalize(){
 outFile->cd(); 
 for(Int_t i = 0;i<6;i++){
     thetaH[i]->Write();
     cout<<" sec  "<<i<<" evt Nr  "<<countEvt[i]<<endl;
     if(countEvt[i]>0) {
	 histo[i][0]->Scale(1./countEvt[i]);
	 histo[i][1]->Scale(1./countEvt[i]);
	 histo[i][0]->Write();
	 histo[i][1]->Write();
     }	
 }
 outFile->Close();  
 return 0;
}
Last change: Sat May 22 13:09:26 2010
Last generated: 2010-05-22 13:09
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.