TRestDetectorGas values can't be initialized from TRestDetector

REST version : v2.3.7
RestDetectorLib version : v1.2

Hello,

I’m trying to use values from TRestDetector to set parameters in TRestDetectorSignalToHitsProcess like this:

<addProcess type="TRestDetectorSignalToHitsProcess" name="signalToHits" value="ON" verboseLevel="info" 
			electricField="[detParams::fPressure]*[TRestDetector::fDriftField]V/cm"
			gasPressure="[detParams->fPressure]"
			driftVelocity="" 
			observable="all"
			method="tripleMax" />

The parameter fPressure is defined in the section TRestDetectorGas inside TRestRun but fDriftField is a member of TRestDetector.
But what I get is -- Warning : TRestDetectorGas::GetDriftVelocity. Warning fElectricField is zero! and in TRestDetectorGas fElectricField and fDriftVelocity are 0.

While the TRestDetector has the correct values:

As you can see, none of them are taken from TRestDetector, even the pressure is different.

Does anyone know what is going on here?

Thanks,
David

Hi @ddiez , what it matters is what you get at TRestDetectorSignalToHitsProcess. What are the values you retrieve there?

The TRestDetectorGas properties are changed on the fly, and what it really matters is the gas mixture. The TRestDetectorSignalToHitsProcess should update those values on InitProcess for the TRestDetectorGas, but I bet the TRestDetectorGas is not written again.

So, what is the result of:

