void CMetadataElementsImpl::FindElementAt(long nIndex, IMWMetadataElement*& ppElement)
{
	if ((0 < nIndex) && (static_cast<long>(GetCollection().size()) >= nIndex))
	{
		HRESULT hr = GetCollection()[nIndex-1].m_T->QueryInterface(__uuidof(IMWMetadataElement), (void**)&ppElement);
		if (FAILED(hr))
			throw Workshare::Com::ComException(_T("Failed to QueryInterface the element for the IMWMetadataElement interface"), hr);

		return;
	}

	TCHAR szMsg[80];	
	::LoadString(_AtlBaseModule.m_hInstResource, IDS_ERROR_INVALID_INDEX_POSITION, szMsg, 80);
	throw Workshare::Com::ComException(szMsg, E_INVALIDARG);
}
Example #2
0
void
Animation::Tick()
{
  // Since we are not guaranteed to get only one call per refresh driver tick,
  // it's possible that mPendingReadyTime is set to a time in the future.
  // In that case, we should wait until the next refresh driver tick before
  // resuming.
  if (mPendingState != PendingState::NotPending &&
      !mPendingReadyTime.IsNull() &&
      mTimeline &&
      !mTimeline->GetCurrentTime().IsNull() &&
      mPendingReadyTime.Value() <= mTimeline->GetCurrentTime().Value()) {
    FinishPendingAt(mPendingReadyTime.Value());
    mPendingReadyTime.SetNull();
  }

  if (IsPossiblyOrphanedPendingAnimation()) {
    MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
               "Orphaned pending animtaions should have an active timeline");
    FinishPendingAt(mTimeline->GetCurrentTime().Value());
  }

  UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);

  // FIXME: Detect the no-change case and don't request a restyle at all
  // FIXME: Detect changes to IsPlaying() state and request RestyleType::Layer
  //        so that layers get updated immediately
  AnimationCollection* collection = GetCollection();
  if (collection) {
    collection->RequestRestyle(CanThrottle() ?
      AnimationCollection::RestyleType::Throttled :
      AnimationCollection::RestyleType::Standard);
  }
}
int name_value_collection___index(lua_State *L) {
  NameValueCollection *collection = GetCollection(L, 1);
  const char *name = luaL_checkstring(L, 2);
  if (strcmp(name, "Count") == 0) {
    lua_pushunsigned(L, collection->GetCount());
  } else if (strcmp(name, "AllKeys") == 0) {
    StringVectorToLuaArray(L, collection->AllKeys());
  } else if (strcmp(name, "Add") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_Add, 1);
  } else if (strcmp(name, "Get") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_Get, 1);
  } else if (strcmp(name, "GetKey") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_GetKey, 1);
  } else if (strcmp(name, "GetValues") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_GetValues, 1);
  } else if (strcmp(name, "Clear") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_Clear, 1);
  } else if (strcmp(name, "Set") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_Set, 1);
  } else if (strcmp(name, "Remove") == 0) {
    lua_pushlightuserdata(L, (void *)collection);
    lua_pushcclosure(L, name_value_collection_Remove, 1);
  } else {
    lua_pushstring(L, "Unknown property or method.");
    lua_error(L);
  }

  return 1;
}
Example #4
0
  //____________________________________________________________________
  void DrawSumCollection(TCollection* top, const TString& name)
  {
    TCollection* c = GetCollection(top, name, false);
    if (!c) return;

    PrintCanvas(Form("Sums - %s", name.Data()));
    
    TIter       next(c);
    TObject*    o = 0;
    while ((o = next())) { 
      Double_t etaMin = 999;
      Double_t etaMax = 999;
      TCollection* bin = GetEtaBin(o, etaMin, etaMax);
      if (!bin) continue;

      fBody->Divide(2,2);
      DrawInPad(fBody, 1, GetH1(bin, "rawDist"), "",          kLogy);
      DrawInPad(fBody, 1, GetH1(bin, "truthAccepted",false),"same", 
		kLogy|kSilent);
      DrawInPad(fBody, 1, GetH1(bin, "truth",false),   "same", 
		kLogy|kLegend|kSilent);
      DrawInPad(fBody, 2, GetH1(bin, "coverage"));
      DrawInPad(fBody, 3, GetH2(bin, "corr"),     "colz");
      DrawInPad(fBody, 4, GetH2(bin, "response",false), "colz",kLogz|kSilent);
      
      PrintCanvas(Form("%+5.1f < #eta < %+5.1f", etaMin, etaMax));
    }
  }
void CMetadataElementsImpl::CreateElement(const CStdString& sName, const CStdString& sCaption, const CStdString& sCleaningCaption, bool bEnabled)
{
	CComObject<CMetadataElement>* _pElement;
	CComPtr<IMWMetadataElement> pElement;

	HRESULT hr = CComObject<CMetadataElement>::CreateInstance(&_pElement);
	if (FAILED(hr))
	{
		if (REGDB_E_CLASSNOTREG == hr)
		{
			throw Workshare::ClassNotFoundException(_T(PROGID_MetawallElements), _T("Failed to create an instance of CMetadataElement."));
		}
		throw Workshare::Com::ComException(_T("Failed to create an instance of CMetadataElement."), hr);
	}

	_pElement->SetName(sName.c_str());
	_pElement->SetCaption(sCaption.c_str());
	_pElement->SetCleaningCaption(sCleaningCaption.c_str());
	_pElement->Enable(bEnabled);

	hr = _pElement->QueryInterface(__uuidof(IMWMetadataElement), reinterpret_cast<void**>(&pElement));
	if (FAILED(hr))
		throw Workshare::Com::ComException(_T("Failed to QueryInterface _pElement for IMWMetadataElement"), hr);

	GetCollection().push_back(pElement);
}
Example #6
0
void CMsregPacketCatalogOrderLineItem::WriteDataToFile(CFile& cfFile, DWORD& dwChecksum)
{
	CString csCollection;

	TRY
	{
		// Write the category name.
		CMsregPacket::WriteString(cfFile, m_csCategory, dwChecksum);

		// Write the quantity.
		CMsregPacket::WriteDword(cfFile, m_dwQuantity, dwChecksum);

		// Write the cost.
		CMsregPacket::WriteDword(cfFile, m_dwCost, dwChecksum);

		// Write the field count.
		CMsregPacket::WriteDword(cfFile, CollectionCount(), dwChecksum);

		// Write collection names.
		for (int i = 0; i < CollectionCount(); i++)
		{
			GetCollection(i, csCollection);
			CMsregPacket::WriteString(cfFile, csCollection, dwChecksum);
		}
	}
	CATCH_ALL(e)
	{
		csCollection.Empty();
		THROW_LAST();
	}
	END_CATCH_ALL
}
Example #7
0
	void SoundSource::SetupSource(Int fadeInTime) {
		if (!mOpenALSourceID && GetResource().GetOpenALBufferID()) {
			mOpenALSourceID =
				GetCollection()->GetAudioContext()->GetSourceID(this);
			if (mOpenALSourceID) {
				alSourcei(mOpenALSourceID, AL_BUFFER, GetResource().GetOpenALBufferID());
				alSourcei(mOpenALSourceID, AL_SAMPLE_OFFSET, mSampleOffset);
				alSourcef(mOpenALSourceID, AL_PITCH, mPitch);
				alSourcei(mOpenALSourceID, AL_LOOPING, mIsLooping ?
					AL_TRUE : AL_FALSE);
				alSourcei(mOpenALSourceID, AL_SOURCE_RELATIVE,
					mIsRelativePosition ? AL_TRUE : AL_FALSE);
				alSource3f(mOpenALSourceID, AL_POSITION,
					mPosition.mX, mPosition.mY, mPosition.mZ);
				mFadeTime = fadeInTime;
				if (fadeInTime) {
					mIsFadingIn = true;
					alSourcef(mOpenALSourceID, AL_GAIN, 0.0f);
				} else {
					mIsFadingIn = false;
					alSourcef(mOpenALSourceID, AL_GAIN, mVolume);
				}
			}
		}
	}
