void DataInterface::getDataProfile(TH2F *hProfile, TH2F *hProjection, Int_t energy) { if (!existsEnergyFile(energy)) { cout << "There are no data files with energy " << energy << endl; return; } TString fn = Form("Data/ExperimentalData/DataFrame_%i_MeV.root", energy); TFile *f = new TFile(fn); TTree *tree = (TTree*) f->Get("tree"); Int_t nentries = tree->GetEntries(); printf("Found %d frames in the DataFrame.\n", nentries); TLeaf *lX = tree->GetLeaf("fDataFrame.fX"); TLeaf *lY = tree->GetLeaf("fDataFrame.fY"); TLeaf *lLayer = tree->GetLeaf("fDataFrame.fLayer"); Float_t x, y, layer; for (Int_t i=0; i<nentries; i++) { tree->GetEntry(i); for (Int_t j=0; j<lY->GetLen(); j++) { x = lX->GetValue(j) + nx/2; y = lY->GetValue(j) + ny/2; layer = lLayer->GetValue(j); hProfile->Fill(y, layer); hProjection->Fill(x, y); } } }
void NCIdeogram::addTree(TTree *tree, const char *mu, const char *sigma) { TLeaf *leafMu = tree->FindLeaf(mu); TLeaf *leafSigma = tree->FindLeaf(sigma); TEventList *elist = tree->GetEventList(); Long64_t j,ix,nbr; nbr = elist ? elist->GetN() : tree->GetEntries(); for (j = 0; j < nbr; j++) { ix = elist ? elist->GetEntry(j) : j; tree->GetEntry(ix); addPoint(leafMu->GetValue(), leafSigma->GetValue()); } } // addTree()
void DataInterface::getDataFrame(Int_t runNo, CalorimeterFrame * cf, Int_t energy) { if (!existsEnergyFile(energy)) { cout << "There are no data files with energy " << energy << endl; return; } Int_t eventIdFrom = runNo * kEventsPerRun; Int_t eventIdTo = eventIdFrom + kEventsPerRun; TString fn = Form("Data/ExperimentalData/DataFrame_%i_MeV.root", energy); TFile *f = new TFile(fn); TTree *tree = (TTree*) f->Get("tree"); Int_t nentries = tree->GetEntries(); if (eventIdTo > nentries) { eventIdTo = nentries; } cout << "Found " << nentries << " frames in the DataFrame.\n"; TLeaf *lX = tree->GetLeaf("fDataFrame.fX"); TLeaf *lY = tree->GetLeaf("fDataFrame.fY"); TLeaf *lLayer = tree->GetLeaf("fDataFrame.fLayer"); Int_t counter = 0; for (Int_t i=eventIdFrom; i<eventIdTo; i++) { tree->GetEntry(i); for (Int_t j=0; j<lX->GetLen(); j++) { Int_t x = lX->GetValue(j) + nx/2; Int_t y = lY->GetValue(j) + ny/2; Int_t z = lLayer->GetValue(j); cf->fillAt(z, x, y); } counter++; } delete f; }
/// \brief Cache MC production trees, store summary information in formated text files -> root trees /// \param dataType - /// \param fileList void CacheTestMCProductions(TString dataType, const char *fileList=NULL){ AliExternalInfo info; info.fLoadMetadata=kFALSE; TObjArray* periodList = NULL; TArrayI nRuns; if (fileList!=NULL) { periodList=(gSystem->GetFromPipe(TString::Format("cat %s", fileList).Data())).Tokenize("\n"); nRuns.Set(periodList->GetEntries()); }else{ TTree * tree = info.GetTree("MonALISA.ProductionMC","",""); Int_t nProd=tree->GetEntries(); periodList = new TObjArray(nProd); nRuns.Set(nProd); TLeaf *leaf = tree->GetLeaf("Tag"); TLeaf *leafRuns = tree->GetLeaf("Number_of_runs"); for (Int_t iProd=0; iProd<nProd; iProd++){ tree->GetEntry(iProd); TString prodName=((char*)leaf->GetValuePointer()); if (prodName.Contains("LHC")==0) continue; periodList->AddAt(new TObjString(((char*)leaf->GetValuePointer())),iProd); nRuns[iProd]=leafRuns->GetValue(); } delete tree; } for (Int_t iPeriod=0; iPeriod<periodList->GetEntriesFast(); iPeriod++){ TObjString * pName= (TObjString*)periodList->At(iPeriod); if (pName==NULL) continue; TTree* tree = info.GetTree(dataType.Data(),periodList->At(iPeriod)->GetName(),"passMC"); if (tree){ Int_t entries=tree->Draw("run","1","goff"); TString sInfo=periodList->At(iPeriod)->GetName(); sInfo+="\t"; sInfo+=dataType; sInfo+="\t"; sInfo+=TString::Format("%d\t",entries); sInfo+=TString::Format("%d\t",nRuns[iPeriod]); for (Int_t j=0; j<entries; j++) { sInfo+=TString::Format("%2.0f,",tree->GetV1()[j]); ::Info("CacheTestMCProductionsRun:","%s\t%s\t%d\t%d\t%d\t%2.0f",periodList->At(iPeriod)->GetName(),dataType.Data(),entries,nRuns[iPeriod],j, tree->GetV1()[j]); } sInfo+="0"; ::Info("CacheTestMCProductionsPeriod:","%s\n",sInfo.Data()); delete tree; }else{ ::Error("CacheTestMCProductionsPeriod:","%s\t%s\t-1\t%d\t0",periodList->At(iPeriod)->GetName(), dataType.Data(),nRuns[iPeriod]); } } }
int main() { // Get a map of the histograms of the Z Masses const std::string Tree_HighCut = "ZFinder/Combined Single Reco/Combined Single Reco"; const std::string Tree_LowCut = "ZFinder/Combined Single Lowered Threshold Reco/Combined Single Lowered Threshold Reco"; const std::string file_name = "/data/whybee0a/user/gude_2/Data/20150324_SingleElectron_2012ALL/hadded.root"; // Open the file and load the tree TTree* treeH = GetTTree(file_name, Tree_HighCut); TBranch* event_infoH = treeH->GetBranch("event_info"); TLeaf* EVNumbH = event_infoH->GetLeaf("event_number"); // Pack into a hitogram std::set<int> eventnumber; std::set<int> eventnumberLow; for (int i = 0; i < treeH->GetEntries(); i++) { treeH->GetEntry(i); if (eventnumber.find(EVNumbH->GetValue()) == eventnumber.end()) { eventnumber.insert(EVNumbH->GetValue()); } else { cout << "multiple events numbered :" << EVNumbH->GetValue()<<" in higher cuts" << endl; } } TTree* TreeLow = GetTTree(file_name, Tree_LowCut); TBranch* event_infoL = TreeLow->GetBranch("event_info"); TLeaf* EVNumbLow = event_infoL->GetLeaf("event_number"); for (int i = 0; i < TreeLow->GetEntries(); i++) { TreeLow->GetEntry(i); eventnumberLow.insert(EVNumbLow->GetValue()); if (eventnumberLow.find(EVNumbLow->GetValue()) == eventnumber.end()) { eventnumberLow.insert(EVNumbLow->GetValue()); } else { cout << "multiple events numbered :" << EVNumbLow->GetValue()<<" in lowered cuts" << endl; } } return EXIT_SUCCESS; }
int analysis(char* filename) { // char* filename = "combined.root"; // Read in the file TFile* f = new TFile(filename); TDirectory* hists = f->GetDirectory("hists;1"); TDirectory* tuples = f->GetDirectory("tuples;1"); TTree* accum = tuples->GetObjectUnchecked("AccumulatedEnergy;1"); TLeaf* einit = accum->GetLeaf("Einit"); TLeaf* edepo = accum->GetLeaf("Edep"); TTree* edeps = tuples->GetObjectUnchecked("EnergyDepositions;1"); TTree* secs = tuples->GetObjectUnchecked("SecondarySpectrum;1"); TLeaf* secsenergy = secs->GetLeaf("KineticEnergy"); double ein = 0; double eout = 0; int nevents = accum->GetEntries(); cout << "Making Summary\n"; FILE* summary = fopen("summ.txt", "a+"); for (int ii = 0; ii<nevents; ii++) { accum->GetEntry(ii); ein+=einit->GetValue(); eout+=edepo->GetValue(); } FILE* summary = fopen("summ.txt", "a+"); time_t t = time(NULL); char* c_time_string = ctime(&t); char* mytime[20]; strncpy(mytime, c_time_string, 19); mytime[ strlen(mytime) - 1 ] = '\0'; fprintf(summary, "%s,%s,%e,%e\n", mytime, filename, ein, eout);//*c_time_string, *filename, ein, eout); //cout << *c_time_string << "," << *filename << "," << ein << "," << eout << "\n"; fclose(summary); // Print out or save these values cout << "Making Histogram\n"; nevents = secs->GetEntries(); TH1F* secondaries = new TH1F("secondaries", "Secondary Electrons <100 keV", 92, 0.010, 0.102); for (int ii = 0; ii<nevents; ii++) { secs->GetEntry(ii); secondaries->Fill(secsenergy->GetValue()); } char* suffix = ".secondaryhisto"; cout << "Making Filenames\n"; char* outfilename = malloc(strlen(filename) + strlen(suffix) + 1); strcpy(outfilename, filename); strcat(outfilename, suffix); printf("Saving Histogram: %s \n", outfilename); h12ascii(secondaries, outfilename); return 0; }
void Example_tags(TString topDir = "/star/rcf/GC/daq/tags") { ////////////////////////////////////////////////////////////////////////// // // // Example_tags.C // // // // shows how to use the STAR tags files // // Input: top level directory // // // // what it does: // // 1. creates TChain from all tags files down from the topDir // // 2. loops over all events in the chain // // // // owner: Alexandre V. Vaniachine <*****@*****.**> // ////////////////////////////////////////////////////////////////////////// gSystem->Load("libTable"); gSystem->Load("St_base"); // start benchmarks gBenchmark = new TBenchmark(); gBenchmark->Start("total"); // set loop optimization level gROOT->ProcessLine(".O4"); // gather all files from the same top directory into one chain // topDir must end with "/" topDir +='/'; St_FileSet dirs(topDir); St_DataSetIter next(&dirs,0); St_DataSet *set = 0; TChain chain("Tag"); while ( (set = next()) ) { if (strcmp(set->GetTitle(),"file") || !(strstr(set->GetName(),".tags.root"))) continue; chain.Add(gSystem->ConcatFileName(topDir,set->Path())); } UInt_t nEvents = chain->GetEntries(); cout<<"chained "<<nEvents<<" events "<<endl; TObjArray *files = chain.GetListOfFiles(); UInt_t nFiles = files->GetEntriesFast(); cout << "chained " << nFiles << " files from " << topDir << endl; TObjArray *leaves = chain.GetListOfLeaves(); Int_t nleaves = leaves->GetEntriesFast(); TString tableName = " "; TObjArray *tagTable = new TObjArray; Int_t tableCount = 0; Int_t *tableIndex = new Int_t[nleaves]; Int_t tagCount = 0; // decode tag table names for (Int_t l=0;l<nleaves;l++) { TLeaf *leaf = (TLeaf*)leaves->UncheckedAt(l); tagCount+=leaf->GetNdata(); TBranch *branch = leaf->GetBranch(); // new tag table name if ( strstr(branch->GetName(), tableName.Data()) == 0 ) { tableName = branch->GetName(); // the tableName is encoded in the branch Name before the "." tableName.Resize(tableName->Last('.')); tagTable->AddLast(new TObjString(tableName.Data())); tableCount++; } tableIndex[l]=tableCount-1; } cout << " tot num tables, tags = " << tableCount << " " << tagCount << endl << endl; //EXAMPLE 1: how to print out names of all tags and values for first event for (l=0;l<nleaves;l++) { leaf = (TLeaf*)leaves->UncheckedAt(l); branch = leaf->GetBranch(); branch->GetEntry(); // tag comment is in the title TString Title = leaf->GetTitle(); Int_t dim = leaf->GetNdata(); if (dim==1) { Title.ReplaceAll('['," '"); Title.ReplaceAll(']',"'"); } cout << "\n Table: "; cout.width(10); cout << ((TObjString*)tagTable->UncheckedAt(tableIndex[l]))->GetString() <<" -- has tag: " << Title << endl; for (Int_t i=0;i<dim;i++) { cout <<" "<< leaf->GetName(); if (dim>1) cout << '['<<i<<']'; cout << " = " << leaf->GetValue(i) << endl; } } // EXAMPLE 2: how to make a plot c1 = new TCanvas("c1","Beam-Gas Rejection",600,1000); gStyle->SetMarkerStyle(8); chain->Draw("n_trk_tpc[0]:n_trk_tpc[1]"); // EXAMPLE 3: how to make a selection (write selected event numbers on the plot) Int_t ncoll=0; char aevent[10]; TText t(0,0,"a"); t.SetTextFont(52); t.SetTextSize(0.02); Float_t cut = 0.35; cout <<"\n Events with ntrk>400 and |asim|<"<<cut<<endl; //loop over all events: READ ONLY n_trk_tpc AND mEventNumber BRANCHES! gBenchmark->Start("loop"); for (Int_t i=0;i<nFiles;i++) { chain.LoadTree(*(chain.GetTreeOffset()+i)); TTree *T = chain.GetTree(); //must renew leaf pointer for each tree TLeaf *ntrk = T->GetLeaf("n_trk_tpc"); TLeaf *run = T->GetLeaf("mRunNumber"); TLeaf *event = T->GetLeaf("mEventNumber"); for (Int_t j=0; j<T->GetEntries(); j++){ ntrk->GetBranch()->GetEntry(j); event->GetBranch()->GetEntry(j); run->GetBranch()->GetEntry(j); Int_t Nm=ntrk->GetValue(0); Int_t Np=ntrk->GetValue(1); Int_t Ntrk = Np+Nm; // avoid division by 0 Float_t asim = Np-Nm; if (Ntrk>0) asim /= Ntrk; if (-cut < asim&&asim < cut && Ntrk>400) { cout<<" Run "<<(UInt_t)run->GetValue() <<", Event "<<event->GetValue() <<endl; ncoll++; sprintf(aevent,"%d",event->GetValue()); t.DrawText(Np+10,Nm+10,aevent); } } } gBenchmark->Stop("loop"); t.SetTextSize(0.05); t.DrawText(50,2550,"ntrk>400 and |(Np-Nm)/(Np+Nm)| < 0.35 "); t.DrawText(500,-300,"Ntrk with tanl<0 "); cout << " Selected " << ncoll << " collision candidates out of " << nEvents << " events" << endl; // stop timer and print benchmarks gBenchmark->Print("loop"); gBenchmark->Stop("total"); gBenchmark->Print("total"); }
int main() { // Get7 a map of the histograms of the Z Masses const std::string file_name = "/data/whybee0a/user/lesko_2/fermi/MadWithInitial/Mad2016_8_25/results/AllMHWithMothers.root"; // Open the file and load the tree const std::string TreeName = "ZFinder/Combined Gen Cuts Reco/Combined Gen Cuts Reco"; TTree* tree = GetTTree(file_name, TreeName); TBranch* reco = tree->GetBranch("reco"); TLeaf* PhiStar = reco->GetLeaf("z_phistar_born"); TLeaf* Mom1 = reco->GetLeaf("z_mom1PDG"); TLeaf* Mom2 = reco->GetLeaf("z_mom2PDG"); TLeaf* PenUltimateMom1 = reco->GetLeaf("z_penultimate1PDG"); TLeaf* PenUltimateMom2 = reco->GetLeaf("z_penultimate2PDG"); TLeaf* Z_YBorn = reco->GetLeaf("z_yBorn"); ExploreTree(tree, Mom1, PenUltimateMom1, Mom2, PenUltimateMom2); TBranch* event_info = tree->GetBranch("event_info"); //TLeaf* EVNumb = event_info->GetLeaf("event_number"); // Pack into a hitogram for (int w = 0; w < 2; w++) { string PlotName; TLeaf* MomOrPenUltimateMom1 = w == 0 ? Mom1 : PenUltimateMom1; TLeaf* MomOrPenUltimateMom2 = w == 0 ? Mom2 : PenUltimateMom2; vector<string> NamesOfPlots; NamesOfPlots.push_back("UpQuarkPair"); //0 NamesOfPlots.push_back("DownQuarkPair"); //1 NamesOfPlots.push_back("StrangeQuarkPair"); //2 NamesOfPlots.push_back("CharmQuarkPair"); //3 NamesOfPlots.push_back("BottomQuarkPair"); //4 NamesOfPlots.push_back("SingleQuark"); //5 NamesOfPlots.push_back("Gluon"); //6 NamesOfPlots.push_back("TwoQuarks"); //7 NamesOfPlots.push_back("TwoAntiQuarks"); //8 NamesOfPlots.push_back("QuarkAntiQuarkPair"); //9 NamesOfPlots.push_back("QuarkAntiQuarkNotPair"); //10 NamesOfPlots.push_back("Quark Quark And AntiQuark AntiQuark"); //11 NamesOfPlots.push_back("Broken"); map<string, TH1*> AllPlots; AllPlots[NamesOfPlots[0]] = new TH1D(NamesOfPlots[0].c_str(), NamesOfPlots[0].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[1]] = new TH1D(NamesOfPlots[1].c_str(), NamesOfPlots[1].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[2]] = new TH1D(NamesOfPlots[2].c_str(), NamesOfPlots[2].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[3]] = new TH1D(NamesOfPlots[3].c_str(), NamesOfPlots[3].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[4]] = new TH1D(NamesOfPlots[4].c_str(), NamesOfPlots[4].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[5]] = new TH1D(NamesOfPlots[5].c_str(), NamesOfPlots[5].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[6]] = new TH1D(NamesOfPlots[6].c_str(), NamesOfPlots[6].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[7]] = new TH1D(NamesOfPlots[7].c_str(), NamesOfPlots[7].c_str(), nphistar, phistarBins); //Two quarks AllPlots[NamesOfPlots[8]] = new TH1D(NamesOfPlots[8].c_str(), NamesOfPlots[8].c_str(), nphistar, phistarBins); //Two Anti quarks AllPlots[NamesOfPlots[9]] = new TH1D(NamesOfPlots[9].c_str(), NamesOfPlots[9].c_str(), nphistar, phistarBins); // AllPlots[NamesOfPlots[10]] = new TH1D(NamesOfPlots[10].c_str(), NamesOfPlots[10].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[11]] = new TH1D(NamesOfPlots[11].c_str(), NamesOfPlots[11].c_str(), nphistar, phistarBins); AllPlots[NamesOfPlots[12]] = new TH1D(NamesOfPlots[12].c_str(), NamesOfPlots[12].c_str(), nphistar, phistarBins); map<string, TH1*> RatioPlots; //using normalized versions of the pairs to see shape changes cout << "test 1" << endl; //Vector<TH1*> YplotsFromParents; //YplotsFromParents.push_back(new TH1D("YSeperatedUpQuarkPair", "UpQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedDownQuarkPair", "DownQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedStrangeQuarkPair", "StrangeQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedCharmQuarkPair", "CharmQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedBottomQuarkPair", "BottomQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedGluonQuarkPair", "GluonQuarkPair", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedGluon", "Gluon", nY, yBins)); //YplotsFromParents.push_back(new TH1D("YSeperatedUnmatchingQuarks", "UnmatchingQuarks", nY, yBins)); //TH2D* Parents = new TH2D("ParentsPDGId", "Parents PDGID", 28, -6.5, 21.5, 28, -6.5, 21.5); TH2D* ProductionVsY = new TH2D("ProductionVsY", "ProductionVsY", 7, 0, 7, 6, yBins); for (int i = 0; i < tree->GetEntries(); i++) { tree->GetEntry(i); if(PhiStar->GetValue()==-1)continue; if (fabs(MomOrPenUltimateMom1->GetValue()) == 1 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue()); AllPlots["UpQuarkPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(0.1, Z_YBorn->GetValue() ); } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 2 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue()); AllPlots["DownQuarkPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(1.1, Z_YBorn->GetValue()); } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 3 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue()); AllPlots["StrangeQuarkPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(2.1, Z_YBorn->GetValue()); } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 4 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue()); AllPlots["CharmQuarkPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(3.1, Z_YBorn->GetValue()); } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 5 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue()); AllPlots["BottomQuarkPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(4.1, Z_YBorn->GetValue()); } else if ((MomOrPenUltimateMom1->GetValue() == 21 && fabs(MomOrPenUltimateMom2->GetValue()) < 7) || (MomOrPenUltimateMom2->GetValue() == 21 && fabs(MomOrPenUltimateMom1->GetValue()) < 7)) { AllPlots["SingleQuark"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(6.1, Z_YBorn->GetValue()); } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 21 && MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) { AllPlots["Gluon"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(6.1, Z_YBorn->GetValue()); } else if ((MomOrPenUltimateMom1->GetValue()) < 7 && (MomOrPenUltimateMom1->GetValue()) > 0 && (MomOrPenUltimateMom2->GetValue()) < 7 && (MomOrPenUltimateMom2->GetValue()) > 0) { AllPlots["TwoQuarks"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(7.1, Z_YBorn->GetValue()); } else if ((MomOrPenUltimateMom1->GetValue()) > -7 && (MomOrPenUltimateMom1->GetValue()) < 0 && (MomOrPenUltimateMom2->GetValue()) > -7 && (MomOrPenUltimateMom2->GetValue()) < 0) { AllPlots["TwoAntiQuarks"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(7.1, Z_YBorn->GetValue()); } else if (fabs(MomOrPenUltimateMom1->GetValue()) < 7 && fabs(MomOrPenUltimateMom1->GetValue()) < 7) { AllPlots["QuarkAntiQuarkNotPair"]->Fill(PhiStar->GetValue()); ProductionVsY->Fill(7.1, Z_YBorn->GetValue()); } else { cout << "SOmething broke" << endl; AllPlots["Broken"]->Fill(PhiStar->GetValue()); } } { cout<<"Our first bin is "<<AllPlots["UpQuarkPair"]->GetBinContent(1)<<endl; } cout << "test 2" << endl; AllPlots["Quark Quark And AntiQuark AntiQuark"]->Add(AllPlots["TwoAntiQuarks"]); cout << "test 2.1" << endl; AllPlots["Quark Quark And AntiQuark AntiQuark"] ->Add(AllPlots["TwoQuarks"]); TH1D* AllQuarksNorm = (TH1D*) AllPlots["QuarkAntiQuarkPair"]->Clone("Devisor"); AllQuarksNorm->Scale(1 / AllQuarksNorm->Integral()); for (int i = 0; i < 5; i++) { string NewName = "Ratio" + NamesOfPlots[i]; RatioPlots[NewName] = (TH1D*) AllPlots[NamesOfPlots[i]]->Clone(NewName.c_str()); RatioPlots[NewName]->Scale(1 / RatioPlots[NewName]->Integral()); RatioPlots[NewName]->Divide(AllQuarksNorm); } cout << "test 3" << endl; for (size_t i = 0; i < AllPlots.size(); i++) { for (size_t j = 1; j <= nphistar; j++) { AllPlots[NamesOfPlots[i]]->SetBinContent(j, AllPlots[NamesOfPlots[i]]->GetBinContent(j) / (phistarBins[j] - phistarBins[j - 1])); } } cout << "test 4" << endl; for (size_t i = 0; i < NamesOfPlots.size(); i++) { TCanvas canvas("canvas", "canvas", 1000, 1000); canvas.cd(); canvas.SetLogx(); canvas.SetLogy(); gStyle->SetCanvasColor(0); gStyle->SetStatBorderSize(1); gStyle->SetOptStat(""); gStyle->SetOptFit(); AllPlots[NamesOfPlots[i]]->GetXaxis()->SetRangeUser(.004, 10); AllPlots[NamesOfPlots[i]]->Draw(); AllPlots[NamesOfPlots[i]]->SetLineWidth(2); string SaveName = NamesOfPlots[i]; SaveName = 0 == w ? "Mom_" + SaveName : "PenUltimate_" + SaveName; string WithType = "PhiStarPlots/Mompng/" + SaveName + ".png"; canvas.Print(WithType.c_str()); WithType = "PhiStarPlots/MomPDF/" + SaveName + ".pdf"; canvas.Print(WithType.c_str()); WithType = "PhiStarPlots/MomC/" + SaveName + ".C"; canvas.Print(WithType.c_str()); //if (i == 8)canvas.Print("Broken.png"); } cout << "test 5" << endl; TCanvas canvas("c2", "c2", 1000, 1000); canvas.cd(); canvas.SetLogx(); canvas.SetLogy(); gStyle->SetCanvasColor(0); gStyle->SetStatBorderSize(1); gStyle->SetOptStat(""); AllPlots[NamesOfPlots[0]]->SetLineColor(kBlack); AllPlots[NamesOfPlots[1]]->SetLineColor(kBlue); AllPlots[NamesOfPlots[2]]->SetLineColor(kRed); AllPlots[NamesOfPlots[3]]->SetLineColor(kGreen + 1); AllPlots[NamesOfPlots[4]]->SetLineColor(kMagenta + 1); AllPlots[NamesOfPlots[5]]->SetLineColor(kOrange + 1); AllPlots[NamesOfPlots[6]]->SetLineColor(TColor::GetColor("#a65628")); AllPlots["Quark Quark And AntiQuark AntiQuark"]->SetLineColor(TColor::GetColor("#999999")); if (w == 0) { AllPlots[NamesOfPlots[0]]->SetTitle(""); AllPlots[NamesOfPlots[0]]->SetXTitle("#phi^{*}"); AllPlots[NamesOfPlots[0]]->GetXaxis()->CenterTitle(); AllPlots[NamesOfPlots[0]]->Draw(); AllPlots[NamesOfPlots[5]]->Draw("same"); } else { AllPlots[NamesOfPlots[5]]->SetTitle(""); AllPlots[NamesOfPlots[5]]->SetXTitle("#phi^{*}"); AllPlots[NamesOfPlots[5]]->GetXaxis()->CenterTitle(); AllPlots[NamesOfPlots[5]]->Draw(); AllPlots[NamesOfPlots[0]]->Draw("same"); } AllPlots[NamesOfPlots[1]]->Draw("same"); AllPlots[NamesOfPlots[2]]->Draw("same"); if (w == 0) { AllPlots[NamesOfPlots[3]]->Draw("same"); AllPlots[NamesOfPlots[4]]->Draw("same"); } AllPlots[NamesOfPlots[6]]->Draw("same"); AllPlots["Quark Quark And AntiQuark AntiQuark"]->Draw("same"); TLegend* leg = new TLegend(0.7, 0.70, 0.87, 0.89); leg->AddEntry(AllPlots[NamesOfPlots[0]], "u#bar{u}"); leg->AddEntry(AllPlots[NamesOfPlots[1]], "d#bar{d}"); leg->AddEntry(AllPlots[NamesOfPlots[2]], "s#bar{s}"); if (w == 0) { leg->AddEntry(AllPlots[NamesOfPlots[3]], "c#bar{c}"); leg->AddEntry(AllPlots[NamesOfPlots[4]], "b#bar{b}"); } leg->AddEntry(AllPlots[NamesOfPlots[5]], "qg or #bar{q}g"); leg->AddEntry(AllPlots[NamesOfPlots[6]], "gg"); //leg->AddEntry(AllPlots[8], "Broken");NamesOfPlots[0]], "Up"); leg->AddEntry(AllPlots[NamesOfPlots[11]], "qq or #bar{q}#bar{q}"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw("same"); PlotName = w == 0 ? "Mom_AllLines.pn" : "PenUltimate_AllLines"; string WithType = "PhiStarPlots/Mompng/" + PlotName + ".png"; canvas.Print(WithType.c_str()); WithType = "PhiStarPlots/MomPDF/" + PlotName + ".pdf"; canvas.Print(WithType.c_str()); WithType = "PhiStarPlots/MomC/" + PlotName + ".C"; canvas.Print(WithType.c_str()); TCanvas canvas3("c3", "c3", 1000, 1000); canvas3.cd(); canvas3.SetLogz(); gStyle->SetCanvasColor(0); gStyle->SetStatBorderSize(1); gStyle->SetOptStat(""); cout << "test last" << endl; ProductionVsY->Draw("colz"); PlotName = w == 0 ? "Mom_TwoDCompProductionToY" : "PenUltimate_TwoDCompProductionToY"; WithType = "PhiStarPlots/Mompng/" + PlotName + ".png"; canvas3.Print(WithType.c_str()); WithType = "PhiStarPlots/MomPDF/" + PlotName + ".pdf"; canvas3.Print(WithType.c_str()); WithType = "PhiStarPlots/MomC/" + PlotName + ".C"; canvas3.Print(WithType.c_str()); cout << "test 7" << endl; TCanvas canvas4("c4", "c4", 1000, 1000); //Ratio Plots canvas4.Divide(1, 3 + 2 * (1 - w)); //canvas4.SetLogx(); //canvas4.SetLogy(); for (int i = 0; i < 3 + 2 * (1 - w); i++) { string NewName = "Ratio" + NamesOfPlots[i]; TPad * p = (TPad *) canvas4.cd(i + 1); p->SetLogx(); RatioPlots[NewName]->GetXaxis()->SetRangeUser(.004, 10); RatioPlots[NewName]->GetXaxis()->SetTitle("#phi^{*}"); RatioPlots[NewName]->GetXaxis()->CenterTitle(); cout << "OUR FIRST BIN IS: " << RatioPlots[NewName]->GetBinContent(1) << endl; RatioPlots[NewName]->Draw(); } //canvas4.cd(0); PlotName = w == 0 ? "Mom_RatioPlots" : "PenUltimate_RatioPlots"; WithType = "PhiStarPlots/Mompng/" + PlotName + ".png"; canvas4.Print(WithType.c_str()); WithType = "PhiStarPlots/MomPDF/" + PlotName + ".pdf"; canvas4.Print(WithType.c_str()); WithType = "PhiStarPlots/MomC/" + PlotName + ".C"; canvas4.Print(WithType.c_str()); string FileName = w == 0 ? "Mom_PhiStarSeperated.root" : "PenUltimate_PhiStarSeperated.root"; TFile SavedHistos(FileName.c_str(), "recreate"); for (size_t i = 0; i < NamesOfPlots.size(); i++) { AllPlots[NamesOfPlots[i]]->Write(); } SavedHistos.Write(); } return EXIT_SUCCESS; }
int macroanalysis(char* filename) { // char* filename = "combined.root"; // Read in the file TFile* f = new TFile(filename); // TDirectory* hists = f->GetDirectory("hists;1"); // TDirectory* tuples = f->GetDirectory("tuples;1"); TTree* accum = (TTree*) f->GetObjectUnchecked("AccumulatedEnergy;1"); TLeaf* einit = (TLeaf*) accum->GetLeaf("Einit"); TLeaf* edepo = (TLeaf*) accum->GetLeaf("Edep"); TTree* edeps = (TTree*) f->GetObjectUnchecked("EnergyDepositions;1"); TLeaf* individualdepos = (TLeaf*) edeps->GetLeaf("Edep"); TTree* secs = (TTree*) f->GetObjectUnchecked("SecondarySpectrum;1"); TLeaf* secsenergy = (TLeaf*) secs->GetLeaf("KineticEnergy"); double ein = 0; double eout = 0; int nevents = accum->GetEntries(); for (int ii = 0; ii<nevents; ii++) { accum->GetEntry(ii); ein+=einit->GetValue(); eout+=edepo->GetValue(); } int ndepos = edeps->GetEntries(); double deposum = 0; for (int ii = 0; ii<ndepos; ii++) { edeps->GetEntry(ii); deposum+=individualdepos->GetValue(); } int nsecs = secs->GetEntries(); double secsum = 0; for (int ii = 0; ii<nsecs; ii++) { secs->GetEntry(ii); secsum+=secsenergy->GetValue(); } cout << "Making Summary\n"; FILE* summary = fopen("macro_summ.txt", "a+"); time_t t = time(NULL); char* c_time_string = std::ctime(&t); char mytime[20]; std::strncpy(mytime, c_time_string, 19); mytime[ std::strlen(mytime) - 1 ] = '\0'; std::fprintf(summary, "%s,%s,%i,%e,%e,%i,%e,%i,%e\n", mytime, filename, nevents, ein, eout, ndepos, deposum, nsecs, secsum); fclose(summary); cout << "Making Histogram\n"; nevents = secs->GetEntries(); TH1F* secondarieslow = new TH1F("secondarieslow", "Secondary Electrons <1 keV", 900, 0.000100, 0.001000); TH1F* secondariesmid = new TH1F("secondariesmid", "Secondary Electrons 1<E<10 keV", 900, 0.001, 0.010); TH1F* secondarieshigh = new TH1F("secondarieshigh", "Secondary Electrons 10<E<100 keV", 900, 0.010, 0.100); TH1F* secondariesveryhigh = new TH1F("secondariesveryhigh", "Secondary Electrons 100keV<E<3 MeV", 2902, 0.100, 3.002); for (int ii = 0; ii<nevents; ii++) { secs->GetEntry(ii); double en = secsenergy->GetValue(); if (en < 0.001) secondarieslow->Fill(en, 1); else if (en < 0.01) secondariesmid->Fill(en, 0.1); else if (en < 0.1) secondarieshigh->Fill(en, 0.01); else secondariesveryhigh->Fill(en, 0.001); } char suffix[] = ".secondaryhisto"; cout << "Making Filenames\n"; char* outfilename = (char*) malloc(std::strlen(filename) + std::strlen(suffix) + 1); std::strcpy(outfilename, filename); std::strcat(outfilename, suffix); std::printf("Saving Histogram: %s \n", outfilename); h12ascii(secondarieslow, secondariesmid, secondarieshigh, secondariesveryhigh, outfilename); return 0; }
int main(int argc, char* argv[]) { vector<vector<double> >* voltages = new vector<vector<double> >; vector<vector<double> >* currents = new vector<vector<double> >; voltages->resize(52); currents->resize(52); TChain* chain = loadChain(argc, argv); int entries = chain->GetEntries(); cout << entries/2 << " files\n"; for(int i=0; i<entries; i++) { chain->GetEvent(i); for(int slot=0; slot<16; slot++) { TLeaf* vleaf = chain->GetLeaf(("VHS_"+target_card[slot]+".VM."+target_channel[slot]).c_str()); voltages->at(slot).push_back(vleaf->GetValue(0)); TLeaf* ileaf = chain->GetLeaf(("VHS_"+target_card[slot]+".IM."+target_channel[slot]).c_str()); currents->at(slot).push_back(ileaf->GetValue(0)); } for(int slot=0; slot<36; slot++) { if(veto_card[slot]=="4_3") { voltages->at(slot+16).push_back(-1); currents->at(slot+16).push_back(-1); } else { TLeaf* vleaf = chain->GetLeaf(("VHS_"+veto_card[slot]+".VM."+veto_channel[slot]).c_str()); voltages->at(slot+16).push_back(vleaf->GetValue(0)); TLeaf* ileaf = chain->GetLeaf(("VHS_"+veto_card[slot]+".IM."+veto_channel[slot]).c_str()); currents->at(slot+16).push_back(ileaf->GetValue(0)); } } } const double allowed_dv = 100; const double allowed_di = 50e-06; vector<bool> pmt_flags_v; vector<bool> pmt_flags_i; pmt_flags_v.resize(52,0); pmt_flags_i.resize(52,0); for( auto pmt = voltages->begin(); pmt!=voltages->end(); ++pmt ) { double meanvalue = mean(*pmt); double deviation = std_dev(*pmt); //cout << "Mean: " << meanvalue << " Dev: " << deviation << endl; for(auto it2 = (*pmt).begin(); it2!=(*pmt).end(); ++it2) { //cout << distance((*it).begin(), it2) << " "; if( abs(*it2-meanvalue) > allowed_dv ) pmt_flags_v.at( distance(voltages->begin(), pmt) ) = true; } } for( auto pmt = currents->begin(); pmt!=currents->end(); ++pmt ) { double meanvalue = mean(*pmt); double deviation = std_dev(*pmt); for(auto it2 = (*pmt).begin(); it2!=(*pmt).end(); ++it2) if( abs(*it2-meanvalue) > allowed_di ) pmt_flags_i.at( distance(currents->begin(), pmt) ) = true; } bool error = false; // Now if we managed to pick up some flags lets say so for(auto it = pmt_flags_v.begin(); it!=pmt_flags_v.end(); ++it) if(*it==true) { cout << "PMT: " << distance(pmt_flags_v.begin(), it) << " varied VOLTAGE more than " << allowed_dv << " from its mean value" << endl; error = true; } for(auto it = pmt_flags_i.begin(); it!=pmt_flags_i.end(); ++it) if(*it==true) { cout << "PMT: " << distance(pmt_flags_i.begin(), it) << " varied CURRENT more than " << allowed_di << " from its mean value" << endl; error = true; } if(error == true) { cout << ">>> See error.txt for full report <<<" << endl; writeReport(voltages, pmt_flags_v, currents, pmt_flags_i); } delete currents; delete voltages; return 0; }
/// Cache MC production information void CacheTrendingProductions(TString dataType){ AliExternalInfo info; info.fLoadMetadata=kFALSE; TObjArray* periodList = NULL, *idList=NULL; // TTree * tree = info.GetTree("MonALISA.ProductionCycle","",""); Int_t nProd=tree->GetEntries(); periodList = new TObjArray(nProd); idList= new TObjArray(nProd); TLeaf *leafTag = tree->GetLeaf("Tag"); TLeaf *leafID = tree->GetLeaf("ID"); for (Int_t iProd=0; iProd<nProd; iProd++){ tree->GetEntry(iProd); TString prodName=((char*)leafTag->GetValuePointer()); TString idName =TString::Format("%d",TMath::Nint(leafID->GetValue())); if (prodName.Contains("LHC")==0) continue; periodList->AddAt(new TObjString(prodName),iProd); idList->AddAt(new TObjString(idName),iProd); } delete tree; // for (Int_t iPeriod=0; iPeriod<periodList->GetEntriesFast(); iPeriod++) { TObjString * pName= (TObjString*)idList->At(iPeriod); if (pName==NULL) continue; TTree* treeP = info.GetTreeProdCycleByID(idList->At(iPeriod)->GetName()); if (treeP==NULL) continue; TLeaf *leafOutput = treeP->GetLeaf("outputdir"); Int_t nRuns= treeP->GetEntries(); treeP->GetEntry(0); TString path=((char*)leafOutput->GetValuePointer()); TObjArray *pArray = path.Tokenize("/"); if (pArray==NULL) continue; Int_t nElems=pArray->GetEntries(); if (nElems<4) continue; TString aperiod=pArray->At(3)->GetName(); TString apass =pArray->At(nElems-1)->GetName(); delete pArray; ::Info("CacheTrendingProductions","%s\t%s\t%s\t%s\t%d",idList->At(iPeriod)->GetName(),path.Data(), aperiod.Data(),apass.Data(),nRuns); delete treeP; TTree* treeQA = info.GetTree(dataType.Data(),aperiod.Data(),apass.Data()); if (treeQA){ Int_t entries=treeQA->Draw("run","1","goff"); TString sInfo=aperiod; sInfo+="\t"; sInfo+=apass; sInfo+="\t"; sInfo+=dataType; sInfo+="\t"; sInfo+=TString::Format("%d\t",entries); sInfo+=TString::Format("%d\t",nRuns); for (Int_t j=0; j<entries; j++) { sInfo+=TString::Format("%2.0f,",treeQA->GetV1()[j]); ::Info("CacheTrendingProductionsRun:","%s\t%s\t%s\t%d\t%d\t%2.0f",aperiod.Data(),apass.Data(),dataType.Data(),entries,nRuns,treeQA->GetV1()[j]); } sInfo+="0"; ::Info("CacheTrendingProductionsPeriod:","%s\n",sInfo.Data()); delete treeQA; }else{ ::Error("CacheTrendingProductionsPeriod:","%s\t%s\t%s\t-1\t%d\t0",aperiod.Data(),apass.Data(), dataType.Data(),nRuns); } } }