30 #include <TGridResult.h> 40 #include <AliAnalysisManager.h> 41 #include <AliVEvent.h> 42 #include <AliAODEvent.h> 43 #include <AliESDEvent.h> 44 #include <AliMCEvent.h> 45 #include <AliInputEventHandler.h> 46 #include <AliVHeader.h> 47 #include <AliAODMCHeader.h> 48 #include <AliGenPythiaEventHeader.h> 66 AliInfoGeneralStream(
"AliAnalysisTaskEmcalEmbeddingHelper") <<
"Trying to connect to AliEn ...\n";
67 TGrid::Connect(
"alien://");
70 AliFatalGeneral(
"AliAnalysisTaskEmcalEmbeddingHelper",
"Cannot access AliEn!");
84 if (!gGrid && filename.find(
"alien://") != std::string::npos) {
89 if (filename.find(
".zip#") != std::string::npos) {
90 std::size_t pos = filename.find_last_of(
"#");
98 bool res =
gSystem->AccessPathName(filename.c_str());
100 res = (res ==
false);
102 AliDebugGeneralStream(
"AliAnalysisTaskEmcalEmbeddingHelper", 4) <<
"File \"" << filename <<
"\" doees not exist!\n";
116 fMCRejectOutliers(false),
117 fPtHardJetPtRejectionFactor(4),
120 fInitializedConfiguration(false),
121 fInitializedNewFile(false),
122 fInitializedEmbedding(false),
123 fWrappedAroundTree(false),
127 fRandomEventNumberAccess(kFALSE),
128 fRandomFileAccess(kTRUE),
131 fUseInternalEventSelection(false),
132 fUseManualInternalEventCuts(false),
133 fInternalEventCuts(),
134 fEmbeddedEventUsed(true),
135 fValidatedPhysicsSelection(false),
136 fInternalEventTriggerMask(0),
139 fRandomRejectionFactor(1.),
141 fAutoConfigurePtHardBins(false),
142 fAutoConfigureBasePath(
""),
143 fAutoConfigureTrainTypePath(
""),
144 fAutoConfigureIdentifier(
""),
147 fFileListFilename(
""),
150 fConfigurationPath(
""),
152 fPythiaCrossSectionFilenames(),
159 fMaxNumberOfFiles(0),
167 fPythiaTrialsFromFile(0),
168 fPythiaCrossSection(0.),
169 fPythiaCrossSectionFromFile(0.),
171 fPrintTimingInfoToLog(false),
175 AliError(
"An instance of AliAnalysisTaskEmcalEmbeddingHelper already exists: it will be deleted!!!");
249 AliError(
"An instance of AliAnalysisTaskEmcalEmbeddingHelper already exists: it will be deleted!!!");
256 DefineOutput(1, AliEmcalList::Class());
285 if (result && initializedYAML) {
289 if (removeDummyTask ==
true) {
313 std::vector<std::string> physicsSelection;
344 std::string baseName =
"internalEventSelection";
348 std::vector <double> centralityRange;
351 if (centralityRange.size() != 2) {
352 AliErrorStream() <<
"Passed centrality range with " << centralityRange.size() <<
" entries, but 2 values are required. Ignoring values.\n";
355 AliDebugStream(1) <<
"Setting internal event centrality range to [" << centralityRange.at(0) <<
", " << centralityRange.at(1) <<
"]\n";
409 AliFatal(TString::Format(
"Requested default (pattern) input filename, but could not determine file type from tree name \"%s\". Please check the tree name and set the pattern input filename",
fTreeName.Data()));
420 AliFatal(
"Requested both pt hard bin auto configuration and selected a non-zero pt hard bin. These are incompatible options. Please check your configuration.");
423 if (success ==
false) {
424 AliFatal(
"Pt hard bin auto configuration requested, but it failed. Please check the logs.\n");
440 bool usedFilePattern =
false;
442 usedFilePattern =
true;
443 AliDebug(2, TString::Format(
"Trying to retrieve file list from AliEn with pattern file %s...",
fFilePattern.Data()));
452 filePattern.ReplaceAll(
"alien://",
"");
455 AliDebug(2, TString::Format(
"Trying to retrieve file list from AliEn with pattern \"%s\" and input filename \"%s\"", filePattern.Data(),
fInputFilename.Data()));
456 auto result = gGrid->Query(filePattern.Data(),
fInputFilename.Data());
462 for (
int i = 0; i < result->GetEntries(); i++)
464 TString path = result->GetKey(i,
"turl");
469 outFile << path <<
"\n";
475 AliErrorStream() <<
"Failed to run grid query\n";
483 if (usedFilePattern) {
484 AliErrorStream() <<
"You set both the file pattern and the file list filename! The file list filename will override the pattern! Pattern: \"" <<
fFilePattern <<
"\", filename: \"" <<
fFileListFilename <<
"\"\nPlease check that this is the desired behavior!\n";
499 std::copy(std::istream_iterator<std::string>(inputFile),
500 std::istream_iterator<std::string>(),
507 AliFatal(TString::Format(
"Filenames from pattern \"%s\" and file list \"%s\" yielded an empty list!",
fFilePattern.Data(),
fFileListFilename.Data()));
514 if (
filename.find(
".zip") != std::string::npos &&
filename.find(
"#") == std::string::npos) {
524 AliError(TString::Format(
"Filename %s contains \".zip\" and not \"#\", but tree name %s is not recognized. Please check the file list to ensure that the proper path is set.",
filename.c_str(),
fTreeName.Data()));
534 if (
filename.find(
"alien://") != std::string::npos) {
542 unsigned int initialSize = fFilenames.size();
544 fFilenames.erase(std::remove_if(fFilenames.begin(), fFilenames.end(), [](
const std::string &
filename) {
return (::
IsFileAccessible(
filename) ==
false);} ), fFilenames.end());
546 AliInfoStream() <<
"Found " << fFilenames.size() <<
" files to embed (" << (initialSize - fFilenames.size()) <<
" filename(s) inaccessible or invalid)\n";
561 std::string externalEventFilename =
"";
569 std::vector <std::string> pythiaBaseFilenames = {
"pyxsec.root",
"pyxsec_hists.root"};
570 AliInfoStream() <<
"Attempting to determine pythia cross section filename. It can be normal to see some TFile::Init() errors!\n";
571 std::string pythiaXSecFilename =
"";
572 for (
auto & name : pythiaBaseFilenames) {
574 if (pythiaXSecFilename !=
"") {
575 AliDebugStream(4) <<
"Found pythia cross section filename \"" << name <<
"\"\n";
584 AliErrorStream() <<
"Failed to find pythia x sec file! Continuing with only the pythia header!\n";
606 if (path.find(run) != std::string::npos) {
621 AliInfo(
"No Embedding YAML configuration was provided");
624 AliInfoStream() <<
"Embedding YAML configuration was provided: \"" <<
fConfigurationPath <<
"\".\n";
627 if (addedConfig < 0) {
628 AliError(
"YAML Configuration not found!");
653 bool returnValue =
false;
655 AliInfoStream() <<
"Attempting to auto configure pt hard bins.\n";
666 const char * trainNumberStr =
gSystem->Getenv(
"TRAIN_RUN_ID");
667 std::stringstream trainNumberSS;
668 if (trainNumberStr) {
669 trainNumberSS << trainNumberStr;
671 if (trainNumberSS.str() ==
"") {
672 AliFatal(
"Cannot retrieve train ID.");
676 trainNumberSS >> trainNumber;
685 std::string yamlExtension =
".yaml";
686 if (
filename.find(yamlExtension) == std::string::npos) {
693 AliInfoStream() <<
"Train pt hard bin configuration file not available, so creating a new empty configuration named \"" <<
fAutoConfigureIdentifier <<
"\".\n";
698 AliInfoStream() <<
"Opening configuration located at \"" <<
filename <<
"\".\n";
705 int tempTrainNumber = -1;
706 bool getPropertyReturnValue =
false;
707 std::stringstream propertyName;
708 for (
int ptHardBin = 1; ptHardBin <=
fNPtHardBins; ptHardBin++)
710 propertyName.str(
"");
711 propertyName << ptHardBin;
712 getPropertyReturnValue = config.
GetProperty(propertyName.str(), tempTrainNumber,
false);
713 if (getPropertyReturnValue !=
true) {
714 AliInfoStream() <<
"Train " << trainNumber <<
" will use pt hard bin " << ptHardBin <<
".\n";
731 AliDebugStream(2) <<
"Found pt hard bin " << ptHardBin <<
" corresponding to train number " << trainNumber <<
".\n";
733 if (tempTrainNumber == trainNumber) {
734 AliInfoStream() <<
"Train run number " << trainNumber <<
" was already found assigned to pt hard bin " << ptHardBin <<
". That pt hard bin will be used.\n";
757 std::string tempStr =
"";
759 tempStr =
"fileList";
763 tempStr += tempUUID.AsString();
778 while (filename.rbegin() != filename.rend() && *(filename.rbegin()) ==
'/') {
798 AliInfo(TString::Format(
"Starting with random file number %i!",
fFilenameIndex+1));
804 AliWarning(TString::Format(
"File index %i out of range from 0 to %lu! Resetting to 0!",
fFilenameIndex,
fFilenames.size()));
853 AliError(
"====================================================================================================");
854 AliError(
"== No more files available to embed from the TChain! Restarting from the beginning of the TChain! ==");
855 AliError(
"== Be careful to check that this is the desired action! ==");
856 AliError(
"====================================================================================================");
880 if (attempts == 1000)
881 AliWarning(
"After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
895 if (!
fChain)
return kFALSE;
906 AliDebug(4,
"Set event properties");
910 AliAODMCHeader* aodMCH =
dynamic_cast<AliAODMCHeader*
>(
fExternalEvent->FindListObject(AliAODMCHeader::StdBranchName()));
912 for (
UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
913 fPythiaHeader =
dynamic_cast<AliGenPythiaEventHeader*
>(aodMCH->GetCocktailHeader(i));
925 AliDebugStream(4) <<
"Taking the pythia cross section avg from the xsec file.\n";
930 AliDebugStream(4) <<
"Taking the pythia trials avg from the xsec file.\n";
935 AliDebugStream(4) <<
"Pythia header is defined!\n";
982 AliDebugStream(3) <<
"Event rejected due to pt hard = 0, indicating a problem with the external event.\n";
994 AliFatal(
"Event selection is not implemented for embedding ESDs.");
1004 res = (
dynamic_cast<AliVAODHeader*
>(aev->GetHeader()))->GetOfflineTrigger();
1009 AliDebug(3, Form(
"Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.",
1010 res, fTriggerMask));
1021 const AliVVertex *externalVert =
fExternalEvent->GetPrimaryVertex();
1022 const AliVVertex *inputVert = AliAnalysisTaskSE::InputEvent()->GetPrimaryVertex();
1023 if (externalVert && inputVert) {
1024 externalVert->GetXYZ(externalVertex);
1025 inputVert->GetXYZ(inputVertex);
1027 if (TMath::Abs(externalVertex[2]) >
fZVertexCut) {
1028 AliDebug(3, Form(
"Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f",
1035 Double_t dist = TMath::Sqrt((externalVertex[0]-inputVertex[0])*(externalVertex[0]-inputVertex[0])+(externalVertex[1]-inputVertex[1])*(externalVertex[1]-inputVertex[1])+(externalVertex[2]-inputVertex[2])*(externalVertex[2]-inputVertex[2]));
1037 AliDebug(3, Form(
"Event rejected because the distance between the current and embedded vertices is > %f. " 1038 "Current event vertex (%f, %f, %f), embedded event vertex (%f, %f, %f). Distance = %f",
1039 fMaxVertexDist, inputVertex[0], inputVertex[1], inputVertex[2], externalVertex[0], externalVertex[1], externalVertex[2], dist));
1059 AliDebugStream(4) <<
"Pythia Njets: " << nTriggerJets <<
", pT Hard: " <<
fPythiaPtHard <<
"\n";
1062 for (
Int_t iJet = 0; iJet< nTriggerJets; iJet++) {
1065 jet.SetPxPyPzE(tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3]);
1067 AliDebugStream(5) <<
"Pythia jet " << iJet <<
", pycell jet pT: " << jet.Pt() <<
"\n";
1071 AliDebugStream(3) <<
"Event rejected because of MC outlier removal. Pythia header jet with: pT Hard " << fPythiaPtHard <<
", pycell jet pT " << jet.Pt() <<
", rejection factor " <<
fPtHardJetPtRejectionFactor <<
"\n";
1089 if (!
fChain)
return kFALSE;
1099 AliError(Form(
"Tree name %s not recognized!",
fTreeName.Data()));
1124 AliDebugStream(1) <<
"Configuring AliEventCuts for internal event selection.\n";
1132 bool useEventCutsAutomaticTriggerSelection =
false;
1133 bool res =
fYAMLConfig.
GetProperty(std::vector<std::string>({
"internalEventSelection",
"useEventCutsAutomaticTriggerSelection"}), useEventCutsAutomaticTriggerSelection,
false);
1134 if (res && useEventCutsAutomaticTriggerSelection) {
1137 AliDebugStream(1) <<
"Using the automatic trigger selection from AliEventCuts.\n";
1142 AliDebugStream(1) <<
"Using the trigger selection specified via YAML: " << triggerMask <<
".\n";
1165 eventCutsOutput->SetOwner(kTRUE);
1166 eventCutsOutput->SetName(
"EventCuts");
1170 fOutput->Add(eventCutsOutput);
1178 histName =
"fHistXsection";
1179 histTitle =
"Pythia Cross Section;p_{T} hard bin; XSection";
1183 histName =
"fHistTrials";
1184 histTitle =
"Number of Pythia Trials;p_{T} hard bin;Trials";
1188 histName =
"fHistPtHard";
1189 histTitle =
"p_{T} Hard Spectra;p_{T} hard;Counts";
1193 histName =
"fHistEventCount";
1194 histTitle =
"Event count;Result;Count";
1196 histEventCount->GetXaxis()->SetBinLabel(1,
"Accepted");
1197 histEventCount->GetXaxis()->SetBinLabel(2,
"Rejected");
1200 histName =
"fHistEmbeddedEventRejection";
1201 histTitle =
"Reasons to reject embedded event";
1202 std::vector<std::string> binLabels = {
"PhysSel",
"MCOutlier",
"Vz",
"VertexDist",
"PtHardIs0"};
1203 auto histEmbeddedEventRejection =
fHistManager.
CreateTH1(histName, histTitle, binLabels.size(), 0, binLabels.size());
1205 for (
unsigned int i = 1; i <= binLabels.size(); i++) {
1206 histEmbeddedEventRejection->GetXaxis()->SetBinLabel(i, binLabels.at(i-1).c_str());
1208 histEmbeddedEventRejection->GetYaxis()->SetTitle(
"Counts");
1211 histName =
"fHistEmbeddedEventsAttempted";
1212 histTitle =
"Number of embedded events rejected by event selection before success;Number of rejected events;Counts";
1216 histName =
"fHistNumberOfFilesEmbedded";
1217 histTitle =
"Number of files which contributed events to be embedded";
1221 histName =
"fHistAbsoluteFileNumber";
1222 histTitle =
"Number of times each absolute file number was embedded";
1227 histName =
"fHistInternalEventCutsStats";
1228 histTitle =
"Number of events to pass each cut";
1229 binLabels = {
"passedEventCuts",
"centrality",
"passedRandomRejection",
"passedAllCuts"};
1230 auto histInternalEventCutsStats =
fHistManager.
CreateTH1(histName, histTitle, binLabels.size(), 0, binLabels.size());
1232 for (
unsigned int i = 1; i <= binLabels.size(); i++) {
1233 histInternalEventCutsStats->GetXaxis()->SetBinLabel(i, binLabels.at(i-1).c_str());
1235 histInternalEventCutsStats->GetYaxis()->SetTitle(
"Number of selected events");
1240 histName =
"fInitTreeCPUtime";
1241 histTitle =
"CPU time to execute InitTree() (s)";
1244 histName =
"fInitTreeRealtime";
1245 histTitle =
"Real time to execute InitTree() (s)";
1252 while ((obj = next())) {
1276 if (
filename.find(
"alien://") != std::string::npos) {
1285 bool wrapped =
false;
1286 std::string fullPythiaXSecFilename =
"";
1301 AliDebugStream(4) <<
"Adding file to the embedded input chain \"" << *
filename <<
"\".\n";
1312 AliDebugStream(4) <<
"Adding pythia cross section file \"" << fullPythiaXSecFilename <<
"\".\n";
1323 AliErrorStream() <<
"Number of input files (" << fFilenames.size() <<
") is larger than the number of available files (" <<
fMaxNumberOfFiles <<
"). Something went wrong when adding some of those files to the TChain!\n";
1328 if (!res)
return kFALSE;
1345 std::string pythiaXSecFilename =
"";
1348 if (externalEventFilename.find(
".zip#") != std::string::npos) {
1349 std::size_t pos = externalEventFilename.find_last_of(
"#");
1350 externalEventFilename.erase(pos);
1354 if (externalEventFilename.find(
".zip") != std::string::npos)
1357 pythiaXSecFilename = externalEventFilename;
1358 pythiaXSecFilename +=
"#";
1359 pythiaXSecFilename += pythiaFilename;
1365 std::unique_ptr<TFile> fTemp(TFile::Open(pythiaXSecFilename.c_str(),
"READ"));
1368 AliDebugStream(4) <<
"File " << pythiaXSecFilename.c_str() <<
" does not exist!\n";
1369 pythiaXSecFilename =
"";
1372 AliDebugStream(4) <<
"Found pythia cross section file \"" << pythiaXSecFilename.c_str() <<
"\".\n";
1379 pythiaXSecFilename =
gSystem->DirName(externalEventFilename.c_str());
1380 pythiaXSecFilename +=
"/";
1381 pythiaXSecFilename += pythiaFilename;
1386 AliDebugStream(4) <<
"Found pythia cross section file \"" << pythiaXSecFilename.c_str() <<
"\".\n";
1389 AliDebugStream(4) <<
"File " << pythiaXSecFilename.c_str() <<
" does not exist!\n";
1390 pythiaXSecFilename =
"";
1395 return pythiaXSecFilename;
1406 AliFatal(
"The configuration is not initialized. Check that Initialize() was called!");
1411 if (!res) {
return; }
1415 AliInfo(
"Random event number access enabled!");
1484 AliDebugStream(3) <<
"Failed to retrieve cross section from xsec file. Will still attempt to get the information from the header.\n";
1488 AliErrorStream() <<
"Attempted to read past the end of the pythia cross section filenames vector. File number: " <<
fFileNumber <<
", vector size: " <<
fPythiaCrossSectionFilenames.size() <<
".\nThis should only occur if we have run out of files to embed!\n";
1492 AliDebug(2, TString::Format(
"Will start embedding file %i beginning from entry %i (entry %i within the file). NOTE: This file number is not equal to the absolute file number in the file list!",
fFileNumber,
fCurrentEntry,
fCurrentEntry -
fLowerEntry));
1506 std::cout <<
"InitTree() complete. CPU time: " <<
fTimer.CpuTime() <<
" (s). Real time: " <<
fTimer.RealTime() <<
" (s)." << std::endl;
1522 std::unique_ptr<TFile> fxsec(TFile::Open(pythiaFileName.c_str()));
1527 double crossSection = 0;
1530 TTree *xtree =
dynamic_cast<TTree*
>(fxsec->Get(
"Xsection"));
1534 xtree->SetBranchAddress(
"xsection",&xsection);
1535 xtree->SetBranchAddress(
"ntrials",&ntrials);
1538 crossSection = xsection;
1541 AliFatal(
"Have no tested pyxsec.root files. Need to determine the proper way to get nevents!!");
1546 TKey* key =
static_cast<TKey*
>(fxsec->GetListOfKeys()->At(0));
1547 if (!key)
return false;
1548 TList *list =
dynamic_cast<TList*
>(key->ReadObj());
1549 if (!list)
return false;
1550 TProfile * crossSectionHist =
static_cast<TProfile*
>(list->FindObject(
"h1Xsec"));
1552 if(!(crossSectionHist->GetEntries())) {
1554 AliErrorStream() <<
"No cross section information available in file \"" << fxsec->GetName() <<
"\". Will still attempt to extract cross section information from pythia header.\n";
1557 crossSection = crossSectionHist->GetBinContent(1);
1558 if(!crossSection) AliErrorStream() << GetName() <<
": Cross section 0 for file " << pythiaFileName << std::endl;
1560 TH1F * trialsHist =
static_cast<TH1F*
>(list->FindObject(
"h1Trials"));
1561 trials = trialsHist->GetBinContent(1);
1562 nEvents = trialsHist->GetEntries();
1577 AliDebugStream(3) <<
"Unable to open file \"" << pythiaFileName <<
"\". Will attempt to use values from the header.";
1592 AliError(
"Chain not initialized before running! Setting up now.");
1608 AliDebugStream(1) <<
"Validating physics selection.\n";
1611 AliDebugStream(1) <<
"Successfully validated the physics selection!\n";
1652 AliFatal(
"No analysis manager to connect to.");
1656 AliDebugStream(3) <<
"Internal event rejected due to event selection. Breaking execution early.\n";
1657 mgr->BreakExecutionChain(kTRUE);
1669 AliError(
"Unable to get the event to embed. Nothing will be embedded.");
1690 AliFatal(
"No analysis manager to connect to.");
1699 UInt_t collisionCandidates = this->GetCollisionCandidates();
1700 bool res = (
fInternalEventCuts.fTriggerMask | collisionCandidates) == collisionCandidates;
1702 std::stringstream message;
1703 message <<
"Collision candidates selected for the embedding helper are more restrictive than" 1704 <<
" the internal event physics selection! You will not have access to all of the events" 1705 <<
" selected in the internal event physics selection. Please expand your trigger mask set" 1706 <<
" via SelectCollisionCandidates().\n" 1707 << std::bitset<32>(
fInternalEventCuts.fTriggerMask) <<
" <- Embedding helper internal event physics selection\n" 1708 << std::bitset<32>(collisionCandidates) <<
" <- Collision candidates\n";
1709 AliFatal(message.str().c_str());
1712 auto tasks = mgr->GetTasks();
1713 for (
auto t : *tasks)
1716 if (!task || task->GetName() == GetName()) {
1728 UInt_t taskCollisionCandidates = task->GetCollisionCandidates();
1729 res = (taskCollisionCandidates | collisionCandidates) == collisionCandidates;
1731 std::stringstream message;
1732 message <<
"The physics selection of all tasks must be a subset of the physics selection used" 1733 <<
" in the embedding helper.\n" 1734 << std::bitset<32>(collisionCandidates) <<
" <- Embedding helper internal event physics selection\n" 1735 << std::bitset<32>(taskCollisionCandidates) <<
" <- Task \"" << task->GetName() <<
"\" collision candidates\n";
1736 AliFatal(message.str().c_str());
1757 AliErrorStream() <<
"No analysis manager to connect to.\n";
1762 std::string dummyTaskName = GetName();
1763 dummyTaskName +=
"_dummyTask";
1768 AliErrorStream() <<
"Could not remove dummy task \"" << dummyTaskName <<
"\" from analysis manager! Was it added?\n";
1771 tasks->Remove(dummyTask);
1772 AliDebugStream(1) <<
"Removed dummy task named \"" << dummyTaskName <<
"\".\n";
1775 AliErrorStream() <<
"Could not retrieve tasks from the analysis manager.\n";
1785 AliErrorStream() <<
"Enable manual mode in AliEventCuts (though the embedding helper) to access this object.\n";
1797 ::Error(
"AddTaskEmcalEmbeddingHelper",
"No analysis manager to connect to.");
1803 AliVEventHandler* handler = mgr->GetInputEventHandler();
1806 ::Error(
"AddTaskEmcalEmbeddingHelper",
"This task requires an input event handler");
1810 TString name =
"AliAnalysisTaskEmcalEmbeddingHelper";
1813 if (mgrTask)
return mgrTask;
1822 mgr->AddTask(embeddingHelper);
1825 AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
1827 TString outputContainerName(name);
1828 outputContainerName +=
"_histos";
1830 AliAnalysisDataContainer * cOutput = mgr->CreateContainer(outputContainerName.Data(),
1832 AliAnalysisManager::kOutputContainer,
1833 Form(
"%s", AliAnalysisManager::GetCommonFileName()));
1835 mgr->ConnectInput(embeddingHelper, 0, cInput);
1836 mgr->ConnectOutput(embeddingHelper, 1, cOutput);
1838 return embeddingHelper;
1848 ::Error(
"ConfigureEmcalEmbeddingHelperOnLEGOTrain",
"No analysis manager to connect to.");
1858 if (!embeddingHelper) {
1859 AliFatalClass(
"Could not find embedding helper, Did you remember to create it?");
1862 AliInfoClassStream() <<
"Found embedding helper to configure.\n";
1866 mgr->AddTask(
new AliAnalysisTaskSE(
"AliAnalysisTaskEmcalEmbeddingHelper_dummyTask"));
1868 return embeddingHelper;
1878 std::stringstream tempSS;
1881 tempSS << std::boolalpha;
1882 tempSS << GetName() <<
": Embedding helper configuration:\n";
1884 tempSS <<
"Pt Hard Bin: " <<
fPtHardBin <<
"\n";
1886 tempSS <<
"File pattern: \"" <<
fFilePattern <<
"\"\n";
1890 tempSS <<
"Tree name: " <<
fTreeName <<
"\n";
1895 tempSS <<
"Number of files to embed: " <<
fFilenames.size() <<
"\n";
1900 tempSS <<
"Internal event selection centrality range: [" <<
fCentMin <<
", " <<
fCentMax <<
"]\n";
1903 tempSS <<
"Internal event selection centrality range disabled.\n";
1905 tempSS <<
"Internal event physics selection via class (should propagate to AliEventCuts): " << std::bitset<32>(
fInternalEventTriggerMask) <<
"\n";
1906 tempSS <<
"Internal event physics selection via AliEventCuts: " << std::bitset<32>(
fInternalEventCuts.fTriggerMask) <<
"\n";
1909 tempSS <<
"\nEmbedded event settings:\n";
1910 tempSS <<
"Trigger mask (binary): " << triggerMask <<
"\n";
1913 tempSS <<
"Z vertex cut: " <<
fZVertexCut <<
"\n";
1914 tempSS <<
"Max difference between internal and embedded vertex: " <<
fMaxVertexDist <<
"\n";
1917 if (includeFileList) {
1918 tempSS <<
"\nFiles to embed:\n";
1920 tempSS <<
"\t" <<
filename <<
"\n";
1924 return tempSS.str();
1949 std::ostream & result = myTask.
Print(in);
1961 std::string temp(opt);
1962 bool includeFileList =
false;
1963 if (temp ==
"FILELIST") {
1964 includeFileList =
true;
1966 Printf(
"%s",
toString(includeFileList).c_str());
Bool_t fRandomEventNumberAccess
If true, it will start embedding from a random entry in the file rather than from the first...
Double_t fZVertexCut
Z vertex cut on embedded event.
void UserExec(Option_t *option)
void RecordEmbeddedEventProperties()
void ConnectToAliEn() const
Int_t fPtHardBin
ptHard bin for the given pythia production
bool fMCRejectOutliers
If true, MC outliers will be rejected.
double fPythiaCrossSection
! Pythia cross section for the current event (extracted from the pythia header).
Int_t fLowerEntry
! First entry of the current tree to be used for embedding
TRandom3 fRandom
for random rejection of events
TString fFileListFilename
Name of the file list containing paths to files to embed.
void SetEmbeddedEventProperties()
int fPythiaTrialsFromFile
! Average number of trials extracted from a xsec file.
Bool_t fRandomFileAccess
If true, it will start embedding from a random file in the input files list.
TStopwatch fTimer
! Timer for the InitTree() function
Int_t fCurrentEntry
! Current entry in the current tree
TFile * fExternalFile
! External file used for embedding
Int_t fNPtHardBins
Total number of pt hard bins.
TChain * fChain
! External TChain (tree) containing the events available for embedding
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
void RemoveDummyTask() const
bool fAutoConfigurePtHardBins
If true, attempt to auto configure pt hard bins. Only works on the LEGO train.
bool fInitializedConfiguration
Notes if the configuration has been initialized.
bool IsRunInRunlist(const std::string &path) const
AliVHeader * fExternalHeader
! Header of the current external event
AliGenPythiaEventHeader * fPythiaHeader
! Pythia header of the current external event
void DetermineFirstFileToEmbed()
const AliEventCuts * GetInternalEventCuts() const
Event cuts object for accessing centrality, etc from another task if so inclined. ...
virtual void RetrieveTaskPropertiesFromYAMLConfig()
TString fInputFilename
Filename of input root files.
friend std::ostream & operator<<(std::ostream &in, const AliAnalysisTaskEmcalEmbeddingHelper &myTask)
std::vector< std::string > fEmbeddedRunlist
Good runlist for files to embed.
std::string fAutoConfigureBasePath
The base path to the auto configuration (for example, "/alice/cern.ch/user/a/alitrain/") ...
void Terminate(Option_t *option)
std::string fConfigurationPath
Path to YAML configuration.
static UInt_t DeterminePhysicsSelectionFromYAML(const std::vector< std::string > &selections)
void CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt="")
Create a new TProfile within the container.
std::string fPythiaXSecFilename
Name of the pythia x sec filename (either "pyxsec.root" or "pyxsec_hists.root")
AliAnalysisTaskEmcalEmbeddingHelper()
THashList * GetListOfHistograms() const
Get the list of histograms.
bool fInitializedEmbedding
! Notes where the TChain has been initialized for embedding
bool fUseInternalEventSelection
If true, apply internal event selection though AliEventCuts.
virtual ~AliAnalysisTaskEmcalEmbeddingHelper()
std::string toString(bool includeFileList=false) const
Implementation of task to embed external events.
UInt_t fMaxNumberOfFiles
! Max number of files that are in the TChain
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
bool PythiaInfoFromCrossSectionFile(std::string filename)
virtual Bool_t CheckIsEmbeddedEventSelected()
void FillProfile(const char *name, double x, double y, double weight=1.)
std::string GenerateUniqueFileListFilename() const
Double_t nEvents
plot quality messages
Double_t fMaxVertexDist
Max distance between Z vertex of internal and embedded event.
AliVEvent * fExternalEvent
! Current external event available for embedding
std::vector< std::string > fPythiaCrossSectionFilenames
Paths to the pythia xsection files.
bool fValidatedPhysicsSelection
Validate that the physics selection is set appropriately.
bool fPrintTimingInfoToLog
Flag to print time to execute InitTree(), for logging purposes.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
TString fTreeName
Name of the ESD/AOD tree where the events are to be found.
void Print(Option_t *opt="") const
Int_t fOffset
! Offset from fLowerEntry where the loop over the tree should start
bool fCreateHisto
If true, create QA histograms.
bool fEmbeddedEventUsed
! If true, the internal event was selected, so the embedded event is used. Defaults to true so other ...
bool IsFileAccessible() const
UInt_t fTriggerMask
Trigger selection mask.
Enhanced TList-derived class that implements correct merging for pt_hard binned production.
bool fWrappedAroundTree
! Notes whether we have wrapped around the tree, which is important if the offset into the tree is no...
Double_t fPtHardJetPtRejectionFactor
Factor which the pt hard bin is multiplied by to compare against pythia header jets pt...
PWG::Tools::AliYAMLConfiguration fYAMLConfig
Hanldes configuration from YAML.
double fPythiaPtHard
! Pt hard of the current event (extracted from the pythia header).
void ValidatePhysicsSelectionForInternalEventSelection()
static AliAnalysisTaskEmcalEmbeddingHelper * AddTaskEmcalEmbeddingHelper()
THistManager fHistManager
Manages access to all histograms.
bool fInitializedNewFile
! Notes where the entry indices have been initialized for a new tree in the chain ...
static AliAnalysisTaskEmcalEmbeddingHelper * fgInstance
! Global instance of this class
UInt_t fFileNumber
! File number corresponding to the current tree
bool fUseManualInternalEventCuts
If true, manual event cuts mode will be used for AliEventCuts.
bool IsFileAccessible(std::string filename)
std::string RemoveTrailingSlashes(std::string filename) const
double fCentMax
Maximum centrality for internal event selection.
AliEmcalList * fOutput
! List which owns the output histograms to be saved
AliEventCuts fInternalEventCuts
If enabled, Handles internal event selection.
UInt_t fInternalEventTriggerMask
Internal event physics selection (trigger mask) to be used with AliEventCuts.
void UserCreateOutputObjects()
std::string fAutoConfigureIdentifier
How the auto configuration YAML file should be identified. (for example, "rehlersTrain") ...
Double_t fRandomRejectionFactor
factor by which to reject events
bool AutoConfigurePtHardBins()
Int_t fUpperEntry
! Last entry of the current tree to be used for embedding
Int_t fFilenameIndex
Index of vector containing paths to files to embed.
double fPythiaCrossSectionFromFile
! Average pythia cross section extracted from a xsec file.
std::vector< std::string > fFilenames
Paths to the files to embed.
bool InitializeYamlConfig()
static AliAnalysisTaskEmcalEmbeddingHelper * ConfigureEmcalEmbeddingHelperOnLEGOTrain()
std::string fAutoConfigureTrainTypePath
The path associated with the train type (for example, "PWGJE/Jets_EMC_PbPb/")
TString fFilePattern
File pattern to select AliEn files using alien_find.
bool Initialize(bool removeDummyTask=false)
void DeterminePythiaXSecFilename()
int fPythiaTrials
! Number of pythia trials for the current event (extracted from the pythia header).
double fCentMin
Minimum centrality for internal event selection.
TList * OpenFile(const char *fname)
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()
std::string ConstructFullPythiaXSecFilename(std::string inputFilename, const std::string &pythiaFilename, bool testIfExists) const