void IDataProvider::InternalDuplicate( const IDataProviderRef& DataProvider, const uint32 FrameStartIndex, const uint32 FrameEndIndex )
{
	for( uint32 FrameIdx = FrameStartIndex; FrameIdx < FrameEndIndex; FrameIdx++ )
	{
		const uint32 SampleStartIndex = GetSamplesIndicesForFrame( FrameIdx ).X;
		const uint32 SampleEndIndex = GetSamplesIndicesForFrame( FrameIdx ).Y;

		for( uint32 SampleIndex = SampleStartIndex; SampleIndex < SampleEndIndex; SampleIndex++ )
		{
			FProfilerSample ProfilerSample( GetCollection()[ SampleIndex ] );

			if( FProfilerSample::IsIndexValid( ProfilerSample._ParentIndex ) )
			{
				ProfilerSample._ParentIndex -= SampleStartIndex;
			}

			for( int32 ChildIdx = 0; ChildIdx < ProfilerSample._ChildrenIndices.Num(); ChildIdx++ )
			{
				ProfilerSample._ChildrenIndices[ChildIdx] -= SampleStartIndex;
			}

			DataProvider->AddDuplicatedSample( ProfilerSample );
		}
		DataProvider->AdvanceFrame( GetFrameTimeMS( FrameIdx ) );
	}
}
Example #9
0
  //____________________________________________________________________
  void Run(const char* fname="forward_multdists.root", UShort_t flags=kNormal)
  {
    // --- Open the file -----------------------------------------------
    TString filename(fname);
    TFile* file = TFile::Open(filename.Data(), "READ");
    if (!file) { 
      Error("Run", "Failed to open \"%s\"", filename.Data());
      return;
    }
    fPause         = flags & kPause;
    
    // --- Make our canvas ---------------------------------------------
    TString pdfName(filename);
    pdfName.ReplaceAll(".root", ".pdf");
    CreateCanvas(pdfName, flags & kLandscape);

    // --- Force MB for pp ---------------------------------------------
    TCollection* c   = GetCollection(file, "ForwardMultSums");

    // --- Make a Title page -------------------------------------------
    DrawTitlePage(c);

    // --- Overview plots ----------------------------------------------
    fBody->Divide(1,3);
    DrawInPad(fBody, 1, GetH1(c, "triggers"),   "hist text30");
    DrawInPad(fBody, 2, GetH1(c, "status"),     "hist text30");
    DrawInPad(fBody, 3, GetH1(c, "diagnostics"),"colz text");
    PrintCanvas("Overview");

    DrawSumCollection(c, "symmetric");
    DrawSumCollection(c, "negative");
    DrawSumCollection(c, "positive");
    DrawSumCollection(c, "other");

    c   = GetCollection(file, "ForwardMultResults");
    if (!c) {
      CloseCanvas();
      return;
    }
    
    DrawResCollection(c, "symmetric");
    DrawResCollection(c, "negative");
    DrawResCollection(c, "positive");
    DrawResCollection(c, "other");

    CloseCanvas();
  }
CSequence *CInstrumentManager::GetSequence(int InstType, int SeqType, int Index) const
{
	auto pManager = GetSequenceManager(InstType);
	if (!pManager) return nullptr;
	auto pCol = pManager->GetCollection(SeqType);
	if (!pCol) return nullptr;
	return pCol->GetSequence(Index);
}
Example #11
0
void
Animation::PostUpdate()
{
  AnimationCollection* collection = GetCollection();
  if (collection) {
    collection->NotifyAnimationUpdated();
  }
}
Example #12
0
void
AnimationPlayer::PostUpdate()
{
  AnimationPlayerCollection* collection = GetCollection();
  if (collection) {
    collection->NotifyPlayerUpdated();
  }
}
Example #13
0
void
Animation::PostUpdate()
{
  AnimationCollection* collection = GetCollection();
  if (collection) {
    collection->RequestRestyle(AnimationCollection::RestyleType::Layer);
  }
}
IMWMetadataElements* CMetadataElementsImpl::Copy()
{
	coll_type& coll = GetCollection();
	IMWMetadataElementsPtr spResult;   
	HRESULT hr = spResult.CreateInstance(PROGID_MetawallElements);
	if (FAILED(hr))
	{
		if (REGDB_E_CLASSNOTREG == hr)
		{
			throw Workshare::ClassNotFoundException(_T(PROGID_MetawallElements), _T("Failed to create an instance of CMetadataElement."));
		}
		throw Workshare::Com::ComException(_T("Failed to create an instance of CMetadataElement."), hr);
	}
	for(coll_type::iterator _Iter = coll.begin(); _Iter != coll.end(); _Iter++)
	{				
		element_type adapter = *_Iter;
		element_pointer element = adapter.m_T;
		_bstr_t sName;
		HRESULT hr = element->get_Name(sName.GetAddress());
		if(FAILED(hr))
			throw Workshare::Com::ComException(_T("Failed to retrieve name of the metadata element."), hr);

		variant_t vtIndex(sName);
		IMWMetadataElementPtr spResultElement;
		hr = spResult->get_Item(vtIndex, &spResultElement);
		if(FAILED(hr))
		{
			CStdString sMessage;
			sMessage.Format(_T("Failed to retrieve metadata element with an index of \"%s\"."), static_cast<const TCHAR*>(sName));
			throw Workshare::Com::ComException(sMessage, hr);
		}

		VARIANT_BOOL bEnabled = VARIANT_FALSE;
		hr = element->get_Enabled(&bEnabled);
		if(FAILED(hr))
		{
			CStdString sMessage;
			sMessage.Format(_T("Failed to determine whether metadata element with an index of \"%s\" is enabled or not."), static_cast<const TCHAR*>(sName));
			throw Workshare::Com::ComException(sMessage, hr);
		}

		hr = spResultElement->put_Enabled(bEnabled);
		if(FAILED(hr))
		{
			LPCTSTR lpszBool = VARIANT_TRUE == bEnabled ? _T("Enable") : _T("Disable");
			CStdString sMessage;
			sMessage.Format(_T("Failed to \"%s\" metadata element with an index of \"%s\"."), lpszBool, static_cast<const TCHAR*>(sName));
			throw Workshare::Com::ComException(sMessage, hr);
		}		
	}

	IMWMetadataElements* pElements = 0;
	hr = spResult.QueryInterface(__uuidof(IMWMetadataElements), reinterpret_cast<void**>(&pElements));
	if(FAILED(hr))
		throw Workshare::Com::ComException(_T("QueryInterface for IMWMetadataElement failed"), hr);

	return(pElements);
}
void CMetadataElementsImpl::FindElementWithName(const CStdString& sName, IMWMetadataElement*& ppElement)
{
	FindElementFunctor functor(sName);				
	coll_type::iterator _Iter = std::find_if(GetCollection().begin(), GetCollection().end(), functor);

	if(GetCollection().end() != _Iter)
	{
		HRESULT hr = _Iter->m_T->QueryInterface(__uuidof(IMWMetadataElement), (void**)&ppElement);
		if (FAILED(hr))
			throw Workshare::Com::ComException(_T("Failed to QueryInterface the element for the IMWMetadataElement interface"), hr);

		return;
	}

	TCHAR szMsg[80];
	::LoadString(_AtlBaseModule.m_hInstResource, IDS_ERROR_INVALID_INDEX_NAME, szMsg, 80);
	throw Workshare::Com::ComException(szMsg, E_INVALIDARG);
}
int name_value_collection_Add(lua_State *L) {
  NameValueCollection *collection = GetCollection(L, lua_upvalueindex(1));

  // TODO: permit nil
  const char *name = luaL_checkstring(L, 1);
  const char *value = luaL_checkstring(L, 2);

  lua_pushboolean(L, collection->Add(name, value));
  return 1;
}
void CMetadataElementsImpl::SelectNoElements()
{
	coll_type& coll = GetCollection();
	for(coll_type::iterator _Iter = coll.begin(); _Iter != coll.end(); _Iter++)
	{				
		element_type adapter = *_Iter;
		element_pointer element = adapter.m_T;
		element->put_Enabled(VARIANT_FALSE);
	}
}
int name_value_collection_GetKey(lua_State *L) {
  NameValueCollection *collection = GetCollection(L, lua_upvalueindex(1));
  lua_Unsigned index = luaL_checkunsigned(L, 1);
  std::string key;
  if (collection->GetKey(index, &key))
    lua_pushlstring(L, key.data(), key.length());
  else
    lua_pushnil(L);
  return 1;
}
Example #19
0
void testMergeCont()
{
   // Macro to test merging of containers.

   gROOT->LoadMacro("$ROOTSYS/tutorials/hsimple.C");
   TList *list = (TList *)GetCollection();
   TList *inputs = new TList();
   for (Int_t i=0; i<10; i++) {
      inputs->AddAt(GetCollection(),0);
      list->Merge(inputs);
      inputs->Delete();
      f->Close();
   }
   delete inputs;
   TH1F *hpx = (TH1F*)(((TList*)list->At(1))->At(0));
   printf("============================================\n");
   printf("Total  hpx: %d entries\n", (int)hpx->GetEntries());
   hpx->Draw();
   list->Delete();
   delete list;
}
Example #20
0
OP_STATUS
DOM_HTMLDocument::GetAllCollection(DOM_Collection *&all)
{
	ES_Value value;
	ES_GetState state = GetCollection(&value, OP_ATOM_all);

	if (state == GET_NO_MEMORY)
		return OpStatus::ERR_NO_MEMORY;

	all = DOM_VALUE2OBJECT(value, DOM_Collection);
	return OpStatus::OK;
}
void CMetadataElementsImpl::RemoveElement(VARIANT vIndex) throw (Workshare::Exception)
{
	//IMWMetadataElement* pElement = GetItem(vIndex);
	//GetCollection().erase(pElement);
	CStdString sName;

	switch(vIndex.vt)
	{
	case VT_BSTR:
		sName = CStdString(vIndex.bstrVal);
		break;

	case VT_I1:
	case VT_I2:		
	case VT_I4:		
	case VT_I8:
	case VT_INT:		
	case VT_UI1:
	case VT_UI2:
	case VT_UI4:
	case VT_UI8:
	case VT_UINT:	
		{
			long lIndex = _variant_t(vIndex);
			if ((0 >= lIndex) || ((long)GetCollection().size() < lIndex))
				throw Workshare::System::IndexOutOfRangeException(_T("The index %d is out of range. Only indexes between (1 and %d)"), lIndex, GetCollection().size());

			IMWMetadataElement* pElement = NULL;
			HRESULT hr =GetCollection()[lIndex-1].m_T->QueryInterface(__uuidof(IMWMetadataElement), (void**)&pElement);
			if (FAILED(hr))
				throw Workshare::Com::ComException(_T("Failed to QueryInterface the element for the IMWMetadataElement interface"), hr);

			CComBSTR bsName;
			hr = pElement->get_Name(&bsName);
			if (FAILED(hr))
				throw Workshare::Com::ComException(_T("Failed to retrieve element name"), hr);

			sName = bsName;
		}
		break;

	default:
		throw Workshare::Com::ComException(_T("Invalid index."), E_INVALIDARG);
	}

	FindElementFunctor functor(sName);
	coll_type::iterator _Iter = std::find_if(GetCollection().begin(), GetCollection().end(), functor);
	if (GetCollection().end() == _Iter)
		throw Workshare::Exception(_T("Invalid element specified."));

	GetCollection().erase(_Iter);
}
Example #22
0
	void SoundSource::Stop(Int fadeOutTime) {
		mIsPaused = false;
		mIsPlaying = false;
		mIsStopped = true;
		mFadeTime = fadeOutTime;
		mIsFadingIn = false;
		if (mOpenALSourceID) {
			if (fadeOutTime) {
				mIsFadingOut = true;
			} else {
				mIsFadingOut = false;
				mSampleOffset = 0;
				alSourceStop(mOpenALSourceID);
				alSourcei(mOpenALSourceID, AL_BUFFER, AL_NONE);
				mOpenALSourceID = 0;
				GetCollection()->GetAudioContext()->FreeSourceID(this);
			}
		}
	}