md0_signalToHits->PrintMetadata();
void TRestDetectorSignalToHitsProcess::InitProcess() {
    // Function to be executed once at the beginning of process
    // (before starting the process of the events)

    // Start by calling the InitProcess function of the abstract class.
    // Comment this if you don't want it.
    // TRestEventProcess::InitProcess();

    fGas = GetMetadata<TRestDetectorGas>();
    if (fGas != NULL) {
#ifndef USE_Garfield
        ferr << "A TRestDetectorGas definition was found but REST was not linked to Garfield libraries."
             << endl;
        ferr << "Please, remove the TRestDetectorGas definition, and add gas parameters inside the process "
                "TRestDetectorSignalToHitsProcess"
             << endl;
        exit(-1);
#endif
        if (fGasPressure <= 0) fGasPressure = fGas->GetPressure();
        if (fElectricField <= 0) fElectricField = fGas->GetElectricField();

        fGas->SetPressure(fGasPressure);
        fGas->SetElectricField(fElectricField);

...
...

As, you see the values of TRestDetectorGas are only updated if the ones defined at the process are above zero.

Of course, this implementation could have the problem that if you have different processes fixing different pressures at the same processing chain, then, there they would enter in conflict.

Thats why I would recommended to define the pressure parameter at the globals section, so all processes take the same value.

<globals>
    <parameter name="pressure" value="4" />
</globals>

In a second independent processing chain, one could use a different value for the pressure. I.e. if you want to consider electron diffusion at 4bars, but drift velocity later on at 8bar. Just to give a hypothetical example.

Values in TRestDetectorSignalToHitsProcess are the same as those in TRestDetectorGas:

So, I guess it’s taking the pressure from the section TRestDetectorGas inside TRestRun and nothing for fDriftField, so it remains 0 and so fElectricField does, which is the product of both.

Here is interesting to read values from TRestDetector because they are taken directly from the .aqs file, so we won’t add any specific value during the processing chain, they remain fixed as settled by TRestDetector.

Perhaps the values at TRestDetector are not ready yet when parsing the RML at TRestDetectorSignalToHitsProcess?

No, no, this is at the stage of hits and TRestDetector is already fine in rawSignals. Actually I run the processing chain in steps so I have intermediate files with TRestDetector fulfilled.

Ok, not sure now if the capability to use [TRestDetector::fPressure] inside process parameters is allowed right now.

I was having a try to implement that at TRestEventProcess::InitFromConfigFile.

This is my test, apparenty fRunInfo is ready and contains the metadata structures that we find inside the file. Then, we could use fRunInfo->ReplaceMetadataMembers(val).

I am able to recover properly the value zS::fPointThreshold, however, that is not the case for detParam::fPressure.

This is the try when I was investigating this possible implementation

    virtual void InitFromConfigFile() {
        map<string, string> parameters = GetParametersList();
    
        for (int n = 0; n < fRunInfo->GetMetadataStructureNames().size(); n++)
            cout << "n: " << n << " --> " << fRunInfo->GetMetadataStructureNames()[n] << endl;
    
        cout << "zS: " << fRunInfo->GetMetadata("zS")->GetDataMemberValue("fPointThreshold") << endl;
        cout << "detParam: " << fRunInfo->GetMetadata("detParam")->GetDataMemberValue("fPressure")
                 << endl;

        for (auto const& [key, val] : parameters) {
            std::cout << key         // string (key)
                      << ':' << val  // string's value
                      << std::endl;
    
            cout << "Replaced: " << fRunInfo->ReplaceMetadataMembers(val) << endl;


        }

        ReadParametersList(parameters);
    }

@nkx you get an idea why I cannot recover TRestDetector::fPressure at that position in the code?

I am testing that at pipeline/trex/

I did try also the following inside TRestEventProcess::InitFromConfigFile.

        fRunInfo->GetMetadata("detParam")->Dump();
        fRunInfo->GetMetadata("zS")->Dump();

And, well, it seems TRestRawZeroSuppressionProcess metadata class dumps proper values, while TRestDetector does not.

==> Dumping object at: 0x000055e299db8ac0, name=detParam, class=TRestDetector

fDetectorName                 TREXDM_0            
fDriftVoltage                 -1                  
fDriftField                   -1                  
fDriftDistance                -1                  
fAmplificationVoltage         -1                  
fAmplificationDistance        -1                  
fAmplificationGain            -1                  
fMass                         -1                  
fHeight                       -1                  
fRadius                       -1                  
fLength                       -1                  
fWidth                        -1                  
fPressure                     -1                  
fElectronicsShapingTime       -1                  
fElectronicsSamplingTime      -1                  
fElectronicsDynamicRange      -1                  
fElectronicsThreshold         -1                  
fElectronicsGain              -1                  
fElectronicsClock             -1                  
fElectronicsShaping           -1                  
fVersion                      2.3.7               <
fVersion.fRep                 ->55e299db8b08      ! String data
fCommit                       c72ddee6            <
fCommit.fRep                  ->55e299db8b20      ! String data
fLibraryVersion               0                   <
fLibraryVersion.fRep          ->55e299db8b38      ! String data
fOfficialRelease              false               <
fCleanState                   false               <
fConfigFileName               null                
fSectionName                  TRestDetector       
configBuffer                                      
messageBuffer                 . TRestMetadata::Rep
fVerboseLevel                 0                   !
endl                          ->55e299db8bd8      !
endl.vref                     -1713665072         
endl.sref                     ->55e299db8be0      
*fHostmgr                     ->55e299eb4ab0      !
fStore                        true                !
*fElement                     ->55e2a6dba9d0      !
*fElementGlobal               ->55e2a6dc1d00      !
fVariables                    ->55e299db8c08      !
fConstants                    ->55e299db8c38      !
fError                        false               !
fErrorMessage                                     !
fErrorMessage.fRep            ->55e299db8c78      ! String data
fName                         detParam            object identifier
fName.fRep                    ->55e299db8ad8      ! String data
fTitle                        defaultTitle        object title
fTitle.fRep                   ->55e299db8af0      ! String data
fUniqueID                     0                   object unique identifier
fBits                         0x03000000          bit field status word
==> Dumping object at: 0x000055e297d52940, name=zS, class=TRestRawZeroSuppresionProcess

*fRawSignalEvent              ->0                 !
*fSignalEvent                 ->55e2a6f56cc0      !
fBaseLineRange                ->55e297d52c18      
fBaseLineRange.fX             20                  components of the vector
fBaseLineRange.fY             150                 
fBaseLineRange.fUniqueID      0                   object unique identifier
fBaseLineRange.fBits          0x03000000          bit field status word
fIntegralRange                ->55e297d52c38      
fIntegralRange.fX             150                 components of the vector
fIntegralRange.fY             450                 
fIntegralRange.fUniqueID      0                   object unique identifier
fIntegralRange.fBits          0x03000000          bit field status word
fPointThreshold               3.5                 
fSignalThreshold              3.5                 
fNPointsOverThreshold         7                   
fNPointsFlatThreshold         512                 
fBaseLineCorrection           true                
fSampling                     0.08                
*fInputEvent                  ->0                 !
*fOutputEvent                 ->0                 !

Ok, just posting, and just it came to my mind the solution. The problem is that TRestDetector is being redefined at the RML again, so it is considering the new definition.

If I comment it out at run.xml I get the good values there.

==> Dumping object at: 0x00005563111a6970, name=detParam, class=TRestDetector

fDetectorName                 TREXDM_0            
fDriftVoltage                 160                 
fDriftField                   -1                  
fDriftDistance                -1                  
fAmplificationVoltage         250                 
fAmplificationDistance        -1                  
fAmplificationGain            -1                  
fMass                         -1                  
fHeight                       -1                  
fRadius                       -1                  
fLength                       -1                  
fWidth                        -1                  
fPressure                     6                   
fElectronicsShapingTime       -1                  
fElectronicsSamplingTime      0.04                
fElectronicsDynamicRange      -1                  
fElectronicsThreshold         -1                  
fElectronicsGain              0x0                 
fElectronicsClock             0x4                 
fElectronicsShaping           0xF                 

I created the following PR in connection with this post

This is to allow retrieving other data member metadata classes at RML processes parameter definition.