コード例 #1
0
ファイル: treefriend.C プロジェクト: adevress/root-1
void CreateFriendTree() {
   // Open the file created by CreateParentTree
   // Copy a subset of the TTree into a new TTree
   //   (see also tutorials copytree.C, copytree2.C and copytree3.C)
   // Create an index on the new TTree ("Run","Event")
   // Write the new TTree (including its index)
   
   TFile *f = new TFile("treeparent.root");
   TTree *T = (TTree*)f->Get("T");
   TFile *ff = new TFile("treefriend.root","recreate");
   TTree *TF = T->CopyTree("z<10");
   TF->SetName("TF");
   TF->BuildIndex("Run","Event");
   TF->Write();
   TF->Print();
   delete ff;
}
コード例 #2
0
void createFiles(TString name, Float_t valConst)
{
   // creates a chains having noTrees trees with the 2*sizes from size array
   // each has branches: val, val2 ( = val*val and val*val+1),
   // val3 ( = val + val2 + valCost) and valConst ( = valConst)

   Int_t nextToFill = 1;
   Int_t val;
   Int_t val2;
   Int_t val3;
   for (int treeNo = 0; treeNo < noTrees; treeNo++) {
      vector<Int_t> data;
      for (int j = 0; j < size[treeNo]; j++) {
         data.push_back(nextToFill++);
      }
      random_shuffle(data.begin(), data.end());

      TString filename = path;
      filename += name;
      filename += treeNo;
      filename += ".root";
      TFile *f = new TFile(filename,"recreate");
      TTree *T = new TTree(name,"test friend trees and indices");
      printf("Creating %s\n", filename.Data());
      T->Branch("val", &val, "val/I");
      T->Branch("val2", &val2, "val2/I");
      T->Branch("val3", &val3, "val3/I");
      T->Branch("valConst", &valConst, "valConst/F");

      for (Int_t j = 0; j < size[treeNo]; j++) {
         val = data[j];
         val2 = val*val;
         val3 = val + val2 + (Int_t)valConst;
         T->Fill();

         val = data[j];
         val2 = val*val + 1;
         val3 = val + val2 + (Int_t)valConst;
         T->Fill();
      }
      if (treeNo % 2 == 1) T->BuildIndex("val", "val2");
      T->Write();
      delete f;
   }
}
コード例 #3
0
void startCorrelation(int run,int eventNumber){

  //int entry=65000;
  char runRootDirectory[FILENAME_MAX];
  sprintf(runRootDirectory,"/unix/anita3/flight0809/root/");

  char headName[FILENAME_MAX];
  char eventName[FILENAME_MAX];
  char gpsName[FILENAME_MAX];
  RawAnitaEvent *evPtr = 0;
  RawAnitaHeader *hdPtr = 0;
  Adu5Pat *patPtr =0;

  sprintf(headName,"%s/run%d/headFile%d.root",runRootDirectory,run,run);
  sprintf(eventName,"%s/run%d/eventFile%d.root",runRootDirectory,run,run);
  sprintf(gpsName,"%s/run%d/gpsFile%d.root",runRootDirectory,run,run);

  TFile *eventFile = new TFile(eventName);
  TFile *headFile = new TFile(headName);
  TFile *fpGps = new TFile(gpsName);

  if(!fpGps){
    std::cout << "no GPS file\n";
    return;
  }

  TTree *adu5PatTree = (TTree*) fpGps->Get("adu5PatTree");
  TTree *eventTree = (TTree*)eventFile->Get("eventTree");
  TTree *headTree = (TTree*)headFile->Get("headTree");

  eventTree->SetBranchAddress("event",&evPtr);
  headTree->SetBranchAddress("header",&hdPtr);
  headTree->BuildIndex("eventNumber");
  adu5PatTree->SetBranchAddress("pat",&patPtr);
  adu5PatTree->BuildIndex("realTime");

  int entry=headTree->GetEntryNumberWithBestIndex(eventNumber);

  eventTree->GetEntry(entry);
  headTree->GetEntry(entry);



  /*
  //for(int phi=0;phi<16;phi++){
    while(hdPtr->triggerTimeNs<349.99e6 || hdPtr->triggerTimeNs>350.005e6 || hdPtr->l3TrigPattern==0){
      if(lastEvent==hdPtr->eventNumber){
	std::cout << "no more entries in run" << std::endl;
	return;
      }
      std::cout << "opened entry " << entry << " (event " << hdPtr->eventNumber << ") with triggerTimeNs " << hdPtr->triggerTimeNs << std::endl;
      lastEvent=hdPtr->eventNumber;
      entry++;
      eventTree->GetEntry(entry);
      headTree->GetEntry(entry);
      adu5PatTree->GetEntry(entry);
    }
    //}
    */

  std::cout << "opened entry " << entry << " (event " << hdPtr->eventNumber << ") with triggerTimeNs " << hdPtr->triggerTimeNs << std::endl;

  //get the pat ptr that corresponds to the timing of the event
  Int_t patEntry;
  patEntry = adu5PatTree->GetEntryNumberWithBestIndex(hdPtr->realTime);
  adu5PatTree->GetEntry(patEntry);

  std::cout << patPtr->realTime << " " << hdPtr->realTime << std::endl;

  if(patPtr->realTime != hdPtr->realTime){
    std:: cout << "pat time doesn't match head time, pat realTime: " << patPtr->realTime << " head realTime: " << hdPtr->realTime << std::endl;
    //return;
  }


  for(int chan=0;chan<90;chan++){
    if(evPtr->xMax[chan]>130 || evPtr->xMin[chan]<-130){
      saturatedChannel[chan]=1;
      std::cout << "saturated " << chan << std::endl;
    }
    else saturatedChannel[chan]=0;
  }


  //entry++;
  TH2D *crossCorrelation = crossCorrelate(evPtr,hdPtr,patPtr);
 
  sprintf(headName,"crossCorrCan");
  TCanvas *crossCorrCan = (TCanvas*)gROOT->FindObject(headName);
  if(!crossCorrCan)
    crossCorrCan = new TCanvas(headName,headName,800,400);
  crossCorrCan->Clear();
  //sumCrossCorrs->Draw("aitoff");
  crossCorrelation->Draw("colz");
  TAxis *phiSectors = new TAxis(16,1,16);
  phiSectors->Draw();

  //std::cout << "event " << hdPtr->eventNumber << " time " << 

  double theta,phi;

  getSignalDirection(crossCorrelation,phi,theta);

  std::cout << "phi " << phi << " theta " << theta << std::endl;

  plotAnitaEventMap(patPtr,phi,theta);

}
コード例 #4
0
void PlotSIPversusT_byRUNS(string tag="PromptGT"){

  //gROOT->ProcessLine(".L TkAlStyle.cc+");
  //TkAlStyle::set(INPROGRESS);	// set publication status

  //gROOT->ProcessLine(".L ./setTDRStyle.C++");
  //setTDRStyle();

  //string tag="ORIGINAL";//"TBDkb";
  //ORIGINAL_DzDisparity_byRUNS.root
  //TBDkb_newIOV_DzDisparity_byRUNS_fromJuly1.root

  string inFileName=tag+".root";
  TFile *f = new TFile(inFileName.c_str());
  TTree* t = (TTree*) f->Get("SIPValidationTree");

  const int DummyNumEvents = int(t->GetEntries());
  const int NumEvents=DummyNumEvents;
  cout<<"NumEvents = "<<NumEvents <<endl;
  
  double lanWidth,lanMPV,area,GWidth;
  double err_lanWidth,err_lanMPV,err_area,err_GWidth;
  double fitChisqNdof;

  int run;

  double x[NumEvents];
  double x_err[NumEvents];
  double y_fake[NumEvents];
  double y_lanWidth[NumEvents];
  double y_lanMPV[NumEvents];
  double y_area[NumEvents];
  double y_GWidth[NumEvents];
  double y_err_lanWidth[NumEvents];
  double y_err_lanMPV[NumEvents];
  double y_err_area[NumEvents];
  double y_err_GWidth[NumEvents];

  double noDatax[10000];
  double noDatay[10000];

  t->SetBranchAddress("run"             , &run         );
  t->SetBranchAddress("lanWidth"        , &lanWidth    );                                                                         
  t->SetBranchAddress("lanMPV"          , &lanMPV      );                                                                         
  t->SetBranchAddress("area"            , &area        );                                                                         
  t->SetBranchAddress("GWidth"          , &GWidth      );                                                                         
                                                                                                                        
  t->SetBranchAddress("err_lanWidth"    , &err_lanWidth);                                                                         
  t->SetBranchAddress("err_lanMPV"      , &err_lanMPV  );                                                                         
  t->SetBranchAddress("err_area"        , &err_area    );                                                                         
  t->SetBranchAddress("err_GWidth"      , &err_GWidth  );                                                                         
  t->SetBranchAddress("fitChisqNdof"    , &fitChisqNdof);  

  //-----------------------------------------------

  int numEventsGood=0;
  int numEventsBad=0;
  
  t->BuildIndex("run");
  TTreeIndex *index = (TTreeIndex*)t->GetTreeIndex();
  for( int i = 0; i <= index->GetN(); i++ ) {
    Long64_t local = t->LoadTree( index->GetIndex()[i] );
   
    t->GetEntry(local);

    if(fitChisqNdof<0.)
      continue;
    
    if(fitChisqNdof>100.){
      noDatay[numEventsBad] = -999.;
      noDatax[numEventsBad] = i;
      numEventsBad++;

    } else {

      y_fake   [numEventsGood]      = 0.;
      y_lanWidth[numEventsGood]     = lanWidth;
      y_lanMPV[numEventsGood]       = lanMPV;
      y_area[numEventsGood]         = area;
      y_GWidth[numEventsGood]       = GWidth;
      
      y_err_lanWidth[numEventsGood] = err_lanWidth;
      y_err_lanMPV[numEventsGood]   = err_lanMPV;
      y_err_area[numEventsGood]     = err_area;
      y_err_GWidth[numEventsGood]   = err_GWidth;
      
      //x[numEventsGood] = run;
      x_err[numEventsGood] = 0.;
      x[numEventsGood] = numEventsGood;

      cout<<" x[" << numEventsGood << "]" << x[numEventsGood] << " y_lanMPV["<<numEventsGood<<"] " <<  y_lanMPV[numEventsGood] << " +/- y_err_lanMPV["<<numEventsGood<<"] " <<   y_err_lanMPV[numEventsGood] << endl; 
      numEventsGood++;
      
    }

  }

  //////***************************************************///////

  Double_t max_scale = 0.9;
  Double_t min_scale = 0.4;

  TGraphErrors *dummyGraph = new TGraphErrors(numEventsGood,x,y_fake,0,0);

  TCanvas *c = new TCanvas("c","", 1000,500);
  c->SetFillColor(0);
  c->SetBottomMargin(0.14);
  c->SetLeftMargin(0.07);
  c->SetRightMargin(0.05);
  c->SetTopMargin(0.08);  
  c->SetGrid();

  TGraphErrors *graph_lanMPV = new TGraphErrors(numEventsGood,x,y_lanMPV,x_err,y_err_lanMPV);
  TGraph *graph_lanMPV_shade = new TGraph(2*numEventsGood);
  for (Int_t i=0;i<numEventsGood;i++) {
    graph_lanMPV_shade->SetPoint(i,x[i],y_lanMPV[i]+1*y_err_lanMPV[i]);
    graph_lanMPV_shade->SetPoint(numEventsGood+i,x[numEventsGood-i-1],y_lanMPV[numEventsGood-i-1]-1*y_err_lanMPV[numEventsGood-i-1]);
    //graph_dxy_phi->GetXaxis()->SetBinLabel(i+1,Form("%i",x[i]));
  }
  graph_lanMPV_shade->SetFillStyle(3013);
  graph_lanMPV_shade->SetFillColor(kBlue);

  makeNiceTGraph(graph_lanMPV);

  graph_lanMPV->GetXaxis()->SetTitle("Run Number index");
  graph_lanMPV->GetYaxis()->SetTitle("MPV of SIP_{3D}");
  graph_lanMPV->SetTitle("MPV(SIP_{3D}) vs. time");
  graph_lanMPV->SetMarkerStyle(20);
  graph_lanMPV->SetMarkerSize(1.2);
  graph_lanMPV->SetMarkerColor(kRed);
  graph_lanMPV->SetLineColor(kRed);

  c->cd();
  dummyGraph->GetYaxis()->SetRangeUser(min_scale,max_scale);
  graph_lanMPV->Draw("alpsame");
  graph_lanMPV_shade->Draw("fsame");

  //******************************

  TCanvas *c2 = new TCanvas("c2","", 1000,500);
  c2->SetFillColor(0);
  c2->SetBottomMargin(0.14);
  c2->SetLeftMargin(0.07);
  c2->SetRightMargin(0.05);
  c2->SetTopMargin(0.08);  
  c2->SetGrid();

  TGraphErrors *graph_GWidth = new TGraphErrors(numEventsGood,x,y_GWidth,x_err,y_err_GWidth);
  TGraph *graph_GWidth_shade = new TGraph(2*numEventsGood);
  for (Int_t i=0;i<numEventsGood;i++) {
    graph_GWidth_shade->SetPoint(i,x[i],y_GWidth[i]+1*y_err_GWidth[i]);
    graph_GWidth_shade->SetPoint(numEventsGood+i,x[numEventsGood-i-1],y_GWidth[numEventsGood-i-1]-1*y_err_GWidth[numEventsGood-i-1]);
    //graph_dxy_phi->GetXaxis()->SetBinLabel(i+1,Form("%i",x[i]));
  }
  graph_GWidth_shade->SetFillStyle(3013);
  graph_GWidth_shade->SetFillColor(kBlue);

  makeNiceTGraph(graph_GWidth);

  graph_GWidth->GetXaxis()->SetTitle("Run Number index");
  graph_GWidth->GetYaxis()->SetTitle("Gaussian width of SIP_{3D}");
  graph_GWidth->SetTitle("#sigma_{G}(SIP_{3D}) vs. time");
  graph_GWidth->SetMarkerStyle(20);
  graph_GWidth->SetMarkerSize(1.2);
  graph_GWidth->SetMarkerColor(kRed);
  graph_GWidth->SetLineColor(kRed);

  c2->cd();
  dummyGraph->GetYaxis()->SetRangeUser(min_scale,max_scale);
  graph_GWidth->Draw("alpsame");
  graph_GWidth_shade->Draw("fsame");

  //******************************

  TCanvas *c3 = new TCanvas("c3","", 1000,500);
  c3->SetFillColor(0);
  c3->SetBottomMargin(0.14);
  c3->SetLeftMargin(0.07);
  c3->SetRightMargin(0.05);
  c3->SetTopMargin(0.08);  
  c3->SetGrid();

  TGraphErrors *graph_area = new TGraphErrors(numEventsGood,x,y_area,x_err,y_err_area);
  TGraph *graph_area_shade = new TGraph(2*numEventsGood);
  for (Int_t i=0;i<numEventsGood;i++) {
    graph_area_shade->SetPoint(i,x[i],y_area[i]+1*y_err_area[i]);
    graph_area_shade->SetPoint(numEventsGood+i,x[numEventsGood-i-1],y_area[numEventsGood-i-1]-1*y_err_area[numEventsGood-i-1]);
    //graph_dxy_phi->GetXaxis()->SetBinLabel(i+1,Form("%i",x[i]));
  }
  graph_area_shade->SetFillStyle(3013);
  graph_area_shade->SetFillColor(kBlue);

  makeNiceTGraph(graph_area);

  graph_area->GetXaxis()->SetTitle("Run Number index");
  graph_area->GetYaxis()->SetTitle("Area parameter of SIP_{3D}");
  graph_area->SetTitle("A(SIP_{3D}) vs. time");
  graph_area->SetMarkerStyle(20);
  graph_area->SetMarkerSize(1.2);
  graph_area->SetMarkerColor(kRed);
  graph_area->SetLineColor(kRed);

  c3->cd();
  // dummyGraph->GetYaxis()->SetRangeUser(min_scale,max_scale);
  graph_area->Draw("alpsame");
  graph_area_shade->Draw("fsame");

  //******************************

  TCanvas *c4 = new TCanvas("c4","", 1000,500);
  c4->SetFillColor(0);
  c4->SetBottomMargin(0.14);
  c4->SetLeftMargin(0.07);
  c4->SetRightMargin(0.05);
  c4->SetTopMargin(0.08);  
  c4->SetGrid();

  TGraphErrors *graph_lanWidth = new TGraphErrors(numEventsGood,x,y_lanWidth,x_err,y_err_lanWidth);
  TGraph *graph_lanWidth_shade = new TGraph(2*numEventsGood);
  for (Int_t i=0;i<numEventsGood;i++) {
    graph_lanWidth_shade->SetPoint(i,x[i],y_lanWidth[i]+1*y_err_lanWidth[i]);
    graph_lanWidth_shade->SetPoint(numEventsGood+i,x[numEventsGood-i-1],y_lanWidth[numEventsGood-i-1]-1*y_err_lanWidth[numEventsGood-i-1]);
    //graph_dxy_phi->GetXaxis()->SetBinLabel(i+1,Form("%i",x[i]));
  }
  graph_lanWidth_shade->SetFillStyle(3013);
  graph_lanWidth_shade->SetFillColor(kBlue);

  makeNiceTGraph(graph_lanWidth);

  graph_lanWidth->GetXaxis()->SetTitle("Run Number index");
  graph_lanWidth->GetYaxis()->SetTitle("Landau width of SIP_{3D}");
  graph_lanWidth->SetTitle("#sigma_{L}(SIP_{3D}) vs. time");
  graph_lanWidth->SetMarkerStyle(20);
  graph_lanWidth->SetMarkerSize(1.2);
  graph_lanWidth->SetMarkerColor(kRed);
  graph_lanWidth->SetLineColor(kRed);

  c4->cd();
  // dummyGraph->GetYaxis()->SetRangeUser(min_scale,max_scale);
  graph_lanWidth->Draw("alpsame");
  graph_lanWidth_shade->Draw("fsame");

}
コード例 #5
0
void correlationTreeLoop(int run,char *baseDir, char *corTreeDir, char *outputDir) {
// antTimeOffset[0] = 0.292591; deltaR[0] = -0.0384839; deltaPhi[ 0] = -0.0100608; deltaZ[0] = 0;
// antTimeOffset[1] = 0.172375; deltaR[1] = 0.00634697; deltaPhi[ 1] = -0.00313443; deltaZ[1] = 0;
// antTimeOffset[2] = 0.342454; deltaR[2] = -0.0861167; deltaPhi[ 2] = -0.015312; deltaZ[2] = 0;
// antTimeOffset[3] = 0.0248334; deltaR[3] = 0.0461873; deltaPhi[ 3] = 0.00206827; deltaZ[3] = 0;
// antTimeOffset[4] = 0.0372539; deltaR[4] = 0.0153388; deltaPhi[ 4] = -0.0227948; deltaZ[4] = 0;
// antTimeOffset[5] = 0.137506; deltaR[5] = -0.00927728; deltaPhi[ 5] = 0.00750385; deltaZ[5] = 0;
// antTimeOffset[6] = 0.0475841; deltaR[6] = 0.0239867; deltaPhi[ 6] = 0.00388065; deltaZ[6] = 0;
// antTimeOffset[7] = 0.123741; deltaR[7] = 0.0125282; deltaPhi[ 7] = -0.00131021; deltaZ[7] = 0;
// antTimeOffset[8] = 0.380551; deltaR[8] = -0.0111636; deltaPhi[ 8] = -0.0299233; deltaZ[8] = 0;
// antTimeOffset[9] = 0.445956; deltaR[9] = -0.0959452; deltaPhi[ 9] = -0.00165365; deltaZ[9] = 0;
// antTimeOffset[10] = 0.439757; deltaR[10] = -0.0330808; deltaPhi[ 10] = -0.0107407; deltaZ[10] = 0;
// antTimeOffset[11] = 0.244031; deltaR[11] = -0.0475617; deltaPhi[ 11] = 0.0145914; deltaZ[11] = 0;
// antTimeOffset[12] = 0.321419; deltaR[12] = 0.0196292; deltaPhi[ 12] = -0.0150373; deltaZ[12] = 0;
// antTimeOffset[13] = 0.118473; deltaR[13] = -0.0190837; deltaPhi[ 13] = -0.0121967; deltaZ[13] = 0;
// antTimeOffset[14] = 0.27363; deltaR[14] = -0.00922367; deltaPhi[ 14] = -0.0038106; deltaZ[14] = 0;
// antTimeOffset[15] = 0.187377; deltaR[15] = -0.0294811; deltaPhi[ 15] = 0.0106842; deltaZ[15] = 0;
// antTimeOffset[16] = 0.0682454; deltaR[16] = 0.0140245; deltaPhi[ 16] = -0.0087849; deltaZ[16] = 0;
// antTimeOffset[17] = 0.296899; deltaR[17] = -0.0621836; deltaPhi[ 17] = 0.000682206; deltaZ[17] = 0;
// antTimeOffset[18] = 0.180588; deltaR[18] = -0.0379325; deltaPhi[ 18] = -0.00516052; deltaZ[18] = 0;
// antTimeOffset[19] = 0.165257; deltaR[19] = -0.0108062; deltaPhi[ 19] = -0.00770935; deltaZ[19] = 0;
// antTimeOffset[20] = 0.176423; deltaR[20] = -0.0601935; deltaPhi[ 20] = -0.00862535; deltaZ[20] = 0;
// antTimeOffset[21] = 0.301777; deltaR[21] = -0.0968276; deltaPhi[ 21] = -0.00920648; deltaZ[21] = 0;
// antTimeOffset[22] = 0.0969425; deltaR[22] = -0.0348523; deltaPhi[ 22] = 0.00037431; deltaZ[22] = 0;
// antTimeOffset[23] = 0.0422886; deltaR[23] = 0.0121726; deltaPhi[ 23] = 0.00310935; deltaZ[23] = 0;
// antTimeOffset[24] = -0.01737; deltaR[24] = 0.0405193; deltaPhi[ 24] = -0.00546085; deltaZ[24] = 0;
// antTimeOffset[25] = 0.0412981; deltaR[25] = 0.0239992; deltaPhi[ 25] = -0.00901249; deltaZ[25] = 0;
// antTimeOffset[26] = 0.166311; deltaR[26] = -0.0405203; deltaPhi[ 26] = -0.0145529; deltaZ[26] = 0;
// antTimeOffset[27] = 0.139405; deltaR[27] = -0.00401756; deltaPhi[ 27] = -0.00666063; deltaZ[27] = 0;
// antTimeOffset[28] = 0.104575; deltaR[28] = -0.0362955; deltaPhi[ 28] = -0.00372999; deltaZ[28] = 0;
// antTimeOffset[29] = 0.0345155; deltaR[29] = -0.00587152; deltaPhi[ 29] = 0.00197442; deltaZ[29] = 0;
// antTimeOffset[30] = 0.082859; deltaR[30] = -0.00611182; deltaPhi[ 30] = -0.000789595; deltaZ[30] = 0;
// antTimeOffset[31] = 0.078192; deltaR[31] = -0.00321244; deltaPhi[ 31] = 0.000188257; deltaZ[31] = 0;
// antTimeOffset[32] = 0.0143052; deltaR[32] = -0.0437687; deltaPhi[ 32] = -0.00289577; deltaZ[32] = 0;
// antTimeOffset[33] = 0.0671887; deltaR[33] = -0.0643475; deltaPhi[ 33] = -0.0203117; deltaZ[33] = 0;
// antTimeOffset[34] = 0.0819606; deltaR[34] = -0.0804245; deltaPhi[ 34] = -0.00503387; deltaZ[34] = 0;
// antTimeOffset[35] = -0.0659071; deltaR[35] = -0.0112675; deltaPhi[ 35] = -0.000220575; deltaZ[35] = 0;
// antTimeOffset[36] = -0.212624; deltaR[36] = 0.0337428; deltaPhi[ 36] = -0.00416114; deltaZ[36] = 0;
// antTimeOffset[37] = -0.00431668; deltaR[37] = -0.0525977; deltaPhi[ 37] = -0.0223176; deltaZ[37] = 0;
// antTimeOffset[38] = 0.0899397; deltaR[38] = -0.101587; deltaPhi[ 38] = 0.0058874; deltaZ[38] = 0;
// antTimeOffset[39] = 0.0294537; deltaR[39] = -0.0401037; deltaPhi[ 39] = 0.00899651; deltaZ[39] = 0;

// antTimeOffset[0] = 0.16044; deltaR[0] = -0.0618352; deltaPhi[ 0] = -0.00280991; deltaZ[0] = 0.0287513;
// antTimeOffset[1] = 0.290365; deltaR[1] = -0.110188; deltaPhi[ 1] = -0.00372876; deltaZ[1] = 0.0170052;
// antTimeOffset[2] = 0.349607; deltaR[2] = -0.140583; deltaPhi[ 2] = -0.024769; deltaZ[2] = 0.0623979;
// antTimeOffset[3] = 0.033917; deltaR[3] = -0.0260668; deltaPhi[ 3] = 0.00113633; deltaZ[3] = 0.0423352;
// antTimeOffset[4] = -0.074643; deltaR[4] = -0.0356161; deltaPhi[ 4] = -0.0141947; deltaZ[4] = -0.00394529;
// antTimeOffset[5] = 0.156259; deltaR[5] = -0.095648; deltaPhi[ 5] = 0.0117896; deltaZ[5] = 0.0105241;
// antTimeOffset[6] = 0.212836; deltaR[6] = -0.0907411; deltaPhi[ 6] = -0.0122972; deltaZ[6] = 0.0516748;
// antTimeOffset[7] = 0.541271; deltaR[7] = -0.157934; deltaPhi[ 7] = -0.00368077; deltaZ[7] = 0.130464;
// antTimeOffset[8] = -0.128575; deltaR[8] = 0.0582477; deltaPhi[ 8] = -0.0111813; deltaZ[8] = -0.035067;
// antTimeOffset[9] = -0.122485; deltaR[9] = -0.0119241; deltaPhi[ 9] = -0.00668961; deltaZ[9] = -0.0579302;
// antTimeOffset[10] = -0.263916; deltaR[10] = 0.0811694; deltaPhi[ 10] = -0.00717066; deltaZ[10] = -0.0897962;
// antTimeOffset[11] = -0.229033; deltaR[11] = 0.00897635; deltaPhi[ 11] = -5.65709e-05; deltaZ[11] = -0.0366053;
// antTimeOffset[12] = -0.222093; deltaR[12] = 0.0800239; deltaPhi[ 12] = -0.00901442; deltaZ[12] = -0.0750748;
// antTimeOffset[13] = -0.68459; deltaR[13] = 0.108285; deltaPhi[ 13] = -0.0148342; deltaZ[13] = -0.133195;
// antTimeOffset[14] = -0.516002; deltaR[14] = 0.107793; deltaPhi[ 14] = -0.00133016; deltaZ[14] = -0.143198;
// antTimeOffset[15] = -0.749822; deltaR[15] = 0.145538; deltaPhi[ 15] = -0.00448024; deltaZ[15] = -0.118927;
// antTimeOffset[16] = 0.0961751; deltaR[16] = -0.0564912; deltaPhi[ 16] = -0.00220892; deltaZ[16] = 0.0532255;
// antTimeOffset[17] = -0.166225; deltaR[17] = 0.00298098; deltaPhi[ 17] = 0.00128378; deltaZ[17] = -0.0263557;
// antTimeOffset[18] = 0.178941; deltaR[18] = -0.0972098; deltaPhi[ 18] = -0.00837075; deltaZ[18] = 0.0461125;
// antTimeOffset[19] = 0.171386; deltaR[19] = -0.0643506; deltaPhi[ 19] = -0.00831496; deltaZ[19] = 0.0592813;
// antTimeOffset[20] = -0.0204964; deltaR[20] = -0.0803763; deltaPhi[ 20] = -0.00428327; deltaZ[20] = -0.00602899;
// antTimeOffset[21] = 0.160323; deltaR[21] = -0.101956; deltaPhi[ 21] = -0.0151547; deltaZ[21] = 0.0514858;
// antTimeOffset[22] = 0.053953; deltaR[22] = -0.0773129; deltaPhi[ 22] = -0.00414444; deltaZ[22] = 0.0562807;
// antTimeOffset[23] = 0.00325878; deltaR[23] = -0.0378326; deltaPhi[ 23] = 0.000528826; deltaZ[23] = 0.0517299;
// antTimeOffset[24] = -0.0670197; deltaR[24] = -0.0225655; deltaPhi[ 24] = -0.00391848; deltaZ[24] = 0.0263552;
// antTimeOffset[25] = 0.0035097; deltaR[25] = -0.0427118; deltaPhi[ 25] = -0.00285503; deltaZ[25] = 0.0211308;
// antTimeOffset[26] = -0.0337735; deltaR[26] = -0.062921; deltaPhi[ 26] = -0.00747562; deltaZ[26] = -0.0138518;
// antTimeOffset[27] = -0.110361; deltaR[27] = -0.0144298; deltaPhi[ 27] = -0.0028118; deltaZ[27] = -0.0318333;
// antTimeOffset[28] = -0.227861; deltaR[28] = -0.0389804; deltaPhi[ 28] = -0.0012114; deltaZ[28] = -0.0674168;
// antTimeOffset[29] = -0.081439; deltaR[29] = -0.0449712; deltaPhi[ 29] = -0.00826954; deltaZ[29] = 0.00548985;
// antTimeOffset[30] = 0.17098; deltaR[30] = -0.0938958; deltaPhi[ 30] = -0.00969672; deltaZ[30] = 0.0597671;
// antTimeOffset[31] = 0.0258336; deltaR[31] = -0.052614; deltaPhi[ 31] = -0.000359792; deltaZ[31] = 0.044548;
// antTimeOffset[32] = -0.425254; deltaR[32] = -0.0372025; deltaPhi[ 32] = -0.00536103; deltaZ[32] = -0.0978299;
// antTimeOffset[33] = -0.440596; deltaR[33] = -0.0534945; deltaPhi[ 33] = -0.0144455; deltaZ[33] = -0.136331;
// antTimeOffset[34] = -0.256048; deltaR[34] = -0.0884831; deltaPhi[ 34] = -0.00580407; deltaZ[34] = -0.0676089;
// antTimeOffset[35] = -0.601107; deltaR[35] = 0.0224642; deltaPhi[ 35] = -0.00283517; deltaZ[35] = -0.115955;
// antTimeOffset[36] = -0.472965; deltaR[36] = 0.0023781; deltaPhi[ 36] = -0.00319073; deltaZ[36] = -0.049661;
// antTimeOffset[37] = -0.498374; deltaR[37] = -0.0241109; deltaPhi[ 37] = -0.0168551; deltaZ[37] = -0.102832;
// antTimeOffset[38] = -0.466373; deltaR[38] = -0.0623884; deltaPhi[ 38] = 0.00665517; deltaZ[38] = -0.131102;
// antTimeOffset[39] = -0.382128; deltaR[39] = -0.040161; deltaPhi[ 39] = 0.00508923; deltaZ[39] = -0.100047;

   AnitaGeomTool *fGeomTool = AnitaGeomTool::Instance();
   fGeomTool->useKurtAnitaIINumbers(1);
   char eventName[FILENAME_MAX];
   char headerName[FILENAME_MAX];
   char gpsName[FILENAME_MAX];
   char corrName[FILENAME_MAX];
   char outName[FILENAME_MAX];

   //   sprintf(baseDir,"http://www.hep.ucl.ac.uk/uhen/anita/private/monitor2/runs/fromLoki/");
   sprintf(eventName,"%s/run%d/eventFile%d.root",baseDir,run,run);
   sprintf(headerName,"%s/run%d/headFile%d.root",baseDir,run,run);
   sprintf(gpsName,"%s/run%d/gpsEvent%d.root",baseDir,run,run);
   sprintf(corrName,"%s/corRun%d.root",corTreeDir,run);
   sprintf(outName,"%s/deltaTFile%d.root",outputDir,run);

   
   RawAnitaHeader *header =0;
   Adu5Pat *pat =0;
   CorrelationSummary *corSum =0;
   
   
   TFile *fpHead = TFile::Open(headerName);
   TTree *headTree = (TTree*) fpHead->Get("headTree");
   headTree->SetBranchAddress("header",&header);
   headTree->BuildIndex("eventNumber");
   
   TFile *fpGps = TFile::Open(gpsName);
   TTree *adu5PatTree = (TTree*) fpGps->Get("adu5PatTree");
   adu5PatTree->BuildIndex("realTime");
   adu5PatTree->SetBranchAddress("pat",&pat);
   
   Int_t labChip;
   UInt_t expTaylorTime;
   TFile *fpCor = new TFile(corrName);
   TTree *corTree = (TTree*) fpCor->Get("corTree");
   corTree->SetBranchAddress("cor",&corSum);
   corTree->SetBranchAddress("labChip",&labChip);
   corTree->SetBranchAddress("expTaylorTime",&expTaylorTime);

   Long64_t numEntries=corTree->GetEntries();
   int counter=0;

   TFile *fpOut = new TFile(outName,"RECREATE");

   Long64_t entry=0;
   UInt_t eventNumber, triggerTime, triggerTimeNs;
   Int_t firstAnt,secondAnt,maxAnt,corInd;
   Double_t deltaT,deltaTExpected;
   Double_t phiWave, phiMaxAnt;
   Double_t thetaWave;
   Double_t corPeak, corRMS;
   Double_t balloonLat, balloonLon, balloonAlt;
   Double_t heading,pitch,roll;
   //   Double_t deltaZ;
   //   Double_t deltaR;
   Double_t meanPhiAntPair;
   Double_t deltaPhiAntPair;
   


   TTree *deltaTTree = new TTree("deltaTTree","Tree of Delta T's");
   deltaTTree->Branch("entry",&entry,"entry/L");
   deltaTTree->Branch("firstAnt",&firstAnt,"firstAnt/I");
   deltaTTree->Branch("secondAnt",&secondAnt,"secondAnt/I");
   deltaTTree->Branch("maxAnt",&maxAnt,"maxAnt/I");
   deltaTTree->Branch("labChip",&labChip,"labChip/I");
   deltaTTree->Branch("deltaT",&deltaT,"deltaT/D");
   deltaTTree->Branch("deltaTExpected",&deltaTExpected,"deltaTExpected/D");
   deltaTTree->Branch("corPeak",&corPeak,"corPeak/D");
   deltaTTree->Branch("corRMS",&corRMS,"corRMS/D");
   deltaTTree->Branch("phiMaxAnt",&phiMaxAnt,"phiMaxAnt/D");
   deltaTTree->Branch("phiWave",&phiWave,"phiWave/D");
   deltaTTree->Branch("thetaWave",&thetaWave,"thetaWave/D");
   deltaTTree->Branch("eventNumber",&eventNumber,"eventNumber/i");
   deltaTTree->Branch("triggerTime",&triggerTime,"triggerTime/i");
   deltaTTree->Branch("triggerTimeNs",&triggerTimeNs,"triggerTimeNs/i");
   deltaTTree->Branch("corInd",&corInd,"corInd/I");
   deltaTTree->Branch("balloonLat",&balloonLat,"balloonLat/D");
   deltaTTree->Branch("balloonLon",&balloonLon,"balloonLon/D");
   deltaTTree->Branch("balloonAlt",&balloonAlt,"balloonAlt/D");
   deltaTTree->Branch("heading",&heading,"heading/D");
   deltaTTree->Branch("pitch",&pitch,"pitch/D");
   deltaTTree->Branch("roll",&roll,"roll/D");
   //   deltaTTree->Branch("deltaZ",&deltaZ,"deltaZ/D");
   //   deltaTTree->Branch("deltaR",&deltaR,"deltaR/D");
   deltaTTree->Branch("meanPhiAntPair",&meanPhiAntPair,"meanPhiAntPair/D");
   deltaTTree->Branch("deltaPhiAntPair",&deltaPhiAntPair,"deltaPhiAntPair/D");
   deltaTTree->Branch("expTaylorTime",&expTaylorTime,"expTaylorTime/i");

  // Double_t thetaWave;

   for(entry=0;entry<numEntries;entry++) { 
  

      corTree->GetEntry(entry);
      Long64_t headEntry=headTree->GetEntryNumberWithIndex(corSum->eventNumber);
      if(headEntry<0) 
	continue;
      headTree->GetEntry(headEntry);
     
      // if(header->triggerTimeNs*1e-9< 0.097 || header->triggerTimeNs*1e-9>0.1)

      triggerTimeNs=header->triggerTimeNs;
      triggerTime=header->triggerTime;
      eventNumber=header->eventNumber;

      adu5PatTree->GetEntry(headEntry);
      
      
   // PrettyAnitaEvent realEvent(event,WaveCalType::kVTFullAGCrossCorClock,header);
      balloonLat=pat->latitude;
      balloonLon=pat->longitude;
      balloonAlt=pat->altitude;
      heading=pat->heading;
      pitch=pat->pitch;
      roll=pat->roll;

	//Simon 30/04/09 numbers     
      //      pat->pitch=0.64;
      //      pat->roll=0.14;


	//Simon 02/05/09 numbers     
      //      pat->pitch=0.76;
      //      pat->roll=0.13;

      //Test heading offset
      //      pat->heading+=0.19;
      //      if(pat->heading>=360) pat->heading-=360;
      //      if(pat->heading<0) pat->heading+=360;

     // 

      //      pat->pitch=0.5;
      //      pat->roll=-0.1;


      //Kurt numbers 
      pat->pitch=-0.29;
      pat->roll=0.89;
//       //Test heading offset
//      pat->heading-=0.32;
      if(pat->heading>=360) pat->heading-=360;
      if(pat->heading<0) pat->heading+=360;

      UsefulAdu5Pat usefulPat(pat);
     
      for(corInd=0;corInd<35;corInd++) {

	 firstAnt=corSum->firstAnt[corInd];
	 secondAnt=corSum->secondAnt[corInd];
	 deltaT=corSum->maxCorTimes[corInd];
	 maxAnt=corSum->centreAntenna;
	 phiMaxAnt=fGeomTool->getAntPhiPositionRelToAftFore(corSum->centreAntenna,AnitaPol::kHorizontal)*TMath::RadToDeg();
	 
	 //Default values
	 deltaTExpected=usefulPat.getDeltaTTaylor(corSum->firstAnt[corInd],corSum->secondAnt[corInd],AnitaPol::kHorizontal);
	 deltaTExpected=usefulPat.getDeltaTWillySeavey(corSum->firstAnt[corInd],corSum->secondAnt[corInd],AnitaPol::kHorizontal);

	 //These two lines are for use with Simon's array of numbers
	 //	 deltaTExpected=usefulPat.getDeltaTTaylorOpt(corSum->firstAnt[corInd],corSum->secondAnt[corInd],deltaR,deltaZ,deltaPhi);
	 //	 deltaT+=(antTimeOffset[firstAnt]-antTimeOffset[secondAnt]);



	 phiWave=usefulPat.getPhiWave();
	 thetaWave=usefulPat.getThetaWave();
	 corPeak=corSum->maxCorVals[corInd];
	 corRMS=corSum->rmsCorVals[corInd];
	 
	 meanPhiAntPair=fGeomTool->getMeanAntPairPhiRelToAftFore(firstAnt,secondAnt,AnitaPol::kHorizontal);
	 deltaPhiAntPair=fGeomTool->getPhiDiff(phiWave,meanPhiAntPair);//,AnitaPol::kHorizontal);
	 
	 //	 std::cout << phiWave << "\t" << meanPhiAntPair << "\t" << deltaPhiAntPair << "\n";

	 //Convert to degrees
	 deltaPhiAntPair*=TMath::RadToDeg();
	 phiWave*=TMath::RadToDeg();
	 thetaWave*=TMath::RadToDeg();	       

	 //Actually fill the tree
	 deltaTTree->Fill();
      }


      counter++; 
      if(counter%100==0)
	 cerr << "*";
   }
   deltaTTree->AutoSave();
   fpOut->Close();
   //   histSimpleDtDiff->Draw();
}
コード例 #6
0
ファイル: H4Reco.cpp プロジェクト: H4VFE/H4Analysis
//**********MAIN**************************************************************************
int main(int argc, char* argv[])
{
    if(argc < 2)
    {
        cout << argv[0] << " cfg file " << "[run]" << endl; 
        return -1;
    }

    //---memory consumption tracking---
    float cpu[2]{0}, mem[2]={0}, vsz[2]={0}, rss[2]={0};

    //---load options---    
    CfgManager opts;
    opts.ParseConfigFile(argv[1]);

    //-----input setup-----    
    if(argc > 2)
    {
        vector<string> run(1, argv[2]);
        opts.SetOpt("h4reco.run", run);
    }
    string outSuffix = opts.GetOpt<string>("h4reco.outNameSuffix");
    string run = opts.GetOpt<string>("h4reco.run");
    TChain* inTree = new TChain("H4tree");
    ReadInputFiles(opts, inTree);
    H4Tree h4Tree(inTree);

    //-----output setup-----
    uint64 index=stoul(run)*1e9;
    TFile* outROOT = new TFile("ntuples/"+outSuffix+TString(run)+".root", "RECREATE");
    outROOT->cd();
    RecoTree mainTree(&index);

    //---Get plugin sequence---
    PluginLoader<PluginBase>* loader;
    vector<PluginLoader<PluginBase>* > pluginLoaders;    
    map<string, PluginBase*> pluginMap;
    vector<PluginBase*> pluginSequence;
    vector<string> pluginList = opts.GetOpt<vector<string> >("h4reco.pluginList");    
    //---plugin creation
    pluginLoaders.reserve(pluginList.size());
    for(auto& plugin : pluginList)
    {
        cout << ">>> Loading plugin <" << plugin << ">" << endl;
        //---create loader 
        loader = new PluginLoader<PluginBase>(opts.GetOpt<string>(plugin+".pluginType"));
        pluginLoaders.push_back(loader);
        pluginLoaders.back()->Create();
        //---get instance and put it in the plugin sequence   
        PluginBase* newPlugin = pluginLoaders.back()->CreateInstance();
        if(newPlugin)
        {
            pluginSequence.push_back(newPlugin);
            pluginSequence.back()->SetInstanceName(plugin);
            pluginMap[plugin] = pluginSequence.back();
        }
        else
        {
            cout << ">>> ERROR: plugin type " << opts.GetOpt<string>(plugin+".pluginType") << " is not defined." << endl;
            return 0;
        }
    }

    //---begin
    for(auto& plugin : pluginSequence)
    {
        plugin->Begin(opts, &index);
        for(auto& shared : plugin->GetSharedData("", "TTree", true))
        {
            TTree* tree = (TTree*)shared.obj;
            tree->SetMaxVirtualSize(10000);
            tree->SetDirectory(outROOT);
        }
    }
            
    //---events loop
    int maxEvents=opts.GetOpt<int>("h4reco.maxEvents");
    cout << ">>> Processing H4DAQ run #" << run << " <<<" << endl;
    while(h4Tree.NextEntry() && (index-stoul(run)*1e9<maxEvents || maxEvents==-1))
    {
        if(index % 1000 == 0)
        {
            cout << ">>>Processed events: " << index-stoul(run)*1e9 << "/"
                 << (maxEvents<0 ? h4Tree.GetEntries() : min((int)h4Tree.GetEntries(), maxEvents))
                 << endl;
            TrackProcess(cpu, mem, vsz, rss);
        }

        //---call ProcessEvent for each plugin
        for(auto& plugin : pluginSequence)
            plugin->ProcessEvent(h4Tree, pluginMap, opts);

        //---fill the main tree with info variables and increase event counter
        mainTree.time_stamp = h4Tree.evtTimeStart;
        mainTree.run = h4Tree.runNumber;
        mainTree.spill = h4Tree.spillNumber;
        mainTree.event = h4Tree.evtNumber;
        mainTree.Fill();
        ++index;
    }

    //---end
    for(auto& plugin : pluginSequence)
    {
        //---call endjob for each plugin
        plugin->End(opts);
        //---get permanent data from each plugin and store them in the out file
        for(auto& shared : plugin->GetSharedData())
        {
            if(shared.obj->IsA()->GetName() == string("TTree"))
            {
                TTree* currentTree = (TTree*)shared.obj;
                outROOT->cd();
                currentTree->BuildIndex("index");
                currentTree->Write(currentTree->GetName(), TObject::kOverwrite);
                mainTree.AddFriend(currentTree->GetName());
            }
            else
            {
                outROOT->cd();
                shared.obj->Write(shared.tag.c_str(), TObject::kOverwrite);
            }
        }
    }
    
    //---close
    mainTree.Write();
    opts.Write("cfg");
    outROOT->Close();
    for(auto& loader : pluginLoaders)
        loader->Destroy();

    //---info
    TrackProcess(cpu, mem, vsz, rss);

    exit(0);
}    
コード例 #7
0
double thetaOpt2(double *par){

  int upperAntNums[NUM_PHI]={8,0,9,1,10,2,11,3,12,4,13,5,14,6,15,7};
  int lowerAntNums[NUM_PHI]={16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
  int lowerAntFromUpper[NUM_PHI]={17,19,21,23,25,27,29,31,16,18,20,22,24,26,28,30};
  int nadirAntNums[NUM_PHI]={32,-1,33,-1,34,-1,35,-1,36,-1,37,-1,38,-1,39,-1};
  int bottomFromNadir[8]={16,18,20,22,24,26,28,30};

  Double_t deltaR[40]={0};  
  Double_t deltaZ[40]={0};  
  Double_t deltaPhi[40]={0};  
  Double_t deltaHeading[1]={0};
  double  deltaTArrayMod[40]={0};
 
 int count3 = 0;


//   for(int i = 0; i<32;i++){
//     deltaR[i]=par[i];   
//     deltaZ[i]=par[i+32];
//     deltaPhi[i]=par[i+64];

//     cout << i << "  " <<0 << " " << deltaR[i] << " " << deltaPhi[i] << " " << deltaZ[i] << endl;

//   }

  for(int i = 7; i<8;i++){
    deltaR[7]=par[0];   
    deltaZ[7]=par[1];
    deltaPhi[7]=par[2];

    cout << i << "  " <<0 << " " << deltaR[i] << " " << deltaPhi[i] << " " << deltaZ[i] << endl;

  }


  // for(int i = 0; i<16;i++){
  //  deltaPhi[i]=deltaPhi[i] + par[16]; 
  //  deltaPhi[i+16]=deltaPhi[i+16] + par[17];     
  // }

  double theReturn = 0;
  double sumMean = 0;
  double sumMean2 = 0;
  int count8 = 0;
  double sumGrads = 0;

  TMultiGraph *myMG = new TMultiGraph;
  TMultiGraph *myMG3 = new TMultiGraph;
  TMultiGraph *myMG2 = new TMultiGraph;;

  AnitaGeomTool *fGeomTool = AnitaGeomTool::Instance();
  char eventName[FILENAME_MAX];
  char headerName[FILENAME_MAX];
  char hkName[FILENAME_MAX];
  char gpsName[FILENAME_MAX];
  char corrName[FILENAME_MAX];
  char outName[FILENAME_MAX];
  char baseDir[FILENAME_MAX];
  char *corTreeDir = "../../../Outfiles";
  double dummyArray[40][1] ={{0}}; 
  TGraph *tempAntGraph;

  vector<vector<double> > phiAngle;
  vector<vector<double> > deltaTVec;
  vector<vector<int> > firstAntVec;
  vector<vector<int> > secondAntVec;

  vector<vector<double> > phiAngleArray2;
  vector<vector<double> > deltaTArray2;

  vector<double> temp;
  vector<int> temp2;
  temp.push_back(0);
  temp2.push_back(0);

  double deltaTArrayLoop[6000] ={0};
  double phiAngleArrayLoop[6000] = {0};


  int leftOpt, rightOpt;


  double meanPhi[40] = {0}; 
  meanPhi[0] =22.5-12.5;
  meanPhi[1] =67.5-12.5;
  meanPhi[2] =112.5-12.5;
  meanPhi[3] =157.5-12.5;
  meanPhi[4] =202.5-12.5;
  meanPhi[5] =247.5-12.5;
  meanPhi[6] =292.5-12.5;
  meanPhi[7] =337.5-12.5;
  meanPhi[8] =45-12.5;
  meanPhi[9] =90-12.5;
  meanPhi[10] =135-12.5;
  meanPhi[11] =180-12.5;
  meanPhi[12] =225-12.5;
  meanPhi[13] =270-12.5;
  meanPhi[14] =315-12.5;
  meanPhi[15] =360-12.5;

  meanPhi[16] = 22.5-12.5;
  meanPhi[17] = 45-12.5;
  meanPhi[18] = 67.5-12.5;
  meanPhi[19] = 90-12.5;
  meanPhi[20] = 112.5-12.5;
  meanPhi[21] = 135-12.5;
  meanPhi[22] = 157.5-12.5;
  meanPhi[23] = 180-12.5;
  meanPhi[24] = 202.5-12.5;
  meanPhi[25] = 225-12.5;
  meanPhi[26] = 247.5-12.5;
  meanPhi[27] = 270-12.5;
  meanPhi[28] = 292.5-12.5;
  meanPhi[29] = 315-12.5;
  meanPhi[30] = 337.5-12.5;
  meanPhi[31] = 360-12.5;


  meanPhi[32] = 22.5-12.5;
  meanPhi[33] = 67.5-12.5;
  meanPhi[34] = 112.5-12.5;
  meanPhi[35] = 157.5-12.5;
  meanPhi[36] = 202.5-12.5;
  meanPhi[37] = 247.5-12.5;
  meanPhi[38] = 292.5-12.5;
  meanPhi[39] = 337.5-12.5;

  for(int i =0; i < 40; i++){
    phiAngleArray2.push_back(temp);
    deltaTArray2.push_back(temp);

  }

  for(int loop = 1; loop <4; loop++){
    int run = 16+loop;
    //int run = 18;

    canSurf->cd(loop+1);

    phiAngle.clear();
    deltaTVec.clear();
    firstAntVec.clear();
    secondAntVec.clear();

    for(int i = 0; i < 40; i++){
      phiAngle.push_back(temp);
      deltaTVec.push_back(temp);
      firstAntVec.push_back(temp2);
      secondAntVec.push_back(temp2);
    }

    //sprintf(baseDir,"http://www.hep.ucl.ac.uk/uhen/anita/private/monitor2/runs/fromLoki/");
    sprintf(baseDir,"/Users/simonbevan/Desktop/");
    sprintf(eventName,"%s/run%d/eventFile%d.root",baseDir,run,run);
    sprintf(headerName,"%s/run%d/headFile%d.root",baseDir,run,run);
    sprintf(gpsName,"%s/run%d/gpsFile%d.root",baseDir,run,run);
    sprintf(corrName,"%s/corRun%d.root",corTreeDir,run);

   
    RawAnitaEvent *event = 0;
    PrettyAnitaHk *hk = 0;
   
    RawAnitaHeader *header =0;
    Adu5Pat *pat =0;
    CorrelationSummary *corSum =0;
   
  
    TFile *fpHead = TFile::Open(headerName);
    TTree *headTree = (TTree*) fpHead->Get("headTree");
    headTree->SetBranchAddress("header",&header);
    headTree->BuildIndex("eventNumber");
   
    TFile *fpGps = TFile::Open(gpsName);
    TTree *adu5PatTree = (TTree*) fpGps->Get("adu5PatTree");
    adu5PatTree->BuildIndex("realTime");
    adu5PatTree->SetBranchAddress("pat",&pat);
   
    Int_t labChip;
    TFile *fpCor = new TFile(corrName);
    TTree *corTree = (TTree*) fpCor->Get("corTree");
    corTree->SetBranchAddress("cor",&corSum);
    corTree->SetBranchAddress("labChip",&labChip);

    Long64_t numEntries=corTree->GetEntries();
    int counter=0;

    Long64_t entry=0;
    UInt_t eventNumber, triggerTime, triggerTimeNs;
    Int_t firstAnt,secondAnt,maxAnt,corInd;
    Double_t deltaT,deltaTExpected;
    Double_t phiWave, phiMaxAnt;
    Double_t corPeak, corRMS;
    Double_t balloonLat, balloonLon, balloonAlt;
    Double_t heading,pitch,roll;
  

    Double_t thetaWave;

    for(entry=0;entry<numEntries;entry++) {

      corTree->GetEntry(entry);
      Long64_t headEntry=headTree->GetEntryNumberWithIndex(corSum->eventNumber);
      if(headEntry<0) 
	continue;
      headTree->GetEntry(headEntry);
     
      if( (header->triggerTimeNs>0.5e6) || (header->triggerTimeNs<0.2e6) )  
	continue; 

      triggerTimeNs=header->triggerTimeNs;
      triggerTime=header->triggerTime;
      eventNumber=header->eventNumber;
  

      Long64_t bestEntry = adu5PatTree->GetEntryNumberWithBestIndex(header->triggerTime);
      if(bestEntry>-1) 
	adu5PatTree->GetEntry(bestEntry);
      else 
	continue;
      
      balloonLat=pat->latitude;
      balloonLon=pat->longitude;
      balloonAlt=pat->altitude;
      heading=pat->heading;
      pat->pitch=0.64;
      pat->roll=0.14;

      pitch=pat->pitch;
      roll=pat->roll;

      UsefulAdu5Pat usefulPat(pat);
      
      for(corInd=0;corInd<19;corInd++) {
	
	firstAnt=corSum->firstAnt[corInd];
	secondAnt=corSum->secondAnt[corInd];

	//replace taylor dome
	
	usefulPat.fSourceLongitude=0;
	//	deltaTExpected=usefulPat.getDeltaTTaylor(corSum->firstAnt[corInd],corSum->secondAnt[corInd]);
	deltaTExpected=usefulPat.getDeltaTTaylorOpt(corSum->firstAnt[corInd],corSum->secondAnt[corInd],deltaR,deltaZ,deltaPhi);
	
	deltaT=corSum->maxCorTimes[corInd];
	maxAnt=corSum->centreAntenna;
	phiWave=usefulPat.getPhiWave()*TMath::RadToDeg();
	phiMaxAnt=fGeomTool->getAntPhiPositionRelToAftFore(corSum->centreAntenna)*TMath::RadToDeg();
	corPeak=corSum->maxCorVals[corInd];
	corRMS=corSum->rmsCorVals[corInd];

	if((deltaT - deltaTExpected)*(deltaT - deltaTExpected) < 1 && (corPeak/corRMS)>8 ){
	  phiAngle[0].push_back(phiWave);
	  deltaTVec[0].push_back(deltaT - deltaTExpected + deltaTArrayMod[firstAnt] - deltaTArrayMod[secondAnt]);
	  firstAntVec[0].push_back(firstAnt);
	  secondAntVec[0].push_back(secondAnt);  
	}
      }

      counter++; 
    
    }

 

    double deltaTArray[40][3000] = {{0}};
    double phiAngleArray[40][3000]= {{0}};

    double deltaTArrayCut[40][3000]= {{0}};
    double phiAngleArrayCut[40][3000]= {{0}};
    int whichCut[40][3000] = {{0}};

    int middleAnt; 
    int leftAnt,rightAnt;

    int countArray[40] = {0};





    //fill arrays
    //for(int ants = par[0]; ants < par[0]+1; ants++){
    for(int ants = 0; ants < 32; ants++){

      double lower  = meanPhi[ants] - 20;
      double upper = meanPhi[ants] + 10;
      //	double lower  = 0;
      //  	double upper = 360;


	     if(ants<8){
	lower = lower;
	upper=upper;

	if(lower < 0){
	  lower = 0;
	  upper = 20;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }else if(ants<16){
	       	lower = lower;
	       upper= upper;
	if(lower < 0){
	  lower = 330;
	  upper = 355;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }




      int count = 0;
      int count2 = 0;
       count3 = 0;
      double sumPhi = 0;
      bool true1 = false;
      bool true2 = false;

      if(ants <32){
	fGeomTool->getThetaPartners(ants,leftAnt,rightAnt); 
      }else{
	leftAnt = ants;
	rightAnt = ants +1;
	if(ants == 39){
	  leftAnt = ants;
	  rightAnt = 32;
	}
      }    

      for(int events = 1; events < phiAngle[0].size(); events++){
	int firstAntTemp = (int)firstAntVec[0][events];
	int secondAntTemp = (int)secondAntVec[0][events];
	int rightTemp = int(rightAnt);

	int aboveTemp = 0;

	if(ants <16){
	  aboveTemp = lowerAntFromUpper[ants];
	}else{
	  aboveTemp = upperAntNums[ants-16];
	}
  
	if(firstAntTemp < 32){
      
 	  if( ((firstAntTemp == ants) &&  (secondAntTemp == rightTemp))){
	    //if((firstAntTemp == ants) &&  (secondAntTemp == rightTemp)){
	    if((phiAngle[0][events] > lower ) && (phiAngle[0][events]< upper)){
 	    deltaTArray[ants][count] = deltaTVec[0][events];
 	    phiAngleArray[ants][count] = phiAngle[0][events];
 	    whichCut[ants][count] = 1; 

	    count++;
	     }


	  } else if(((firstAntTemp == ants) &&  (secondAntTemp == aboveTemp))){
// 	    //if((firstAntTemp == ants) &&  (secondAntTemp == rightTemp)){

      double lower  = meanPhi[ants] - 20;
      double upper = meanPhi[ants] + 10;
      //	double lower  = 0;
      //  	double upper = 360;


	     if(ants<8){
	lower = lower;
	upper=upper;

	if(lower < 0){
	  lower = 0;
	  upper = 20;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }else if(ants<16){
	       	lower = lower - 45;
	       upper= upper - 45;
	if(lower < 0){
	  lower = 330;
	  upper = 355;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }



	    //    if((phiAngleArray[ants][events] > lower ) && (phiAngleArray[ants][events]< upper)){
	  if((phiAngle[0][events] > lower ) && (phiAngle[0][events]< upper)){
	    deltaTArray[ants][count] = deltaTVec[0][events];
	      phiAngleArray[ants][count] = phiAngle[0][events];
	      whichCut[ants][count] = 0; 

	      count++;   
	      }
	  }
 
	}else{
      
	  rightTemp = firstAntTemp+1;
	  if(rightTemp>39){
	    rightTemp = 32;
	  }
      
	  if(firstAntTemp == ants){
	
	  }
      
	  if((firstAntTemp == ants) &&  (secondAntTemp == rightTemp)){
		
	    deltaTArray[ants][count] = deltaTVec[0][events];
	    phiAngleArray[ants][count] = phiAngle[0][events];
	whichCut[ants][count] = 3; 
	    count++;
	  }
	}
    
    
      }
      countArray[ants] = count;
      
  
    }
    
    
    //make cuts
    for(int ants = 0; ants < 32; ants++){
   
       count3 = 0;
      if(ants <32){
	fGeomTool->getThetaPartners(ants,leftAnt,rightAnt); 
      }else{
	leftAnt = ants -1;
	rightAnt = ants +1;
	if(ants == 39){
	  leftAnt = ants - 1;
	  rightAnt = 32;
	}
      }    

      double sumPhi = 0;
    double   lower  = meanPhi[ants] - 20;
    double   upper = meanPhi[ants] + 10;
      //	double lower  = 0;
      //   	double upper = 360;


 

	     if(ants<8){
	lower = lower;
	upper=upper;

	if(lower < 0){
	  lower = 0;
	  upper = 20;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }else if(ants<16){
	       	lower = lower;
	       upper= upper;
	if(lower < 0){
	  lower = 330;
	  upper = 355;
	}

	if(upper > 360){
	  lower = 330;
	  upper = 360;
	}

      }


      for(int events = 0; events < countArray[ants]; events++){
	  
 
// 	if(whichCut[ants][events]==1){
//      lower  = meanPhi[ants] - 20;
//       upper = meanPhi[ants] + 20;
// 		if(lower < 0){
// 	  lower = 0;
// 	  upper = 20;
// 	}

// 	if(upper > 360){
// 	  lower = 330;
// 	  upper = 360;
// 	}



// 	}

//	if((phiAngleArray[ants][events] > lower ) && (phiAngleArray[ants][events]< upper)){
	  phiAngleArrayCut[ants][count3] = phiAngleArray[ants][events];
	  deltaTArrayCut[ants][count3] = deltaTArray[ants][events];
	    
	  	  count3++;
	      
		  //		  	}

      }
	
      for(int events = 0; events < count3-1; events++){
	phiAngleArray2[ants].push_back(phiAngleArrayCut[ants][events]);
	deltaTArray2[ants].push_back(deltaTArrayCut[ants][events]);
      }

	
    }
    
    delete event;
    delete hk; 
    delete header;
    delete pat;
    delete corSum;

    delete fpHead;
    delete fpGps ;
    delete fpCor;

  }

  sumMean = 0;
  sumMean2 = 0;
  sumGrads = 0;
  for(int ants = 0; ants < 32; ants++){
    count8 = 0;
    for(int events = 1; events < phiAngleArray2[ants].size(); events++){

      if( deltaTArrayLoop[count8]<1){      
	deltaTArrayLoop[count8] = deltaTArray2[ants][events];
	phiAngleArrayLoop[count8] = phiAngleArray2[ants][events];
	count8++;
      }
      
    }
    
    if(count8==0){
      tempAntGraph  = new TGraph(1, dummyArray[ants], dummyArray[ants]);
    }else{
      
      tempAntGraph  = new TGraph(count8-1,  phiAngleArrayLoop, deltaTArrayLoop);
      
      if(ants == 7){  
	
	canSurf->cd(1);
	
	tempAntGraph->SetMinimum(-0.5);
	tempAntGraph->SetMaximum(0.5);
	tempAntGraph->Draw("ap");    

	tempAntGraph->SetMarkerStyle(1);
	tempAntGraph->GetXaxis()->SetLimits(0,360);
    
	sumMean = sumMean + tempAntGraph->GetMean(2)*tempAntGraph->GetMean(2);

	if(ants == 8 || ants == 16 || ants == 12 || ants == 24){
	  tempAntGraph->SetMarkerColor(8);
	}

	if(ants == 3 || ants == 7 || ants == 23 || ants == 31){
	  tempAntGraph->SetMarkerColor(1);
	}
    
	if(ants == 9 || ants == 13 || ants == 18 || ants == 26){
	  tempAntGraph->SetMarkerColor(2);
	}
    
    
	if(ants == 10 || ants == 14 || ants == 20 || ants == 28){
	  tempAntGraph->SetMarkerColor(3);
	}
    
	if(ants == 11 || ants == 15 || ants == 22 || ants == 30){
	  tempAntGraph->SetMarkerColor(4);
	}
    
	if(ants == 0 || ants == 4 || ants == 17 || ants == 25){
	  tempAntGraph->SetMarkerColor(5);
	}


	if(ants == 2 || ants == 6 || ants == 21 || ants == 29){
	  tempAntGraph->SetMarkerColor(6);
	}

	if(ants == 1 || ants == 5 || ants == 19 || ants == 27){
	  tempAntGraph->SetMarkerColor(7);
	}
    
	tempAntGraph->GetXaxis()->SetTitle("phi (degrees)");
	tempAntGraph->GetYaxis()->SetTitle("actual - expected time");
	myMG2->Add(tempAntGraph);
	myMG2->Draw("p");
	
 	vector<double> myFit = leastSquares(phiAngleArrayLoop, deltaTArrayLoop, count8-1);
	double slope = myFit[0];
	double intercept = myFit[1];
	
	double tempX[2] = {slope*(meanPhi[ants]-20)+intercept,slope*(meanPhi[ants]+20)+intercept};
	double tempY[2] = {(meanPhi[ants]-20),(meanPhi[ants]+20)};
	sumGrads = sumGrads + myFit[0]*myFit[0]*10000;
      
      }
    } 
    

  }
  
  cout << " " << endl;
  cout << sumMean << "  " << sumGrads <<endl;
  canSurf->Update();
  cout << "  " << endl;  

  theReturn = sumMean+sumGrads;

  return theReturn;
   
}
コード例 #8
0
// provide either a root file or text file with root file paths
int createTrainingTree(TString infile, TString outfile)
{
    //static
    // initialize variables for filling struct 
    Float_t fEnergyGeV, fPrimaryZenithDeg, fPrimaryAzimuthDeg, fLength, fWidth, fSize, fDist, fTimeGradient, fLoss;
    triggeredSimEvent trigSimEvent = triggeredSimEvent(); // for writing 

    // for branch, if type is other than float, need to specify types with varname/F, for example
    const char* leafList = "fEnergyGeV:fLength:fWidth:fSize";
    //:fPrimaryZenithDeg:fPrimaryAzimuthDeg:fTimeGradient:fLoss:fDist
    
    // quality cuts 
    int NTubesMin = 5; // default in VEGAS 
    float distanceUpper = 1.38; // 1.43 [degrees]

    
    // create output file for writing new branch
    TFile hfile(outfile,"RECREATE","simplified ROOT file with single branch structure for training on simulated events");

    // Create a ROOT Tree
    TTree *trainTree = new TTree("Training","ROOT tree with single training branch");
    //trainTree->Branch("triggeredSimEvent", &trigSimEvent, leafList);
    trainTree->Branch("fEnergyGeV", &fEnergyGeV, "fEnergyGeV");
    trainTree->Branch("fLength", &fLength, "fLength");
    trainTree->Branch("fWidth", &fWidth, "fWidth");
    trainTree->Branch("fSize", &fSize, "fSize");
    trainTree->Branch("fDist", &fDist, "fDist");
    trainTree->Branch("fLoss", &fLoss, "fLoss");
    trainTree->Branch("fTimeGradient", &fTimeGradient, "fTimeGradient");
    trainTree->Branch("fPrimaryAzimuthDeg", &fPrimaryAzimuthDeg, "fPrimaryAzimuthDeg");
    // should make 4 branches for each telescope 
    //noise parameter (same as when producing tables)
    
    
    //// set up input to connect simulated events to shower events /////
    
    // open input file for reading only
    VARootIO* pfRootIO = new VARootIO(string(infile.Data()), true); 

    pfRootIO->loadTheRootFile();
    if(!pfRootIO->IsOpen())
        {
            cerr << "Couldn't open " << infile << endl;
	    return 1;
        }

    // parameterised event data holds shower params for each telescope 
    VAParameterisedEventData* paramData = nullptr;
    TTree* paramEventsTree = pfRootIO->loadTheParameterisedEventTree();
    paramEventsTree->SetBranchAddress("P", &paramData);
    //vector<VAParameterisedEventTelData*> vfTels
    //VAHillasData*           pfHillasData;

    // get the simulation tree for true energy, etc. 
    TTree* simTree = pfRootIO->loadTheSimulationEventTree();    
    VASimulationData* simData = nullptr;
    simTree->SetBranchAddress("Sim", &simData);

    // check for trees and branches 
    if(!paramEventsTree)
      {
	  cerr << "Couldn't get a pointer to the shower tree" << endl;
	  return 1;
      }
    if(!simTree)
      {
	  cerr << "Couldn't get a pointer to the simulation tree" << endl;
	  return 1;
      }
    if(!simTree->GetBranch(gSimulatedEventsBranchName.c_str()))
	{
	    cerr << "Couldn't find a branch called " << gSimulatedEventsBranchName << endl;
	    return false;
	}

    
    cout << "simulated events: " << simTree->GetEntries() << endl;
    cout << "parameterised events: " << paramEventsTree->GetEntries() << endl;

    cout << "Building simulation index" << endl;
    paramEventsTree->BuildIndex("fRunNum", "fArrayEventNum");    
    //paramEventsTree->BuildIndex("P.fRunNum", "P.fArrayEventNum");
    //simTree->BuildIndex("fRunNum", "fArrayEventNum");
    cout << "done" << endl;
    

    // now loop over all entries 
    unsigned long long int simEntries = simTree->GetEntries();    
    for(unsigned long long int i = 0; i < simEntries; i++)
      {
	  if(simTree->GetEntry(i) <= 0)
	    {
		cerr << "could not get entry " << i <<endl;
		return 1;
	    }

	  if(i%1000000 == 0)
	  {
	      cout << "event\t" << i <<endl;
	  }
	  
	  // check simData is not null and generated an array event 
	  if(simData && simData->fTriggeredArray) 
	    {
		// 
		Long64_t stereoEntryNumber = paramEventsTree->
		    GetEntryWithIndex(simData->fRunNum, simData->fArrayEventNum);

		// ensure shower event is valid 
		if(stereoEntryNumber >= 0 && paramData) 
		  {

		      //VAParameterisedEventTelData* = paramData->
		      VAHillasData* hillasData = paramData->vfTels.at(0)->pfHillasData;

		      // check quality (cuts) 
		      if(hillasData->fGoodImage
			 && hillasData->fPixelsInImage >= NTubesMin
			 && hillasData->fDist <= distanceUpper){ // && NTubes >= NTubesMin, DistanceUpper

			  // now set the appropriate values in the struct before filling tree
			  fLength = hillasData->fLength;
			  fWidth = hillasData->fWidth;
			  fSize = hillasData->fSize;
			  fTimeGradient = hillasData->fTimeGradient;
			  fLoss = hillasData->fLoss;
			  fDist = hillasData->fDist;
			  
			  // energy needs to come from simulated event
			  fEnergyGeV = simData->fEnergyGeV;

			  // direction 
			  fPrimaryAzimuthDeg = simData->fPrimaryAzimuthDeg;
			  fPrimaryZenithDeg = simData->fPrimaryZenithDeg;

		      } // if telescope image is good 

		      // write the event to the tree in new branch 
		      trainTree->Fill();
		      
		      /*
			uint32_t    fRunNum; //The number of the run - important when many runs get
			//combined since the fEventIndex and fArrayEventNum
			//will no longer be unique
			uint32_t    fArrayEventNum;//Event number - unique for single run only.

			double      fOriginRA;     //Ra and Dec of center of camera at event time.
			double      fOriginDec;    //In radians
			double      fOriginElevationRad; //Elevation of the camera center at event time
			double      fOriginAzimuthRad; //Azimuth of the camera center at event time
			uint16_t    fTelId;         //Telescope ID (node # T1=0)this telescope event
			
			double      fXO;       //X in cameraplane(deg) of assumed source position
			double      fYO;       //Y in cameraplane(deg) of assumed source position
			// Used to recenter camera plane to
			// Field-of-view(FOV) where XO,YO is now 0,0 in fov
			double      fXC;           //X in FOV(deg) of centroid location
			double      fYC;           //Y in FOV(deg) of centroid location

			double      fCosPsi;        //Direction cosigns of major axis
			double      fSinPsi;
			double      fAsymmetry;     //Asymmetry along major axis
			double      fMinorAsymmetry;//Asymmetry along minor axis
			VAEventType fTriggerCode;
			bool        fGoodImage;    //Flag that this image can be analyized(size>0)
			bool        fIsL2Triggered;//Flag that this telescope had an L2 trigger

		      */

		  } // successfully got param data entry corresponding to triggered sim event 
	    } // successfully got sim data that triggered array 
      }	// for loop over entries in simulation tree 

    // write all (branches) to this file 
    hfile.Write();
    cout << "tree written to file! " << outfile <<endl;
    
    hfile.Close();
    //pfRootIO->Close();
    //delete VASimulationData();

    return 0; // great job!
} // createTrainingTree
コード例 #9
0
ファイル: main.C プロジェクト: chnzhangrui/WtAna
void calculateEff(int nArguments) {
	string configSysName = Form("share/file.txt");
	ifstream configSystematic(configSysName.c_str());
	vector<string> fileNames;
	vector<string> treeNames;
	string fileName, treeName;
	while (!configSystematic.eof()) {
		configSystematic >> fileName >> treeName;
		if ((fileName.compare(0, 1, "#") == 0))
			continue;

		if (!configSystematic.good())
			break;

		fileNames.push_back(fileName);
		treeNames.push_back(treeName);
	}
	ofstream fout;
	fout.open("share/table.txt");
	fout << left << setw(60) << "#Systematics" << "\t\t" << setw(25) << "purity(corr,rec)(B/A+B)" << "\t\t" << setw(25) << "accept(corr,fid)(B/B'+C)" << "\t\t" << setw(25) << "eff_{fid}=a/p"
			<< setw(25) << "N_{fid}" << setw(25) << "N_{gen}" << endl;
	for (int iSys = 0; iSys < fileNames.size(); ++iSys) {
		bool c_debug(false);

		if (nArguments > 2) {
			cerr << "\n\t[INFO]\t" << "* * * main applyFiducialCut starts * * *" << endl;
			applyFiducialCut(fileNames.at(iSys).c_str());
			cerr << "\n\t[INFO]\t" << "* * * main applyFiducialCut finishes * * *" << endl;
		} else {
			cerr << "\n\t[INFO]\t" << "* * * main SKIP applyFiducialCut * * *" << endl;
		}

		/* nominal Trees */
		TFile* nominalFile = new TFile("../data/2016-04-05/reprocess/reprocess_1j1b_v11_20160405.root");
		TTree *nominalTree = (TTree*) nominalFile->Get(treeNames.at(iSys).c_str());
		cerr << "\t[INFO]\t" << "Reco  Tree " << nominalTree->GetName() << " " << nominalTree->GetEntries() << endl;
		TFile* particleFile = new TFile(Form("root/fiducialRegion_%s.root", fileNames.at(iSys).c_str()));
		TTree* particleTree = (TTree*) particleFile->Get("particleLevel");
		cerr << "\t[INFO]\t" << "Truth Tree " << particleTree->GetName() << " " << particleTree->GetEntries() << endl;

		Int_t runRecNominal;
		Int_t eventRecNominal;
		Float_t EventWeight, EventWeight_noPU, weight_leptonSF, weight_bTagSF_77, mc_weight;

		nominalTree->SetBranchAddress("mcChannelNumber", &runRecNominal);
		nominalTree->SetBranchAddress("EventNumber", &eventRecNominal);
		nominalTree->SetBranchAddress("EventWeight_noPU", &EventWeight_noPU);
		nominalTree->SetBranchAddress("EventWeight", &EventWeight);
		nominalTree->SetBranchAddress("weight_leptonSF", &weight_leptonSF);
		nominalTree->SetBranchAddress("weight_bTagSF_77", &weight_bTagSF_77);
		nominalTree->SetBranchAddress("weight_mc", &mc_weight);

		UInt_t runParticle;
		ULong64_t eventParticle;
		Float_t weight_mc;
		particleTree->SetBranchAddress("mcChannelNumber", &runParticle);
		particleTree->SetBranchAddress("eventNumber", &eventParticle);
		particleTree->SetBranchAddress("weight_mc", &weight_mc);

		/************/
		/* counting */
		/************/

		/* build particleTree index */
		particleTree->BuildIndex("mcChannelNumber", "eventNumber");
		nominalTree->BuildIndex("mcChannelNumber", "EventNumber");

		double totalEventWeight(0.), totalOverlapEventWeight(0.), totalOverlapweight_mc(0.), totalweight_mc(0.), totalOverlapmc_weight(0.);
		double ExperimentalWeight(0.);
		ofstream bugstr;
		if (c_debug)
			bugstr.open("share/bug.log");
		bool useWeight(true);
		for (Long64_t ievt = 0; ievt < (c_debug ? 10 : nominalTree->GetEntries()); ievt++) {
			nominalTree->GetEntry(ievt);
			ExperimentalWeight = (EventWeight_noPU == 0) ? 0 : (EventWeight / EventWeight_noPU) * weight_leptonSF * weight_bTagSF_77 * mc_weight;
			totalEventWeight += useWeight ? ExperimentalWeight : 1; // A+B
			if (particleTree->GetEntryWithIndex(runRecNominal, eventRecNominal) > 0) {
				totalOverlapEventWeight += useWeight ? ExperimentalWeight : 1; // B
				totalOverlapmc_weight += useWeight ? mc_weight : 1;
				if (c_debug)
					bugstr << "recon matched " << runRecNominal << " " << eventRecNominal << " totalOverlapmc_weight=" << totalOverlapmc_weight << endl;
			} else {
				if (c_debug)
					bugstr << "recon notmatc " << runRecNominal << " " << eventRecNominal << " totalOverlapmc_weight=" << totalOverlapmc_weight << endl;
			}
		}
		int dupl(0);
		vector<int> duplevts;
		ifstream ifile(Form("share/%s.overlap.dupEvt", fileNames.at(iSys).c_str()));
		if (ifile) {
			int evt;
			while (!ifile.eof()) {
				ifile >> evt;
				if (!ifile.good())
					break;
				duplevts.push_back(evt);
			}
		}
		for (Long64_t ievt = 0; ievt < (c_debug ? 10 : particleTree->GetEntries()); ievt++) {
			particleTree->GetEntry(ievt);
			totalweight_mc += useWeight ? weight_mc : 1; // B'+C
			if (nominalTree->GetEntryWithIndex(runParticle, eventParticle) > 0) {
				for (int id = 0; id < duplevts.size(); ++id) {
					if (eventParticle == duplevts.at(id)) {
						dupl++;
						cerr << "\t[WARNING]\t" << "duplicated evt No. " << eventParticle << ". But still counted." << endl;
						duplevts.erase(duplevts.begin() + id);
					}
				}

				totalOverlapweight_mc += useWeight ? weight_mc : 1; // B'
				if (c_debug)
					bugstr << "truth matched " << runParticle << " " << eventParticle << " totalOverlapweight_mc=" << totalOverlapweight_mc << endl;
			} else {
				if (c_debug)
					bugstr << "truth notmatc " << runParticle << " " << eventParticle << " totalOverlapweight_mc=" << totalOverlapweight_mc << endl;
			}
		}

		/* Make sure overlap events are the same */
		assert(fabs(totalOverlapmc_weight - totalOverlapweight_mc) < dupl + 0.001);

		double purity = totalOverlapEventWeight / totalEventWeight;
		double accept = totalOverlapEventWeight / totalweight_mc;
		cerr << "\n\t[INFO]\t" << "* * * * * * * * * * * * * * * * * * * * * * * * ";
		cerr << "\n\t[INFO]\t" << "* * * prime(') stands for weight_mc * * * * * * ";
		cerr << "\n\t[INFO]\t" << "* * * reconstructed events (A + B)  " << totalEventWeight << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * fiducial      events (B'+ C)  " << totalweight_mc << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * overlapped    events (B)    " << totalOverlapEventWeight << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * overlapped    events (B')   " << totalOverlapweight_mc << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * purity (corr, rec)  (B / A+B ) " << purity << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * accept (corr, fid)  (B / B'+C) " << accept << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * eff_{fid}             " << accept / purity << " * * *";
		cerr << "\n\t[INFO]\t" << "* * * * * * * * * * * * * * * * * * * * * * * * \n";
		cerr << "\033[1;31m\n\t[INFO]\t" << iSys << "/" << treeNames.size() << ")\t" << treeNames.at(iSys) << "\t\t" << purity << "\t\t" << accept << "\t\t" << purity / accept << "\t\t"
				<< totalweight_mc << "\033[0m" << endl;
		fout << left << setw(60) << treeNames.at(iSys) << "\t\t" << setw(25) << purity << "\t\t" << setw(25) << accept << "\t\t" << setw(25) << accept / purity << setw(25) << totalweight_mc << endl;
	}
	return;
}
コード例 #10
0
ファイル: qaTrending.C プロジェクト: ktf/AliPhysics
TTree * InitTrees(const char * detector,  const char *referenceDet){
  //
  // Init tree for given period
  //  all  trees stored in qaMap
  //  FriendTree added to the master treeQADet
  // Currentrly in the code we assume ID="run";
  // Bug in root tree ?  - in case more than one friend tree set - indeces looks corrupted 
  //    0.) QA tree per detector Raw+MC (if exist)
  //    1.) QA trees per refernce detectors specified by string refDet e.g "TPC;TRD;TOF"
  //    2.) Logbook tree per run
  //    3.) Logbook tree per run/detector
  //    3.) RCT table
  //    4.) CPass table 
  // 
  //  tree is created with addition of friend trees which can be used in queries
  //  queries as analog to the SQL statement

  /* 
    period="LHC15o"; pass="******"
  */
  ::Info("qaTrending::InitTrees::Begin","Detector %s, RefDet=%s",detector, referenceDet);
  AliExternalInfo info;
  Int_t treeCounter=0;
  // Load trees
  TObjArray * detArray=TString(referenceDet).Tokenize(";");
  Int_t nrefDets=detArray->GetEntries();
  TVectorF runCounter(5+nrefDets*2);  // <QADet>, <Logbook>, <Logbook.Det>, <MonAlisa>, <CPass>, <QA.RefDet>xnrefDets, <Logbook.RefDet>xnrefDets
  //
  ::Info("qaTrending::InitTrees::End","Laoding trees");
  treeQADet = info.GetTreeDataQA(detector,period, pass);
  if (!treeQADet){
    ::Error("qaTrending.InitTrees", "Input QA tree %s not available", detector); 
    return 0;
  }
  runCounter[treeCounter++]=treeQADet->Draw("run","1","goff");
  qaMap[TString::Format("QA.%s",detector).Data()]=treeQADet;
  //
  qaMap["Logbook"]=info.GetTree("Logbook",period,"");
  qaMap["Logbook"]->AddFriend(treeQADet,"QADet");
  treeQADet->AddFriend(qaMap["Logbook"],"Logbook");
  runCounter[treeCounter++]=treeQADet->Draw("run","1","goff");
  //
  qaMap["MonALISA.RCT"]=info.GetTree("MonALISA.RCT",period,pass);
  qaMap["MonALISA.RCT"]->AddFriend(treeQADet,"QADet");
  treeQADet->AddFriend(qaMap["MonALISA.RCT"],"MonALISA.RCT");
  runCounter[treeCounter++]=treeQADet->Draw("run","1","goff");
  //
  TTree *treeLogbookDetector =info.GetTree("Logbook.detector",period,"");
  if (treeLogbookDetector){
    if (detArray->GetEntries()>0){
      for (Int_t idet=0; idet<detArray->GetEntries(); idet++){
	// Load Logbook.RefDet
	const char *detName=detArray->At(idet)->GetName();	
	TTree * treeLog =treeLogbookDetector->CopyTree(TString::Format("detector==\"%s\"",detName).Data());
	if (treeLog->GetEntries()<=0){
	  ::Error("qaTrending.InitTrees","Missing Tree Logbook. %s - check the syntax",detName);
	}else{
	  treeLog->BuildIndex("run");
	  qaMap[TString::Format("Logbook.%s",detName).Data()]=treeLog;
	  treeLog->AddFriend(treeQADet, "QADet");
	  treeQADet->AddFriend(treeLog,  TString::Format("Logbook.%s",detName).Data());
	  runCounter[treeCounter++]=treeQADet->Draw("run","1","goff");
	}
	// Load QA.RefDet
	TTree * treeQARefDet = info.GetTreeDataQA(detName,period, pass);
	if (treeQARefDet){
	  qaMap[TString::Format("QA.%s",detName).Data()]=treeQARefDet;
	  treeQARefDet->AddFriend(treeQADet, "QADet");
	  treeQADet->AddFriend(treeQARefDet,  TString::Format("QA.%s",detName).Data());
	  runCounter[treeCounter++]=treeQADet->Draw("run","1","goff");
	}else{
	  ::Error("qaTrending.InitTrees","Missing Tree QA.%s - check the syntax",detName);
	}
      }
    }
  }
  //
  // Check consistency of data
  // 
  ::Info("qaTrending::InitTrees::End","Checking trees");
  TList *arrFriends = treeQADet->GetListOfFriends();
  for (Int_t ifriend=0; ifriend<arrFriends->GetEntries(); ifriend++){
    Int_t entries = treeQADet->Draw(TString::Format("run-%s.run", arrFriends->At(ifriend)->GetName()).Data(),"1","goff");
    Double_t mean=0;
    if (entries>0) {
      mean=TMath::Mean(entries, treeQADet->GetV1());
    }
    if (mean==0){
      ::Info("qaTrending::InitTrees", "Friend:\t%s\t%d\t%f", arrFriends->At(ifriend)->GetName(), entries,mean);
    }else{
      ::Error("qaTrending::InitTrees", "Friend:\t%s\t%d\t%f", arrFriends->At(ifriend)->GetName(), entries,mean);
    }
  }
  delete detArray;
  ::Info("qaTrending::InitTrees::End","Detector %s, RefDet=%s",detector, referenceDet);

  return treeQADet;  
}
コード例 #11
0
void fullPedestalAnalysis(string inputDIR, string outputDIR, string inputCablingMap, string outputFileName){

  gROOT->ProcessLine("gErrorIgnoreLevel = 1");
  
  // open the file and prepare the cluster tree, adding the other trees as frined --> memory consuming                                                                                                
  std::cout<<"##################################"<<std::endl;
  std::cout<<"###### fullPedestalAnalysis ######"<<std::endl;
  std::cout<<"##################################"<<std::endl;

  clock_t tStart = clock();

  // prepare style and load macros                                                                                                                                                                    
  setTDRStyle();
  gROOT->SetBatch(kTRUE);

  system(("mkdir -p "+outputDIR).c_str());
  ifstream file;

  std::cout<<"### Make input file list"<<std::endl;
  system(("find "+inputDIR+" -name \"*.root\" > file.temp").c_str());
  std::ifstream infile;
  string line;
  vector<string> fileList;
  infile.open("file.temp",ifstream::in);
  if(infile.is_open()){
    while(!infile.eof()){
      getline(infile,line);
      if(line != "" and TString(line).Contains(".root") and line !="\n"){
        fileList.push_back(line);
      }
    }
  }
  system("rm file.temp");
  std::sort(fileList.begin(),fileList.end());

  TFile* cablingFile = TFile::Open(inputCablingMap.c_str(),"READ");
  cablingFile->cd();
  TTree* readoutMap = (TTree*) cablingFile->FindObjectAny("readoutMap");
  TTreeReader reader(readoutMap);
  TTreeReaderValue<uint32_t> detid    (reader,"detid");
  TTreeReaderValue<uint16_t> fecCrate (reader,"fecCrate");
  TTreeReaderValue<uint16_t> fecSlot  (reader,"fecSlot");
  TTreeReaderValue<uint16_t> fecRing  (reader,"fecRing");
  TTreeReaderValue<uint16_t> ccuAdd   (reader,"ccuAdd");
  TTreeReaderValue<uint16_t> ccuChan  (reader,"ccuChan");
  TTreeReaderValue<uint16_t> lldChannel  (reader,"lldChannel");
  TTreeReaderValue<uint16_t> fedId  (reader,"fedId");
  TTreeReaderValue<uint16_t> fedCh  (reader,"fedCh");

  // output tree
  TFile* ouputTreeFile = new TFile((outputDIR+"/"+outputFileName).c_str(),"RECREATE");
  ouputTreeFile->cd();
  ouputTreeFile->SetCompressionLevel(0);
  TTree* outputTree = new TTree("pedestalFullNoise","pedestalFullNoise");
  
  // branches
  uint32_t detid_,fedKey_;
  uint16_t fecCrate_,fecSlot_, fecRing_, ccuAdd_, ccuChan_, lldChannel_, fedId_, fedCh_, apvId_, stripId_;
  float    noiseMean_,noiseRMS_, noiseSkewness_, noiseKurtosis_;
  float    fitChi2_, fitChi2Probab_, fitStatus_;
  float    fitGausMean_, fitGausSigma_, fitGausNormalization_;
  float    fitGausMeanError_, fitGausSigmaError_, fitGausNormalizationError_;
  float    noiseIntegral3Sigma_, noiseIntegral3SigmaFromFit_;
  float    noiseIntegral4Sigma_, noiseIntegral4SigmaFromFit_;
  float    noiseIntegral5Sigma_, noiseIntegral5SigmaFromFit_;
  float    kSValue_, kSProbab_, jBValue_, jBProbab_, aDValue_, aDProbab_;
  vector<float> noiseDistribution_, noiseDistributionError_;
  float xMin_, xMax_, nBin_ ;

  outputTree->Branch("detid",&detid_,"detid/i");
  outputTree->Branch("fedKey",&fedKey_,"fedKey/i");
  outputTree->Branch("fecCrate",&fecCrate_,"fecCrate/s");
  outputTree->Branch("fecSlot",&fecSlot_,"fecSlot/s");
  outputTree->Branch("fecRing",&fecRing_,"fecRing/s");
  outputTree->Branch("ccuAdd",&ccuAdd_,"ccuAdd/s");
  outputTree->Branch("ccuChan",&ccuChan_,"ccuChan/s");
  outputTree->Branch("lldChannel",&lldChannel_,"lldChannel/s");
  outputTree->Branch("fedId",&fedId_,"fedId/s");
  outputTree->Branch("fedCh",&fedCh_,"fedCh/s");
  outputTree->Branch("apvId",&apvId_,"apvId/s");
  outputTree->Branch("stripId",&stripId_,"stripId/s");

  outputTree->Branch("noiseMean",&noiseMean_,"noiseMean/F");
  outputTree->Branch("noiseRMS",&noiseRMS_,"noiseRMS/F");
  outputTree->Branch("noiseSkewness",&noiseSkewness_,"noiseSkewness/F");
  outputTree->Branch("noiseKurtosis",&noiseKurtosis_,"noiseKurtosis/F");
  outputTree->Branch("fitGausNormalization",&fitGausNormalization_,"fitGausNormalization/F");
  outputTree->Branch("fitGausMean",&fitGausMean_,"fitGausMean/F");
  outputTree->Branch("fitGausSigma",&fitGausSigma_,"fitGausSigma/F");
  outputTree->Branch("fitGausNormalizationError",&fitGausNormalizationError_,"fitGausNormalizationError/F");
  outputTree->Branch("fitGausMeanError",&fitGausMeanError_,"fitGausMeanError/F");
  outputTree->Branch("fitGausSigmaError",&fitGausSigmaError_,"fitGausSigmaError/F");
  outputTree->Branch("fitChi2",&fitChi2_,"fitChi2/F");
  outputTree->Branch("fitChi2Probab",&fitChi2Probab_,"fitChi2Probab/F");
  outputTree->Branch("fitStatus",&fitStatus_,"fitStatus_F");
  outputTree->Branch("noiseIntegral3Sigma",&noiseIntegral3Sigma_,"noiseIntegral3Sigma/F");
  outputTree->Branch("noiseIntegral3SigmaFromFit",&noiseIntegral3SigmaFromFit_,"noiseIntegral3SigmaFromFit/F");
  outputTree->Branch("noiseIntegral4Sigma",&noiseIntegral4Sigma_,"noiseIntegral4Sigma/F");
  outputTree->Branch("noiseIntegral4SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral4SigmaFromFit/F");
  outputTree->Branch("noiseIntegral5Sigma",&noiseIntegral4Sigma_,"noiseIntegral5Sigma/F");
  outputTree->Branch("noiseIntegral5SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral5SigmaFromFit/F");
  outputTree->Branch("kSValue",&kSValue_,"kSValue/F");
  outputTree->Branch("jBValue",&jBValue_,"jBValue/F");
  outputTree->Branch("aDValue",&aDValue_,"aDValue/F");
  outputTree->Branch("kSProbab",&kSProbab_,"kSProbab/F");
  outputTree->Branch("jBProbab",&jBProbab_,"jBProbab/F");
  outputTree->Branch("aDProbab",&aDProbab_,"aDProbab/F");
  outputTree->Branch("xMin",&xMin_,"xMin/F");
  outputTree->Branch("xMax",&xMax_,"xMax/F");
  outputTree->Branch("nBin",&nBin_,"nBin/F");

  bool histoBranches = false;

  // Loop on the file list to extract each histogram 2D DQM histo with full noise distribution  
  TH1F* histoNoiseStrip = NULL;
  TF1*  fitFunc = NULL;
  TH1F* randomHisto = NULL;
  TFitResultPtr result;
  for(auto file : fileList){
    cout<<"input file: "<<file<<endl;
    TFile* inputFile = TFile::Open(file.c_str(),"READ");
    inputFile->cd();
    // take into account that the DQM file structure for strips is always the same --> use cabling map to browse the histograms
    reader.SetEntry(0);
    TH2* histoNoise = NULL;
    long int iChannel = 0;
    int noFitResult = 0;
    while(reader.Next()){
      cout.flush();
      if(iChannel %10 == 0) cout<<"\r"<<"iChannel "<<100*double(iChannel)/(readoutMap->GetEntries()/reductionFactor)<<" % ";
      if(iChannel > double(readoutMap->GetEntries())/reductionFactor) break;
      iChannel++;
      TString objName;
      uint32_t fedKey =  SiStripFedKey(*fedId,SiStripFedKey::feUnit(*fedCh),SiStripFedKey::feChan(*fedCh)).key();
      std::stringstream stream;
      stream << std::hex << fedKey;
      string fedKeyStr = stream.str();
      if(fedKeyStr.size() == 4)
	objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x0000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel);      
      else if(fedKeyStr.size() == 5)
	objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel);      
      else
	cerr<<"hex number to short "<<fedKeyStr<<" --> please check "<<endl;

      inputFile->GetObject(objName.Data(),histoNoise);
      // extract single strip noise histogram --> loop on the y-axis
      uint16_t apvID = 0;
      uint16_t stripID = 0;       
      if(histoNoiseStrip == 0 or histoNoiseStrip == NULL){
	histoNoiseStrip = new TH1F ("histoNoiseStrip","",histoNoise->GetNbinsX(),histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax());
	histoNoiseStrip->Sumw2();
      }
      for(int iBinY = 0; iBinY < histoNoise->GetNbinsY(); iBinY++){
	histoNoiseStrip->Reset();
	histoNoiseStrip->SetDirectory(0);
	// two multiplexed APV per line
	if(iBinY < histoNoise->GetNbinsY()/2) apvID = 1;
	else apvID = 2;
	// strip id
	stripID++;
	if(stripID > 128) stripID = 1;
	// loop on x-axis bin
	for(int iBinX = 0; iBinX < histoNoise->GetNbinsX(); iBinX++){
	  histoNoiseStrip->SetBinContent(iBinX+1,histoNoise->GetBinContent(iBinX+1,iBinY+1));
	  histoNoiseStrip->SetBinError(iBinX+1,histoNoise->GetBinError(iBinX+1,iBinY+1));	    
	}
     	
	// to initialize branches
	detid_ = 0; fedKey_ = 0; fecCrate_ = 0; fecSlot_ = 0; fecRing_ = 0; ccuAdd_ = 0; ccuChan_ = 0; lldChannel_ = 0; fedId_ = 0; fedCh_ = 0; apvId_ = 0; stripId_ = 0; 
	noiseMean_ = 0.; noiseRMS_ =  0.; noiseSkewness_ = 0.; noiseKurtosis_ = 0.; 
	fitGausMean_ = 0.; fitGausSigma_ = 0.;fitGausNormalization_ = 0.;
	fitGausMeanError_ = 0.; fitGausSigmaError_ = 0.;fitGausNormalizationError_ = 0.;	  	  
	fitChi2_ = 0.; fitChi2Probab_ = 0.; fitStatus_ = -1.; 
	noiseIntegral3Sigma_ = 0.; noiseIntegral3SigmaFromFit_ = 0.; 
	noiseIntegral4Sigma_ = 0.; noiseIntegral4SigmaFromFit_ = 0.; 
	noiseIntegral5Sigma_ = 0.; noiseIntegral5SigmaFromFit_ = 0.; 
	kSProbab_ = 0.; jBProbab_ = 0.;
	kSValue_ = 0.; jBValue_ = 0.; 
	aDValue_= 0.; aDProbab_ = 0.;
	nBin_ = 0.; xMin_ = 0.; xMax_ = 0.;
	
	// basic info
	detid_ = *detid;
	fedKey_ = fedKey;
	fecCrate_ = *fecCrate;
	fecSlot_ = *fecSlot;
	fecRing_ = *fecRing;
	ccuAdd_  = *ccuAdd;
	ccuChan_ = *ccuChan;
	lldChannel_ = *lldChannel;
	fedId_   = *fedId;
	fedCh_   = *fedCh;
	apvId_   = apvID;
	stripId_ = stripID;
	
	// basic info of nioise distribution
	noiseMean_ = histoNoiseStrip->GetMean();
	noiseRMS_  = histoNoiseStrip->GetRMS();
	noiseSkewness_ = histoNoiseStrip->GetSkewness();
	noiseKurtosis_ = histoNoiseStrip->GetKurtosis();
	float integral = histoNoiseStrip->Integral();	
	noiseIntegral3Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*3)))/integral;
	noiseIntegral4Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*4)))/integral;
	noiseIntegral5Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*5)))/integral;
	
	// make a gaussian fit	  	
	if(fitFunc == NULL or fitFunc == 0){
	  fitFunc = new TF1 ("fitFunc","gaus(0)",histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax());
	}
	fitFunc->SetRange(histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax());
	fitFunc->SetParameters(histoNoiseStrip->Integral(),noiseMean_,noiseRMS_);
	result = histoNoiseStrip->Fit(fitFunc,"QSR");

	if(result.Get()){
	    fitStatus_     = result->Status();
	    fitGausNormalization_  = fitFunc->GetParameter(0);
	    fitGausMean_   = fitFunc->GetParameter(1);
	    fitGausSigma_  = fitFunc->GetParameter(2);
	    fitGausNormalizationError_  = fitFunc->GetParError(0);
	    fitGausMeanError_  = fitFunc->GetParError(1);
	    fitGausSigmaError_ = fitFunc->GetParError(2);
	    fitChi2_           = result->Chi2();
	    fitChi2Probab_     = result->Prob();

	    noiseIntegral3SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*3)))/histoNoiseStrip->Integral();
	    noiseIntegral4SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*4)))/histoNoiseStrip->Integral();
	    noiseIntegral5SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*5)))/histoNoiseStrip->Integral();
	    
	    jBValue_   = (histoNoiseStrip->Integral()/6)*(noiseSkewness_*noiseSkewness_+(noiseKurtosis_*noiseKurtosis_)/4);	  
	    jBProbab_  = ROOT::Math::chisquared_cdf_c(jBValue_,2);

	    if(randomHisto == 0 or randomHisto == NULL)
	      randomHisto = (TH1F*) histoNoiseStrip->Clone("randomHisto");	    	    
	    randomHisto->Reset();
	    randomHisto->SetDirectory(0);     
	
      
	    if(integral != 0){	      
	      if(generateRandomDistribution){
		randomHisto->FillRandom("fitFunc",histoNoiseStrip->Integral());	    
		kSValue_  = histoNoiseStrip->KolmogorovTest(randomHisto,"MN");
		kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N");	    
		aDValue_  = histoNoiseStrip->AndersonDarlingTest(randomHisto,"T");
		aDProbab_ = histoNoiseStrip->AndersonDarlingTest(randomHisto);
	      }
	      else{
		
		randomHisto->Add(fitFunc);		
		kSValue_  = histoNoiseStrip->KolmogorovTest(randomHisto,"MN"); 
		kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N");
		// AD test
		ROOT::Fit::BinData data1;
		ROOT::Fit::BinData data2;
		ROOT::Fit::FillData(data1,histoNoiseStrip,0);
		data2.Initialize(randomHisto->GetNbinsX()+1,1);
		for(int ibin = 0; ibin < randomHisto->GetNbinsX(); ibin++){ 
		  if(histoNoiseStrip->GetBinContent(ibin+1) != 0 or randomHisto->GetBinContent(ibin+1) >= 1)
		    data2.Add(randomHisto->GetBinCenter(ibin+1),randomHisto->GetBinContent(ibin+1),randomHisto->GetBinError(ibin+1));
		}
	  
		double probab;
		double value;
		ROOT::Math::GoFTest::AndersonDarling2SamplesTest(data1,data2,probab,value);
		aDValue_ = value;
		aDProbab_ = probab;
	      }
	    }
	}
	else
	  noFitResult++;
	
	if(not histoBranches){
	  noiseDistribution_.clear();
	  noiseDistributionError_.clear();
	  outputTree->Branch("noiseDistribution","vector<float>",&noiseDistribution_);
	  outputTree->Branch("noiseDistributionError","vector<float>",&noiseDistributionError_);
	  histoBranches = true;
	}
    
	// set histogram
	noiseDistribution_.clear();
	noiseDistributionError_.clear();
	for(int iBin = 0; iBin < histoNoiseStrip->GetNbinsX(); iBin++){
	  noiseDistribution_.push_back(histoNoiseStrip->GetBinContent(iBin+1));
	  noiseDistributionError_.push_back(histoNoiseStrip->GetBinError(iBin+1));	      
	}
    
	nBin_ = histoNoiseStrip->GetNbinsX();
	xMin_ = histoNoise->GetXaxis()->GetBinLowEdge(1);
	xMax_ = histoNoise->GetXaxis()->GetBinLowEdge(histoNoise->GetNbinsX()+1);

	// fill all branches for each strip
	ouputTreeFile->cd();
	outputTree->Fill();
      }
    }
    inputFile->Close();
    std::cout<<std::endl;
    cout<<"No fit results found for "<<100*double(noFitResult)/iChannel<<endl;
  }
  outputTree->BuildIndex("detid");
  outputTree->Write(outputTree->GetName(),TObject::kOverwrite);
  ouputTreeFile->Close();
  cablingFile->Close();

  /* Do your stuff here */
  cout<<"Time taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC<<endl;  
}