int name_value_collection_Get(lua_State *L) {
  NameValueCollection *collection = GetCollection(L, lua_upvalueindex(1));

  // TODO: permit nil
  if (lua_type(L, 1) == LUA_TNUMBER) {
    lua_Unsigned index = luaL_checkunsigned(L, 1);
    std::string value;
    if (collection->Get(index, &value))
      lua_pushlstring(L, value.data(), value.length());
    else
      lua_pushnil(L);
  } else {
    const char *name = luaL_checkstring(L, 1);
    std::string value;
    if (collection->Get(name, &value))
      lua_pushlstring(L, value.data(), value.length());
    else
      lua_pushnil(L);
  }
  return 1;
}
int name_value_collection_GetValues(lua_State *L) {
  NameValueCollection *collection = GetCollection(L, lua_upvalueindex(1));
  const NameValueCollection::value_list_type *values;

  // TODO: permit nil
  if (lua_type(L, 1) == LUA_TNUMBER) {
    lua_Unsigned index = luaL_checkunsigned(L, 1);
    if (collection->GetValues(index, &values))
      StringVectorToLuaArray(L, *values);
    else
      lua_pushnil(L);
  } else {
    luaL_checktype(L, 1, LUA_TSTRING);
    const char *name = luaL_checkstring(L, 1);

    if (collection->GetValues(name, &values))
      StringVectorToLuaArray(L, *values);
    else
      lua_pushnil(L);
  }

  return 1;
}
Example #25
0
void
Animation::Tick()
{
  // Finish pending if we have a pending ready time, but only if we also
  // have an active timeline.
  if (mPendingState != PendingState::NotPending &&
      !mPendingReadyTime.IsNull() &&
      mTimeline &&
      !mTimeline->GetCurrentTime().IsNull()) {
    // Even though mPendingReadyTime is initialized using TimeStamp::Now()
    // during the *previous* tick of the refresh driver, it can still be
    // ahead of the *current* timeline time when we are using the
    // vsync timer so we need to clamp it to the timeline time.
    mPendingReadyTime.SetValue(std::min(mTimeline->GetCurrentTime().Value(),
                                        mPendingReadyTime.Value()));
    FinishPendingAt(mPendingReadyTime.Value());
    mPendingReadyTime.SetNull();
  }

  if (IsPossiblyOrphanedPendingAnimation()) {
    MOZ_ASSERT(mTimeline && !mTimeline->GetCurrentTime().IsNull(),
               "Orphaned pending animtaions should have an active timeline");
    FinishPendingAt(mTimeline->GetCurrentTime().Value());
  }

  UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);

  // FIXME: Detect the no-change case and don't request a restyle at all
  // FIXME: Detect changes to IsPlaying() state and request RestyleType::Layer
  //        so that layers get updated immediately
  AnimationCollection* collection = GetCollection();
  if (collection) {
    collection->RequestRestyle(CanThrottle() ?
      AnimationCollection::RestyleType::Throttled :
      AnimationCollection::RestyleType::Standard);
  }
}
void makesimpleplot(void)
{
  //  set_plot_style();
  TChain *chain = new TChain("OSTwoLepAna/summaryTree");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_1.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_10.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_11.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_12.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_13.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_14.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_15.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_16.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_17.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_18.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_19.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_2.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_20.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_3.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_4.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_5.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_6.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_7.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_8.root");
  chain->Add("root://eoscms.cern.ch//eos/cms/store/user/muell149/ttH-leptons_Skims/acceptance_study_v5/ttHJetToNonbb_M125_13TeV_amcatnloFXFX_madspin_pythia8/crab_ttH125/150916_225227/0000/multilep_michaeltest_deleteme_9.root");

  int chainentries = chain->GetEntries();   
  cout << "tree entries: " << chainentries << endl;  
  
  Int_t cachesize = 100000000;   //100 MBytes
  chain->SetCacheSize(cachesize);   //<<<
  chain->SetCacheLearnEntries(20); 
  
  double mcwgt_intree = -999.;
  double wgt_intree = -999.;
  int hDecay_intree = -999;
  int eventNum_intree = -999;

  vector<ttH::GenParticle> *pruned_genParticles_intree = 0; 
  vector<ttH::Electron> *raw_electrons_intree = 0; 
  vector<ttH::Electron> *preselected_electrons_intree = 0; 
  vector<ttH::Electron> *tight_electrons_intree = 0; 
  vector<ttH::Muon> *raw_muons_intree = 0; 
  vector<ttH::Muon> *preselected_muons_intree = 0; 
  vector<ttH::Muon> *tight_muons_intree = 0; 
  vector<ttH::Lepton> *tight_leptons_intree = 0; 
  vector<ttH::Lepton> *preselected_leptons_intree = 0; 
  vector<ttH::Lepton> raw_leptons;
  
  chain->SetBranchAddress("mcwgt", &mcwgt_intree);
  chain->SetBranchAddress("wgt", &wgt_intree);
  chain->SetBranchAddress("eventnum", &eventNum_intree);
  chain->SetBranchAddress("higgs_decay", &hDecay_intree);
  chain->SetBranchAddress("pruned_genParticles", &pruned_genParticles_intree);
  chain->SetBranchAddress("raw_electrons", &raw_electrons_intree);
  chain->SetBranchAddress("preselected_electrons", &preselected_electrons_intree);
  chain->SetBranchAddress("tightMvaBased_electrons", &tight_electrons_intree);
  chain->SetBranchAddress("raw_muons", &raw_muons_intree);
  chain->SetBranchAddress("preselected_muons", &preselected_muons_intree);
  chain->SetBranchAddress("tightMvaBased_muons", &tight_muons_intree);
  chain->SetBranchAddress("tightMvaBased_leptons", &tight_leptons_intree);
  chain->SetBranchAddress("preselected_leptons", &preselected_leptons_intree);

  int positiveCharge;
  int negativeCharge;
  double leadPt;
  double trailPt;

  int duplicate = 0;
  int total_count = 0;
  int ss2l_reco_count =0;
  int ss2l_reco_agree_count =0;
  int ss2l_gen_count =0;
  int ss2l_ee_gen_count =0;
  int ss2l_mm_gen_count =0;
  int ss2l_em_gen_count =0;
  int ss2l_me_gen_count =0;
  int l3_reco_count =0;
  int l3_reco_agree_count =0;
  int l3_gen_count =0;
  int l4_reco_count =0;
  int l4_reco_agree_count =0;
  int l4_gen_count =0;

  int ss2l_PS_count = 0;
  int ss2l_raw_count = 0;
  int l3_PS_count = 0;
  int l3_raw_count = 0;
  int l4_PS_count = 0;
  int l4_raw_count = 0;
  
  int wgt;

  //pure rate study
  vector<int> cut_vec_ele_int (7,0);
  vector<int> cut_vec_mu_int (7,0);
  int raw_ele_size = 0;
  int raw_mu_size = 0;
    
  //2D plot vars
  vector<ttH::GenParticle> genMuons;
  vector<ttH::GenParticle> genElectrons;   
  vector<ttH::GenParticle> genLeptonsMatched;   
  vector<ttH::GenParticle> genLeptonsUnmatched;   

  int xRange = 40;
  int yRange = 40;
  int xBins = 20;
  int yBins = 20;
  int xBinSize = xRange/xBins; 
  int yBinSize = yRange/yBins; 

  TH2D *pT_hist_2lss = new TH2D("leading and trailing lepton pT 2lss","2lss",xBins,0,xRange,yBins,0,yRange); 
  TH2D *pT_hist_2lss_ee = new TH2D("leading and trailing lepton pT 2lss","2lss ee",xBins,0,xRange,yBins,0,yRange); 
  TH2D *pT_hist_2lss_mm = new TH2D("leading and trailing lepton pT 2lss","2lss mumu",xBins,0,xRange,yBins,0,yRange); 
  TH2D *pT_hist_2lss_em = new TH2D("leading and trailing lepton pT 2lss","2lss e mu",xBins,0,xRange,yBins,0,yRange); 
  TH2D *pT_hist_2lss_me = new TH2D("leading and trailing lepton pT 2lss","2lss mu e",xBins,0,xRange,yBins,0,yRange); 

  TH2D *pT_hist_3l = new TH2D("leading and trailing lepton pT 3l","3l",xBins,0,xRange,yBins,0,yRange); 
  TH2D *pT_hist_4l = new TH2D("leading and trailing lepton pT 4l","4l",xBins,0,xRange,yBins,0,yRange); 

  TH1D *pT_hist_matched = new TH1D("pT","pT matched",100,0,200);
  TH1D *pT_hist_unmatched = new TH1D("pT","pT unmatched",100,0,200);
  TH1D *eta_hist_matched = new TH1D("delta R","dR between matched gen-reco",50,0,0.075);

  TH1D *id_hist_matched = new TH1D("pdgID","pdgID of un matched PS lep",20,0,20);
  TH1D *id_hist_matched_parent = new TH1D("pdgID","pdgID of un matched PS lep grandparent",600,0,600);

  TH1D *charge_hist_2lss = new TH1D("charge","extra lep charge symmetry between 2lss",5,-2,3);
  TH1D *pt_hist_2lss = new TH1D("pt","extra lep pt ordering between 2lss",7,-2,5);

  TH1D *hist_numPsLeps_2lss = new TH1D("PS lepton multiplicity","PS lepton multiplicity 2lss",8,0,8);
  TH1D *hist_numPsLeps_3l = new TH1D("PS lepton multiplicity","PS lepton multiplicity 3l",8,0,8);
  TH1D *hist_numPsLeps_4l = new TH1D("PS lepton multiplicity","PS lepton multiplicity 4l",8,0,8);

  for (int i=0; i<chainentries; i++)
    {
      //report every 40k events
      //if (i == 1000) break; //testing feature
      if (i % 10000 == 0) std::cout << int(100.*i/chainentries) << "% of events processed" << std::endl; 

      chain->GetEntry(i);

      if (mcwgt_intree > 0) wgt =1;
      else wgt =-1;
      total_count +=wgt;

      positiveCharge = 0;
      negativeCharge = 0;
      vector<ttH::GenParticle> signalLeps;   
      
      for (const auto & genParticle : *pruned_genParticles_intree)
      	{
	  if ((abs(genParticle.pdgID) == 11 && genParticle.obj.pt() > 0) || (abs(genParticle.pdgID) == 13 && genParticle.obj.pt() > 0) )
      	    {
	      if (genParticle.isPromptFinalState || genParticle.isDirectPromptTauDecayProductFinalState)
      		{
      		  if  (genParticle.pdgID > 0) positiveCharge +=1;
      		  if  (genParticle.pdgID < 0) negativeCharge +=1;
		  if (abs(genParticle.pdgID) == 11) genElectrons.push_back(genParticle);
		  if (abs(genParticle.pdgID) == 13) genMuons.push_back(genParticle);
		  signalLeps.push_back(genParticle);
      		}
      	    }
      	}

      bool found_duplicate = false;
      vector<ttH::Lepton> raw_matches;      
      for (auto &promptGenLep: signalLeps)
	{
	  ttH::Lepton match = findRecoMatch(promptGenLep, *raw_electrons_intree, *raw_muons_intree);
	  for (auto & raw_match: raw_matches)
	    {
	      if (match.obj.pt() == raw_match.obj.pt())
		{
		  duplicate+=wgt;
		  found_duplicate = true;
		  break;
		}
	    }
	  if (found_duplicate) break;
	  else raw_matches.push_back(match);
	}
      if (found_duplicate) continue;      
      raw_leptons = GetCollection(*raw_muons_intree,*raw_electrons_intree);

      auto matchedLepTuple = findMatchedCollections(raw_matches,*raw_electrons_intree,*preselected_electrons_intree,*raw_muons_intree,*preselected_muons_intree);
      vector<ttH::Electron> matched_raw_electrons = std::get<0>(matchedLepTuple); 
      vector<ttH::Electron> matched_ps_electrons = std::get<1>(matchedLepTuple); 
      vector<ttH::Muon> matched_raw_muons = std::get<2>(matchedLepTuple); 
      vector<ttH::Muon> matched_ps_muons = std::get<3>(matchedLepTuple); 
      vector<ttH::Lepton> ps_matches = GetCollection(matched_ps_muons,matched_ps_electrons);
      

      
      //2lss
      if ((positiveCharge == 2 && negativeCharge == 0) || (negativeCharge ==2 && positiveCharge == 0)) //2lss
	{
	  
	  ttH::Lepton leadMatch = findRecoMatch(signalLeps[0], *raw_electrons_intree, *raw_muons_intree);
	  ttH::Lepton trailMatch = findRecoMatch(signalLeps[1], *raw_electrons_intree, *raw_muons_intree);
	  leadPt = leadMatch.obj.pt();
	  trailPt = trailMatch.obj.pt();

	  vector<ttH::Lepton> raw_matches;	  
	  raw_matches.push_back(leadMatch);
	  raw_matches.push_back(trailMatch);
	  
	  if (leadPt == trailPt)
	    { 
	      duplicate += wgt;
	      continue;
	    }
	  
	  hist_numPsLeps_2lss->Fill(preselected_leptons_intree->size()*wgt);

	  auto matchedLepTuple = findMatchedCollections(raw_matches,*raw_electrons_intree,*preselected_electrons_intree,*raw_muons_intree,*preselected_muons_intree);
	  vector<ttH::Electron> matched_raw_electrons = std::get<0>(matchedLepTuple); 
	  vector<ttH::Electron> matched_ps_electrons = std::get<1>(matchedLepTuple); 
	  vector<ttH::Muon> matched_raw_muons = std::get<2>(matchedLepTuple); 
	  vector<ttH::Muon> matched_ps_muons = std::get<3>(matchedLepTuple); 
	  vector<ttH::Lepton> ps_matches = GetCollection(matched_ps_muons,matched_ps_electrons);
	  
	  ss2l_PS_count += ps_matches.size()*wgt;
	  ss2l_raw_count += raw_matches.size()*wgt;
	  
	  vector<bool> promptVector;
	  vector<bool> promptTauVector;
	  
	  vector<ttH::Lepton> unmatchedPSLeptons;

	  vector<int> motherIdVector;
	  vector<int> grandMotherIdVector;
	  vector<int> unMatchedGrandMotherIdVector;
	  bool lead_ps_raw_match = false;
	  bool trail_ps_raw_match = false;
	  for (const auto & lep : *preselected_leptons_intree)
	    {
	      if (leadMatch.obj.pt() == lep.obj.pt())
		{
		  lead_ps_raw_match = true;
		  motherIdVector.push_back(abs(lep.genMotherPdgID));
		  grandMotherIdVector.push_back(abs(lep.genGrandMotherPdgID));
		  pT_hist_matched->Fill(lep.obj.pt());
		}
	      else if (trailMatch.obj.pt() == lep.obj.pt())
		{
		  trail_ps_raw_match = true;
		  motherIdVector.push_back(abs(lep.genMotherPdgID));
		  grandMotherIdVector.push_back(abs(lep.genGrandMotherPdgID));
		  pT_hist_matched->Fill(lep.obj.pt());
		}
	      else
		{
		  if (preselected_leptons_intree->size() == 3 )
		    {
		      
		      if (lep.charge == leadMatch.charge) charge_hist_2lss->Fill(1);
		      else charge_hist_2lss->Fill(-1);

		      if (lep.obj.pt() < trailMatch.obj.pt() && lep.obj.pt() < leadMatch.obj.pt()) pt_hist_2lss->Fill(-1);
		      else if (lep.obj.pt() > trailMatch.obj.pt() && lep.obj.pt() < leadMatch.obj.pt()) pt_hist_2lss->Fill(1);
		      else if (lep.obj.pt() > leadMatch.obj.pt()) pt_hist_2lss->Fill(3);
		      
		      id_hist_matched->Fill(abs(lep.pdgID));
		    }
		  unmatchedPSLeptons.push_back(lep);
		}
	    }


	  //START For finding the missing PS lepton
	  vector<ttH::Electron> ps_unmatched_raw_electrons; 
	  vector<ttH::Muon> ps_unmatched_raw_muons; 
	  if (!lead_ps_raw_match)
	    {
	      if (abs(leadMatch.pdgID) == 13)
		{
		  for (auto &mu: matched_raw_muons) if (leadMatch.obj.pt() == mu.obj.pt()) ps_unmatched_raw_muons.push_back(mu);
		}
	      else 
		{
		  for (auto &ele: matched_raw_electrons) if (leadMatch.obj.pt() == ele.obj.pt()) ps_unmatched_raw_electrons.push_back(ele);
		}
	    }
	  if (!trail_ps_raw_match)
	    {
	      if (abs(trailMatch.pdgID) == 13)
		{
		  for (auto &mu: matched_raw_muons) if (trailMatch.obj.pt() == mu.obj.pt()) ps_unmatched_raw_muons.push_back(mu);
		}
	      else 
		{
		  for (auto &ele: matched_raw_electrons) if (trailMatch.obj.pt() == ele.obj.pt()) ps_unmatched_raw_electrons.push_back(ele);
		}
	    }
	  
	  preselectionEff(ps_unmatched_raw_muons, &cut_vec_mu_int, &raw_mu_size, ps_unmatched_raw_electrons, &cut_vec_ele_int, &raw_ele_size);
	  //END For finding the missing PS lepton		      

	  motherIdVector.clear();
	  grandMotherIdVector.clear();
	  
	  eta_hist_matched->Fill(reco::deltaR(signalLeps[0].obj.eta(),signalLeps[0].obj.phi(),leadMatch.obj.eta(),leadMatch.obj.phi()));
	  eta_hist_matched->Fill(reco::deltaR(signalLeps[1].obj.eta(),signalLeps[1].obj.phi(),trailMatch.obj.eta(),trailMatch.obj.phi()));
	  
	  fill_2D(pT_hist_2lss,leadPt,trailPt,wgt, xBinSize, yBinSize);
	  ss2l_gen_count += wgt;
	  if (abs(leadMatch.pdgID) == 11)
	    {
	      if (abs(trailMatch.pdgID) == 11)
		{
		  fill_2D(pT_hist_2lss_ee,leadPt,trailPt,wgt, xBinSize, yBinSize);
		  ss2l_ee_gen_count += wgt;
		}
	      else if (abs(trailMatch.pdgID) == 13)
		{
		  fill_2D(pT_hist_2lss_em,leadPt,trailPt,wgt, xBinSize, yBinSize);
		  ss2l_em_gen_count += wgt;
		}
	    }
	  else if (abs(leadMatch.pdgID) == 13)
	    {
	      if (abs(trailMatch.pdgID) == 11)
		{
		  fill_2D(pT_hist_2lss_me,leadPt,trailPt,wgt, xBinSize, yBinSize);
		  ss2l_me_gen_count += wgt;
		}
	      else if (abs(trailMatch.pdgID) == 13)
		{
		  fill_2D(pT_hist_2lss_mm,leadPt,trailPt,wgt, xBinSize, yBinSize);
		  ss2l_mm_gen_count += wgt;
		}
	    }
	  
	  if (tight_leptons_intree->size() == 2 && abs((*tight_leptons_intree)[0].charge+(*tight_leptons_intree)[1].charge) == 2)
	    {
	      // leadPt = (*tight_leptons_intree)[0].obj.pt();
	      // trailPt = (*tight_leptons_intree)[1].obj.pt();
	      // fill_2D(pT_hist_2lss,leadPt,trailPt,wgt, xBinSize, yBinSize);
	      ss2l_reco_agree_count +=wgt;
	    }
	}
      
      else if (positiveCharge+negativeCharge == 3) //3l
      	{
	  l3_PS_count += preselected_leptons_intree->size()*wgt;
	  l3_raw_count += raw_leptons.size()*wgt;

	  hist_numPsLeps_3l->Fill(preselected_leptons_intree->size()*wgt);
      	  ttH::Lepton leadMatch = findRecoMatch(signalLeps[0], *raw_electrons_intree, *raw_muons_intree);
	  ttH::Lepton subLeadMatch = findRecoMatch(signalLeps[1], *raw_electrons_intree, *raw_muons_intree);
      	  ttH::Lepton trailMatch = findRecoMatch(signalLeps[2], *raw_electrons_intree, *raw_muons_intree);

	  vector<ttH::Lepton> raw_matches;	  
	  raw_matches.push_back(leadMatch);
	  raw_matches.push_back(subLeadMatch);
	  raw_matches.push_back(trailMatch);
	  
	  if (leadMatch.obj.pt() == subLeadMatch.obj.pt() ||
	      subLeadMatch.obj.pt() == trailMatch.obj.pt() || 
	      leadMatch.obj.pt() == trailMatch.obj.pt())
	    {
	      duplicate += wgt;
	      continue;	      
	    }


      	  // leadPt = leadMatch.obj.pt();
      	  // trailPt = trailMatch.obj.pt();
      	  // leadPt = signalLeps[0].obj.pt();
      	  // trailPt = signalLeps[2].obj.pt();	  
      	  // fill_2D(pT_hist_3l,leadPt,trailPt,wgt, xBinSize, yBinSize);
      	  // pT_hist_matched->Fill(abs(signalLeps[0].obj.pt()-leadPt));
      	  // pT_hist_matched->Fill(abs(signalLeps[2].obj.pt()-trailPt));
      	  // eta_hist_matched->Fill(deltaR(signalLeps[0],leadMatch));
      	  // eta_hist_matched->Fill(deltaR(signalLeps[2],trailMatch));

      	  l3_gen_count += wgt;
      	  if (tight_leptons_intree->size() == 3)
      	    {
      	      // leadPt = (*tight_leptons_intree)[0].obj.pt();
      	      // trailPt = (*tight_leptons_intree)[2].obj.pt();
      	      // fill_2D(pT_hist_3l,leadPt,trailPt,wgt, xBinSize, yBinSize);
      	      l3_reco_agree_count +=wgt;	      
      	    }
      	}
      else if (positiveCharge+negativeCharge >= 4) //4l
      	{
	  l4_PS_count += preselected_leptons_intree->size()*wgt;
	  l4_raw_count += raw_leptons.size()*wgt;

	  hist_numPsLeps_4l->Fill(preselected_leptons_intree->size()*wgt);
      	  // ttH::Lepton leadMatch = findRecoMatch(signalLeps[0], *raw_electrons_intree, *raw_muons_intree);
      	  // ttH::Lepton trailMatch = findRecoMatch(signalLeps[3], *raw_electrons_intree, *raw_muons_intree);
      	  // leadPt = leadMatch.obj.pt();
      	  // trailPt = trailMatch.obj.pt();
	  //      	  leadPt = signalLeps[0].obj.pt();
	  //      	  trailPt = signalLeps[3].obj.pt();	  
	  //      	  fill_2D(pT_hist_4l,leadPt,trailPt,wgt, xBinSize, yBinSize);
      	  // pT_hist_matched->Fill(abs(signalLeps[0].obj.pt()-leadPt));
      	  // pT_hist_matched->Fill(abs(signalLeps[3].obj.pt()-trailPt));
      	  // eta_hist_matched->Fill(deltaR(signalLeps[0],leadMatch));
      	  // eta_hist_matched->Fill(deltaR(signalLeps[3],trailMatch));

      	  l4_gen_count += wgt;
      	  if (preselected_leptons_intree->size() >= 4)
      	    {
      	      // leadPt = (*preselected_leptons_intree)[0].obj.pt();
      	      // trailPt = (*preselected_leptons_intree)[preselected_leptons_intree->size()-1].obj.pt();	  
      	      // fill_2D(pT_hist_4l,leadPt,trailPt,wgt, xBinSize, yBinSize);
      	      l4_reco_agree_count +=wgt;
      	    }
      	}
    }
  std::cout << "event loop complete. drawing hists." << std::endl;

  gStyle->SetOptStat(0);
  //  TCanvas* pT_can = new TCanvas("pt can", "pt can");  
  //  TLegend *pT_leg = new TLegend(0.83,0.66,0.99,0.77,NULL,"brNDC"); 
  //  TLegend *pT_leg = new TLegend(0.83,0.66,0.99,0.77); 
  //  pT_hist_matched->SetLineColor(1);
  //  pT_hist_unmatched->SetLineColor(2);
  //  pT_hist_matched->Scale(1/pT_hist_matched->Integral());
  //  pT_hist_unmatched->Scale(1/pT_hist_unmatched->Integral());
  //  pT_hist_matched->Draw();  
  //  pT_hist_matched->Draw("same");  
  //  pT_leg->AddEntry(pT_hist_matched,"gen-matched","l");
  //  pT_leg->AddEntry(pT_hist_unmatched,"not gen-matched","l");
  //  pT_leg->Draw("same");

  TCanvas* id_can = new TCanvas("id can", "id can");  
  id_hist_matched->Scale(1./id_hist_matched->Integral());
  id_hist_matched->Draw();  
  // TLegend *id_leg = new TLegend(0.83,0.66,0.99,0.77,NULL,"brNDC"); 
  // id_hist_unnmatched->SetLineColor(1);
  // id_hist_unmatched->SetLineColor(2);
  // id_hist_matched->SetLineColor(kBlue);

  //  id_hist_unmatched->Draw("same");  
  //  id_hist_matched->Draw("same");  
  //  id_leg->AddEntry(id_hist_matched,"matched W grandmothers","l");
  //  id_leg->AddEntry(id_hist_unmatched,"un matched W grandmother","l");
  //  id_leg->AddEntry(id_hist_unnmatched,"both matched","l");
  //  id_leg->Draw("same");

  TCanvas* charge_can1 = new TCanvas("charge can1", "charge can1");  
  charge_hist_2lss->Scale(1./charge_hist_2lss->Integral());
  charge_hist_2lss->Draw();

  TCanvas* pt_can1 = new TCanvas("pt can1", "pt can1");  
  pt_hist_2lss->Scale(1./pt_hist_2lss->Integral());
  pt_hist_2lss->Draw();

  TCanvas* id_can1 = new TCanvas("id can1", "id can1");  
  id_hist_matched_parent->Scale(1./id_hist_matched_parent->Integral());
  id_hist_matched_parent->Draw();  

  TCanvas* pT_can = new TCanvas("pt can", "pt can");  
  TLegend *pT_leg = new TLegend(0.83,0.66,0.99,0.77,NULL,"brNDC"); 
  pT_hist_matched->SetLineColor(1);
  pT_hist_unmatched->SetLineColor(2);
  //pT_hist_matched->Scale(1/pT_hist_matched->Integral());
  //  pT_hist_unmatched->Scale(1/pT_hist_unmatched->Integral());
  pT_hist_matched->Draw();  
  pT_hist_unmatched->Draw("same");  
  pT_leg->AddEntry(pT_hist_matched,"matched","l");
  pT_leg->AddEntry(pT_hist_unmatched,"not matched","l");
  pT_leg->Draw("same");

  TCanvas* can_numPS2 = new TCanvas("num can2", "num can2");  
  hist_numPsLeps_2lss->Scale(1./hist_numPsLeps_2lss->Integral());
  lepMultiplicity(hist_numPsLeps_2lss, "2lss");
  hist_numPsLeps_2lss->Draw();

  TCanvas* can_numPS3 = new TCanvas("num can3", "num can3");  
  hist_numPsLeps_3l->Scale(1./hist_numPsLeps_3l->Integral());
  lepMultiplicity(hist_numPsLeps_3l, "3l");
  hist_numPsLeps_3l->Draw();

  TCanvas* can_numPS4 = new TCanvas("num can4", "num can4");  
  hist_numPsLeps_4l->Scale(1./hist_numPsLeps_4l->Integral());
  lepMultiplicity(hist_numPsLeps_4l, "4l");
  hist_numPsLeps_4l->Draw();
  

  std::cout << "double matches " << duplicate << std::endl;  

  std::cout << "total_count = " << total_count << std::endl;
  std::cout << "ss2l_reco_count = " << ss2l_reco_count << std::endl;
  std::cout << "ss2l_reco_agree_count = " << ss2l_reco_agree_count << std::endl;
  std::cout << "ss2l_gen_count = " << ss2l_gen_count << std::endl;
  std::cout << "l3_reco_count = " << l3_reco_count << std::endl;
  std::cout << "l3_reco_agree_count = " << l3_reco_agree_count << std::endl;
  std::cout << "l3_gen_count = " << l3_gen_count << std::endl;
  std::cout << " > l4_reco_count = " << l4_reco_count << std::endl;
  std::cout << " > l4_reco_agree_count = " << l4_reco_agree_count << std::endl;
  std::cout << "> l4_gen_count = " << l4_gen_count << std::endl;


  std::cout << "> ss2l_PS_count = " << ss2l_PS_count << std::endl;
  std::cout << "> ss2l_raw_count = " << ss2l_raw_count << std::endl;
  std::cout << "> ss2l_eff = " << ss2l_PS_count/ss2l_raw_count << std::endl;
  std::cout << "> l3_PS_count = " << l3_PS_count << std::endl;
  std::cout << "> l3_raw_count = " << l3_raw_count << std::endl;
  std::cout << "> l3_eff = " << l3_PS_count/l3_raw_count << std::endl;
  std::cout << "> l4_PS_count = " << l4_PS_count << std::endl;
  std::cout << "> l4_raw_count = " << l4_raw_count << std::endl;
  std::cout << "> l4_eff = " << l4_PS_count/l4_raw_count << std::endl;

 

  int i = 0;
  for (int & frac : cut_vec_mu_int)
    {
      std::cout << frac << " " << raw_mu_size << std::endl;
      std::cout << "mu cut # " << i << " is removing: " << 100. - 100.*double(frac)/double(raw_mu_size) << "%" << std::endl;
      //std::cout << "mu cut # " << i << " failed uniquely: " << double(frac)/double(raw_mu_size) << "%" << std::endl;
      i +=1;
    }
  
  int j = 0;
  for (int & frac : cut_vec_ele_int)
    {
      std::cout << frac << " " << raw_mu_size << std::endl;
      std::cout << "ele cut # " << j << " is removing: " << 100. - 100.*double(frac)/double(raw_ele_size) << "%" << std::endl;
      //      std::cout << "ele cut # " << j << " failed uniquely: " << double(frac)/double(raw_ele_size) << "%" << std::endl;
      j +=1;
    }
  
}
Example #27
0
CollAnalyticData* Session::GetCollection(string collectionId) {
    return GetCollection(collectionId, "");
}
Example #28
0
  /** 
   * Run the unfolding and correction task. 
   *
   * The @a measuredFile is assumed to have the structure 
   *
   * @verbatim
   *     /- ForwardMultSums         (TCollection)
   *          |- [type]             (TCollection)
   *          |    |- [bin]         (TCollection) 
   *          |    |    `- rawDist  (TH1)
   *          |    |- [bin]
   *          |    ...
   *          |- [type]
   *          ...
   * @endverbatim 
   * 
   * and @a corrFile is assumed to have the structure 
   *
   * @verbatim
   *     /- ForwardMultResults            (TCollection)
   *          |- [type]                   (TCollection)
   *          |    |- [bin]               (TCollection) 
   *          |    |    |- truth          (TH1)
   *          |    |    |- truthAccepted  (TH1)
   *          |    |    |- triggerVertex  (TH1)
   *          |    |    `- response       (TH2)
   *          |    |- [bin]
   *          |    ...
   *          |- [type]
   *          ...
   * @endverbatim 
   *
   * where @c [type] is one of <i>symmetric</i>, <i>positive</i>,
   * <i>negative</i>, or <i>other</i>, and [bin] is the @f$ \eta@f$
   * bin named like
   *
   * @verbatim
   *   [bin]          := [eta_spec] _ [eta_spec]
   *   [eta_spec]     := [sign_char] [integer_part] d [decimal_part]
   *   [sign_part]    := p          positive eta 
   *                  |  m          negative eta 
   *   [integer_part] := [number]
   *   [decimal_part] := [number] [number]
   *   [number]       := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 
   * @endverbatim
   *
   * That is, the bin @f$ -3\le\eta\ge3@f$ is labeled
   * <b>m3d00_p3d00</b>, @f$ 0\le\eta\ge2.5@f$ is <b>p0d00_p2d50</b> 
   *
   * @a measuredFile and @a corrFile can point to the same file.  If
   * @a corrFile is not specified, it is assumed that @a measuredFile
   * has the expected @a corrFile @e in @e addition to the
   * expected content of that file.
   * 
   * @param measuredFile Name of file containing measured data
   * @param corrFile     Name of file containing correction data
   * @param method       Unfolding method to use 
   * @param regParam     Regularization parameter 
   */  
  void Run(const TString& measuredFile, const TString& corrFile,
	   const TString& method="Bayes", Double_t regParam=4)
  {
    // Get the input collections 
    if (measuredFile.IsNull()) {
      Error("Run", "No measurements given");
      return;
    }
    TCollection* mTop = GetTop(measuredFile, false);
    TCollection* cTop = GetTop(corrFile.IsNull() ? measuredFile : corrFile, 
			       true);
    if (!mTop || !cTop) return;

    // Get some info from the input collection 
    UShort_t sys;
    UShort_t sNN; 
    ULong_t  trig; 
    Double_t minZ; 
    Double_t maxZ;
    GetParameter(mTop, "sys",     sys);	  
    GetParameter(mTop, "sNN",     sNN);	  
    GetParameter(mTop, "trigger", trig);
    GetParameter(mTop, "minIpZ",  minZ); 
    GetParameter(mTop, "maxIpZ",  maxZ); 
    if (sys == 0 || sNN == 0) 
      Warning("Run", "System (%d) and/or collision energy (%d) unknown", 
	      sys, sNN);
    
    // Open the output file 
    TFile* out = TFile::Open("forward_unfolded.root", "RECREATE");
    if (!out) { 
      Error("Run", "Failed to open output file");
      return;
    }

    // Decode method option and store in file 
    TString meth(method);
    UInt_t  mId = MethodId(meth);
    if (mId == 0xDeadBeef) return;

    // Store information 
    SaveInformation(out,meth,mId,regParam,sys,sNN,trig,minZ,maxZ,
		    corrFile.IsNull());

    // Load other data 
    TString savPath(gROOT->GetMacroPath());
    gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2/scripts",
                             gROOT->GetMacroPath()));
    // Always recompile 
    if (!gROOT->GetClass("OtherPNch"))
      gROOT->LoadMacro("OtherPNchData.C++");
    gROOT->SetMacroPath(savPath);

    // Loop over the input 
    const char*  inputs[] = { "symmetric", "positive", "negative", 0 };
    const char** pinput   = inputs;
    while (*pinput) { 
      TCollection* mInput = GetCollection(mTop, *pinput, false);
      TCollection* cInput = GetCollection(cTop, *pinput, false);
      if (mInput && cInput)
	ProcessType(mInput, cInput, mId, regParam, out,
		    sys, sNN);
      pinput++;
    }      

    out->Write();
    // out->ls();
    out->Close();

    SaveSummarize();
  }
