//void MakeBigRIPSTree(char *outfile="bigrips.root"){
void MakeBigRIPSTree(char *infile, char *outfile="bigrips.root"){

  //signal(SIGINT,stop_interrupt); // CTRL + C , interrupt

  gSystem->Load("libXMLParser.so");
  gSystem->Load("libanaroot.so");

  TArtStoreManager * sman = TArtStoreManager::Instance();
  TArtEventStore *estore = new TArtEventStore();
  estore->SetInterrupt(&stoploop);
  estore->Open(infile);
  //estore->Open(1);

  TArtBigRIPSParameters *para = TArtBigRIPSParameters::Instance();
  para->LoadParameter("db/BigRIPSPPAC.xml");
  para->LoadParameter("db/BigRIPSPlastic.xml");
  para->LoadParameter("db/BigRIPSIC.xml");
  para->LoadParameter("db/FocalPlane.xml");
  TArtCalibPID *brcalib= new TArtCalibPID();
  TArtCalibTSRef *tsrefcalib= new TArtCalibTSRef();

  TFile *fout = new TFile(outfile,"RECREATE");
  TTree *tree = new TTree("tree","tree");

  // define data nodes which are supposed to be dumped to tree 
  TClonesArray * info_array = 
    (TClonesArray *)sman->FindDataContainer("EventInfo");
  tree->Branch(info_array->GetName(),&info_array);
  TClonesArray * ppac_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPPAC");
  tree->Branch(ppac_array->GetName(),&ppac_array);
  TClonesArray * pla_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPlastic");
  tree->Branch(pla_array->GetName(),&pla_array);
  TClonesArray * ic_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSIC");
  tree->Branch(ic_array->GetName(),&ic_array);
  TClonesArray * fpl_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSFocalPlane");
  tree->Branch(fpl_array->GetName(),&fpl_array);

  int neve = 0;
  while(estore->GetNextEvent()){
    if(neve%1000==0)
      cout << "event: " << neve << endl;

    tsrefcalib->LoadData();
    brcalib->ClearData();
    brcalib->ReconstructData();

    tree->Fill();
    neve ++;
  }

  fout->Write();
  fout->Close();


}
void RecoTrack_wSks(char *ridffile="./ridf/sm_com/sdaq02/run0208.ridf", Int_t nevent=100000000000){
//void RecoTrack_wSks(char *ridffile="./ridf/sm_com/sdaq02/run0208.ridf", Int_t nevent=100){

  TArtStoreManager * sman = TArtStoreManager::Instance();
  TArtEventStore *estore = new TArtEventStore;
  estore->Open(ridffile);

  TArtBigRIPSParameters * bripsparameters = TArtBigRIPSParameters::Instance();
  bripsparameters->LoadParameter((char*)"db/BigRIPSPlastic.xml");

  TArtSAMURAIParameters * samuraiparameters = TArtSAMURAIParameters::Instance();
  samuraiparameters->LoadParameter((char*)"db/SAMURAIFDC1.xml");
  samuraiparameters->LoadParameter((char*)"db/SAMURAIFDC2.xml");

  TArtCalibPlastic * calpla     = new TArtCalibPlastic;
  TArtCalibSAMURAI * calsamurai = new TArtCalibSAMURAI;

  TArtRecoFragment *reco = new TArtRecoFragment();
  TClonesArray *fdc1trks = (TClonesArray*)sman->FindDataContainer("SAMURAIFDC1Track");
  TClonesArray *fdc2trks = (TClonesArray*)sman->FindDataContainer("SAMURAIFDC2Track");
  TClonesArray *frags = (TClonesArray*)sman->FindDataContainer("SAMURAIFragment");

  calsamurai->LoadDCTDCDistribution((char*)"db/dc/run0203.root"); // for 3T Brho scan analysis

  Double_t fdc1chi2, fdc2chi2;
  Double_t delta, brho, trchi2, trpos[3], trl2hod;
  Double_t f3plat, f3plaq;
  Double_t f13plat, f13plaq;
  Int_t trstatus, trnhit;

  TFile *fout = new TFile("fout.root","RECREATE");
  TTree *otree = new TTree("otree","otree");
  otree->Branch("f3plaq",&f3plaq,"f3plaq/D");
  otree->Branch("f3plat",&f3plat,"f3plat/D");
  otree->Branch("f13plaq",&f13plaq,"f13plaq/D");
  otree->Branch("f13plat",&f13plat,"f13plat/D");
  otree->Branch("tr1chi2",&fdc1chi2,"tr1chi1/D");
  otree->Branch("tr2chi2",&fdc2chi2,"tr2chi1/D");
  otree->Branch("delta",&delta,"delta/D");

  otree->Branch("trstatus",&trstatus,"trstatus/I");
  otree->Branch("brho",&brho,"brho/D");
  otree->Branch("trchi2",&trchi2,"trchi2/D");
  otree->Branch("trnhit",&trnhit,"trnhit/I");
  otree->Branch("trpos",trpos,"trpos[3]/D");
  otree->Branch("trl2hod",&trl2hod,"trl2hod/D");

  int neve = 0;
  while(estore->GetNextEvent()&&neve < nevent){

    if(neve%1000==0) cout << "event: " << neve << endl;

    //    if(neve<33410) {neve ++; continue;} if(neve%100==0) cout << "event: " << neve << endl;

    calpla->ClearData();
    calsamurai->ClearData();
    reco->ClearData();

    calpla->ReconstructData();
    calsamurai->ReconstructData();
    reco->ReconstructData();

    f3plat = -9999; f3plaq = -9999;
    f13plat = -9999; f13plaq = -9999;
    fdc1chi2 = -9999; fdc2chi2 = -9999;
    delta = -9999; 
    brho = -9999;
    trchi2 = -9999;
    for(int i=0;i<3;i++) trpos[i] = -9999;
    trl2hod = -9999;
    trstatus = 0;
    trnhit = -1;

    TArtPlastic *pla = calpla->FindPlastic((char*)"F3pl");
    if(pla){
      if(pla->GetTLRaw() > 0 && pla->GetTRRaw() > 0)
	f3plat = ((Double_t)pla->GetTLRaw() + (Double_t)pla->GetTRRaw())/2;
      if(pla->GetQLRaw() > 0 && pla->GetQRRaw() > 0)
	f3plaq = pla->GetQAveRaw();
    }
    else{
      cout << "cannot find f3pla object!!" << endl;
    }

    pla = calpla->FindPlastic((char*)"F13pl-1");
    if(pla){
      if(pla->GetTLRaw() > 0 && pla->GetTRRaw() > 0)
	f13plat = ((Double_t)pla->GetTLRaw() + (Double_t)pla->GetTRRaw())/2;
      if(pla->GetQLRaw() > 0 && pla->GetQRRaw() > 0)
	f13plaq = pla->GetQAveRaw();
    }
    else{
      cout << "cannot find f13pla-1 object!!" << endl;
    }

    int nfdc1trks = fdc1trks->GetEntries();
    int nfdc2trks = fdc2trks->GetEntries();
    int nfrags = frags->GetEntries();

    cout << "num of fdc1trks in event: " << nfdc1trks << endl;
    for(int i=0;i<nfdc1trks&&i<1;i++){
      TArtDCTrack *trk = (TArtDCTrack*)fdc1trks->At(i);
      int nhit = trk->GetNumHitLayer();
      int ndf  = trk->GetNDF();
      fdc1chi2 = trk->GetChi2()/(double)ndf;
      /*
      cout << "fdc1tr " << i << endl;
      cout << "chi2/ndf: " << fdc1chi2 << endl;
      cout << "    nhit: " << nhit << endl;
      for(int j=0;j<nhit;j++){
	cout << "       hitx[" << j << "]= " << trk->GetHitXPosition(j);
	cout << "       hitz[" << j << "]= " << trk->GetHitZPosition(j);
	cout << "    planeid[" << j << "]= " << trk->GetHitPlaneID(j) << endl; 
      }
      */
    }

    cout << "num of fdc2trks in event: " << nfdc2trks << endl;
    for(int i=0;i<nfdc2trks&&i<1;i++){
      TArtDCTrack *trk = (TArtDCTrack*)fdc2trks->At(i);
      int nhit = trk->GetNumHitLayer();
      int ndf  = trk->GetNDF();
      fdc2chi2 = trk->GetChi2()/(double)ndf;;
      /*
      cout << "fdc2tr " << i << endl;
      cout << "  chi2: " << fdc2chi2 << endl;
      cout << "  nhit: " << nhit << endl;
      for(int j=0;j<nhit;j++){
	cout << "       hitx[" << j << "]= " << trk->GetHitXPosition(j);
	cout << "       hitz[" << j << "]= " << trk->GetHitZPosition(j);
	cout << "    planeid[" << j << "]= " << trk->GetHitPlaneID(j) << endl; 
      }
      */
    }

    cout << "num of frags in event: " << nfrags << endl;

    for(int i=0;i<nfrags&&i<1;i++){
      TArtFragment *f= (TArtFragment*)frags->At(i);
      delta = f->GetDelta();
      brho = f->GetBrho();
      trchi2 = f->GetChi2();
      trpos[0] = f->GetPrimaryPosition().X();
      trpos[1] = f->GetPrimaryPosition().Y();
      trpos[2] = f->GetPrimaryPosition().Z();
      trl2hod = f->GetPathLengthToHOD();
      trstatus = f->GetRKtraceStatus() ? 1 : 0;
      trnhit = f->GetNHit();

      cout << "Ana Delta:" << delta << endl;
      cout << "Ana  Brho:" << brho << endl;
    }

    otree->Fill();
    neve ++;


    cout << endl;
    cout << endl;
    cout << endl;

  }

  fout->Write();
  fout->Close();

}
//void MakeFullBigRIPSTree(char *outfile="bigrips.root"){
void MakeFullBigRIPSTree(char *infile, char *outfile="bigrips.root"){

  //  signal(SIGINT,stop_interrupt); // CTRL + C , interrupt

  gSystem->Load("libXMLParser.so");
  gSystem->Load("libanaroot.so");

  TArtStoreManager * sman = TArtStoreManager::Instance();
  TArtEventStore *estore = new TArtEventStore();
  estore->SetInterrupt(&stoploop);
  estore->Open(infile);
  //  estore->Open(2); // bigrips online

  TArtBigRIPSParameters *para = TArtBigRIPSParameters::Instance();
  para->LoadParameter("db/BigRIPSPPAC.xml");
  para->LoadParameter("db/BigRIPSPlastic.xml");
  para->LoadParameter("db/BigRIPSIC.xml");
  para->LoadParameter("db/FocalPlane.xml");
  TArtCalibPID *brcalib = new TArtCalibPID();
  TArtCalibCoin *calcoin= new TArtCalibCoin();
  TArtRecoPID  *brreco = new TArtRecoPID();

  // setting up rips parameters
  TArtRIPS * rips3to5 = brreco->DefineNewRIPS(3,5,"matrix/mat1.mat",7.5715); // f3 - f5
  TArtRIPS * rips5to7 = brreco->DefineNewRIPS(5,7,"matrix/mat2.mat",7.0675); // f5 - f7

  // setting up tof
  TArtTOF * tof3to7  = brreco->DefineNewTOF("F3pl","F7pl",242.513,5);

  // setting up beam id devices
  //  TArtBeam *beam35 = brreco->DefineNewBeam(rips3to5,tof3to7,"F7IC");
  //  TArtBeam *beam57 = brreco->DefineNewBeam(rips5to7,tof3to7,"F7IC");
  //  TArtBeam *beam35ic11 = brreco->DefineNewBeam(rips3to5,tof3to7,"F11IC");
  //TArtBeam *beam57ic11 = brreco->DefineNewBeam(rips5to7,tof3to7,"F11IC");
  TArtBeam *beam37ic7 = brreco->DefineNewBeam(rips3to5,rips5to7,tof3to7,"F11IC");
  //  TArtBeam *beam37ic11 = brreco->DefineNewBeam(rips3to5,rips5to7,tof3to7,"F11IC");

  TFile *fout = new TFile(outfile,"RECREATE");
  TTree *tree = new TTree("tree","tree");

  Int_t maxbit;
  tree->Branch("maxbit",&maxbit,"maxbit/I");
  // define data nodes which are supposed to be dumped to tree 
  TClonesArray * info_array = 
    (TClonesArray *)sman->FindDataContainer("EventInfo");
  tree->Branch(info_array->GetName(),&info_array);
  TClonesArray * ppac_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPPAC");
  tree->Branch(ppac_array->GetName(),&ppac_array);
  TClonesArray * pla_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPlastic");
  tree->Branch(pla_array->GetName(),&pla_array);
  TClonesArray * ic_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSIC");
  tree->Branch(ic_array->GetName(),&ic_array);
  TClonesArray * fpl_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSFocalPlane");
  tree->Branch(fpl_array->GetName(),&fpl_array);
  TClonesArray * tof_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSTOF");
  tree->Branch(tof_array->GetName(),&tof_array);
  TClonesArray * rips_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSRIPS");
  tree->Branch(rips_array->GetName(),&rips_array);
  TClonesArray * beam_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSBeam");
  tree->Branch(beam_array->GetName(),&beam_array);

  TArtBeam *beam = (TArtBeam*)beam_array->At(0);

  int neve = 0;
  while(estore->GetNextEvent()){
    maxbit = 0;
    if(neve%1000==0)
      cout << "event: " << neve << endl;

    calcoin->ClearData();
    calcoin->LoadData();
    brcalib->ClearData();
    brcalib->ReconstructData();
    brreco->ClearData();
    brreco->ReconstructData();

    //    beam->SetAoQ(beam->GetAoQ()-0.042);

    Int_t tbit = ((TArtEventInfo*)info_array->At(0))->GetTriggerBit();
    for(int i=1;;i++){
      if(tbit%2 == 1)
	maxbit = i;
      else break;

      tbit = tbit/2;
    }
    tree->Fill();

    neve ++;
  }

  fout->Write();
  fout->Close();


}
void RecoSAMURAI(char * finname="calib.root", 
		 char * foutname="reco.root",
		 Int_t nevents = 99999999,
		 Int_t starteventn = 0 ){

  Double_t samurai_center_brho = 7.2751; // Tm
  Double_t hodpos_offset = 246.44; // mm
  Double_t hodtof_offset = 146.5; // ns
  Double_t dist_pla2target = 2824.; // mm

  TFile *fin = new TFile(finname,"READ");
  gROOT->cd();
  TTree *itree = (TTree*)fin->Get("sm");
  TArtStoreManager * sman = TArtStoreManager::Instance();
  sman->LoadDataFromTree(itree);

  TArtRecoFragment * recofrag = new TArtRecoFragment;
  recofrag->SetCenterBrho(samurai_center_brho);
  recofrag->SetTOFOffSet(hodtof_offset);
  recofrag->SetPla2TargetLength(dist_pla2target);

  std::cout << "getting data containers" << std::endl;
  TClonesArray *fragments = (TClonesArray *)sman->FindDataContainer("SAMURAIFragment");

  Double_t fragdelta, fragbrho, fragtof, fragbeta, fragaoq;
  Double_t trchi2, trpos[3], trl2hod;
  Int_t trstatus, trnhit;

  TFile *fout = new TFile(foutname,"RECREATE");
  TTree *otree = itree->CloneTree(0);
  /*
  TObjArray *branchArray = itree->GetListOfBranches();
  for (Int_t i=0; i<(size_t)(branchArray->GetEntriesFast()); i++) {
    TBranch *branch = (TBranch *) ((*branchArray)[i]);
    otree->Branch(branch->GetName(),&branch);
  }
  */

  otree->Branch("fragdelta",&fragdelta,"fragdelta/D");
  otree->Branch("fragbrho",&fragbrho,"fragbrho/D");
  otree->Branch("fragtof",&fragtof,"fragtof/D");
  otree->Branch("fragbeta",&fragbeta,"fragbeta/D");
  otree->Branch("fragaoq",&fragaoq,"fragaoq/D");
  otree->Branch("trstatus",&trstatus,"trstatus/I");
  otree->Branch("trchi2",&trchi2,"trchi2/D");
  otree->Branch("trnhit",&trnhit,"trnhit/I");
  otree->Branch("trpos",trpos,"trpos[3]/D");
  otree->Branch("trl2hod",&trl2hod,"trl2hod/D");

  int nentries = itree->GetEntries();
  int neve = starteventn;
  std::cout << "entries in input tree: " << nentries << std::endl;
  std::cout << "start to scan from event" << neve << std::endl;

  while(neve<nevents+starteventn && neve < nentries){

    itree->GetEntry(neve);
    recofrag->ClearData();
    recofrag->ReconstructData();

    if(fragments){
      if(fragments->GetEntriesFast()>0){
	TArtFragment *f= (TArtFragment*)fragments->At(0);
	fragdelta = f->GetDelta();
	fragbrho = f->GetBrho();
	//	std::cout << fragbrho << std::endl;
	fragtof = f->GetTOF();
	fragbeta = f->GetBeta();
	fragaoq = f->GetAoQ();
	trchi2 = f->GetChi2();
	trpos[0] = f->GetPrimaryPosition().X();
	trpos[1] = f->GetPrimaryPosition().Y();
	trpos[2] = f->GetPrimaryPosition().Z();
	trl2hod = f->GetPathLengthToHOD();
	trstatus = f->GetRKtraceStatus() ? 1 : 0;
	trnhit = f->GetNHit();
      }
      else{
	fragdelta = -9999;
	fragbrho = -9999;
	fragtof = -9999;
	fragbeta = -9999;
	fragaoq = -9999;
	trchi2 = -9999;
	for(int i=0;i<3;i++) trpos[i] = -9999;
	trl2hod = -9999;
	trstatus = 0;
	trnhit = -1;
      }
    }
    else{
      fragdelta = -9999;
      fragbrho = -9999;
      fragtof = -9999;
      fragbeta = -9999;
      fragaoq = -9999;
      trchi2 = -9999;
      for(int i=0;i<3;i++) trpos[i] = -9999;
      trl2hod = -9999;
      trstatus = 0;
      trnhit = -1;
    }

    otree->Fill();
    neve ++;
  }


  std::cout << "finish to scan" << std::endl;

  fout->Write();
  fout->Close();

}
Exemple #5
0
// void MakeAllTree(char *infile, char *outfile="run0025.root"){
int main(int argc, char** argv){

  if(argc!=2){
    cout << "Usage: ./maketree <run_number>" << endl;
    exit(-1);
  }

  //  signal(SIGINT,stop_interrupt); // CTRL + C , interrupt

  // ========= Define input and output files
  Int_t RunNumber = std::atoi(argv[argc-1]);
  cout << endl << "---> Start analyzing Run# = " << RunNumber << endl;
  char* inputfilename  = (char*)Form("./ridf/72Fe/psp14%04d.ridf",RunNumber);
  char* outputfilename = (char*)Form("./rootfiles/yama_run%04d.root",RunNumber);

  // Create StoreManager both for calibration "TArtCalib..." and treatment "TArtReco..."
  //------------------------------------------------------------------------------------
  TArtStoreManager * sman = TArtStoreManager::Instance();
  
  // Create EventStore to control the loop and get the EventInfo
  //------------------------------------------------------------
/*
  TArtEventStore *estore = new TArtEventStore();
  estore->SetInterrupt(&stoploop); 
  estore->Open(infile);
  std::cout<<"estore ->"<< infile <<std::endl;
*/

  cout << "---> Open file name = " << inputfilename << endl << endl;
  TArtEventStore *estore = new TArtEventStore();
  estore->SetInterrupt(&stoploop); 
  int es = estore->Open(inputfilename);
  if(es==0){
    cout << endl << " === No data file === " << endl << endl;
    exit(-1);
  }
  cout << endl << endl;

  // Create BigRIPSParameters to get Plastics, PPACs, ICs and FocalPlanes parameters from ".xml" files
  //--------------------------------------------------------------------------------------------------	
  TArtBigRIPSParameters *para = TArtBigRIPSParameters::Instance();
  para->LoadParameter("db/BigRIPSPPAC.xml");
  para->LoadParameter("db/BigRIPSPlastic.xml");
  para->LoadParameter("db/BigRIPSIC.xml");
  para->LoadParameter("db/FocalPlane.xml");
  para->SetFocusPosOffset(8,138.5);

  // Create CalibPID to get and calibrate raw data ( CalibPID -> 
  //[CalibPPAC , CalibIC, CalibPlastic , CalibFocalPlane] 
  TArtCalibPID *brcalib     = new TArtCalibPID();
  TArtCalibPPAC *ppaccalib  = brcalib->GetCalibPPAC();
  TArtCalibPlastic *plasticcalib = brcalib->GetCalibPlastic();

  // Create RecoPID to get calibrated data and to reconstruct TOF, AoQ, Z, ... (RecoPID -> 
  //[ RecoTOF , RecoRIPS , RecoBeam] )
  TArtRecoPID *recopid = new TArtRecoPID();

  //para->PrintListOfPPACPara();
  //return;

  // Definition of observables we want to reconstruct
  std::cout << "Defining bigrips parameters" << std::endl;  
  //TArtRIPS *rips3to5 = recopid->DefineNewRIPS(3,5,"matrix/mat1.mat",5.45); // F3 - F5
  //TArtRIPS *rips5to7 = recopid->DefineNewRIPS(5,7,"matrix/mat2.mat",4.665); // F5 - F7
  //TArtRIPS *rips8to9 = recopid->DefineNewRIPS(8,9,"matrix/F8F9_LargeAccAchr.mat",3.831); // F8 - F9
  //TArtRIPS *rips9to11 = recopid->DefineNewRIPS(9,11,"matrix/F9F11_LargeAccAchr.mat",3.805); // F9 - F11  
  TArtRIPS *rips3to5 =  recopid->DefineNewRIPS(3, 5,"matrix/mat1.mat","D3"); // F3 - F5  
  TArtRIPS *rips5to7 =  recopid->DefineNewRIPS(5, 7,"matrix/mat2.mat","D5"); // F5 - F7
  TArtRIPS *rips8to9 =  recopid->DefineNewRIPS(8, 9,"matrix/F8F9_LargeAccAchr.mat","D7"); // F8 - F9
  TArtRIPS *rips9to11 = recopid->DefineNewRIPS(9,11,"matrix/F9F11_LargeAccAchr.mat","D8"); // F9 - F11 

/*
  TArtRIPS *rips3to5 = recopid->DefineNewRIPS(3,5,"matrix/mat1.mat",6.303); // F3 - F5
  TArtRIPS *rips5to7 = recopid->DefineNewRIPS(5,7,"matrix/mat2.mat",5.788); // F5 - F7
  TArtRIPS *rips8to9 = recopid->DefineNewRIPS(8,9,"matrix/F8F9_LargeAccAchr.mat",4.609); // F8 - F9
  TArtRIPS *rips9to11 = recopid->DefineNewRIPS(9,11,"matrix/F9F11_LargeAccAchr.mat",4.566); // F9 - F11  
*/
  // Reconstruction of TOF DefineNewTOF(fisrt plane, second plane, time offset)
  TArtTOF *tof3to7  = recopid->DefineNewTOF("F3pl","F7pl",302,5); // F3 - F7
  //TArtTOF *tof8to11 = recopid->DefineNewTOF("F8pl","F11pl-1",-160.5,9); // F8 - F11
  TArtTOF *tof8to11 = recopid->DefineNewTOF("F8pl","F11pl-1",-749.2,9); // F8 - F11
  // Reconstruction of IC observables for ID
  TArtBeam *beam_br_35 = recopid->DefineNewBeam(rips3to5,rips5to7,tof3to7,"F7IC");
  TArtBeam *beam_br_57 = recopid->DefineNewBeam(rips5to7,tof3to7,"F7IC");   
  TArtBeam *beam_zd_89 = recopid->DefineNewBeam(rips8to9,tof8to11,"F11IC");
  TArtBeam *beam_zd_911 = recopid->DefineNewBeam(rips9to11,tof8to11,"F11IC");

  //to get trigger pattern
  //TArtEventInfo *evtinfo=new TArtEventInfo();

  // Create DALIParameters to get ".xml"
  //------------------------------------

  TArtDALIParameters *dpara = TArtDALIParameters::Instance();
  dpara->LoadParameter("db/DALI.xml");
  
  // Create CalibDALI to get and calibrate raw data
  //-----------------------------------------------
  TArtCalibDALI *dalicalib = new TArtCalibDALI();
  //TArtCalibDALI *dalicalib2 = new TArtCalibDALI();

  // Create MINOSParameters to get ".xml"
  //------------------------------------

  TArtMINOSParameters *mpara = new TArtMINOSParameters("MINOSParameters","MINOSParameters");
  mpara->LoadParameters("./db/MINOS.xml");

  // Parameters for the MINOS ANALYSIS
  string ConfigBeam;
  double MINOSthresh;
  double TimeBinElec; //in ns
  double VDrift; //in cm/µs
  double Tshaping; // in ns
  double DelayTrig; // in ns
  double DALIOffset;

  ifstream ConfigFile;
  ConfigFile.open("./../ConfigFileSetup.txt");
  string Header;
  ConfigFile >> ConfigBeam;
  ConfigFile >> Header >> MINOSthresh;
  ConfigFile >> Header >> TimeBinElec;
  ConfigFile >> Header >> VDrift;
  ConfigFile >> Header >> Tshaping;
  ConfigFile >> Header >> DelayTrig;
  ConfigFile >> Header >> DALIOffset;
  ConfigFile.close();

  
  // Create CalibMINOS to get and calibrate raw data
  //-----------------------------------------------
  TArtCalibMINOS *minoscalib = new TArtCalibMINOS();
  TArtAnalyzedMINOS *minosanalyzed = new TArtAnalyzedMINOS(minoscalib);
  TArtTrackMINOS *minostrack = new TArtTrackMINOS();
  TArtVertexMINOS *minosvertex = new TArtVertexMINOS();

  std::cout<<"para"<<std::endl;

/*
  TFile *fout = new TFile(outfile,"RECREATE");
  TTree *tree = new TTree("tree","tree");
*/

  cout << endl << "---> Output file name = " << outputfilename << endl << endl;
  TFile *fout = new TFile(outputfilename,"RECREATE");
  TTree *tree = new TTree("tree","tree");

  // define data nodes which are supposed to be dumped to tree 
  //EventInfo is importand for the fBit information to know the trigger!
  TClonesArray * info_array = (TClonesArray *)sman->FindDataContainer("EventInfo");
  std::cout<<info_array->GetName()<<std::endl;
  tree->Branch(info_array->GetName(),&info_array);
  
  TClonesArray * ppac_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPPAC");
  std::cout<<ppac_array->GetName()<<std::endl;
  tree->Branch(ppac_array->GetName(),&ppac_array);
  
  TClonesArray * pla_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSPlastic");
  tree->Branch(pla_array->GetName(),&pla_array);
 
  TClonesArray * ic_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSIC");
  tree->Branch(ic_array->GetName(),&ic_array);
  
  TClonesArray * fpl_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSFocalPlane");
  tree->Branch(fpl_array->GetName(),&fpl_array);
  
  //Dali data
  TClonesArray * dali_array=
   (TClonesArray *)sman->FindDataContainer("DALINaI");
  tree->Branch(dali_array->GetName(),&dali_array);
  
  //PID reconstructed data:
  TClonesArray *rips_array = 
   (TClonesArray *)sman->FindDataContainer("BigRIPSRIPS");
  std::cout<<rips_array->GetName()<<std::endl;     
  tree->Branch(rips_array->GetName(),&rips_array); 
  
  TClonesArray *tof_array  = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSTOF");
  std::cout<<tof_array->GetName()<<std::endl;     
  tree->Branch(tof_array->GetName(),&tof_array);   
  
  TClonesArray *beam_array = 
    (TClonesArray *)sman->FindDataContainer("BigRIPSBeam");	
  std::cout<<beam_array->GetName()<<std::endl;     
  tree->Branch(beam_array->GetName(),&beam_array); 

  TClonesArray *analyzedminos_array = 
    (TClonesArray *)sman->FindDataContainer("AnalyzedMINOS");
  std::cout<<analyzedminos_array->GetName()<<std::endl;
  tree->Branch(analyzedminos_array->GetName(),&analyzedminos_array);

  TClonesArray *trackminos_array = 
    (TClonesArray *)sman->FindDataContainer("TrackMINOS");
  std::cout<<trackminos_array->GetName()<<std::endl;
  tree->Branch(trackminos_array->GetName(),&trackminos_array);

/*
  //minos
  anaminos_array =(TClonesArray *)sman->FindDataContainer("AnalyzedMINOS");
  tree->Branch(anaminos_array->GetName(),&anaminos_array);
  trackminos_array =(TClonesArray *)sman->FindDataContainer("TrackMINOS");
  tree->Branch(trackminos_array->GetName(),&trackminos_array);
*/

  //_________________________________________________________________________
  //Making new branches
  
  //%%%%%%%%%%%%%%%%%%%%%%
  //BigRIPS
  Double_t fF8PPACX[4]   = {-999.};
  Double_t fF8PPACY[4]   = {-999.};
  Double_t fF8PPACZ[4]   = {-999.};
  Double_t fF8PosX[2]    = {-999.};
  Double_t fF8PosY[2]    = {-999.};
  Double_t fF8PosZ[2]    = {-999.};

  Double_t fXTar        = -999.;
  Double_t fYTar        = -999.;

  Int_t fGoodPPACFocus[12] = {0};
  Int_t fGoodPPACFocusOr[12] = {0};

  tree->Branch("xtar",&fXTar,"fXTar/D");
  tree->Branch("ytar",&fYTar,"fYTar/D");
  //tree->Branch("f8ppacx",fF8PPACX,"fF8PPACX[6]/D");
  //tree->Branch("f8ppacy",fF8PPACY,"fF8PPACY[6]/D");
  //tree->Branch("f8posx",fF8PosX,"fF8PosX[3]/D");
  //tree->Branch("f8posy",fF8PosY,"fF8PosY[3]/D");
  tree->Branch("fgoodppacfocus",fGoodPPACFocus,"fGoodPPACFocus[12]/I");
  tree->Branch("fgoodppacfocusor",fGoodPPACFocusOr,"fGoodPPACFocusOr[12]/I");
    
  //%%%%%%%%%%%%%%%%%%%%%%
  //DALI
  Int_t dalimultwotime = 0;
  Int_t dalimult = 0;
  Int_t dalitimetruemult = 0;
  Int_t dalimultthres = 0;
  Int_t dalitimetruemultthres = 0;

  tree->Branch("dalimultwotime",&dalimultwotime,"dalimultwotime/I");
  tree->Branch("dalimult",&dalimult,"dalimult/I");
  tree->Branch("dalitimetruemult",&dalitimetruemult,"dalitimetruemult/I");
  tree->Branch("dalimultthres",&dalimultthres,"dalimultthres/I");
  tree->Branch("dalitimetruemultthres",&dalitimetruemultthres,"dalitimetruemultthres/I");

  //%%%%%%%%%%%%%%%%%%%%%%
  //MINOS

  Double_t z_vertex=0.;
  tree->Branch("z_vertex",&z_vertex,"z_vertex/D");

  Double_t beta_vertex=0.;
  tree->Branch("beta_vertex",&beta_vertex,"beta_vertex/D");

  int neve = 0;
  while(estore->GetNextEvent()){
    if(neve%1000==0)
      std::cout << "event: " << neve << std::endl;
      
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Making the BigRIPS tree calibration
    brcalib->ClearData();
    brcalib->ReconstructData();
    
    //Reconstructiong the PID
    recopid->ClearData();
    recopid->ReconstructData();
  
    //Reconstructing the scattering angle:
    //Beam spot on target reconstruction
    fXTar=-999.;
    fYTar=-999.;
     
    for(int i=0;i<4;i++){
      fF8PPACX[i] = -999.;
      fF8PPACY[i] = -999.;
      fF8PPACZ[i] = -999.;
    }
    
    for(int i=0;i<2;i++){
      fF8PosX[i] = -999.;
      fF8PosY[i] = -999.;
      fF8PosZ[i] = -999.;
    }
    
    for(int i=0;i<12;i++) {
      fGoodPPACFocus[i] = 0;
      fGoodPPACFocusOr[i] = 0;
    }
    
    bool  fired[14] = {false};
    bool  posRec = false;
    
    TArtPPAC *fppac[12];
    fppac[0] = ppaccalib->FindPPAC("F8PPAC-1A");
    fppac[1] = ppaccalib->FindPPAC("F8PPAC-1B");
    fppac[2] = ppaccalib->FindPPAC("F8PPAC-2A");
    fppac[3] = ppaccalib->FindPPAC("F8PPAC-2B");
    fppac[4] = ppaccalib->FindPPAC("F9PPAC-1A");
    fppac[5] = ppaccalib->FindPPAC("F9PPAC-1B");
    fppac[6] = ppaccalib->FindPPAC("F9PPAC-2A");
    fppac[7] = ppaccalib->FindPPAC("F9PPAC-2B");
    fppac[8] = ppaccalib->FindPPAC("F11PPAC-1A");
    fppac[9] = ppaccalib->FindPPAC("F11PPAC-1B");
    fppac[10] = ppaccalib->FindPPAC("F11PPAC-2A");
    fppac[11] = ppaccalib->FindPPAC("F11PPAC-2B");

    for(int i=0;i<12;i++){
      if(fppac[i]!=0){
        if(fppac[i]->IsFiredX()&&fppac[i]->IsFiredY()) fired[i] = true;
      } 
    }

    if(fppac[0]!=0&&fppac[1]!=0&&fppac[2]!=0&&fppac[3]!=0){
      if(fppac[0]->IsFiredX()&&fppac[1]->IsFiredX()&&fppac[2]->IsFiredX()&&fppac[3]->IsFiredX()) fGoodPPACFocus[8] = 1;
      if((fppac[0]->IsFiredX()||fppac[1]->IsFiredX())&&(fppac[2]->IsFiredX()||fppac[3]->IsFiredX())) 
        fGoodPPACFocusOr[8] = 1;
    }
    if(fppac[4]!=0&&fppac[5]!=0&&fppac[6]!=0&&fppac[7]!=0){
      if(fppac[4]->IsFiredX()&&fppac[5]->IsFiredX()&&fppac[6]->IsFiredX()&&fppac[7]->IsFiredX()) fGoodPPACFocus[9] = 1;
      if((fppac[4]->IsFiredX()||fppac[5]->IsFiredX())&&(fppac[6]->IsFiredX()||fppac[7]->IsFiredX())) 
        fGoodPPACFocusOr[9] = 1;
    }
    if(fppac[8]!=0&&fppac[9]!=0&&fppac[10]!=0&&fppac[11]!=0){
      if(fppac[8]->IsFiredX()&&fppac[9]->IsFiredX()&&fppac[10]->IsFiredX()&&fppac[11]->IsFiredX()) fGoodPPACFocus[11] = 1;
      if((fppac[8]->IsFiredX()||fppac[9]->IsFiredX())&&(fppac[10]->IsFiredX()||fppac[11]->IsFiredX())) 
        fGoodPPACFocusOr[11] = 1;
    }

    for(int i=0;i<4;i++){
      if(fired[i]==false) continue;
      fF8PPACX[i] = fppac[i]->GetX();
      fF8PPACY[i] = fppac[i]->GetY();
      fF8PPACZ[i] = fppac[i]->GetXZPos();
    }

    //For the F8 scattering angle:
    for(int i=0;i<2;i++){
      if(fired[2*i]==true&&fired[2*i+1]==true) {
        fF8PosX[i] = (fppac[2*i]->GetX()+fppac[2*i+1]->GetX())/2; 
        fF8PosY[i] = (fppac[2*i]->GetY()+fppac[2*i+1]->GetY())/2; 
        fF8PosZ[i] = (fppac[2*i]->GetXZPos()+fppac[2*i+1]->GetXZPos())/2;
        //posRec = true;
      }
      else if (fired[2*i]==true||fired[2*i+1]==true){
        int j;
        posRec = true;
        if (fired[2*i]==true) j = 2*i;
        else j = 2*i+1;
        
        fF8PosX[i] = fppac[j]->GetX(); 
        fF8PosY[i] = fppac[j]->GetY(); 
        fF8PosZ[i] = fppac[j]->GetXZPos(); 
      }  
      else continue;
      //cout<<"posX: "<<posX[i]<<endl;
    }
    
    if( (fired[0]==true||fired[1]==true) && 
        (fired[2]==true||fired[3]==true)) posRec = true;

    if(posRec) {
      
      double mX = (fF8PosX[1]-fF8PosX[0])/(fF8PosZ[1]-fF8PosZ[0]);
      double mY = (fF8PosY[1]-fF8PosY[0])/(fF8PosZ[1]-fF8PosZ[0]);
      
      fXTar = fF8PosX[1] + mX * 880;
      fYTar = fF8PosY[1] + mY * 880;
    }

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Making MINOS
    minoscalib->ClearData();
    minosanalyzed->ClearData();
    minostrack->ClearData();
    minosvertex->ClearData();
    minoscalib->ReconstructData();
    minosanalyzed->ReconstructData(); 
    minostrack->ReconstructData();
    minosvertex->ReconstructVertex();
    // Convert the reconstructed vertex in z (mm)
    z_vertex = minosvertex->GetZvCal(1e-3*VDrift, TimeBinElec, DelayTrig); //time bin*(ns/us)*vdrift(cm/us) == z_vertex in cm
    beta_vertex = minosvertex->GetBetaV();


    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    //Making DALI
    dalicalib->ClearData();
    //dalicalib->SetPlTime(plasticcalib->FindPlastic("F8pl")->GetTime());
    //dalicalib->SetVertex(z_vertex-DALIOffset/10.);
    //dalicalib->SetBeta(beta_vertex);

/*
    dalicalib2->ClearData();
    //dalicalib2->SetPlTime(plasticcalib->FindPlastic("F8pl")->GetTime());
    //dalicalib2->SetVertex(z_vertex-DALIOffset/10.);
    //dalicalib2->SetBeta(beta_vertex);
*/
       //Add above to remove F8plastic tof.
    dalicalib->ReconstructData();
    //dalicalib2->ReconstructData();
    
    dalimultwotime = dalicalib->GetMultWithoutT();
    dalimult = dalicalib->GetMult();
    dalitimetruemult = dalicalib->GetTimeTrueMult();
    dalimultthres = dalicalib->GetMultThres();
    dalitimetruemultthres = dalicalib->GetTimeTrueMultThres();
 


    tree->Fill();
    neve++;
  }
  cout<<"Writing the tree."<<endl;
  
  fout->Write();
  fout->Close();
}
Exemple #6
0
void MakeDALITree(UInt_t run){
  gSystem->Load("libXMLParser.so");
  gSystem->Load("libanaroot.so");

  TArtStoreManager * sman = TArtStoreManager::Instance();
  TArtEventStore *estore = new TArtEventStore();
  estore->SetInterrupt(&stoploop);
  //estore->Open(0);
  Char_t* name = "calibration";
  UInt_t run_=run;
  if(run>200){
    name = "calib2XO";
    run_=run-200;
  }else if(run>100){
    name = "labr14Ni";
    run_=run-100;
  }
  estore -> Open(Form("data/ridf/ggdaq04/%s%04d.ridf",name,run_));

  //  estore -> Open(Form("ridf/ggdaq04/labr14Ni%04d.ridf",run));

  TArtDALIParameters *dpara = TArtDALIParameters::Instance();
  dpara->LoadParameter("db/DALI.xml");
  TArtCalibDALI *dalicalib= new TArtCalibDALI();

  //check if the tree is readable, otherwise change here to array and save once in a while during the loop and delete the tree, start again.
  //TFile *fout[100];
  //TTree *tree;
   
  Char_t* path = "data/Histo/calib/";
  Char_t* rename;
  if(run<34)
    rename = "before_empty/run";
  else if(run<39)
    rename = "before_Sn132/run";
  else if(run<43)
    rename = "before_Sn128/run";
  else if(run<46)
    rename = "during_Sn128/run";
  else if(run<52)
    rename = "after_Sn128/run";
  else 
    rename = "after_exp/run";
  TFile *fout = new TFile(Form("%s%s%04d.root",path,rename,run),"RECREATE");
  TTree *tree = new TTree("tree","tree");
  
  // define data nodes which are supposed to be dumped to tree 
  TClonesArray * info_array = (TClonesArray *)sman->FindDataContainer("EventInfo");
  TArtRawEventObject* frawevent = (TArtRawEventObject *)sman->FindDataContainer("RawEvent");
  std::cout<<info_array->GetName()<<std::endl;
  //std::cout<<info_array->GetDate()<<std::endl;
  tree->Branch(info_array->GetName(),&info_array);

  TClonesArray * dali_array=
     (TClonesArray *)sman->FindDataContainer("DALINaI");
  tree->Branch(dali_array->GetName(),&dali_array);

  Int_t MIDGAIN[8] = {0x0};
  Int_t LOWGAIN[8] = {0x0};
  Int_t HIGAIN[8]  = {0x0};

  tree->Branch("MIDGAIN",MIDGAIN,"MIDGAIN[8]/I");
  tree->Branch("LOWGAIN",LOWGAIN,"LOWGAIN[8]/I");
  tree->Branch("HIGAIN" ,HIGAIN ,"HIGAIN[8]/I");

  int neve = 0;
  Int_t ii = -1;
  UInt_t  fQTC[3][8] = {28, 29, 30, 1, 31, 4, 3, 2,
			24, 25, 26, 6, 27, 9, 8, 7,
			20, 21, 22,11, 23,14,13,12};
  TRandom3 rndm;

  while( estore->GetNextEvent() ){
    //while(neve<9000000){
    //	  estore->GetNextEvent();
    if(neve%500000==0){
      std::cout << "event: " << neve << std::endl;
      //not tested
/*
      if(neve%(Int_t)1e7==0){
	if(neve!=0){
	  fout[ii]->Write();
	  delete tree;
	}    
	ii++;
	if(ii > 99){
	  std::cout<< "file array is not big enough please increase the array size"<<std::endl;
	  return;
	}
	tree = new TTree("tree","tree");
	fout[ii] = new TFile(Form("rootfiles/calibration/calibration%04d_%i.root",run,ii),"RECREATE");
	}*/
    }

    dalicalib->ClearData();
    dalicalib->ReconstructData();

    Int_t tref = -9000;
    Int_t qtc_dummy[2][130];
    for( int i=0; i<130; i++ ){
      for( int j=0; j<2; j++ ){
	qtc_dummy[j][i] = -9999;
      }
    }
    for(int i=0; i<frawevent -> GetNumSeg(); i++){
      TArtRawSegmentObject *seg = frawevent -> GetSegment(i);
      Int_t fpl = seg -> GetFP();
      if(fpl==8){
	for(int j=0; j < seg -> GetNumData(); j++){
	  TArtRawDataObject *d = seg -> GetData(j);
	  Int_t geo  = d -> GetGeo();
	  Int_t ch   = d -> GetCh();
	  Int_t val  = d -> GetVal();
	  Int_t edge = d -> GetEdge();
	  if(geo==9) qtc_dummy[edge][ch] = val + (rndm.Rndm()- 0.5);
	  //if(ch == fQTC[1][1] )cout<<qtc_dummy[edge][ch]<< " qtc_dummy  "<<ch<<endl;
	  if(geo ==9 && ch==127 && edge == 0) tref = val;					
	}//for
      }//if
    }//for
  
    for(short ilabr=0; ilabr<8; ilabr++){
      HIGAIN[ilabr]  = (qtc_dummy[1][ fQTC[0][ilabr] ] - qtc_dummy[0][ fQTC[0][ilabr] ]);
      MIDGAIN[ilabr] = (qtc_dummy[1][ fQTC[1][ilabr] ] - qtc_dummy[0][ fQTC[1][ilabr] ]);
      LOWGAIN[ilabr] = (qtc_dummy[1][ fQTC[2][ilabr] ] - qtc_dummy[0][ fQTC[2][ilabr] ]);
    }
    tree->Fill();
    neve ++;
  }
  fout->Write();
  fout->Close();

 

}