Example #29
0
  /** 
   * Process a single type - i.e., one of <i>symmetric</i>,
   * <i>positive</i>, <i>negative</i>, or <i>other</i> - by looping
   * over all contained objects and call ProcessBin for each found
   * bin.
   * 
   * @param measured     Input collection of measured data
   * @param corrections  Input collection of correction data
   * @param method       Unfolding method to use 
   * @param regParam     Regularisation parameter
   * @param out          Output directory. 
   * @param sys          Collision system
   * @param sNN          Collision energy 
   */
  void ProcessType(TCollection* measured, 
		   TCollection* corrections,
		   UInt_t       method,
		   Double_t     regParam,
		   TDirectory*  out,
		   UShort_t     sys, 
		   UShort_t     sNN)
  {
    Printf("  Processing %s ...", measured->GetName());
    TDirectory* dir = out->mkdir(measured->GetName());
    
    // Make some summary stacks 
    THStack*  allMeasured  = new THStack("measured",      
					 "Measured P(#it{N}_{ch})");
    THStack*  allTruth     = new THStack("truth",        
					 "MC 'truth' P(#it{N}_{ch})");
    THStack*  allTruthA    = new THStack("truthAccepted",
					 "MC 'truth' accepted P(#it{N}_{ch})");
    THStack*  allUnfolded  = new THStack("unfolded",
					 "Unfolded P(#it{N}_{ch})");
    THStack*  allCorrected = new THStack("corrected",
					 "Corrected P(#it{N}_{ch})");
    THStack*  allRatio     = (sys != 1 ? 0 : 
			      new THStack("ratios", "Ratios to other"));
    TMultiGraph* allALICE  = (sys != 1 ? 0 : 
			      new TMultiGraph("alice", "ALICE Published"));
    TMultiGraph* allCMS    = (sys != 1 ? 0 : 
			      new TMultiGraph("cms", "CMS Published"));

    // Loop over the list of objects. 
    static TRegexp regex("[pm][0-9]d[0-9]*_[pm][0-9]d[0-9]*");
    TIter          next(measured);
    TObject*       o = 0;
    Int_t          i = 0;
    Double_t       r = regParam;
    while ((o = next())) {
      // Go back to where we where 
      dir->cd();
      
      // if not a collection, don't bother 
      if (!o->IsA()->InheritsFrom(TCollection::Class())) continue;
    
      // If it doesn't match our regular expression, don't bother 
      TString n(o->GetName());
      if (n.Index(regex) == kNPOS) { 
	// Warning("ScanType", "%s in %s doesn't match eta range regexp", 
	//         n.Data(), real->GetName());
	continue;
      }
      TCollection* mBin = static_cast<TCollection*>(o);
      TCollection* cBin = GetCollection(corrections, n.Data());
      if (!cBin) continue;

      THStack* binS = ProcessBin(mBin, cBin, method, r, dir);
      if (!binS) continue;

      TH1* result = 0;
      Bin2Stack(binS, i, allMeasured, allTruth, allTruthA, 
		allUnfolded, allCorrected, result);

      TGraph* alice = 0;
      TGraph* cms   = 0;
      Other2Stack(o->GetName(), i, sNN, allALICE, allCMS, alice, cms);
      Ratio2Stack(i, result, alice, cms, allRatio);
      i++;
    }
    dir->Add(allMeasured);
    dir->Add(allTruth);
    dir->Add(allTruthA);
    dir->Add(allUnfolded);
    dir->Add(allCorrected);
    if (allALICE && allALICE->GetListOfGraphs()) {
      if (allALICE->GetListOfGraphs()->GetEntries() > 0)
	dir->Add(allALICE);
      else 
	delete allALICE;
    }
    if (allCMS && allCMS->GetListOfGraphs()) {
      if (allCMS->GetListOfGraphs()->GetEntries() > 0) 
	dir->Add(allCMS);
      else 
	delete allCMS;
    }
    if (allRatio && allRatio->GetHists()) { 
      if (allRatio->GetHists()->GetEntries() > 0) 
	dir->Add(allRatio);
      else 
	delete allRatio;
    }
  }
Example #30
0
/* virtual */ ES_GetState
DOM_HTMLDocument::GetName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime)
{
	DOM_EnvironmentImpl *environment = GetEnvironment();
	DOM_Runtime *runtime = environment->GetDOMRuntime();
	FramesDocument *frames_doc = environment->GetFramesDocument();

	switch(property_name)
	{
	case OP_ATOM_title:
		return GetTitle(value);

	case OP_ATOM_domain:
		if (value)
		{
			DOMSetString(value);
			if (!runtime->GetMutableOrigin()->IsUniqueOrigin())
			{
				const uni_char *domain;
				runtime->GetDomain(&domain, NULL, NULL);
				DOMSetString(value, domain);
			}
		}
		return GET_SUCCESS;

	case OP_ATOM_URL:
		if (value)
		{
			const uni_char *url;

			if (frames_doc)
				url = frames_doc->GetURL().GetAttribute(URL::KUniName_With_Fragment_Username_Password_Hidden).CStr();
			else
				url = NULL;

			DOMSetString(value, url);
		}
		return GET_SUCCESS;

	case OP_ATOM_head:
		if (value)
		{
			HTML_Element *element = GetPlaceholderElement();
			if (element)
			{
				element = element->FirstChildActual();
				while (element && !element->IsMatchingType(HE_HTML, NS_HTML))
					element = element->SucActual();

				if (element)
				{
					element = element->FirstChildActual();
					while (element && !element->IsMatchingType(HE_HEAD, NS_HTML))
						element = element->SucActual();
				}
			}
			return DOMSetElement(value, element);
		}
		return GET_SUCCESS;

	case OP_ATOM_body:
		if (value)
		{
			DOM_Element *element;

			GET_FAILED_IF_ERROR(GetBodyNode(element));

			DOMSetObject(value, element);
		}
		return GET_SUCCESS;

	case OP_ATOM_bgColor:
	case OP_ATOM_fgColor:
	case OP_ATOM_linkColor:
	case OP_ATOM_alinkColor:
	case OP_ATOM_vlinkColor:
		if (value)
		{
			DOM_Element *element;

			GET_FAILED_IF_ERROR(GetBodyNode(element));

			if (element && element->GetThisElement()->IsMatchingType(HE_BODY, NS_HTML))
			{
				if (property_name == OP_ATOM_fgColor)
					property_name = OP_ATOM_text;
				else if (property_name == OP_ATOM_linkColor)
					property_name = OP_ATOM_link;
				else if (property_name == OP_ATOM_alinkColor)
					property_name = OP_ATOM_aLink;
				else if (property_name == OP_ATOM_vlinkColor)
					property_name = OP_ATOM_vLink;

				return element->GetName(property_name, value, origining_runtime);
			}
			else
				DOMSetString(value);
		}
		return GET_SUCCESS;

	case OP_ATOM_images:
	case OP_ATOM_applets:
	case OP_ATOM_links:
	case OP_ATOM_forms:
	case OP_ATOM_anchors:
	case OP_ATOM_embeds:
	case OP_ATOM_plugins:
	case OP_ATOM_scripts:
	case OP_ATOM_all:
		return GetCollection(value, property_name);

	case OP_ATOM_frames:
		DOMSetObject(value, environment->GetWindow());
		return GET_SUCCESS;

	case OP_ATOM_compatMode:
		if (value)
			if (HLDocProfile *hld_profile = GetHLDocProfile())
			{
				if (hld_profile->IsInStrictMode())
					DOMSetString(value, UNI_L("CSS1Compat"));
				else
					DOMSetString(value, UNI_L("BackCompat"));
			}
		return GET_SUCCESS;

	case OP_ATOM_activeElement:
		if (value)
			if (frames_doc && IsMainDocument())
				return DOMSetElement(value, frames_doc->DOMGetActiveElement());
			else
				DOMSetNull(value);
		return GET_SUCCESS;
	}

	return DOM_Document::GetName(property_name, value, origining_runtime);
}